Set Break
断点命令(break)缩写为b,格式如下:
- break function : b main
- break line : b 256
- break file:line : b app_main.c:256
- break file:function : b app_main.c:main
- break +offset : b +3
- break -offset : b -3
- break *addr : b *0x0811efd4
Set Catch
catch point作用是让程序在发生某种事件的时候停止运行。设置events如下:
- catch assert – Catch failed Ada assertions
- catch catch – Catch an exception
- catch exception – Catch Ada exceptions
- catch exec – Catch calls to exec
- catch fork – Catch calls to fork
- catch syscall – Catch system calls by their names and/or numbers
- catch throw – Catch an exception
- catch vfork – Catch calls to vfork
Show Backtrace
backtrace命令可以断点处执行显示栈帧,简写为bt,别名有where & info stack,格式如下:
- bt : show all
- bt N : show start N
- bt -N : show end N
- bt full : show all & locals
查看桢信息:
- frame n: 查看第n桢的信息, frame可以用f缩写
- frame addr: 查看pc地址为addr的桢的相关信息
- up n: 查看当前桢上面第n桢的信息
- down n: 查看当前桢下面第n桢的信息
查看更加详细的信息:
- info frame
- info frame n
- info frame addr
示例如下:
(cskygdb) info frame 1
Stack frame at 0x32aa9518:
pc = 0x4ce00 in app_ott_vod_detail_create_exec (ott/app_ott_vod_detail.c:606); saved pc 0x49fee
called by frame at 0x32aa9538, caller of frame at 0x32aa9500
source language c.
Arglist at 0x32aa9500, args: nAlbumNo=0, pName=0xa916d0 "危险关系", pPic=0x96e628 "/tmp/6C880089F646D38.jpg",
pVid=0xa916a8 "706afed05f"
Locals at 0x32aa9500, Previous frame's sp is 0x32aa9518
Saved registers:
r8 at 0x32aa9514, r15 at 0x32aa9510, pc at 0x32aa9510
上图中显示的信息有:
- 当前桢的地址: 0x32aa9518
- 当前桢PC: pc = 0x4ce00
- 当前桢函数: app_ott_vod_detail_create_exec (ott/app_ott_vod_detail.c:606)
- caller桢的PC: saved pc 0x49fee
- caller桢的地址: called by frame at 0x32aa9538
- callee桢的地址: caller of frame at 0x32aa9500
- 源代码所用的程序的语言(c/c++): source language c
- 当前桢的参数的地址及值: Arglist at at 0x32aa9500, args: nAlbumNo=0, pName=0xa916d0 “危险关系”, pPic=0x96e628 “/tmp/6C880089F646D38.jpg” …
- 当前相中局部变量的地址:Locals at 0x32aa9500, Previous frame’s sp is 0x32aa9518
- . 当前桢中存储的寄存器: Saved registers: r8 at 0x32aa9514, r15 at 0x32aa9510, pc at 0x32aa9510
info args:查看当前桢中的参数
(cskygdb) info args
window_name = 0x5650a8 "wnd_ott_vod_detail"
info locals:查看当前桢中的局部变量
(cskygdb) info locals
widget = 0x0
window = 0x0
info catch:查看当前桢中的异常处理器(exception handlers)
(cskygdb) info catch
print_frame_label_vars disabled.
示例2:
(cskygdb) info frame 3
Stack frame at 0x32aa9550:
pc = 0x4a40c in app_ott_vod_keypress (ott/app_ott_vod.c:489); saved pc 0x11cd86
called by frame at 0x32aa9568, caller of frame at 0x32aa9538
source language c.
Arglist at 0x32aa9538, args: widgetname=0x6c44d0 "wnd_ott_vod", usrdata=0x32aa963c
Locals at 0x32aa9538, Previous frame's sp is 0x32aa9550
Saved registers:
r8 at 0x32aa954c, r15 at 0x32aa9548, pc at 0x32aa9548
(cskygdb) frame 3
#3 0x0004a40c in app_ott_vod_keypress (widgetname=0x6c44d0 "wnd_ott_vod", usrdata=0x32aa963c) at ott/app_ott_vod.c:489
489 app_ott_page_ok_keypress(find_virtualkey(event->key.scancode));
(cskygdb) info args
widgetname = 0x6c44d0 "wnd_ott_vod"
usrdata = 0x32aa963c
(cskygdb) info locals
event = 0x32aa963c
__FUNCTION__ = "app_ott_vod_keypress"
(cskygdb) info catch
print_frame_label_vars disabled.
Show Variable & Registers
print命令可以显示变量,简写为p。
info registers可以显示寄存器,简写为info reg。
在寄存器名之前添加$,可以显示寄存器内容:
p &pc
支持的格式如下:
- x : 十六进制
- d : 十进制
- u : 无符号十进制
- o : 八进制
- t : 二进制
- a : 地址
- c : ASCII
- f : 浮点
- s : 字符串
用x命令可以显示内存内容,支持以上格式之外还支持:
i : 显示为汇编语言
使用x命令格式为 x/NFU ADDR,参数意义如下:
- ADDR : 希望显示的地址
- N : 重复次数
- F : 支持格式(x,d,u,o,t,a,c,f,s,i)
- U : 单位,下所示
- b : 字节
- h : 半字(2字节)
- w : 字(4字节,默认值)
- g : 双字(8字节)
反汇编存在命令:disassemble
show value命令显示历史中的最后10个值
attach到进程
条件断点
使用格式如下:
break 断点 if 条件
例如:
b main if mode==1
使用condition可以给已存在的断点添加或删除触发条件:
condition Bn
condition Bn 条件
反复执行
在指定的断点、监控点或捕获点忽略指定次数,格式如下:
ignore Bn N
类似命令如下:
- continue N
- step N
- stepi N
- next N
- nexti N
- finish
- until
- until ADDR
断点命令
指定程序在某个breakpoint处停下来后执行一串命令,格式:
commands [bnum]
… command-list …
end
指定程序在第bnum个breakpoint处停下来后,执行由command-list指定的命令串,
如果没有指定bnum,则对最后一个breakpoint生效,例子:
break foo if x>0
commands
silent
printf “x is %d\n”,x
continue
end
上面的例子含义:当x>0时,在foo函数处停下来,然后打印出x的值,然后继续运行程序