User Tools

Site Tools


tech:gnu:gdb

GDB备忘录

1. 在GDB中引用Shell:
shell  ls
2. 设置输入参数:
set  args  inputfile  10
3. 断点:
b  main.c:12
b  getargs
b  3353  (current  context)
info  b
del  1
enable  1
disable  3
4. 观察点:
watch  var==value  (static  or  global)
watch  *((int  *)(0x888888))    (address  in  memory)

通常,添加观察点是为了捕捉运行时对某个变量进行修改的代码段,由于变量的可见范围是有限的,往往不能使用变量名来定义观察点,否则常常会出现如下信息:

Watchpoint X deleted because the program has left the block in which its expression is valid. 

这是由于C语言依赖函数调用来对变量进行操作,一旦进入到另一个函数调用,使用变量名定义的观察点便失效了。因此,往往使用如下的手法来跟踪变量的改动:

(gdb) p &var
$1 = 0x821e008
(gdb) watch (*(int *)(0x821e008))
Hardware watchpoint 3: *(int *) 136437768
(gdb) c
Continuing.
Hardware watchpoint 2: *(int *) 136437768

Old value = 8750528
New value = 0
5. 查看数据:
x  /16b  pBuf          (examine  memory  in  Bytes)
print  sParam        (查看变量)
6. 远程调试:
<target>  ./gdbserver  :1111  test
<host>  arm-linux-gdb  test
<host>  target  remote  x.x.x.x:1111
<host>  b  main
<host>  c
...
tech/gnu/gdb.txt · Last modified: 2014/11/10 08:22 (external edit)