1. 首先生成core文件,示例代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void core1()
{
char *p = NULL;
*p = 'a';
printf("p:%s\n", p);
}
int main()
{
core1();
return 0;
}
[ljq@ycy aup]$ gcc coredump.c -o coredump -g
[ljq@ycy aup]$ ./coredump
段错误 (核心已转储)
[ljq@ycy aup]$ ll core.*-rw-------. 1 ljq ljq 217088 5月 16 15:45 core.5004
core文件已生成。
2. 使用gdb调试core文件,定位错误位置:
[ljq@ycy aup]$ gdb coredump core.5004
GNU gdb (GDB) Fedora 7.10-23.fc23
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying