0%

gdb 使用

参考资料

  1. A collection of gdb tips](https://github.com/hanxinle/100-gdb-tips))
  2. A collection of gcc tips

常用命令

命令 缩写 说明
run r 运行程序
break b 设置断点,如 b main、b 10
info breakpoints i b 查看所有断点
delete d 删除断点
continue c 继续运行到下一个断点
next n 单步执行,不进入函数
step s 单步执行,进入函数
finish - 跳出当前函数
print p 打印变量值
watch - 监视变量,值变化时中断
backtrace bt 查看调用堆栈
list l 查看源码
quit q 退出 gdb

补充用法

1 设置运行参数.

1
set args <your args>

c会运行到程序结束,finish 跳出 step over(快捷键 s) 进入的函数.

2 vim 编辑代码

终端中输入 export EDITOR=vim 后在 gdb 中输入 edit 即可在 vim 中打开文件.