Nee*_*fra 24 stack-overflow buffer gdb
作为参考,我使用以下代码:
#include <stdio.h>
#include <string.h>
int main (void) {
char buf[100]; // ------> How do I find the address in gdb?
printf ("Buffer is at memory location: %08x\n", &buf);
strcpy (buf, "some random text");
printf ("Text is [%s]\n", buf);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能gdb告诉我buf变量的地址?
&当gdb设置为C语言模式(和Objective-C)时,运算符将工作.
在任何语言模式下,您都可以使用
(gdb) info address buf
Symbol "buf" is static storage at address 0x903278.
Run Code Online (Sandbox Code Playgroud)
(输出与你的代码并不完全一致.)我正在写这个答案,因为即使是那些寻找其他语言(包括我自己)答案的人也能找到这个问题.也可以始终切换到C模式set language c,但在此更改后符号名称可能会有所不同.
如果在 gdb 中输入以下内容,您将获得地址:
start
p &buf
Run Code Online (Sandbox Code Playgroud)
如以下记录:
pax$ gdb ./qq.exe
GNU gdb 6.8.0.20080328-cvs (cygwin-special)
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-cygwin"...
(gdb) start
Breakpoint 1 at 0x401144: file qq.c, line 2.
Starting program: /home/pax/qq.exe
[New thread 2912.0xf9c]
[New thread 2912.0x518]
main () at qq.c:2
2 int main (int argc, char **argv) {
(gdb) p &buf
$1 = (char (*)[100]) 0x22ccd0
(gdb)
Run Code Online (Sandbox Code Playgroud)