How to print the string a pointer points to while debugging using GDB?
How do开发者_高级运维 I inspect a string a pointer is pointing to when stepping through a program using GDB?
I can see the a pointer is pointing to 0x82c6e10
. I know it is a string. How do I print it?
Using printf("%s\n", 0x82c6e10)
gives Bad format string, missing '"'.
The fact that gdb does not complain of unknown command tells me that the solution is some variation of what I am doing. Am I right? I tried escaping the quotes but that did not help.
Use x
rather than p
:
x /s 0x82c6e10
Try:
print (char *)pointer
Here printf
is not a function, but a gdb
command. Omit the parentheses.
Better yet, just use the print
command, or the x
command with format /s
(You can actually call the C function printf()
with the call
command.)`
gdb
has voluminous help available with the help
command. Try it.
print (char*)0x82c6e10
精彩评论