我正在
Ubuntu Linux
上做一个项目,当我使用 GDB
调试应用程序并按 CTRL + Z
中断时,我得到了 SIGTSTP
和预期的 GDB
中断。
但是当我在那之后使用
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 ?? ()
那么有什么理由吗?谢谢。
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)
...
在这种情况下,
continue
将在不向其发送任何信号的情况下恢复它。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.
因此,
signal 0
将在没有向其传递 SIGTSTP 信号的情况下恢复程序。
我通常使用 Ctrl+C (SIGINT) 来中断正在运行的进程并设置断点。
我认为这会有所帮助 http://web.mit.edu/gnu/doc/html/gdb_toc.html#SEC40
这是在 OP 之后很久但如果其他人登陆这里: 我在调试具有多个线程的 gRPC 应用程序时得到了这个,我使用 Ctrl-z 停止了它。我不得不跑
handle SIGTSTP nopass nostop
使continue
实际上在所有线程中恢复执行。