我正在尝试调试一个需要读取EOF作为输入的程序。
但是,当程序在GDB中运行时,当我按Control-D发送EOF时,GDB捕获EOF,并且不将其传递给应用程序。
如何使gdb将EOF发送到应用程序?
发布于 2012-10-13 18:44:12
但是,当程序在GDB中运行时,当我按Control D发送EOF时,GDB会捕获EOF,并且不会将其传递给应用程序。
GDB不会,不会做这样的事情。
在正常(全部停止)模式下,应用程序或GDB可以控制终端,但不能同时控制两者。
如果应用程序正在读取终端输入,那么will 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
更新:
当应用程序正在读取时(不是在gdb提示符下),并且应用程序没有确认它收到了
-D,我按下了Control D。当应用程序尝试读取时,它读取0字节。
这正是应该发生的事情(返回0的read
表示您已经到达文件末尾)。如果您期望应用程序读取神奇的EOF
符号,那么您的期望是错误的--根本没有这样的符号。
https://stackoverflow.com/questions/12875582
复制