RE: [GD-Linux] signals and exceptions
Brought to you by:
vexxed72
From: Mads B. D. <ma...@ch...> - 2001-11-15 09:20:44
|
On Thu, 15 Nov 2001, Daniel Vogel wrote: > > Shouldn't you be able to do this from a signal handler as well? I do that, > > although very simplistic. It adds a few extra stackframes, but those can > > be ignored. > > We already have all this "nice" code doing this and printing out extended > backtraces (together with extra information we put on the stack) that relies > on unwinding the stack and I thought I could easily get that to work on > Linux without our current setjmp/ longjmp approach. > > Mind sharing your code? I guess I'm just a bit too confused now to see > obvious solutions :) I do not mind, but I warn you, it is extremely simplistic: #ifdef HAVE_EXECINFO_H #include <execinfo.h> #endif #include <iostream> /* Dump a backtrace to cerr */ void BackTrace() { #ifdef HAVE_EXECINFO_H cerr << "Dumping stacktrace" << endl; void *aTrace[32]; char **tString; int size, i; size = backtrace(aTrace, 32); tString = backtrace_symbols(aTrace, size); for (i = 0; i < size; i++) { cerr << "In " << tString[i] << endl;; } #else cerr << "No stacktrace available" << endl; #endif } I told you it was simple :-) My signal handler is then setup to call this function for certain signals. The first couple of lines will be references to the signal handler, but below that, is the usual stackframes. I may have misunderstood your needs, and this may be entirely unusable for you. It does help me though. Mads P.S. The HAVE_EXECINFO_H is define by autoconf for me - should be present on any system that uses glibc. -- Mads Bondo Dydensborg. ma...@ch... UNIX always presumes you know what you're doing. You're the human being, after all, and it is a mere operating system. |