linux - 我如何防止 gdb 捕获 control-D?

标签 linux debugging gdb

我正在尝试调试需要读取 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/

相关文章:

c# - Silverlight 3 WCF 服务 `CommunicationException` 服务器返回错误 : NotFound

c++ - gdbinit、 pretty-print 和相关目录?

c - 为什么我不能在 gdb 中打印出环境变量?

linux - 如何将字符串中的一个字符与 NASM x86_64 Linux 程序集中的另一个字符进行比较

linux - 放入文件 : index of line and total numbers of specific pattern

c# - Visual Studio Package - 如何获取本地窗口中的信息?

javascript - 无论如何将 Firebug 'profile' 结果记录到外部文件?

c - 是否可以从打开的文件描述符重新创建文件?

linux - 如何在 Linux 中验证计划运行

c++ - GDB 中用于 C++ 模板(moSTLy boost)的代码更清晰、更漂亮的堆栈跟踪