问题描述
我想强制核心转储在我的C ++应用程序的特定位置。
I would like to force a core dump at a specific location in my C++ application.
我知道我可以做这样的事情做到这一点:
I know I can do it by doing something like:
int * crash = NULL;
*crash = 1;
不过,我想知道是否有一个更清洁的方式?
But I would like to know if there is a cleaner way?
我使用Linux的方式。
I am using Linux by the way.
推荐答案
的( SIGABRT
在Linux中)信号6号集资的方式做到这一点的一种方式(尽管保持介意SIGABRT不是的需要的是在所有的POSIX实现6所以你可能要使用 SIGABRT
值本身,如果这是不是快以外的任何其他n'dirty调试code)。
Raising of signal number 6 (SIGABRT
in Linux) is one way to do it (though keep in mind that SIGABRT is not required to be 6 in all POSIX implementations so you may want to use the SIGABRT
value itself if this is anything other than quick'n'dirty debug code).
#include <signal.h>
: : :
raise (SIGABRT);
调用中止()
也将导致核心转储,你甚至可以做到这一点的没有的调用终止你的进程叉()
然后按中止()
在孩子 - 见的。
Calling abort()
will also cause a core dump, and you can even do this without terminating your process by calling fork()
followed by abort()
in the child only - see this answer for details.
这篇关于如何编程导致C / C核心转储++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!