8/22/2008

GDB 技巧

比较有用的命令:

1.p(print) Print value of expression EXP
p/x Print value of variable and format it are x(hex)
2.ptype Print definition of type TYPE
3.whatis Print data type of expression EXP
4.display Print value of expression EXP each time the program stops
5.define Define a new command name
6.layout Change the layout of windows. Layout names are: src/asm/split/regs

举例如下:

获取struct page结构的大小
(gdb) p mem_map
$80 = (struct page *) 0xc1000000
(gdb) p mem_map+1
$81 = (struct page *) 0xc1000020
(gdb) p/x 0xc1000020 - 0xc1000000
$82 = 0×20

p *array@len


自定义函数
(gdb) define nbt
Type commands for definition of “nbt”.
End with a line saying just “end”.
>next
>bt
>end
(gdb) nbt

TUI模式
layout src 仅显示源代码窗口
layout asm 仅显示汇编代码窗口
layout split 显示源代码和汇编代码窗口
layout regs 显示寄存器和源代码窗口,或者寄存器和汇编代码窗口
layout next , layout prev 切换窗口
C+l 刷新屏幕
C-x 1 只用一个窗口
C-x 2 用两个窗口,按多次会有不同两个窗口的组合形式
C-x o active 窗口转移
C-x s 进入和退出TUI SingleKey 模式
C-x a 退出TUI模式,回到传统模式

没有评论: