基本使用
启动gdb
1
gdb exe_name
gdb中运行程序
1
2
3
4
5
6
7
8
9# 连续运行
(gdb) run
(gdb) r
# 分步调试
(gdb) start
# 向下执行
(gdb) n(ext)
# 单步调试进入函数,不能进入库函数
(gdb) s(tep)退出gdb
1
(gdb) quit
运行中给变量赋值
1
2
3
4# 设置主函数运行参数
(gdb) set args param1 param2
# 调试中变量赋值
(gdb) set param=val显示代码
1
2(gdb) list
(gdb) list file_name:line_ID设置断点
1
2
3(gdb) break line_ID
(gdb) b func_name
(gdb) b file_name:line_ID查看断点
1
(gdb) i(nfo) b
删除断点
1
(gdb) d break_ID
运行到下一个断点
1
(gdb) c(ontinue)
查看变量
1
2
3
4
5
6
7
8(gdb) p(rint) var_name
(gdb) ptype var_name
# 运行时打印变量,用于追踪变量
(gdb) display var
# 查看当前display的变量
(gdb) info display
# 取消打印变量
(gdb) undisplay var_ID设置条件断点
1
(gdb) b line_ID if condition
gdb调试core
设置生成 core:
1
2
3
4
5设置生成core
ulimit -c size
ulimit -c unlimited
取消生成core
ulimit -c 0