Chinaunix首页 | 论坛 | 博客
  • 博客访问: 248506
  • 博文数量: 22
  • 博客积分: 1806
  • 博客等级: 上尉
  • 技术积分: 272
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-16 20:10
文章分类

全部博文(22)

文章存档

2010年(6)

2009年(16)

分类: C/C++

2010-07-01 18:11:25

利用GDB7.0的反向调试(reverse debug)特性调试程序

 

GDB7.0 2009 10 6号份正式发布的,其提供了一个名为反向调试 (reverse debugReverse debugging, Process record and replay) 的新特性对于我们平常调试程序会有所帮助。

October 06, 2009: GDB 7.0 Released!

The latest version of GDB, version 7.0, is available for download.

Changes in this release include:

Support for native x86/x86_64 Darwin, x86_64 MinGW

Support for Lattice Mico32, x86/x86_64 DICOS, S+core 3 targets

gdbserver support for x86 Windows CE

Python scripting support

Reverse debugging, Process record and replay

Non-stop debugging

Multi-architecture debugging

Multi-inferior, multi-process debugging

See the NEWS file for a more complete and detailed list of what this release includes.

 

从字面上理解,平常我们的调试总是下一步,下一步来进行,而“反向调试”应该就是上一步,上一步,事实上,GDB7.0提供的确实也是这样的功能。在对一个较为复杂的软件程序进行调试时,我们往往无法做到一次性的把断点设置在最恰当的地方,所以经常会发现重要的代码执行路径已经错过。遇到这种情况,一般是重新启动调试会话,从头再来。而GDB7.0提供的反向调试功能使得我们无须重新启动调试程序,只要简单地让被调试进程反向执行到那个被怀疑的地方即可,该功能很明显的好处就是这无疑将极大地提高工作效率。

 

       废话少说,看实例,170上目录/home/gqk/gqk/gdb下已经有最新的gdb7.1程序,实例中几个命令查下文档就知道了,不用多说:O(_)O~

 

gqk/AC ~/gqk/gdb $ ls

gdb-7.1/  gdb.7.1*  gdb-7.1.tar.bz2  test*  test.c

gqk/AC ~/gqk/gdb $ ./gdb.7.1 -q

(gdb) exec-file test

(gdb) l

No symbol table is loaded.  Use the "file" command.

(gdb) file test

Reading symbols from /usr/src/home/gqk/gdb/test...done.

(gdb) l

1     #include

2     #include

3     int main()

4     {

5            int a = 100;

6            a ++;

7            a --;

8            a += 2;

9            a -= 3;

10         return 0;

(gdb) b 5

Breakpoint 1 at 0x8048304: file test.c, line 5.

(gdb) r

Starting program: /usr/src/home/gqk/gdb/test

 

Breakpoint 1, main () at test.c:5

5            int a = 100;

(gdb) record

(gdb) n

6            a ++;

(gdb) n

7            a --;

(gdb) p a

$1 = 101

(gdb) rn

6            a ++;

(gdb) p a

$2 = 100

(gdb) n

 

No more reverse-execution history.

main () at test.c:7

7            a --;

(gdb) p a

$3 = 101

(gdb) n

8            a += 2;

(gdb) p a

$4 = 100

(gdb) n

9            a -= 3;

(gdb) p a

$5 = 102

(gdb) n

10         return 0;

(gdb) p a

$6 = 99

(gdb) rn

9            a -= 3;

(gdb) p a

$7 = 102

(gdb)

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