在gdb调试器中标识符号的源文件名 [英] Identify source file name for a symbol in gdb debugger
问题描述
我正在Ubuntu 18.04上的 gdb
中调试基于多个C ++共享库的应用程序,而
想查找源代码(或至少找到它的名称)共享库或C ++名称空间)称为 TRUE
的符号。
I am debugging an application based on multiple C++ shared libraries in gdb
on Ubuntu 18.04 and
want to find the source code (or at least the name of the shared library or C++ namespace) of a symbol called TRUE
.
所有代码均已使用 -g3 -O0 -Wall
。
编辑: 仅可用于共享库的调试符号,并且使用 -g3 -O0 -Wall
编译应用程序代码。
I have "only" the debug symbols available for shared libraries and the application code is compiled with -g3 -O0 -Wall
.
这是我对 gdb
中的符号的了解:
Here is what I know about the symbol in gdb
:
(gdb) ptype TRUE
type = enum {FALSE, TRUE}
(gdb) whatis TRUE
type = enum {...}
(gdb) info line TRUE
(gdb)
我如何找出谁定义了枚举
我的 TRUE
符号`?
How can I find out who defined the enum
of my TRUE
symbol`?
有类似的问题,但答案没有提供预期的输出(但为空,请参见上面的日志): https://stackoverflow.com/a/20771062
There is a similar question but the answer does not give the expected output (but empty, see log above): https://stackoverflow.com/a/20771062
编辑:我又走了一步(但对于这样一种常见的文件名,仍然缺少完整路径):
I am one step further (but still the full path is missing for such a common kind of file name):
(gdb) python print(gdb.lookup_symbol("TRUE")[0].symtab)
api.cpp
推荐答案
我终于找到了! Python是解决方案,与纯本地的 gdb
命令相比,Python中的 gdb
对象确实提供了更详细的信息:
I have found it finally! Python is the solution, the gdb
object within Python does offer more detailed information than the pure native gdb
commands:
(gdb) python print(gdb.lookup_symbol("TRUE")[0].symtab.fullname())
/media/devmount/dev/R/Rcpp/src/api.cpp
有关详细信息,请参阅文档: https:/ /sourceware.org/gdb/download/onlinedocs/gdb/Symbol-Tables-In-Python.html#Symbol-Tables-In-Python
For details see the documentation: https://sourceware.org/gdb/download/onlinedocs/gdb/Symbol-Tables-In-Python.html#Symbol-Tables-In-Python
编辑:我已经找到了 gdb
命令,但是对于我来说似乎不起作用:
I have found gdb
command for that but it seems not to work in my case:
(gdb) set print symbol-filename on
(gdb) show print symbol-filename
Printing of source filename and line number with <symbol> is on.
(gdb) ptype TRUE
type = enum {FALSE, TRUE}
这篇关于在gdb调试器中标识符号的源文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!