glibc backtrace_symbols()
Badari Pulavarty
pbadari@us.ibm.com
Mon Mar 11 09:28:00 GMT 2002
Hi,
I am trying to use glibc backtrace_symbols() to get the call trace.
It is not working as expected. How to get it working ?
Here is the test pgm:
---------------------
#include <execinfo.h>
#include <stdlib.h>
#include <stdio.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;
}
Here is the output it prints:
-----------------------------
Obtained 5 stack frames.
/tmp/xx3(backtrace_symbols+0x124) [0x8048534]
/tmp/xx3(backtrace_symbols+0x1a7) [0x80485b7]
/tmp/xx3(backtrace_symbols+0x1b7) [0x80485c7]
/lib/i686/libc.so.6(__libc_start_main+0x93) [0x20042507]
/tmp/xx3(backtrace_symbols+0x31) [0x8048441]
I was expecting something like:
-------------------------------
print_trace+
dummy_function +
main +
...
I am not gettig the function names. How can I get function names ?
I compiled with "-g". I am running RedHat 7.2.
# gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98)
Could you please "cc" me on the reply ?
Thanks
Badari
More information about the Gcc
mailing list