使用 GDB 进行调试的全面指南
1. 核心转储与 GDB 查看核心文件
在发生核心转储后,我们可以在/corefiles目录下找到类似core.sort-debug.1431425613这样的文件。若想了解更多信息,可参考手册页core(5)。
下面是一个使用 GDB 查看核心文件的示例会话:
$ arm-poky-linux-gnueabi-gdb sort-debug /home/chris/rootfs/corefiles/core.sort-debug.1431425613 [...] Core was generated by `./sort-debug'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x000085c8 in addtree (p=0x0, w=0xbeac4c60 "the") at sort-debug.c:41 41 p->word = strdup (w);这表明程序在第 41 行停止。使用list命令可以查看附近的代码:
(gdb) list 37 static struct tnode *addtree (struct tnode *p, char *w) 38 { 39 int cond; 40 41 p->word = str