Re: [ES40-developers] [patch] display backtrace on segfault
Status: Alpha
Brought to you by:
iamcamiel
From: Camiel V. <iam...@gm...> - 2008-02-07 20:34:28
|
This has been committed to the CVS repository. I hope you get a segfault real soon! ;-) Camiel. On Feb 7, 2008 3:48 PM, Brian Wheeler <bdw...@in...> wrote: > Sometimes I get a segfault when I'm running es40. I've added code > (specific to g++) which will dump a backtrace and exit. Of course, > since I've added that code I've not seen a segfault, but I'm hopeful :) > > Brian > > =================================================================== > RCS file: /cvsroot/es40/es40/src/Makefile,v > retrieving revision 1.20 > diff -u -r1.20 Makefile > --- Makefile 2 Feb 2008 16:43:01 -0000 1.20 > +++ Makefile 7 Feb 2008 14:47:48 -0000 > @@ -102,7 +102,7 @@ > # -O3 -- optimize at level 3 > # -mtune=<cpu> -- cpu is one of: generic, core2, athlon64, > pentium4, etc > # > -CTUNINGFLAGS = -O3 -mtune=generic > +CTUNINGFLAGS = -O3 -mtune=generic > > # > # CDEBUGFLAGS - turn on debugging in ES40 > @@ -124,8 +124,9 @@ > # -DDEBUG_KBD Turn on keyboard debugging > # -DDEBUG_PIC Turn on Programmable Interrupt > Controller debugging > # -DDEBUG_LPT Turn on debugging for LPT Port > +# -DDEBUG_BACKTRACE Turn on backtrace dump on SIGSEGV > # > -CDEBUGFLAGS = -g -DHIDE_COUNTER > +CDEBUGFLAGS = -g -DHIDE_COUNTER -DDEBUG_BACKTRACE > > # > # ES40 Options > @@ -247,4 +248,3 @@ > $(DEPEND) -o.do -a -- $(IDB_CFLAGS) -- $(SRCS) > clean: > rm -f es40 es40_idb es40_lss es40_lsm *.o *.do *.mao *.slo *.trc > gui/*.o gui/*.mao gui/*.slo gui/*.do > - > Index: AlphaSim.cpp > =================================================================== > RCS file: /cvsroot/es40/es40/src/AlphaSim.cpp,v > retrieving revision 1.39 > diff -u -r1.39 AlphaSim.cpp > --- AlphaSim.cpp 5 Feb 2008 10:15:57 -0000 1.39 > +++ AlphaSim.cpp 7 Feb 2008 14:47:48 -0000 > @@ -180,6 +180,46 @@ > 0 > }; > > + > +#ifdef DEBUG_BACKTRACE > +#ifdef __GNUG__ > +#include <execinfo.h> > +#include <signal.h> > +#define HAS_BACKTRACE > + > +#define BTCOUNT 100 > +void *btbuffer[BTCOUNT]; > + > +void segv_handler(int signum) { > + int nptrs = backtrace(btbuffer, BTCOUNT); > + char **strings; > + > + printf("%%SYS-F-SEGFAULT: The Alpha Simulator has Segfaulted.\n"); > + printf("-SYS-F-SEGFAULT: Backtrace follows.\n"); > + > + printf("backtrace() returned %d addresses.\n",nptrs); > + strings = backtrace_symbols(btbuffer,nptrs); > + if(strings==NULL) { > + perror("backtrace_symbols"); > + exit(1); > + } > + > + for(int i = 0; i < nptrs; i++) { > + printf("%3d %s\n",nptrs-i, strings[i]); > + } > + free(strings); > + exit(1); > +} > + > +#else > +#warning "Your compiler isn't configured to support backtraces." > +#endif // __GNUG__ > +#endif > + > + > + > + > + > /** > * Entry point for the application. > * > @@ -214,6 +254,12 @@ > char *filename = 0; > FILE *f; > > +#ifdef HAS_BACKTRACE > +#ifdef __GNUG__ > + signal(SIGSEGV, &segv_handler); > +#endif > +#endif > + > try > { > #if defined(IDB) && (defined(LS_MASTER) || defined(LS_SLAVE)) > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Es40-developers mailing list > Es4...@li... > https://lists.sourceforge.net/lists/listinfo/es40-developers > |