gdb 使用

1.计算一个结构体成员offset

p/x &((struct A *)0)->b 其中A表示结构体,b是成员

2.输入被调试程序输入参数:

r -sysdir /home/skyeye/android_test -system initrd_96M.img -data userdata.img -ramdisk  ramdisk.img -kernel zImage -show-kernel -verbose

3.breakpoint

 b cpu_arm_exec or

(gdb) b  *0x40000000
Breakpoint 3 at 0x40000000

查看断点信息:

(gdb) info breakpoints
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x000000000057bf50 in qemu_cpu_exec at /home/skyeye/s2e/s2e/qemu_android/cpus.c:562
    breakpoint already hit 2 times
2       breakpoint     keep y   0x0000000000513bb0 in cpu_arm_exec at /home/skyeye/s2e/s2e/qemu_android/cpu-exec.c:248
    breakpoint already hit 1 time
3       breakpoint     keep y   0x0000000040000000

4.查看某个变量

(gdb)  p/x *(struct CPUARMState *)0x0x1d9a010


5.查看某个地址的值:

(gdb) x/20i 0x40000000

6.查看寄存器

(gdb) info  registers 

7.查看变量类型:

(gdb) ptype env

(gdb) whatis env

8.查找变量:

(gdb) info variables env (查找env变量,可以着正则式);info variables查看所以变量。类似的查看函数,info functions 以及info  functions REX

9.查看类型定义:

(gdb) info types env 使用方法跟上面类似

10.signals :

info  signals

handle signal keywords...
Change the way GDB handles signal signal. signalcan be the number of a signal or its name (with or without the `SIG' at the beginning); a list of signal numbers of the form `low-high'; or the word `all', meaning all theknown signals. The keywords say what change to make.

The keywords allowed by the handle command can be abbreviated.Their full names are:

nostop
GDB should not stop your program when this signal happens. It maystill print a message telling you that the signal has come in.

stop
GDB should stop your program when this signal happens. This impliesthe print keyword as well.

print
GDB should print a message when this signal happens.

noprint
GDB should not mention the occurrence of the signal at all. Thisimplies the nostop keyword as well.

pass

noignore
GDB should allow your program to see this signal; your programcan handle the signal, or else it may terminate if the signal is fataland not handled. pass and noignore are synonyms.

nopass

ignore

GDB should not allow your program to see this signal.nopass and ignore are synonyms.

core dump:

If you can enable core dumps on that system, just run the program, let it crash, then pull the core dump off the target machine onto your development machine and load it into a GDB built to debug the target architecture - that should tell you exactly where the crash occurred. Just use GDB's core command to load the core file into the debugger.

  • To enable core dumps on the target:

    ulimit -c unlimited
  • pseudo-files that control how the core file will be named (cat these to see the current configuration, write to them to change the configuration):

    /proc/sys/kernel/core_pattern
    /proc/sys/kernel/core_uses_pid

On my system, once core dumps are enabled, a crashing program will write a file simply named "core" in the working directory. That's probably good enough for your purposes, but changing how the core dump file is named lets you keep a history of core dumps if that's necessary (maybe for a more intermittent problem).



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值