简单的GDB调试core文件

//demo.c
#include <stdio.h>


void test()
{
    int *p = NULL;
    *p = 1;
}

int main()
{
    test();
    return 0;
}

以上述的文件代码为例,执行以下步骤:

gcc -g -o demo demo.c -ldl
./demo

段错误 (核心已转储)

ulimit -c unlimited // 设置 core 文件大小为无限制
./demo 生成 core 文件
gdb ./demo core 调试段错误

然后如下进行操作,可定位到demo.c的第七行有问题。。。 

(gdb) break 6
Breakpoint 1 at 0x55c693afe14e: file demo.c, line 6.
(gdb) r
Starting program: /home/ts-ly/CPP-study/10.Skill/demo 

Breakpoint 1, test () at demo.c:6
6           int *p = NULL;
(gdb) n
7           *p = 1;
(gdb) n

Program received signal SIGSEGV, Segmentation fault.
0x000055555555515a in test () at demo.c:7
7           *p = 1;
(gdb) 

猜你喜欢

转载自blog.csdn.net/m0_37844072/article/details/118363724