[Bug libstdc++/33903] Backtrace info in std::exception
--- Comment #6 from pinskia at gcc dot gnu dot org 2007-12-02 22:27 --- Not really a good request as GCC support for this is hard and non standard. You can do it yourself as shown below. -- pinskia at gcc dot gnu dot org changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution||WONTFIX http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33903
[Bug libstdc++/33903] Backtrace info in std::exception
--- Comment #5 from pluto at agmk dot net 2007-11-05 15:44 --- (In reply to comment #4) This is a possible solution. Not ideal though, because, then all exceptions will be trigger the breakpoint at __cxa_throw. If however, I put a breakpoint in the catch in question, then I know I will get the exception that I was looking for, and if bakctrace info was part of this exception, then I could find out exactly what happened where. gnu/ld has a nice option called --wrap that you can use to hack the g++/throw() and embbed stacktrace in way you like ;-) $ cat u.cpp #include cstdio #include unwind.h #include dlfcn.h _Unwind_Reason_Code helper( struct _Unwind_Context* ctx, void* ) { void* p = reinterpret_cast void* ( _Unwind_GetIP( ctx ) ); Dl_info info; if ( dladdr( p, info ) ) { if ( info.dli_saddr ) { long d = reinterpret_cast long ( p ) - reinterpret_cast long ( info.dli_saddr ); printf( %p %s+0x%lx\n, p, info.dli_sname, d ); } } return _URC_NO_REASON; } extern C void __real___cxa_throw( void* thrown_exception, std::type_info* tinfo, void ( *dest )( void* ) ) __attribute__(( noreturn )); extern C void __wrap___cxa_throw( void* thrown_exception, std::type_info* tinfo, void ( *dest )( void* ) ) { _Unwind_Backtrace( helper, 0 ); __real___cxa_throw( thrown_exception, tinfo, dest ); } void __attribute__(( noinline )) zoo( void ) { try { std::puts( ping! ); throw 1; } catch ( int ) { std::puts( pong! ); } } void __attribute__(( noinline )) bar( void ( *f )( /*void*/ ) ) { f(); } void __attribute__(( noinline )) foo( void ) { bar( zoo ); } int main() { foo(); return 0; } $ g++ u.cpp -ldl -rdynamic -Wl,--wrap,__cxa_throw ./a.out ping! 0x80489c7 __wrap___cxa_throw+0x15 0x8048a16 _Z3zoov+0x3a 0x8048a7d _Z3barPFvvE+0xb 0x8048a93 _Z3foov+0x13 0x8048ab9 main+0x21 0x2e3e23 __libc_start_main+0xd3 pong! -- pluto at agmk dot net changed: What|Removed |Added CC||pluto at agmk dot net http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33903
[Bug libstdc++/33903] Backtrace info in std::exception
--- Comment #3 from pinskia at gcc dot gnu dot org 2007-11-02 06:27 --- (In reply to comment #2) I am using debugger. After the exception is thrown, the program asserts. So I get a backtrace to the system fatal call, having no idea where the exception was thrown. Since GCC follows the IA64 C++ ABI, you can have a breakpoint at __cxa_throw (the function which is called for throwing the exception). -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33903
[Bug libstdc++/33903] Backtrace info in std::exception
--- Comment #2 from djh at emss dot co dot za 2007-11-02 06:08 --- I am using debugger. After the exception is thrown, the program asserts. So I get a backtrace to the system fatal call, having no idea where the exception was thrown. I dont know about you guys but I find the .net/java exceptions with backtraces built in to be a lot more useful. Sure you can place a breakpoint in the constructor of an exception but it has to be done and can be very annoying in complicated debug sessions. Especially since GDB is not the fastest animal around and is being used used on larger and larger projects (which take a _long_ time to load in gdb). -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33903
[Bug libstdc++/33903] Backtrace info in std::exception
--- Comment #4 from djh at emss dot co dot za 2007-11-02 06:54 --- This is a possible solution. Not ideal though, because, then all exceptions will be trigger the breakpoint at __cxa_throw. If however, I put a breakpoint in the catch in question, then I know I will get the exception that I was looking for, and if bakctrace info was part of this exception, then I could find out exactly what happened where. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33903
[Bug libstdc++/33903] Backtrace info in std::exception
-- djh at emss dot co dot za changed: What|Removed |Added Severity|normal |enhancement http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33903