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查找一个内存地址对应什么函数
基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 这个宏可以转换成函数吗? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
