cgdb---ubuntu14.04下安装cgdb及gdb的使用

前端之家收集整理的这篇文章主要介绍了cgdb---ubuntu14.04下安装cgdb及gdb的使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
一. ubuntu 14.04 下安装cgdb@H_502_2@@H_502_2@
1.ubuntun14.04下安装cgdb@H_502_2@
cong@msi:~$ sudo apt-get install cgdb@H_502_2@
2. 使用:cgdb ./hello就可以了
a. cgdb分为上面的vi窗口与下面的gdb窗口
  1. ESC-@H_502_2@>@H_502_2@切到vi窗口
    @H_502_2@
  2. i>@H_502_2@切到gdb窗口
  3. >@H_502_2@减小vi窗口
  4. =@H_502_2@>@H_502_2@增大vi窗口
  5. shift>@H_502_2@减小很多vi窗口
  6. shift>@H_502_2@增大很多vi窗口
b.断点
空格添加/删除断点
c. gdbinit脚本不能用@H_502_2@
  • warning@H_502_2@:@H_502_2@File@H_502_2@"/work/ffmpeg/jpeg/jpegc/.gdbinit"@H_502_2@auto@H_502_2@-@H_502_2@loading has been declined by your `auto@H_502_2@-@H_502_2@load safe@H_502_2@-@H_502_2@path@H_502_2@'@H_502_2@@H_502_2@set@H_502_2@@H_502_2@to@H_502_2@@H_502_2@"$debugdir:$datadir/auto-loa@H_502_2@d".@H_502_2@
  • To@H_502_2@enable execution of this file addadd@H_502_2@-@H_502_2@auto@H_502_2@load@H_502_2@safe@H_502_2@path@H_502_2@/@H_502_2@work@H_502_2@ffmpeg@H_502_2@jpeg@H_502_2@jpegc@H_502_2@/@H_502_2@.@H_502_2@gdbinit@H_502_2@@H_502_2@lineto@H_502_2@your configuration file@H_502_2@"/home/cong/.gdbinit"@H_502_2@To@H_502_2@completely disable this security protection add set@H_502_2@load safe@H_502_2@/@H_502_2@ @H_502_2@lineFor@H_502_2@more information about this security protection see the "Auto-loading safe path"section@H_502_2@in@H_502_2@the GDB manual@H_502_2@.@H_502_2@E@H_502_2@.@H_502_2@g@H_502_2@.@H_502_2@,@H_502_2@run from the shell@H_502_2@:@H_502_2@
  • info"(gdb)Auto-loading safe path"@H_502_2@
  • 临时的方法:在gdb的命令行里面 source .gdbinit@H_502_2@
    永久的方法:cong@msi:~$ cat .gdbinit@H_502_2@
    set auto-load safe-path /@H_502_2@
    二. gdb的使用@H_502_2@@H_502_2@
    1. 断点
    a. 在指定文件中指定函数处设断点
    b<@H_502_2@filename>@H_502_2@:@H_502_2@<@H_502_2@func_name>@H_502_2@
    @H_502_2@
  • b<@H_502_2@line_num>@H_502_2@ --> 例:break mm/slab.c:673
  • @H_502_2@2. 打印
    2.1
    p {i,j,k,l} -->打印多个变量@H_502_2@
    display {i,l} --> 每执行一次都打印这几个变量
    undisplay --> 去掉display

    3.2 打印某个地址处的数据
    (@H_502_2@gdb)@H_502_2@help x
    @H_502_2@
  • Examine memory:@H_502_2@x/@H_502_2@FMT ADDRESS.@H_502_2@
  • ADDRESSis@H_502_2@an expressionfor@H_502_2@the memory addressto@H_502_2@examine.@H_502_2@
  • FMTis@H_502_2@a repeat count followed by a format letterand@H_502_2@a size letter.-->显示格式用@H_502_2@两部分表示@H_502_2@@H_502_2@
  • Format letters are: -->格式类型@H_502_2@
  • o(@H_502_2@octal)@H_502_2@,@H_502_2@
  • x(@H_502_2@hex@H_502_2@502_2@
  • d(@H_502_2@decimal502_2@
  • u(@H_502_2@unsigned decimal502_2@
  • t(@H_502_2@binary502_2@
  • f(@H_502_2@float502_2@
  • a(@H_502_2@address502_2@
  • i(@H_502_2@instruction502_2@
  • c(@H_502_2@char502_2@
  • sstring@H_502_2@)@H_502_2@
  • z502_2@zero paddedon@H_502_2@theleft@H_502_2@.@H_502_2@
  • Size letters are: -->长度类型@H_502_2@@H_502_2@
  • b(@H_502_2@byte502_2@
  • h(@H_502_2@halfword502_2@
  • w(@H_502_2@word502_2@
  • g(@H_502_2@giant502_2@8 bytes.@H_502_2@
  • The specified number of objects of the specified size are printed
  • accordingto@H_502_2@the format.@H_502_2@
  • 例如要按16进制显示类型为short的inode->i_zone
    (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自动显示-->@H_502_2@ display /40wx 0xc0101f80@H_502_2@

    2.3 gdb汇编级调试
    )@H_502_2@display/@H_502_2@5i $pc -->pc是gdb的一个内部变量,打印当前的5条汇编指令@H_502_2@@H_502_2@
    @H_502_2@
  • 1/@H_502_2@5i $pc
  • >@H_502_2@0x1111dc<@H_502_2@system_call:@H_502_2@push%@H_502_2@eax
  • 0x1111dd+@H_502_2@1:@H_502_2@cld
  • 0x1111de+@H_502_2@2%@H_502_2@gs
  • 0x1111e0+@H_502_2@4%@H_502_2@fs
  • 0x1111e2+@H_502_2@6%@H_502_2@es
  • )@H_502_2@ni --> ni(nexti) 或si(stepi)进行汇编指令级调试@H_502_2@@H_502_2@
  • 0x001111ddin@H_502_2@system_call(@H_502_2@)@H_502_2@
  • 猜你在找的Ubuntu相关文章