1.ubuntun14.04下安裝cgdb
cong@msi:~$ sudo apt-get install cgdb
a. cgdb分爲上面的vi窗口與下面的gdb窗口
-
ESC-->切到vi窗口
-
i -->切到gdb窗口
-
- -->減小vi窗口
-
= -->增大vi窗口
-
shift - -->減小很多vi窗口
- shift = -->增大很多vi窗口
空格添加/刪除斷點
c. gdbinit腳本不能用
- warning: File "/work/ffmpeg/jpeg/jpegc/.gdbinit" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
- To enable execution of this file add add-auto-load-safe-path /work/ffmpeg/jpeg/jpegc/.gdbinit line to your configuration file "/home/cong/.gdbinit".
- To completely disable this security protection add set auto-load safe-path / line to your configuration file "/home/cong/.gdbinit".
- For more information about this security protection see the "Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
- info "(gdb)Auto-loading safe path"
永久的方法: cong@msi:~$ cat .gdbinit
set auto-load safe-path /
二. gdb的使用
1. 斷點
a. 在指定文件中指定函數處設斷點
-
b <filename>: <func_name>
- b <filename>: <line_num> --> 例: break mm/slab.c:673
2.1
p {i,j,k,l} -->打印多個變量
display {i,j,k,l} --> 每執行一次都打印這幾個變量
undisplay --> 去掉display
3.2 打印某個地址處的數據
-
(gdb) help x
-
Examine memory: x/FMT ADDRESS.
-
ADDRESS is an expression for the memory address to examine.
-
FMT is a repeat count followed by a format letter and a size letter. -->顯示格式用兩部分表示
-
Format letters are: -->格式類型
-
o(octal),
-
x(hex),
-
d(decimal),
-
u(unsigned decimal),
-
t(binary),
-
f(float),
-
a(address),
-
i(instruction),
-
c(char),
-
s(string)
-
z(hex, zero padded on the left).
-
Size letters are: -->長度類型
-
b(byte),
-
h(halfword),
-
w(word),
-
g(giant, 8 bytes).
-
The specified number of objects of the specified size are printed
- according to the format.
(gdb) x /20xh inode->i_zone
0x2cb92 : 0xbbc7 0xbbc8 0xbbc9 0xbbca 0xbbcb 0xbbcc 0xbbcd 0xbbce
0x2cba2 : 0x0000 0x0000 0x0000 0x0000 0x0000 0x0b6b 0x9bdc 0x0000
0x2cbb2 : 0x0000 0x0301 0x0931 0x0001
注: 要用display自動顯示--> display /40wx 0xc0101f80
-
(gdb) display /5i
$pc -->pc是gdb的一個內部變量,打印當前的5條彙編指令
-
1: x/5i $pc
-
=> 0x1111dc <system_call>: push %eax
-
0x1111dd <system_call+1>: cld
-
0x1111de <system_call+2>: push %gs
-
0x1111e0 <system_call+4>: push %fs
-
0x1111e2 <system_call+6>: push %es
-
(gdb) ni -->
ni(nexti) 或si(stepi)進行彙編指令級調試
- 0x001111dd in system_call ()