Linux 在 C++ 中打印完整的回溯

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7979043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:58:03  来源:igfitidea点击:

Printing full backtrace in c++

c++linuxg++backtrace

提问by petersohn

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.

我想以与在 gdb 中完成的格式类似的格式从 Linux 中的 C++ 程序转储回溯。为此,我尝试使用 backtrace() 和 backtrace_symbols() 函数。这些返回的函数名称和偏移量。我可以使用 __cxa_demangle() 函数来获取可读的函数名称。

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

有没有办法获取文件/行位置,因为它是由 gdb 完成的?

采纳答案by KoKuToru

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

如何更好地从程序调用 gdb 来打印其堆栈跟踪?`

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

Methode #4,显示了一种获取文件名和行的方法。但是使用外部程序..