Open
Description
Essential Commands
简记 | 描述 |
---|---|
gdb program [core] | 调试core文件 |
b [file:] function | 设置断点在函数上 |
r run简写 | 运行你的程序 |
bt backtrace | 显示程序栈 |
p expr | 打印显示表达式的值 |
c continue | 继续运行程序 |
n next | 下一行 跳过函数调用 |
s step | 下一行 步入函数调用 |
Starting GDB
命令 | 描述 |
---|---|
gdb | 开启gdb 没有debug文件 |
gdb program | 开始调试可执行文件 |
gdb program core dump file | 调试core是程序非法执行后core dump后产生的文件 |
gdb --help | 命令行帮助选项 |
Stoping GDB
命令 | 描述 |
---|---|
quit q or EOF | 退出GDB; eg C-d |
INTERRUPT | 终止当前命令,eg C-c |
Getting Help
命令 | 描述 |
---|---|
help | 列出命令的类型 |
help class | 命令类型的描述 |
help command | 命令描述 |
Executing your Program
命令 | 描述 |
---|---|
run arglist | 使用arglist开始程序 |
run | 使用当前参数列表开始程序 |
run outf | 使用input output开始程序 |
kill | 结束运行程序 |
tty dev | 使用dev作为标准输入输出为下一次的run |
set args arglist | 为下一次run指定arglist |
set args | 指定空参数列表 |
show args | 显示参数列表 |
show args var | 显示环境中var的值 |
set env var string | 设置环境变量var=string |
unset env var | 移除环境变量var |
Shell Commands
命令 | 描述 |
---|---|
cd dir | 改变当前目录到dir |
pwd | 打印当前目录 |
make | 调用 make |
shell cmd | 执行shell 命令串 |
Breakpoint and Watchpoints
命令 | 描述 |
---|---|
break [file:] line | 设置断点在file中line行处 |
b [file:] line | eg: break mian.c :37. |
break [file:] func | 设置断点在file中func处 |
break +offset or -offset | 设置断点在offset行距离当前停止 |
break *addr | 在地址addr处设置断点 |
break...if expr | 设置条件断点在expr不为0的时候 |
tbreak ... | 临时断点 在到达后无效 |
rbreak [file:]regex | 设置在所有函数匹配 regex在file中 |
watch expr | 设置一个观察点对表达式expr |
catch event | 设置在event上能够被catch,throw,exec,fork,vfork,load,or unload. |
info break | 显示定义的断点 |
info watch | 显示定义的观察点 |
clear | 删除调断点在下一个描述上 |
clear [file:]fun | 删除在fun()入口的断点 |
clear [file: ]line | 清除第line行的断点 |
delete [n] | 删除断点n[或者断点n] |
disable [n] | 暂停第n个断点 |
enable [n] | 开启第n个断点 |
Execution Control
命令 | 描述 |
---|---|
continue [count] | 继续执行,到下一个断点处或运行结束 |
c [count] | continue简写 |
step [count] | 单步调试如果有函数调用,则进入函数 |
s [count] | step简写 |
stepi [count] | 单步执行一条机器指令 |
si [count] | stepi 简写 |
next [count] | 执行下一行包括函数调用 |
n [count] | next 简写 |
nexti [count] | 执行下一条机器指令而不是原始行 |
ni [count] | nexti 简写 |
until [location] | 运行至某行,不仅仅用来跳出循环 |
finish | 运行程序直到当前函数完成返回,并打印函数返回时的堆栈地址返回值及参数值 |
jump line | 重新执行在指定的行数或地址 |
jump* address |
Display
命令 | 描述 |
---|---|
print [/f] [expr] | 显示表达式expr的值 |
p [/f] [expr] | 格式化f 详细 |
x [N u f] expr | 查看内存的 /后可以指定格式化显示 |
whatis | 查询变量或函数 |
Source Code
命令 | 描述 |
---|---|
dir names | 添加目录名names到源路径 |
dir | 清理源路径 |
show dir | 显示当前源路径 |
whatis | 查询变量或函数 |
list | 显示下十行源代码或者将接着上一次 list 命令的输出下边的内容 |
list - | 显示前十行 |
list lines | 将显示当前文件以lines为中心的前后10行代码 |
info line num | 显示编译代码在num行处开始结束地址 |
info source | 显示源文件的名字 |
info sources | 显示所有源文件在使用中 |
forw regex | 搜索regex在下面源码中 |
GDB Quick 查询卡片
参考资料
http://www.yolinux.com/TUTORIALS/GDB-Commands.html
https://sourceware.org/gdb/onlinedocs/gdb/
http://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/gdb.html