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.
The usual way to examine data in your program is with the print command (abbreviated p ), or its synonym inspect . It evaluates and prints the value of an expression of the language your program is written in (see section Using GDB with Different Languages).
The ptype [ARG] command will print the type. Show activity on this post.
To execute one line of code, type "step" or "s". If the line to be executed is a function call, gdb will step into that function and start executing its code one line at a time. If you want to execute the entire function with one keypress, type "next" or "n".
Use the set variable (gdb) and the assign (dbx) commands to change the value associated with a variable, memory address, or expression that is accessible according to the scope and visibility rules of the language. The expression can be any expression that is valid in the current context.
Use x
rather than p
:
x /s 0x82c6e10
Try:
print (char *)pointer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With