如何使用GDB查找某个内存地址对应什么函数
我正在使用谷歌的堆检查器来追踪内存泄漏。它为我提供了堆栈跟踪,例如:
Leak of 21 bytes in 1 objects allocated from:
@ 0xf6088241
@ 0xf60890d2
@ 0xf6089246
@ 0x8054781
@ 0x8054862
@ 0xf684ee76
@ 0xf684f343
@ 0x804be4c
@ 0x80544f6
@ 0xf5e52bb6
@ 0x804b101
如何确定这些内存地址对应的函数/代码行?
I am using google's heap checker to track down a memory leak. It gives me a stack trace such as:
Leak of 21 bytes in 1 objects allocated from:
@ 0xf6088241
@ 0xf60890d2
@ 0xf6089246
@ 0x8054781
@ 0x8054862
@ 0xf684ee76
@ 0xf684f343
@ 0x804be4c
@ 0x80544f6
@ 0xf5e52bb6
@ 0x804b101
How do I determine what functions/lines of code these memory addresses correspond to?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
信息符号
gdb 命令。 16 检查符号表。打印存储在地址 addr 处的符号名称。如果没有符号准确地存储在 addr 处,gdb 将打印最近的符号以及距该符号的偏移量:
这与 info address 命令相反。您可以使用它来查找给定地址的变量或函数的名称。
对于动态链接的可执行文件,还会打印包含该符号的可执行文件或共享库的名称:
Use
info symbol
gdb command. 16 Examining the Symbol Table.Print the name of a symbol which is stored at the address addr. If no symbol is stored exactly at addr, gdb prints the nearest symbol and an offset from it:
This is the opposite of the info address command. You can use it to find out the name of a variable or a function given its address.
For dynamically linked executables, the name of executable or shared library containing the symbol is also printed:
最初的问题询问如何在 GDB 中执行此操作:
*
对于info line
是必需的,不应该用于info symbol
。您还可以使用带有
/m
标志的disassemble
命令:...尽管它相当冗长,并且
info line
准确地给出了所请求的内容。The original question asked how to do this in GDB:
The
*
is necessary forinfo line
and shouldn't be used forinfo symbol
.You can also use the
disassemble
command with its/m
flag:... though it's rather verbose and
info line
gives exactly what was requested.假设您的二进制文件具有调试信息
g++ -g
您可以使用x/
来获取信息,我知道这适用于 vtable。x/xw
打印内存的
十六进制字,gdb 将使用有关该地址的信息来注释左侧。Assuming your binary has debug information
g++ -g
you may be able to usex/
to get the info, I know that works for vtables.x/<num>xw
to print<num>
hex words of memory, and gdb will annotate the left side with information about what's at the address.