Find the answer to your Linux question:
Results 1 to 3 of 3
Hello!!! I am using backtrace(...) and backtrace_symbols(...) (defined in <execinfo.h>) in a C++ program for diagnostics purposes. I compile with -g passed to G++ and link with the --rdynamic option, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2005
    Posts
    7

    backtrace_symbols() with no symbols!


    Hello!!!

    I am using backtrace(...) and backtrace_symbols(...) (defined in <execinfo.h>) in a C++ program for diagnostics purposes. I compile with -g passed to G++ and link with the --rdynamic option, but backtrace_symbols(...) just gives me this sort of output:

    ./app [0x804c6c6]
    ./app [0x8049405]
    ./app [0x8049413]
    ./app [0x8049437]
    /lib/tls/libc.so.6(__libc_start_main+0xe3) [0xbdbe33]
    ./app(__gxx_personality_v0+0x61) [0x8048ff1]

    I know g++ is likely to give me mangled symbols, but that is better than nothing! What do I need to do to compile symbol information backtrace_symbols(...) can use into the program?

    Thanks,

    Matt.

  2. #2
    Just Joined!
    Join Date
    Jun 2008
    Posts
    3

    -rdynamic

    I had this problem, and I believe if you add "-rdynamic" during linkage, then backtrace_symbols() will get the function names. From the gcc manual:

    -rdynamic
    Pass the flag -export-dynamic to the ELF linker, on targets that support it. This instructs the linker to add all symbols, not only used ones, to the dynamic symbol table. This option is needed for some uses of "dlopen" or to allow obtaining backtraces from within a program.

  3. #3
    Just Joined!
    Join Date
    Jun 2008
    Posts
    3

    Remove static qualifiers on function declarations

    Also, static functions are anonymized during compilation, so it's necessary to remove or comment out any static qualifiers for their names to be available. From the backtrace_symbols(3) man page:
    The symbol names may be unavailable without the use of special linker
    options. For systems using the GNU linker, it is necessary to use the
    -rdynamic linker option. Note that names of "static" functions are not
    exposed, and won’t be available in the backtrace.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •