【发布时间】:2014-07-21 13:58:05
【问题描述】:
所以,我正在学习如何用 C 编程,并且我正在(或至少,试图)在 GDB 中获得一些乐趣。
所以我写了这个简单的代码:
#include <stdio.h>
int main (int argc, char *argv[]){
int i;
int n = atoi(argv[2]);
for (i=0; i<n ; i++){
printf("%s \n",i+1,argv[1]); // prints the string provided in
} // the arguments for n times
return 0;
}
我试图使用 GDB 来获取一些关于它的信息。 所以我用它来尝试从内存地址中获取参数,但这就是我得到的:
(gdb) break main
Breakpoint 1 at 0x4005d7: file repeat2.c, line 14.
(gdb) break 17
Breakpoint 2 at 0x40062c: file repeat2.c, line 17.
(gdb) run hello 5
Starting program: /root/Scrivania/Programmazione/repeat2 hello 5
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
Breakpoint 1, main (argc=3, argv=0x7fffffffe948) at repeat2.c:14
14 int n = atoi(argv[2]);
(gdb) cont
Continuing.
1 ------> hello
2 ------> hello
3 ------> hello
4 ------> hello
5 ------> hello
Breakpoint 2, main (argc=3, argv=0x7fffffffe948) at repeat2.c:18
18 return 0;
(gdb) x/3xw 0x7fffffffe948 (I try to read what argv contains)
0x7fffffffe948: 0xffffebbc 0x00007fff 0xffffebe3
(gdb) x/s 0xffffebbc (I try to read one of the argoments in the array)
0xffffebbc: <Address 0xffffebbc out of bounds>
为什么我不断收到此错误?我是 64 位的,我使用的是 Kali Linux
该程序,如果编译,可以工作,只是我不明白为什么我不能用 GDB 读取这些值。
【问题讨论】: