Linux上backtrace()的替代方法,可以找到静态函数的符号 [英] Alternative to backtrace() on Linux that can find symbols for static functions
问题描述
在手册页中,Linux上的backtrace()
函数显示:
In the man page, the backtrace()
function on Linux says:
请注意,静态"功能的名称 没有暴露,并且在回溯中将不可用.
Note that names of "static" functions are not exposed, and won't be available in the backtrace.
但是,在启用调试符号(-g
)的情况下,像addr2line
和gdb
这样的程序仍可以获取静态函数的名称.有没有办法从流程本身内部以编程方式获取静态函数的名称?
However, with debugging symbols enabled (-g
), programs like addr2line
and gdb
can still get the names of static functions. Is there a way to get the names of static functions programmatically from within the process itself?
推荐答案
如果您的可执行文件(和链接的库)是用调试信息编译的(例如,使用-g
标记为gcc
或g++
),则可以使用Ian Taylor的libbacktrace
(在此处宣布)-参见其代码此处
If your executable (and linked libraries) are compiled with debugging information (i.e. with -g
flag to gcc
or g++
) then you could use Ian Taylor's libbacktrace
(announced here) from inside GCC - see its code here
该库(BSD许可的免费软件)正在使用 DWARF 调试可执行文件和共享库中的信息通过过程链接.参见其自述文件文件.
That library (BSD licensed free software) is using DWARF debug information from executables and shared libraries linked by the process. See its README file.
请注意,如果您使用优化进行编译,则可以内联某些函数(即使没有在源代码中显式标记inline
,并且static
内联函数也可能没有任何适当的自己的代码).然后回溯不会告诉他们太多信息.
Beware that if you compile with optimizations, some functions could be inlined (even without being explicitly tagged inline
in the source code, and static
inlined functions might not have any proper own code). Then backtracing won't tell much about them.
这篇关于Linux上backtrace()的替代方法,可以找到静态函数的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!