gpt4 book ai didi

c - gdb 不接受用户输入

转载 作者:IT王子 更新时间:2023-10-29 00:42:12 24 4
gpt4 key购买 nike

我目前正在关注 this video关于如何使用汇编和 gdb,使用 this C program ,但我遇到了问题。下面是我编译和运行 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 退出程序,什么也做不了。我最终不得不从另一个 session 中终止进程,这样我才能重新获得控制权。知道 gdb 为什么这样做,或者我可能做错了什么吗?

谢谢!

最佳答案

我不确定为什么这对你不起作用;它在这里按预期工作...

不过,我发现在单独的终端中运行执行交互式 I/O 的程序更容易,也许它会对你有所帮助。

在一个终端中,

$ gdbserver --multi localhost:4242listening on port 4242

还有一个,

$ gdb ./SimpleDemo(gdb) target extended-remote localhost:4242Remote debugging using localhost:4242(gdb) run 10 20

回到运行gdbserver的终端,

Remote debugging from host 127.0.0.1Process ./SimpleDemo created; pid=PIDdemodemoSum of 10+20 = 30Child exited with status 0

关于c - gdb 不接受用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11089251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com