如何在不将信号传递给应用程序的情况下执行步骤?
How to step without passing signal to application?
假设 GDB 下的进程 运行 由于接收到信号而停止,例如SIGSEGV
由于访问了无效位置。然后我修复了位置(通过写入寄存器或以任何其他方式)并想单步执行,重试错误指令。
有一个命令 stepi
,如果信号被忽略或一开始就没有收到,它会起作用。但是由于有待处理的信号,我不能使用它,至少不能直接使用。如果我使用 signal 0
命令,它会忽略该信号,但随后它会像 continue
一样工作。因此,如果我使用 signal 0
,我必须找出下一条指令的起始位置,在其上添加一个 tb
等等。这很不方便。
另一种方法是 handle SIGSEGV ignore
后跟 stepi
后跟另一个 handle
命令以恢复其原始状态。也很不方便:甚至不能 define
一个 "black box" 函数,因为信号处理的原始状态可能不是默认的,并且在 si
之后恢复它会遇到麻烦。
那么,有什么简单的方法可以在不继续执行的情况下删除挂起信号吗?
在 gdb 中 version 7.9 and later, there is a queue-signal
command that will let you send a signal (or no signal at all, if you give it 0
as an argument) the next time the target is resumed. Here's some of the documentation:
Queue signal to be delivered immediately to the current thread when execution of the thread resumes. The signal can be the name or the number of a signal. The handling of the signal must be set to pass the signal to the program, otherwise GDB will report an error. You can control the handling of signals from GDB with the handle
command.
Alternatively, if signal is zero, any currently queued signal for the current thread is discarded and when execution resumes no signal will be delivered.
This command differs from the signal
command in that the signal is just queued, execution is not resumed. And queue-signal
cannot be used to pass a signal whose handling state has been set to nopass
.
假设 GDB 下的进程 运行 由于接收到信号而停止,例如SIGSEGV
由于访问了无效位置。然后我修复了位置(通过写入寄存器或以任何其他方式)并想单步执行,重试错误指令。
有一个命令 stepi
,如果信号被忽略或一开始就没有收到,它会起作用。但是由于有待处理的信号,我不能使用它,至少不能直接使用。如果我使用 signal 0
命令,它会忽略该信号,但随后它会像 continue
一样工作。因此,如果我使用 signal 0
,我必须找出下一条指令的起始位置,在其上添加一个 tb
等等。这很不方便。
另一种方法是 handle SIGSEGV ignore
后跟 stepi
后跟另一个 handle
命令以恢复其原始状态。也很不方便:甚至不能 define
一个 "black box" 函数,因为信号处理的原始状态可能不是默认的,并且在 si
之后恢复它会遇到麻烦。
那么,有什么简单的方法可以在不继续执行的情况下删除挂起信号吗?
在 gdb 中 version 7.9 and later, there is a queue-signal
command that will let you send a signal (or no signal at all, if you give it 0
as an argument) the next time the target is resumed. Here's some of the documentation:
Queue signal to be delivered immediately to the current thread when execution of the thread resumes. The signal can be the name or the number of a signal. The handling of the signal must be set to pass the signal to the program, otherwise GDB will report an error. You can control the handling of signals from GDB with the
handle
command.Alternatively, if signal is zero, any currently queued signal for the current thread is discarded and when execution resumes no signal will be delivered.
This command differs from the
signal
command in that the signal is just queued, execution is not resumed. Andqueue-signal
cannot be used to pass a signal whose handling state has been set tonopass
.