Printing full backtrace in c++

petersohn picture petersohn · Nov 2, 2011 · Viewed 19.8k times · Source

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?

Answer

KoKuToru picture KoKuToru · Nov 2, 2011

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..