为什么每次使用'cont'命令时,在gdb中运行时一个CTRL-Z会不断给出SIGTSTP信号?

Zij*_*gWu 4 linux api gdb pthreads linux-kernel

我正在开发一个项目Ubuntu Linux,当我使用GDB和中断调试应用程序时CTRL + Z,我得到了SIGTSTPGDB预期的中断.

但是当我cont在那之后使用时,我仍然有SIGTSTP,我重复cont了很多时间,但接缝它的行为是一样的,只是反复给我SIGTSTP.

以下两个调用堆栈或者重复:

The call stack is as following alterativly:
Program received signal SIGTSTP, Stopped (user).
[Switching to Thread 0x7fffef73d700 (LWP 32591)]
0x00007ffff636dffd in read () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0  0x00007ffff636dffd in read () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007ffff6301ff8 in _IO_file_underflow () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007ffff630303e in _IO_default_uflow () from /lib/x86_64-linux-gnu/libc.so.6
#3  0x00007ffff62f718a in _IO_getline_info () from /lib/x86_64-linux-gnu/libc.so.6
#4  0x00007ffff62f606b in fgets () from /lib/x86_64-linux-gnu/libc.so.6
... .... .... ....
#11 0x00007ffff664ee9a in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
#12 0x00007ffff637b3fd in clone () from /lib/x86_64-linux-gnu/libc.so.6
#13 0x0000000000000000 in ?? ()
(gdb) c
Continuing.
Program received signal SIGTSTP, Stopped (user).
[Switching to Thread 0x7fffeef3c700 (LWP 32592)]
0x00007ffff6374763 in select () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0  0x00007ffff6374763 in select () from /lib/x86_64-linux-gnu/libc.so.6
... ... ... ...
#6  0x00007ffff664ee9a in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
#7  0x00007ffff637b3fd in clone () from /lib/x86_64-linux-gnu/libc.so.6
#8  0x0000000000000000 in ?? ()
Run Code Online (Sandbox Code Playgroud)

那有什么理由吗?谢谢.

Mar*_*ick 5

gdb 通常(它是可配置的)安排停止程序并在程序即将接收信号时重新获得对终端的控制.

gdb 通常(它是可配置的)在您恢复执行时将信号发送到程序.

可以使用info signals命令查看设置.

(gdb) info signals
Signal        Stop  Print   Pass to program Description
SIGINT        Yes   Yes     No              Interrupt
...
SIGTSTP       Yes   Yes     Yes             Stopped (user)
...
Run Code Online (Sandbox Code Playgroud)

在这种情况下,

  • 键入Ctrl-C将停止程序,continue并将恢复它而不向其发送任何信号.
  • 键入Ctrl-Z将停止程序,并将continue伴随SIGTSTP信号恢复它,因此它将立即再次停止.如果continue再次输入,则应该恢复.

有两种方法可以在不向其发送SIGTSTP信号的情况下恢复程序.

第一种是使用handle SIGTSTP nopass命令,它将"传递给程序"标志更改为"否".

第二种是使用signal命令代替continue.从内置帮助:

(gdb) help signal
Continue program with the specified signal.
Usage: signal SIGNAL
The SIGNAL argument is processed the same as the handle command.

An argument of "0" means continue the program without sending it a signal.
This is useful in cases where the program stopped because of a signal,
and you want to resume the program while discarding the signal.
Run Code Online (Sandbox Code Playgroud)

因此,signal 0将在没有SIGTSTP信号传递给它的情况下恢复程序.