Search code examples
c++linuxg++backtrace

Printing full backtrace in c++


I want to dump a backtrace from a C++ program in Linux in a similar format as it is done in gdb. I tried to use the backtrace() and backtrace_symbols() functions for this purpose. These returned function names and offsets. I can use the __cxa_demangle() function to get a readable function name.

Is there any way to get the file/line positions too, as it is done by gdb?


Solution

  • How it's better to invoke gdb from program to print its stacktrace?`

    Methode #4, shows a way to get filename and line. But uses a extern program..