This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: why no stacktrace?


On Tue, Jan 04, 2000 at 04:18:26PM +0100, Ulrich Lauther wrote:
> > % cat tbt.c
> > #include <stdlib.h>
> > #include <signal.h>
> > #include <execinfo.h>
> > 
> > void crash()
> > {
> >         void *bt[10];
> >         int n,c;
> >         n = backtrace(bt,10);
> >         for (c=0; c<n; c++)
> >                 printf("%#x\n",bt[c]);
> >         abort();  // generate core dump anyways
> > }
> > 
> > main()
> > {
> >         signal(SIGSEGV, crash);
> >         *((int *)0) = 0;
> > }
> > % cc -g tbt.c
> > % ./a.out  > X
> > zsh: abort (core dumped)  ./a.out > X
> > % addr2line < X
> 
> Better than printing to stdout (as in your example) would be to pipe
> directly into addr2line within the crash procedure. Thus you don't need to start
> the executable again.

You don't know if you have an executable with crash dump info around,
and it can be tricky to find the exact path of the location (you need argv[0]
and the PATH environment variable and a search function). Better do it this
way.

But coredumps are generally a better idea for user space.

-Andi

-- 
This is like TV. I don't like TV.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]