How to use GDB to find what function a memory address corresponds to

前端 未结 3 1927
情话喂你
情话喂你 2021-01-30 22:56

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:                          


        
3条回答
  •  走了就别回头了
    2021-01-30 23:14

    Use info symbol gdb command. 16 Examining the Symbol Table.

    info symbol addr
    

    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
    

    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
    

提交回复
热议问题