1.gdb调试的介绍
GUN工具集中的调试工具是gdb,该程序是一个交互式工具,工作在字符模式。
2.gdb是功能强大的调试器,可完成如下调试任务:
1)设置断点
2)监视程序变量的值
3)程序的单步执行
4)显示/修改变量的值
5)显示/修改寄存器
6)查看程序的堆栈情况
7)远程调试
3.gdb 常用命令
1)l (list) ---------------------------------- 列出程序清单 l 1从第一行开始列出
2)r (run)---------------------------------- 运行程序
3)b [行号\函数名] -------------------- 设置断点 例 b 13 给13行设置断点
4)info b----------------------------------- 查看断点
5)clear [行号] --------------------------- 清除断点
6) c (continue)----------------------------- 继续运行程序
7)s (step) -------------------------------- 单步跳入运行 step into
8) n (next)----------------------------------- 单步跳过裕兴 step over
9)finish ------------------------------------- 跳出函数
10) print [变量/表达式] ------------------- 显示变量或表达式的值
11) display [变量/表达式] ----------------- 每次运行停止打印变量的值
12)undisplay 标号------------------------- 清除标号对应变量值的显示
4. 简单使用GDB 调试
1)[wang@localhost text]$ gcc -g sum.c -o sum //调试 sum.c 必须带 -g
2)[wang@localhost text]$ gdb sum //调试sum文件 会出现gdb的版本信息
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-92.el6)
Copyright (C) 2010 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 "i686-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/wang/Desktop/text/sum...done.
(gdb) l