通常coredump会产生core文件,然后通过调试core文件定位那具体地方,google coredumper也能够达到相同的效果,但会以一个更美观的文本文件存起来供调试
下载coredumper,安装十分简单
./configure && make && make install
如果编译没法通过,修改include里头文件的文件目录即可
测试程序(产生coredump):
#include <stdio.h> //printf
#include <stdlib.h>//exit
#include <signal.h>//signal
#include <google/coredumper.h>//WriteCoreDump
void sig_func(int signo)
{
printf(“segment fault: caught signal: %d\n”,signo);
if( WriteCoreDump(“coredump.txt”) ==0 ) {
printf(“success: WriteCoreDump to coredump.txt\n”);
} else {
printf(“failure: WriteCoreDump to coredump.txt\n”);
}
exit(-1);//important, comment the line will lead to dead loop signal
}
void error1()
{
int a = 5/0;
}
int main()
{
signal(SIGSEGV, &sig_func);
signal(SIGFPE, &sig_func);
error1();
return 0;
}
编译: cc test_core.c –lcoredumper
运行:./a.out
segment fault: caught signal: 8
success: WriteCoreDump to coredump.txt
调试:gdb ./a.out coredump.txt
bt