如何防止gdb捕获control-D?

时间:2012-10-13 18:10:17

标签: linux debugging gdb

我正在尝试调试需要读取EOF作为输入的程序。

但是,当程序在GDB中运行时,当我按Control-D发送EOF时,GDB会捕获EOF并且不会将其传递给应用程序。

如何让gdb将EOF发送到应用程序?

1 个答案:

答案 0 :(得分:1)

  

但是,当程序在GDB中运行时,当我按Control-D发送EOF时,GDB会捕获EOF并且不会将其传递给应用程序。

GDB 做任何此类事情。

在正常(全停)模式下,应用程序或GDB可以控制终端,但不能同时控制两者。

如果应用程序正在读取终端输入,那么Control-D将使其读取EOF,并且GDB不会干扰它。

如果您正在查看(gdb)提示符,那么应用程序正在读取输入 - 它已停止 - 并且发送Control-D确实会发送{{1}到GDB。不要那样做。

示例:

EOF

更新

  

当应用程序正在读取时(不是在gdb提示符下),我正在按Control-D,并且应用程序不会确认它已收到Control-D。当应用程序尝试读取时,它读取0个字节。

那是完全应该发生的事情(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 返回0意味着你已到达文件末尾)。如果您希望应用程序读取神奇的read符号,那么您的期望是错误 - 没有这样的符号。

相关问题