Exception Traceback / Frame Unwind 2
Bud Davis
bdavis@f77.linksysnet.com
Thu Mar 4 15:49:00 GMT 2004
try:
info libc
and look under "debugging"
--bud
Here is the example from the info page:
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
/* Obtain a backtrace and print it to `stdout'. */
void
print_trace (void)
{
void *array[10];
size_t size;
char **strings;
size_t i;
size = backtrace (array, 10);
strings = backtrace_symbols (array, size);
printf ("Obtained %zd stack frames.\n", size);
for (i = 0; i < size; i++)
printf ("%s\n", strings[i]);
free (strings);
}
/* A dummy function to make the backtrace more interesting. */
void
dummy_function (void)
{
print_trace ();
}
int
main (void)
{
dummy_function ();
return 0;
}
On Thu, Mar 04, 2004 at 01:41:05PM +0000, Ben Clewett wrote:
> Bud,
>
> This looks exactly what I am looking for. Thanks for the reply.
>
> Would you happen to know the name of the lib or include file so that I
> can google some information on this?
>
> Regards, Ben.
>
>
> Bud Davis wrote:
>
> >If you are using glibc, they have a mechanism for retreiving the
> >call stack and printing out the information. Here is a portion
> >of the info page:
> >
> >Backtraces
> >==========
> >
> > A "backtrace" is a list of the function calls that are currently
> >active in a thread. The usual way to inspect a backtrace of a program
> >is to use an external debugger such as gdb. However, sometimes it is
> >useful to obtain a backtrace programmatically from within a program,
> >e.g., for the purposes of logging or diagnostics.
> >
> >
> >Is this what you are looking for ?
> >
> >
> >regards,
> >bud davis
>
>
More information about the Gcc-help
mailing list