string 装配 GDB 打印字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2821033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 00:44:59  来源:igfitidea点击:

Assembly GDB Print String

stringassemblygdbprinting

提问by Ken

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."

在 GDB 中,我输入“p Sample”(不带引号),它会输出 0x73696854。我想要打印出实际的字符串。所以我尝试了“printf“%s”,Sample”(同样,没有引号),它吐出“无法访问地址0x73696854的内存”。

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

简短版本:如何在 GDB 中打印字符串?

回答by Ken

My teacher just emailed me back. For anyone wondering:

我的老师刚刚给我回了电子邮件。对于任何想知道的人:

p(char[20]) Sample

Where 20 is the number of characters to print out.

其中 20 是要打印的字符数。

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

要打印 C 样式NUL终止的字符串,您还应该能够执行以下操作:

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

回答by orustam

I had the same issue! Try this one:

我遇到过同样的问题!试试这个:

x/s &Sample # prints the whole string

"x" - Stands generally for examining data.

“x” - 通常代表检查数据。

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"