gdb使用记录

gdb使用记录

用于记录日常调试用到的方法,而不是简单的命令说明

首先还是先将用过的命令列出
命令:缩写:说明
run:r:执行程序
break:b:设置断点
print:p:打印变量内容
next:n:执行到下一条语句
step:s:进入函数执行(gdb官方说法是Step program until it reaches a different source line.)
continue:c:继续执行
backtrace:bt:打印调用堆栈
frame::显示当前堆栈信息
finish::完成当前函数的执行(gdb手册的官方说法是Execute until selected stack frame returns.此处的函数为通俗说法)
examine:x:打印内存内容
until:u:完成当前循环的(不过在很多情况下并非如此,gdb手册的官方说法是Execute until the program reaches a source line greater than the current or a specified location (same args as break command) within the current frame.)
jump:j:跳到指定的位置执行
handle::选择gdb对信号的处理方式
thread::进行线程之间的切换
info::提供相应的信息
display::每次完成执行显示变量内容
watch::观察变量的变化,在变量发生变化时程序中断
delete:d:删除断点(break)/观察点(watch)/显示点(display)

常用的手段
1、重定向。run 0<input.file 1>output.file或者set args 0<input.file 1>output.file
2、重复执行代码(在同一函数内)。b line_number \n j line_number\n
3、打印内存。x/8xb address,以16进制方式打印8个字节

配置.gdbinit
set print pretty on
set print object on
handle SIGUSR1 nostop noprint

posted @ 2014-09-26 16:29  惡盈好謙  阅读(209)  评论(0编辑  收藏  举报