If you are on systems with BSD backtrace functionality available (Linux, OSX 1.5, BSD, of course), you can do this programmatically in your signal handler.
For example ( backtrace code obtained from IBM example ):
#include <execinfo.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> void sig_handler(int sig) { void * array[25]; int nSize = backtrace(array, 25); char ** symbols = backtrace_symbols(array, nSize); for (int i = 0; i < nSize; i++) { puts(symbols[i]);; } free(symbols); signal(sig, &sig_handler); } void h() { kill(0, SIGSEGV); } void g() { h(); } void f() { g(); } int main(int argc, char ** argv) { signal(SIGSEGV, &sig_handler); f(); }
Output:
0 a.out 0x00001f2d sig_handler + 35 1 libSystem.B.dylib 0x95f8f09b _sigtramp + 43 2 ??? 0xffffffff 0x0 + 4294967295 3 a.out 0x00001fb1 h + 26 4 a.out 0x00001fbe g + 11 5 a.out 0x00001fcb f + 11 6 a.out 0x00001ff5 main + 40 7 a.out 0x00001ede start + 54
This does not give bonus points for additional functions (except that a graphical interface is not required), but it has the advantage that it is very simple and does not require any additional libraries or programs.
Derek park
source share