我目前正在关注这个关于如何使用这个 C 程序使用程序集和 gdb 的视频,但我遇到了一个问题。这是我编译和运行 gdb 的方法:
chiggins@host:~/assem$ gcc -ggdb -o SimpleDemo SimpleDemo.c
chiggins@host:~/assem$ gdb ./SimpleDemo
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2) 7.4-2012.04
Copyright (C) 2012 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 "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/chiggins/assem/SimpleDemo...done.
(gdb) list
4 int add(int x, int y)
5 {
6 int z =10;
7
8 z = x + y;
9 return z;
10 }
11
12 main(int argc, char **argv)
13 {
(gdb)
14 int a = atoi(argv[1]);
15 int b = atoi(argv[2]);
16 int c;
17 char buffer[100];
18
19 gets(buffer);
20 puts(buffer);
21
22 c = add(a,b);
23
(gdb)
24 printf("Sum of %d+%d = %d\n",a, b, c);
25
26 exit(0);
27
28 }
(gdb) run 10 20
Starting program: /home/chiggins/assem/SimpleDemo 10 20
demo
现在,我在最后输入了“演示”,这就是程序应该接受用户输入的地方。但是当我在输入回车后按回车时,什么也没有发生。我不能ctrl+c退出程序,什么也做不了。我最终不得不从另一个会话中终止该进程,这样我才能重新获得控制权。任何想法为什么 gdb 会这样做,或者我可能做错了什么?
谢谢!