
On Wednesday, May 3, 2006 at 09:03:03 (-0700) Robert Ramey writes:
Heres what I do.
I run the debugger.
I set a trap anywhere. or I can wait until it traps on its own.
I did want to share something I kvetched about: the pain in the neck when C++ exceptions are thrown and you get no call stack of how that exception came to be thrown (e.g., "stream error"). I discovered what seems to be a fairly easy solution under gdb. Compile this test code with -g: #include <iostream> #include <stdexcept> using namespace std; void a() { throw runtime_error("bad dog"); } void b() { a(); } void c() { b(); } void d() { c(); } int main(int ac, char* av[]) { try { d(); } catch (const exception& e) { cerr << "error: " << e.what() << '\n'; } } In gdb 6.4, you can simply say "catch throw". In the 6.3 version (perhaps earlier), you can set the "catch throw" after shared libraries have been loaded: % gdb ./a.out (gdb) set stop-on-solib-events 1 (gdb) run Starting program: /home/blear/a.out Stopped due to shared library event (gdb) catch throw Catchpoint 1 (throw) (gdb) c Continuing. Stopped due to shared library event (gdb) c Continuing. Stopped due to shared library event (gdb) c Continuing. Catchpoint 1 (exception thrown) 0x00aeaf11 in __cxa_throw () from /usr/lib/libstdc++.so.6 (gdb) where #0 0x00aeaf11 in __cxa_throw () from /usr/lib/libstdc++.so.6 #1 0x08048c04 in a () at t.cc:6 #2 0x08048c0f in b () at t.cc:7 #3 0x08048c1d in c () at t.cc:8 #4 0x08048c2b in d () at t.cc:9 #5 0x08048c50 in main (ac=1, av=0xbff68dd4) at t.cc:13 (gdb) Hope this helps others. Bill