Adding to what John answered, you basically need a function like this to print backtrace. This function will be called on SIGSEGV. But I'm the second, I think that letting the system generate a corefile would be a much better debugging mechanism for you.
void print_trace(int nSig) { printf("print_trace: got signal %d\n", nSig); void *array[32]; size_t size; char **strings; size_t nCnt; size = backtrace(array, 32); strings = backtrace_symbols(array, size); for (nCnt = 0; nCnt < size; nCnt++) fprintf(stderr, "%s\n", strings[nCnt]); exit(-1); }
source share