How to use GDB to find what function a memory address corresponds to(如何使用GDB查找一个内存地址对应什么函数)
问题描述
我正在使用 google 的堆检查器来追踪内存泄漏.它给了我一个堆栈跟踪,例如:
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?
推荐答案
使用info symbol
gdb 命令.16 检查符号表.
Use info symbol
gdb command. 16 Examining the Symbol Table.
info symbol addr
打印存储在地址 addr 中的符号名称.如果没有符号完全存储在 addr 中,gdb 会打印最近的符号及其偏移量:
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:
(gdb) info symbol 0x54320
_initialize_vx + 396 in section .text
这与 info address 命令相反.您可以使用它来找出给定地址的变量或函数的名称.
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 symbol 0x400225
_start + 5 in section .text of /tmp/a.out
(gdb) info symbol 0x2aaaac2811cf
__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
这篇关于如何使用GDB查找一个内存地址对应什么函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用GDB查找一个内存地址对应什么函数


基础教程推荐
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09