1.ubuntun14.04下安装cgdb
cong@msi:~$ sudo apt-get install cgdb
2. 使用:cgdb ./hello就可以了
a. cgdb分为上面的vi窗口与下面的gdb窗口
b.断点
空格添加/删除断点
c. gdbinit脚本不能用
warning:File"/work/ffmpeg/jpeg/jpegc/.gdbinit"auto-loading has been declined by your `auto-load safe-path'setto"$debugdir:$datadir/auto-load".@H_404_23@
Toenable execution of this file addadd-autoloadsafepath/workffmpegjpegjpegc/.gdbinitlinetoyour configuration file"/home/cong/.gdbinit"Tocompletely disable this security protection add setload safe/ lineFormore information about this security protection see the "Auto-loading safe path"sectioninthe GDB manual.E.g.,run from the shell:@H_404_23@
info"(gdb)Auto-loading safe path"@H_404_23@
临时的方法:在gdb的命令行里面 source .gdbinit
永久的方法:cong@msi:~$ cat .gdbinit
set auto-load safe-path /
二. gdb的使用
1. 断点
a. 在指定文件中指定函数处设断点
2. 打印
2.1
p {i,j,k,l} -->打印多个变量
display {i,l} --> 每执行一次都打印这几个变量
undisplay --> 去掉display
3.2 打印某个地址处的数据
(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
2.3 gdb汇编级调试
原文链接:https://www.f2er.com/ubuntu/355731.htmla. cgdb分为上面的vi窗口与下面的gdb窗口
空格添加/删除断点
c. gdbinit脚本不能用
永久的方法:cong@msi:~$ cat .gdbinit
set auto-load safe-path /
二. gdb的使用
1. 断点
a. 在指定文件中指定函数处设断点
2. 打印
2.1
p {i,j,k,l} -->打印多个变量
display {i,l} --> 每执行一次都打印这几个变量
undisplay --> 去掉display
3.2 打印某个地址处的数据
(gdb)help x
@H_404_23@ Examine memory:x/FMT ADDRESS.
@H_404_23@ ADDRESSisan expressionforthe memory addresstoexamine.
@H_404_23@ FMTisa repeat count followed by a format letteranda size letter.-->显示格式用两部分表示
@H_404_23@ Format letters are: -->格式类型
@H_404_23@ o(octal),
@H_404_23@ x(hex @H_404_23@
d(decimal @H_404_23@
u(unsigned decimal @H_404_23@
t(binary @H_404_23@
f(float @H_404_23@
a(address @H_404_23@
i(instruction @H_404_23@
c(char @H_404_23@
sstring)
@H_404_23@ zontheleft.
@H_404_23@ Size letters are: -->长度类型
@H_404_23@ b(byte @H_404_23@
h(halfword @H_404_23@
w(word @H_404_23@
g(giant.
@H_404_23@ The specified number of objects of the specified size are printed
@H_404_23@ accordingtothe format.@H_404_23@
例如要按16进制显示类型为short的inode->i_zone
@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@
(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
2.3 gdb汇编级调试
)display/5i $pc -->pc是gdb的一个内部变量,打印当前的5条汇编指令
@H_404_23@ 1/5i $pc
@H_404_23@ >0x1111dc<system_call:push%eax
@H_404_23@ 0x1111dd+1:cld
@H_404_23@ 0x1111de+2%gs
@H_404_23@ 0x1111e0+4%fs
@H_404_23@ 0x1111e2+6%es
@H_404_23@ )ni --> ni(nexti) 或si(stepi)进行汇编指令级调试
@H_404_23@ 0x001111ddinsystem_call()@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@
@H_404_23@