Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly GDB Print String

So in assembly I declare the following String:

Sample db "This is a sample string",0

In GDB I type "p Sample" (without quotes) and it spits out 0x73696854. I want the actual String to print out. So I tried "printf "%s", Sample" (again, without quotes) and it spits out "Cannot access memory at address 0x73696854."

Short version: How do I print a string in GDB?

like image 807
Ken Avatar asked May 12 '10 17:05

Ken


2 Answers

My teacher just emailed me back. For anyone wondering:

p(char[20]) Sample

Where 20 is the number of characters to print out.

To print a C-style NUL-terminated string, you should also be able to do this:

print (char*) &Sample
printf "%s", &Sample
like image 93
Ken Avatar answered Oct 29 '22 17:10

Ken


I had the same issue! Try this one:

x/s &Sample # prints the whole string

"x" - Stands generally for examining data.

For a signle character you could youse this code

x/c &Sample # prints: "T"

And if you want see multiple characters you could give the number of wished characters

x/3c &Sample # prints: "T" "h" "i"
like image 20
orustammanapov Avatar answered Oct 29 '22 16:10

orustammanapov