一、gdb 调试段错误
(1)编写代码
vim segfault.c
#include<stdio.h>
int main()
{
char *buf;
*buf = "Hello,world";
retrun 1;
}
(2)编译
#gcc -g segfault.c
#ls
a.out segfault.c
(3)调试
#./a.out
Segmentation fault (core dumped)
#gdb ./a.out ./core
#0 0x2b38 in main (argc=1, argv=0x7f7f06b4) at segfault.c:8
8 *buf = "xxx";
哈哈出来了!
二、gdb调试进程
#ps -ef | grep test
获取进程号,比如是1777
#gdb
(gdb)attach 1777
(gdb) bt