18

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.

0

4 Answers 4

21

Use x rather than p:

x /s 0x82c6e10
Sign up to request clarification or add additional context in comments.

Comments

19

Try:

print (char *)pointer

Comments

18

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.

Comments

3

print (char*)0x82c6e10

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.