Log the stack trace to file?
Benjamin Kosnik
bkoz@redhat.com
Mon Oct 30 10:49:00 GMT 2006
> I would like to be able to log the stack to a file when my program encounters
> errors and exceptions, is there a utility to do this?
This is kind of a vaguely-worded question, but I'll try to help.
For exceptions, there are some possibilities. Since "errors" is pretty
vague, I'm assuming you could either figure this out yourself as part
of error-checking for whatever you are doing, or re-use whatever you
use for exceptions. (Or define "errors" to throw exceptions.)
One thing you could use is gdb, if you use "catch catch" and "catch
throw." If you run an executable after setting this, then gdb will
break after throwing/catching an exception. Stack traces are possible
in gdb. Dunno if you consider gdb a utility.
Have you looked at the verbose terminate handler? This comes into play
with uncaught exceptions, so if this is the only thing you care about,
this might be a good place to work. It's also easier to modify this
without messing with the underlying C++ run-time.
http://gcc.gnu.org/onlinedocs/libstdc++/18_support/howto.html#4
This doesn't give a stack trace, but is probably a useful starting
point for a terminate handler that does.
If you just want stack data for all thrown exceptions, even if they are
caught, you could augment __cxa_throw to log this
information.
best,
-benjamin
More information about the Libstdc++
mailing list