views:

1185

answers:

3

I'm not sure if the following is possible, but can one retrieve the name of a symbol that a memory address points to 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?

Thanks!

+7  A: 

I believe your 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

Brian Gianforcaro
+1  A: 

If it is a stack variable, there is no way that I am aware to do it. Otherwise, try p/a <pointer symbol or address> and it will print the symbol name (or offset to the nearest symbol name).

Volte
+1  A: 

po 0x46767f0

will send a -description message to the object. That will print out the contents of your NSString but I suggest using Brian's answer to check the contets of your address before you send random messages to random addresses.

Roger Nolan