GDB基本命令
2014-08-27 11:34
239 查看
最近学习了一下在CLI里编写和调试C语言,总结一下常用的GDB调试命令:
gdb常用命令
x命令的格式说明:
(gdb) help x
Examine memory: x/FMT ADDRESS.
ADDRESS is an expression for the memory address to examine.
FMT is a repeat count followed by a format letter and a size letter.
Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),
t(binary), f(float), a(address), i(instruction), c(char) and s(string).
Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
The specified number of objects of the specified size are printed
according to the format.
Defaults for format and size letters are those previously used.
Default count is 1. Default address is following last thing printed
with this command or "print".
example:
backtrac / bt | 查看各级函数调用及参数 |
finish | 连续运行到当前函数返回为止,然后停下来等待命令 |
frame(或f) 帧编号 | 选择栈帧 |
info(或i) locals | 查看当前栈帧局部变量的值 |
list(或l) | 列出源代码,接着上次的位置往下列,每次列10行 |
list 行号 | 列出从第几行开始的源代码 |
list 函数名 | 列出某个函数的源代码 |
next(或n) | 执行下一行语句 |
print(或p) | 打印表达式的值,通过表达式可以修改变量的值或者调用函数 |
quit(或q) | 退出gdb 调试环境 |
set var | 修改变量的值 |
start | 开始执行程序,停在main 函数第一行语句前面等待命令 |
step(或s) | 执行下一行语句,如果有函数调用则进入到函数中 |
break(或b) 行号 | 在某一行设置断点 |
break 函数名 | 在某个函数开头设置断点 |
break ... if ... | 设置条件断点 |
delete breakpoints 断点号 | 删除断点 |
disable breakpoints 断点号 | 禁用断点 |
enable 断点号 | 启用断点 |
info(或i) breakpoints | 查看当前设置了哪些断点 |
continue(或c) | 从当前位置开始连续运行程序 |
run(或r) | 从头开始连续运行程序 |
display 变量名 | 跟踪查看某个变量,每次停下来都显示它的值 |
undisplay 跟踪显示号 | 取消跟踪显示 |
watch | 设置观察点,就是数据断点,当程序访问某个存储单元时中断 |
info(或i) watchpoints | 查看当前设置了哪些观察点 |
x | 从某个位置开始打印存储单元的内容,全部当成字节来看,而不区分哪个字节属于哪个变量 |
gdb ./xxx
(gdb) help x
Examine memory: x/FMT ADDRESS.
ADDRESS is an expression for the memory address to examine.
FMT is a repeat count followed by a format letter and a size letter.
Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),
t(binary), f(float), a(address), i(instruction), c(char) and s(string).
Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
The specified number of objects of the specified size are printed
according to the format.
Defaults for format and size letters are those previously used.
Default count is 1. Default address is following last thing printed
with this command or "print".
example:
(gdb) x/7b input7b 是打印格式,b表示每个字节一组,7表示打印7组