Handling SIGSEGV

Dear all,

In my application, when a crash occur I get a nice stack trace (ROOT magic I guess, I don’t do anything to get this) :

[code]*** Break *** segmentation violation

===========================================================
There was a crash (#8 0x010b7004 in SigHandler () from /local/root/lib/libCore.so.5.26).
This is the entire stack trace of all threads:

Thread 3 (Thread -1209762912 (LWP 2341)):
#0 0x0027a7a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1 0x016149f1 in ___newselect_nocancel () from /lib/tls/libc.so.6
#2 0x001dc1d8 in dim_usleep (usecs=100000) at ./src/dtq.c:285

[/code]

Ideally, I would like to display the date and time before displaying the stack trace. I tried to add a signal handler that prints this information :

[code]void handler_exc(int sig) {
TDatime d;
cout << "Signal " << sig << " received on " << d.AsString() << endl;
exit(1);
}

int main(int argc, char *argv[])
{

signal(SIGSEGV, handler_exc);[/code]

But then I don’t have the stack trace anymore, only the date and time.

Is there a way to do what I want ?

Thanks in advance for your help,
Barth

Hi,

Since the call to signal replace the existing signal handler, you will need to explicitly call in your signal handling function the code you need. For example root does the following for a seg fault:

gSystem->Break("TUnixSystem::DispatchSignals", "%s", UnixSigname(sig)); gSystem->StackTrace(); if (gApplication) gApplication->HandleException(sig); else gSystem->Exit(sig);(inspired from TUnixSystem::DispatchSignals).

Cheers,
Philippe.