为什么每次我使用“cont”命令时,在 gdb 中运行时一个 CTRL-Z 会一直发出 SIGTSTP 信号?

问题描述 投票:0回答:3

我正在

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 ?? ()

那么有什么理由吗?谢谢。

linux api linux-kernel gdb pthreads
3个回答
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)
...

在这种情况下,

  • 键入 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.

因此,

signal 0
将在没有向其传递 SIGTSTP 信号的情况下恢复程序。


0
投票

我通常使用 Ctrl+C (SIGINT) 来中断正在运行的进程并设置断点。

我认为这会有所帮助 http://web.mit.edu/gnu/doc/html/gdb_toc.html#SEC40


0
投票

这是在 OP 之后很久但如果其他人登陆这里: 我在调试具有多个线程的 gRPC 应用程序时得到了这个,我使用 Ctrl-z 停止了它。我不得不跑

handle SIGTSTP nopass nostop
使
continue
实际上在所有线程中恢复执行。

© www.soinside.com 2019 - 2024. All rights reserved.