本文介绍了执行int 3中断会停止Linux上的整个过程还是仅停止当前线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设体系结构是x86。操作系统基于Linux。给定一个多线程进程,其中一个线程执行 int 3 指令,则中断处理程序会停止执行整个进程,还是只是执行 int 3 指令?

Suppose the architecture is x86. And the OS is Linux based. Given a multithreaded process in which a single thread executes an int 3 instruction, does the interrupt handler stop from executing the entire process or just the thread that executed the int 3 instruction?

推荐答案

由于问题是特定于Linux的,因此让我们深入了解内核源代码吧!我们知道 int 3 将生成SIGTRAP,正如我们在。 是终止进程并转储核心

Since the question is Linux specific, let's dive into kernel sources! We know int 3 will generate a SIGTRAP, as we can see in do_int3. The default behaviour of SIGTRAP is to terminate the process and dump core.

do_int3 调用在经过很多间接调用后,称为,其中大多数魔术都发生在这里。在评论之后,很明显就可以看到正在发生的事情,而无需太多解释:

do_int3 calls do_trap which, after a lot of indirection, calls complete_signal, where most of the magic happens. Following the comments, it's quite clear to see what is happening without much need for explanation:


  • 发现有一个线程可以将信号传递给它。主线程被赋予第一个裂纹,但是除非明确声明它不希望,否则任何线程都可以得到它。

  • SIGTRAP是致命的(并且我们假设我们想确定默认行为是),并且必须转储内核,因此这对整个组都是致命的。

  • 第1003行的循环唤醒所有线程并传递信号。

编辑:要回答评论:

正在处理 ptrace d,该行为在(请参见信号传递停止)。基本上,内核选择了处理信号的任意线程之后,如果跟踪了所选线程,则进入信号传递停止状态-这意味着信号尚未传递到进程,并且可以由跟踪进程抑制。调试器就是这种情况:在调试时,死进程对我们没有用(这不是完全正确的,但让我们考虑实时调试方案,这是在这种情况下唯一有意义的方案),因此默认情况下除非用户另行指定,否则我们将阻止SIGTRAP。在这种情况下,被跟踪的进程如何处理SIGTRAP(SIG_IGN或SIG_DFL或自定义处理程序)无关紧要,因为它永远不会知道它发生了。

When the process is being ptraced, the behaviour is pretty well documented in the manual page (see "Signal-delivery-stop"). Basically, after the kernel selects an arbitrary thread which handles the signal, if the selected thread is traced, it enters signal-delivery-stop -- this means the signal is not yet delivered to the process, and can be suppressed by the tracer process. This is the case with a debugger: a dead process is of no use to us when debugging (that's not entirely true, but let's consider the live-debugging scenario, which is the only one which makes sense in this context), so by default we block SIGTRAP unless the user specifies otherwise. In this case it is irrelevant how the traced process handles SIGTRAP (SIG_IGN or SIG_DFL or a custom handler) because it will never know it occurred.

请注意,在SIGTRAP,跟踪程序进程必须考虑正在停止的进程以外的各种情况,这在每个ptrace操作下的手册页中也有详细介绍。

Note that in the case of SIGTRAP, the tracer process must account for various scenarios other than the process being stopped, as also detailed in the man page under each ptrace action.

这篇关于执行int 3中断会停止Linux上的整个过程还是仅停止当前线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 18:08