GDB Print String Assembly

So, in the assembly, I declare the following line:

Sample db "This is a sample string",0 

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

Short version: How to print a string in GDB?

+4
source share
2 answers

My teacher just sent me a letter. For someone interested:

 p(char[20]) Sample 

Where 20 is the number of characters to print. A.

To print a line with the text C-style NUL -terminated, you can also do this:

 print (char*) &Sample printf "%s", &Sample 
+8
source

I had the same problem! Try the following:

 x/s &Sample # prints the whole string 

"x" - Stands are usually for checking data.

You can use this code for a character symbol.

 x/c &Sample # prints: "T" 

And if you want to see several characters, you can specify the number of characters you want

 x/3c &Sample # prints: "T" "h" "i" 
+5
source

Source: https://habr.com/ru/post/1309579/


All Articles