用gdb处理信号 [英] Handling signals with gdb

查看:400
本文介绍了用gdb处理信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Ubuntu 10.04调试一个C ++应用程序,它有时会收到一个 SIGKILL 信号。
我希望捕捉信号并阻止其执行,以查看是否可以在该时刻获得应用程序状态的一些有用信息。



阅读 gdb文档,我发现句柄命令,所以我试图将它应用于SIGKILL信号:

 (gdb)handle SIGKILL stop nopass 
Signal Stop Print Pass to program描述
SIGKILL是是已杀死

因此,正如我所理解的那样:

  stop 
GDB应该停止您的程序当这个信号发生时。这也意味着print关键字。
print
当这个信号发生时,GDB应该会打印一条消息。
nopass
GDB不应该让程序看到这个信号。

发出 SIGKILL 信号后,

gdb 应该以某种方式捕获它,



你知道我该如何捕捉信号吗? p>

有用信息


  • 在另一个线程中执行时发出信号 4.4.3

  • g ++版本: 7.1


解决方案

unix signal(7)手册页:

 信号SIGKILL和SIGSTOP不能被捕获,或被忽略。 

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


I'm debugging a C++ app for Ubuntu 10.04 that sometimes receives a SIGKILL signal. I want to catch the signal and stop it from killing the execution, just to see if I can get some useful info of the app's state at that precise moment.

Reading the gdb documentation I found the handle command, so I tried to apply it to the SIGKILL signal:

(gdb) handle SIGKILL stop nopass
Signal        Stop  Print   Pass to program Description
SIGKILL       Yes   Yes     No              Killed

So, as I understand this correctly:

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. 

once the SIGKILL signal is emitted, gdb should somehow catch it, print the message, stop the execution and don't let the app kill itself, right?

The problem is that this doesn't happen and the app terminates.

Do you know how could I catch the signal?

Useful Info:

  • The piece of code that is running when the signal is emitted is executed in another thread.
  • gdb version: 4.4.3
  • g++ version: 7.1

解决方案

From unix signal(7) man page:

  The  signals SIGKILL and SIGSTOP cannot be caught, blocked, or ignored.

So the debugger can set the handler but that doesn't make any sense. The OS directly performs the needed action. If SIGKILL could be handled from application the OS has no chance to terminate a broken application. For that reason SIGKILL is a bit special :-)

这篇关于用gdb处理信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆