GDB调试

Posted 暴力的轮胎

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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调试的主要内容,如果未能解决你的问题,请参考以下文章

代码调试篇:gdb调试快速入门指南

GDB代码调试与使用

GDB调试

使用GNU/gdb调试Linux C/C++可执行程序查看出错源代码、设置断点

代码调试工具GDB

代码调试篇:如何编写 gdb 自定义命令