Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2121921
  • 博文数量: 438
  • 博客积分: 3871
  • 博客等级: 中校
  • 技术积分: 6075
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-10 00:11
个人简介

邮箱: wangcong02345@163.com

文章分类

全部博文(438)

文章存档

2017年(15)

2016年(119)

2015年(91)

2014年(62)

2013年(56)

2012年(79)

2011年(16)

分类: LINUX

2016-07-01 19:22:30

一. ubuntu 14.04 下安装cgdb
1.ubuntun14.04下安装cgdb
cong@msi:~$ sudo apt-get install cgdb
2. 使用: cgdb ./hello就可以了
a. cgdb分为上面的vi窗口与下面的gdb窗口
  1. ESC-->切到vi窗口
  2. i -->切到gdb窗口
  3. - -->减小vi窗口
  4. = -->增大vi窗口
  5.  shift - -->减小很多vi窗口
  6.  shift = -->增大很多vi窗口
b.断点
空格添加/删除断点
c. gdbinit脚本不能用
  1. warning: File "/work/ffmpeg/jpeg/jpegc/.gdbinit" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
  2. 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".
  3. To completely disable this security protection add    set auto-load safe-path /    line to your configuration file "/home/cong/.gdbinit".
  4. For more information about this security protection see the  "Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
  5.         info "(gdb)Auto-loading safe path"
临时的方法: 在gdb的命令行里面  source .gdbinit
永久的方法: cong@msi:~$ cat .gdbinit 
set auto-load safe-path /
二. gdb的使用
1. 断点
a. 在指定文件中指定函数处设断点
  1. b <filename>: <func_name>
  2. b <filename>: <line_num>   --> 例: break mm/slab.c:673
2. 打印
2.1 
{i,j,k,l}            -->打印多个变量
display {i,j,k,l}   --> 每执行一次都打印这几个变量
undisplay           --> 去掉display

3.2 打印某个地址处的数据
  1. (gdb) help x
  2. Examine memory: x/FMT ADDRESS.
  3. ADDRESS is an expression for the memory address to examine.
  4. FMT is a repeat count followed by a format letter and a size letter-->显示格式用两部分表示
  5. Format letters are:                     -->格式类型 
  6.     o(octal),
  7.     x(hex),
  8.     d(decimal),
  9.     u(unsigned decimal),
  10.     t(binary),
  11.     f(float),
  12.     a(address),
  13.     i(instruction),
  14.     c(char),
  15.     s(string)
  16.     z(hex, zero padded on the left).
  17. Size letters are:                        -->长度类型 
  18.     b(byte),
  19.     h(halfword),
  20.     w(word),
  21.     g(giant, 8 bytes).
  22. The specified number of objects of the specified size are printed
  23. according to the format.
例如要按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自动显示--> display /40wx 0xc0101f80

2.3 gdb汇编级调试
  1. (gdb) display /5i $pc                  -->pc是gdb的一个内部变量,打印当前的5条汇编指令
  2. 1: x/5i $pc
  3. => 0x1111dc <system_call>:    push %eax
  4.    0x1111dd <system_call+1>:    cld
  5.    0x1111de <system_call+2>:    push %gs
  6.    0x1111e0 <system_call+4>:    push %fs
  7.    0x1111e2 <system_call+6>:    push %es
  8. (gdb) ni                              --> ni(nexti) 或si(stepi)进行汇编指令级调试
  9. 0x001111dd in system_call ()

1. ddd一启动就显示忙,关闭ddd时提示 GDB ddd is still busy
    rm -rf ~/.ddd

阅读(3018) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~