Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the symbol name for a memory address in GDB?

For instance, I know that 0x46767f0 belongs to an NSString*, is there any way I can find out what NSString it is to help me find some bugs I'm after?

like image 876
Coocoo4Cocoa Avatar asked Apr 18 '09 00:04

Coocoo4Cocoa


People also ask

How do I find the address of a function in gdb?

Use info symbol gdb command. 16 Examining the Symbol Table. 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.

What is symbol in gdb?

The symbol table contains debugging information that tells a debugger what memory locations correspond to which symbols (like function names and variable names) in the original source code file. The symbol table is usually stored inside the executable, yes.

How do I add debug symbols in gdb?

To add additional symbols you might use add-symbol-file . The add-symbol-file command reads additional symbol table information from the file filename. You would use this command when filename has been dynamically loaded (by some other means) into the program that is running.

What is SP in gdb?

concept: the stack pointer There's an x86 register called ESP called the “stack pointer”. Basically it's the address of the start of the stack for the current function. In gdb you can access it with $sp . When you call a new function or return from a function, the value of the stack pointer changes.


1 Answers

I believe you're looking for:

info symbol <addresss> 

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.

Example:

(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 

You can read more about it here.

like image 67
Brian Gianforcaro Avatar answered Sep 19 '22 11:09

Brian Gianforcaro