首页 > 代码库 > GDB调试

GDB调试

一 GDB调试Core_dump

 1 设置core文件大小为无限制:

  ulimit -c unlimited

 2 运行程序 ./a.out,产生段错误,生成core文件。

   3 使用gdb查看core文件 :

  gdb ./a.out ./core

  输出如下:

GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9
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"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a.out...done.
[New LWP 3115]
Core was generated by `./a.out.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x000000000040051b in do_it () at ./test.c:11
11        *p = a;

  如果只想显示错误所在行,使用where:

(gdb) where
#0  0x000000000040051b in do_it () at ./test.c:11
#1  0x0000000000400504 in main () at ./test.c:4

二 GDB插入断点

  

GDB调试