我正在尝试调试需要读取 EOF 作为输入的程序。
但是,当程序在 GDB 中运行时,当我按下 Control-D 发送 EOF 时,GDB 捕获了 EOF 并且没有将它传递给应用程序。
如何让 gdb 将 EOF 发送到应用程序?
最佳答案
However, when I hit Control-D to send EOF when the program is running in GDB, GDB traps the EOF and does not pass it to the application.
GDB 不会做任何这样的事情。
在正常(全停止)模式下,应用程序或 GDB 可以控制终端,但不能同时控制两者。
如果应用程序正在读取终端输入,那么 Control-D 会导致它读取 EOF
,而 GDB 不会干涉它。
如果您正在查看 (gdb)
提示符,那么应用程序不会读取输入——它已停止——发送 Control-D 确实会发送 EOF
到 GDB。不要那样做。
例子:
gdb -q /bin/cat
Reading symbols from /bin/cat...done.
(gdb) run
Starting program: /bin/cat
foof # my input
foof # cat output
# Control-D
[Inferior 1 (process 12782) exited normally] # cat received EOF and exited
(gdb) run
Starting program: /bin/cat
foof # my input
foof # cat output
^C
Program received signal SIGINT, Interrupt.
0x00007ffff7b31ee0 in __read_nocancel () at ../sysdeps/unix/syscall-template.S:82
82 ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) quit # I typed Control-D, GDB translated that into quit
A debugging session is active.
Inferior 1 [process 12787] will be killed.
Quit anyway? (y or n) y
更新:
I am hitting Control-D when the application is reading (not at gdb prompt), and the application does not acknowledge that it received Control-D. When the application tries to read, it reads 0 bytes.
这正是应该发生的事情(read
返回 0 意味着您已经到达文件末尾)。如果您期望应用程序读取神奇的 EOF
符号,那么您的期望是错误的 -- 没有这样的符号。
关于linux - 我如何防止 gdb 捕获 control-D?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12875582/