Debug小妙招·「1」--使用GDB分析进程Core Dump
Reading symbols from /root/code/blog_test/coredump_test/test...
[New LWP 825]
Core was generated by `./test'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x000055ff8446d16d in main () at test.c:10
10 *p = 42;
(gdb) bt
#0 0x000055ff8446d16d in main () at test.c:10
(gdb) frame
#0 0x000055ff8446d16d in main () at test.c:10
10 *p = 42;
(gdb) list
5 int *p = NULL; // 定义一个空指针
6
7 printf("Attempting to dereference a NULL pointer...\n");
8
9 // 尝试访问空指针,引发段错误
10 *p = 42;
11
12 // 这个语句不会被执行
13 printf("This will never be printed.\n");
14
(gdb) info registers
rax 0x0 0
rbx 0x55ff8446d190 94555924255120
rcx 0x7fd748fa5297 140562619060887
rdx 0x0 0
rsi 0x55ff849b62a0 94555929797280
rdi 0x7fd7490857e0 140562619979744
rbp 0x7ffc13b67b60 0x7ffc13b67b60
rsp 0x7ffc13b67b50 0x7ffc13b67b50
r8 0x2c 44
r9 0x7c 124
r10 0x7fd749083be0 140562619972576
r11 0x246 582
r12 0x55ff8446d060 94555924254816
r13 0x7ffc13b67c50 140720639212624
r14 0x0 0
r15 0x0 0
rip 0x55ff8446d16d 0x55ff8446d16d <main+36>
eflags 0x10246 [ PF ZF IF RF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
(gdb) info frame
Stack level 0, frame at 0x7ffc13b67b70:
rip = 0x55ff8446d16d in main (test.c:10); saved rip = 0x7fd748ebb083
source language c.
Arglist at 0x7ffc13b67b48, args:
Locals at 0x7ffc13b67b48, Previous frame's sp is 0x7ffc13b67b70
Saved registers:
rbp at 0x7ffc13b67b60, rip at 0x7ffc13b67b68
Undefined command: "infso". Try "help".
(gdb) info locals
p = 0x0
(gdb)