问题描述
我在Linux下编写了一个使用AVX指令的小型C ++程序。但程序收到 SIGKILL
信号并退出。看来原因是某些非法指令或错误的价值传递给了指令。我需要了解它在程序的哪个地方接收到 SIGKILL
(最好在什么指令下)。但是,当我在GDB中运行我的程序时,程序在收到 SIGKILL
时无法调试。我尝试设置:
(gdb)句柄SIGKILL stop print nopass
但是在我调试它之前,程序仍然收到SIGKILL并退出。您有任何提示如何处理这个问题吗?
手册页告诉你在非法机器指令(或。 (在那些不支持AVX的应用程序中,它可能是一个非法的操作码)。输入 cat / proc / cpuinfo
(或者 grep avx / proc / cpuinfo
)来知道你的处理器是否接受它。查看 您可以捕获 SIGILL
em> 无法捕捉 SIGKILL
)。
我在适用于 SIGILL
;用一些非常复杂的机器和系统特定的C代码,你可以捕获 SIGILL
,并确保从信号返回处理程序(安装时使用 SA_SIGINFO
并深入处理 ucontext_t *
第三个参数),执行继续执行非法指令。 / p>
您可以配置 gdb
明智地处理 SIGILL
。阅读GDB文档的,您可能需要处理SIGILL
和/或 p $ _siginfo
命令。
I have written small C++ program under Linux that uses AVX instructions. But the program receives SIGKILL
signal and exits. It seems that the reason is some illegal instruction or wrong value passed to an instruction. I would need to learn at what point of the program it receives SIGKILL
(at what instruction at best). But, when I run my program in GDB, program exits at the moment when it receives SIGKILL
and cannot be debugged. I tried to set:
(gdb) handle SIGKILL stop print nopass
but program still receives SIGKILL and exits before I can debug it. Do you have any tip how to work with this?
The signal(7) man page tells that on illegal machine instruction (or illegal opcode), the
signal is sent. Notice that it is SIGILL
not SIGKILL
(the letter K
makes a big difference).
Recall that not every processor know about AVX. (On those that don't support AVX, it probably is an illegal opcode). Type cat /proc/cpuinfo
(or grep avx /proc/cpuinfo
) to know if your's processor accepts it. See proc(5)
You can catch SIGILL
(but you cannot catch SIGKILL
).
What I explained in this answer (about SIGSEGV
) is applicable to SIGILL
; with some very tricky machine and system specific C code, you might catch SIGILL
and ensure that upon return from the signal handler (installed with SA_SIGINFO
and deeply processing the ucontext_t*
third argument) the execution continues outside of the illegal instructions.
And you could configure gdb
to handle SIGILL
wisely. Read the signals chapter of GDB documentation, you probably want the handle SIGILL
and/or p $_siginfo
command.
这篇关于调试在Linux下捕获SIGKILL的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!