使用gdb处理信号

Adr*_*.S. 5 c++ multithreading gdb signals ubuntu-10.04

我正在为Ubuntu 10.04调试一个C++应用程序,它有时会收到一个SIGKILL信号.我想抓住信号并阻止它杀死执行,只是为了看看我是否可以在那个精确的时刻获得应用程序状态的一些有用信息.

阅读gdb文档我找到了handle命令,所以我尝试将它应用于SIGKILL信号:

(gdb) handle SIGKILL stop nopass
Signal        Stop  Print   Pass to program Description
SIGKILL       Yes   Yes     No              Killed
Run Code Online (Sandbox Code Playgroud)

所以,正如我所理解的那样:

stop
    GDB should stop your program when this signal happens. This implies the print keyword as well. 
print
    GDB should print a message when this signal happens. 
nopass
    GDB should not allow your program to see this signal. 
Run Code Online (Sandbox Code Playgroud)

一旦SIGKILL信号被发出,gdb应该以某种方式捕获它,打印消息,停止执行并且不要让应用程序自杀,对吧?

问题是,这不会发生,应用程序终止.

你知道我怎么能抓住这个信号?

实用信息:

  • 发出信号时运行的代码段在另一个线程中执行.
  • gdb版本: 4.4.3
  • g ++版本: 7.1

Kla*_*aus 7

来自unix signal(7)手册页:

  The  signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.
Run Code Online (Sandbox Code Playgroud)

所以调试器可以设置处理程序,但这没有任何意义.操作系统直接执行所需的操作.如果可以从应用程序处理SIGKILL,则操作系统无法终止损坏的应用程序.出于这个原因,SIGKILL有点特别 :-)