I am doing some C++ programming on Mac OSX Lion, and want to print out stack trace when crashing or exception. In the following discussion, I tried both MacPort's gcc47 and apple's llvm-gcc42.
I came to use glog because it prints pretty stack trace. It looks fine the prints the following stack trace if I let the program crash by accessing a null pointer:
*** Aborted at 1333289352 (unix time) try "date -d @1333289352" if you are using GNU date ***
PC: @ 0x1091a9137 C::h()
*** SIGSEGV (@0x0) received by PID 29623 (TID 0x7fff722d4960) stack trace: ***
@ 0x7fff8cabdcfa _sigtramp
@ 0x1091a9138 C::h()
@ 0x1091a9112 C::g()
@ 0x1091a90ef C::f()
@ 0x1091a903a main
Segmentation fault: 11
However, if I crashed the program by throwing an exception, the stack trace printed out is not quite useful:
terminate called after throwing an instance of 'std::runtime_error'
what(): Haha
*** Aborted at 1333289406 (unix time) try "date -d @1333289406" if you are using GNU date ***
PC: @ 0x7fff8450f82a __kill
*** SIGABRT (@0x7fff8450f82a) received by PID 52106 (TID 0x7fff722d4960) stack trace: ***
@ 0x7fff8cabdcfa _sigtramp
Abort trap: 6
I tried the samething on a CentOS system and it prints out reasonable stack trace with uncaught exceptions, so it should not be a problem of glog.
So my question is: is there a way to let glog print out the stack trace for uncaught exceptions?