Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 817
petersohn Avatar asked Nov 02 '11 10:11

petersohn


1 Answers

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

like image 114
KoKuToru Avatar answered Sep 30 '22 20:09

KoKuToru