This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: why no stacktrace?
- To: Andi Kleen <ak at muc dot de>
- Subject: Re: why no stacktrace?
- From: Ulrich Lauther <ulrich dot lauther at mchp dot siemens dot de>
- Date: Tue, 4 Jan 2000 16:18:19 +0100 (MET)
- CC: gcc at gcc dot gnu dot org
- Reply-To: Ulrich dot Lauther at mchp dot siemens dot de
>
> If you're using glibc 2.1 (e.g. in newer Linux distributions) you can use
> its builtin backtrace() function. GNU binutils' addr2line converts it
> to symbol addresses.
>
I didn't know about backtrace(); thanks a lot.
> % 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.
-ulrich
----------------------------------------------------------------------------
Ulrich Lauther ph: +49 89 636 48834 fx: ... 636 42284
Siemens ZT SE 4 Internet: Ulrich.Lauther@mchp.siemens.de