I don't remember whether I posted this before. It's an external that doesn't define any classes, but installs a crash report handler that prints to the terminal. It requires <execinfo.h> which is linux-specific. It decodes C++ symbols using <cxxabi.h> (provided by glibc). This means you don't need to run gdb to get a basic listing of what happens. However you will still need gdb if you need to know what the function arguments were.
If you run an older version of GridFlow (9.11 or earlier) you will need to ensure "segfault" appears after "gridflow" in the Startup menu. If not, the order does not matter (unless you need to trap a crash at load-time).
------------------8<--------cut-here--------8<------------------
// segfault.cxx 1.0 by Mathieu Bouchard, 2010 // compile with : g++ segfault.cxx -shared -o segfault.pd_linux
#include <stdio.h> #include <string.h> #include <unistd.h> #include <execinfo.h> #include <signal.h> #include <cxxabi.h>
static void fault (int sig) { const char *s; if (sig==SIGSEGV) s="Segmentation Fault"; if (sig==SIGABRT) s="Abort"; if (sig==SIGILL) s="Invalid Instruction"; if (sig==SIGBUS) s="Bus Error"; fprintf(stderr,"\n------------------------------ caught %s\n",s); #if defined(MACOSX) || defined(__WIN32__) fprintf(stderr,"unhandled exception\n"); #else void *array[100]; char demangled[1024]; size_t length=1024; int status; int nSize = backtrace(array,100); char **symbols = backtrace_symbols(array, nSize); // for (int i=0; i<nSize; i++) fprintf(stderr,"%d: %s\n",i,symbols[i]); for (int i=1; i<nSize; i++) { char *a = strchr(symbols[i],'('); char *b = strchr(symbols[i],'+'); if (a&&b) { char mangled[1024]; sprintf(mangled,"%.*s",int(b-a-1),a+1); if (abi::__cxa_demangle(mangled,demangled,&length,&status)) fprintf(stderr,"%3d: %.*s\n",i,int(length),demangled); else fprintf(stderr,"%3d: %s\n",i,symbols[i]); } else fprintf(stderr,"%3d: %s\n",i,symbols[i]); } #endif fprintf(stderr,"-------- crash report displayed by segfault.pd_linux 1.0 (by matju)\n\n"); signal(sig,SIG_DFL); _exit(128+sig); }
extern "C" void segfault_setup (void) { signal(SIGSEGV,fault); signal(SIGABRT,fault); signal(SIGILL, fault); signal(SIGBUS, fault); }
| Mathieu Bouchard ------------------------------ Villeray, Montréal, QC
Sounds very cool, any plan to distribute as a binary, or at least a
tarball with a build system?
.hc
On Nov 2, 2010, at 8:44 PM, Mathieu Bouchard wrote:
I don't remember whether I posted this before. It's an external that
doesn't define any classes, but installs a crash report handler that
prints to the terminal. It requires <execinfo.h> which is linux- specific. It decodes C++ symbols using <cxxabi.h> (provided by
glibc). This means you don't need to run gdb to get a basic listing
of what happens. However you will still need gdb if you need to know
what the function arguments were.If you run an older version of GridFlow (9.11 or earlier) you will
need to ensure "segfault" appears after "gridflow" in the Startup
menu. If not, the order does not matter (unless you need to trap a
crash at load-time).------------------8<--------cut-here--------8<------------------
// segfault.cxx 1.0 by Mathieu Bouchard, 2010 // compile with : g++ segfault.cxx -shared -o segfault.pd_linux
#include <stdio.h> #include <string.h> #include <unistd.h> #include <execinfo.h> #include <signal.h> #include <cxxabi.h>
static void fault (int sig) { const char *s; if (sig==SIGSEGV) s="Segmentation Fault"; if (sig==SIGABRT) s="Abort"; if (sig==SIGILL) s="Invalid Instruction"; if (sig==SIGBUS) s="Bus Error"; fprintf(stderr,"\n------------------------------ caught %s\n",s); #if defined(MACOSX) || defined(__WIN32__) fprintf(stderr,"unhandled exception\n"); #else void *array[100]; char demangled[1024]; size_t length=1024; int
status; int nSize = backtrace(array,100); char **symbols = backtrace_symbols(array, nSize); // for (int i=0; i<nSize; i++) fprintf(stderr,"%d: %s \n",i,symbols[i]); for (int i=1; i<nSize; i++) { char *a = strchr(symbols[i],'('); char *b = strchr(symbols[i],'+'); if (a&&b) { char mangled[1024]; sprintf(mangled,"%.*s",int(b- a-1),a+1); if
(abi::__cxa_demangle(mangled,demangled,&length,&status)) fprintf(stderr,"%3d: %.*s \n",i,int(length),demangled); else fprintf(stderr,"%3d: %s\n",i,symbols[i]); } else fprintf(stderr,"%3d: %s\n",i,symbols[i]); } #endif fprintf(stderr,"-------- crash report displayed by
segfault.pd_linux 1.0 (by matju)\n\n"); signal(sig,SIG_DFL); _exit(128+sig); }extern "C" void segfault_setup (void) { signal(SIGSEGV,fault); signal(SIGABRT,fault); signal(SIGILL, fault); signal(SIGBUS, fault); }
| Mathieu Bouchard ------------------------------ Villeray,
Montréal, QC_______________________________________________ Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
Terrorism is not an enemy. It cannot be defeated. It's a tactic.
It's about as sensible to say we declare war on night attacks and
expect we're going to win that war. We're not going to win the war on
terrorism. - retired U.S. Army general, William Odom
On Sun, 7 Nov 2010, Hans-Christoph Steiner wrote:
Sounds very cool, any plan to distribute as a binary, or at least a tarball with a build system?
If you don't bundle it on your own as part of pd-extended's builds, I might bundle it on my own as part of GridFlow's builds.
Perhaps it could be renamed to "crashreport" or somesuch ; I haven't really thought about it yet.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
On Mon, 2010-11-08 at 15:48 -0500, Mathieu Bouchard wrote:
On Sun, 7 Nov 2010, Hans-Christoph Steiner wrote:
Sounds very cool, any plan to distribute as a binary, or at least a tarball with a build system?
If you don't bundle it on your own as part of pd-extended's builds, I might bundle it on my own as part of GridFlow's builds.
Perhaps it could be renamed to "crashreport" or somesuch ; I haven't really thought about it yet.
These days I'm trying to reduce maintanence duties, so I'm not adding anything to Pd-extended. I suggest releasing it as its own lib, even tho its small. It would be annoying to have to download and figure out all of gridflow in order to get this little useful util.
.hc
On Mon, 8 Nov 2010, Hans-Christoph Steiner wrote:
These days I'm trying to reduce maintanence duties, so I'm not adding anything to Pd-extended. I suggest releasing it as its own lib, even tho its small. It would be annoying to have to download and figure out all of gridflow in order to get this little useful util.
But you don't have to figure out all of gridflow in order to get this little useful util. Plus, if someone takes the 3 minutes it takes to install gridflow binaries nowadays, after that they can't really complain that they would have to install gridflow in order to have access to any external or abstraction that one can find in gridflow.
That's because, you see, I'm trying to reduce maintenance duties as well.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC