This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


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

backtrace_symbols function buggy?


Hi,

The /usr/include/execinfo.h header defines some functions for
obtaining a stack trace within a running program.

Unfortunately, the output these functions are producing is not very
useful --- the function names are not correct (see attached details).
Is this a bug or a known limitation?  It would be very useful (to me
at least) if it gave accurate function names.

This is an i686 Linux system with Debian libc6-2.2-10 (i.e.,
glibc-2.2).  This problem also occurs on RedHat 7 with glibc-2.2
updates.

Ralph.

Below, I'd expect to see the functions print_bt, foo2 and main in the
printed backtrace; instead, backtrace_symbols is printed three times.

---------------shell transcript------------------

~] gcc -o temp -Wall temp.c
~] ./temp
./temp(backtrace_symbols+0x110) [0x80484a4]
./temp(backtrace_symbols+0x187) [0x804851b]
./temp(backtrace_symbols+0x19f) [0x8048533]
/lib/i686/libc.so.6(__libc_start_main+0xd0) [0x4003da54]
~] cat temp.c
#include <execinfo.h>
#include <stdio.h>

void print_bt()
{
   void * stack[10];
   int items = backtrace (stack, 10);

   char ** strings = backtrace_symbols (stack, items);

   int i;
   for (i = 0; i < items; ++i)
      printf ("%s\n", strings[i]);
}

void foo1()
{
}

void foo2()
{
   print_bt();
}

void foo3()
{
}

int main (int argc, char ** argv)
{
   foo2();
   return 0;
}

~] 
----------------------------------------------------

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