[英]GDB debugger : char array type examine and print command
In C program i have declared a buffer of characters: char buffer_in[500]
; 在C程序中,我声明了一个字符缓冲区:
char buffer_in[500]
; When i run this program step by step on GDB i test the buffer reference with this commands: 当我在GDB上逐步运行该程序时,我使用以下命令测试缓冲区引用:
(gdb) ptype buffer_in
type = char [500]
(gdb) ptype &buffer_in
type = char (*)[500]
(gdb) p &buffer_in
$9 = (char (*)[500]) 0x7fffffffdb60
(gdb) x buffer_in
0x7fffffffdb60: 0x2e
(gdb) x &buffer_in
0x7fffffffdb60: 0x2e
In C if I declared and array of characters the object is referenced like a pointer. 在C中,如果我声明了字符数组,则对象被引用为指针。 I &buffer_in it is the address of first element of the array why the output of command
x buffer_in
is the same than x &buffer_in
?. I&buffer_in它是数组的第一个元素的地址,为什么命令
x buffer_in
的输出与x &buffer_in
?相同。 I think that x buffer_in
must trie to examine 0x2e address and so it is wrong referenced. 我认为
x buffer_in
必须trie来检查x buffer_in
地址,因此引用错误。
Thanks 谢谢
So, gdb's x command expects a memory address - the command's purpose is to dump some memory in hex. 因此,gdb的x命令需要一个内存地址 - 该命令的目的是以十六进制转储一些内存。 If you give it an array variable, it will assume you mean you want it to dump starting at the address the array is stored at.
如果你给它一个数组变量,它会假设你想要它从存储数组的地址开始转储。 If you give it a pointer to an array variable, it will assume you mean you want it to dump starting at that pointer.
如果你给它一个指向数组变量的指针,它会假设你想要它从那个指针开始转储。 Those two are the same - this is much like the way C is actually compiled.
这两个是相同的 - 这很像C实际编译的方式。
To put a finer point on it, 为了更好一点,
printf("0x%8.8lX 0x%8.8lX\n", (unsigned long)buffer_in, (unsigned long)&buffer_in);
prints the same number twice. 两次打印相同的数字。 So you'd expect gdb to dump the same byte from memory when asked to dump each address expression.
因此,当您被要求转储每个地址表达式时,您希望gdb从内存中转储相同的字节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.