随笔-19  评论-21  文章-0  trackbacks-0

经常使用这些工具,有那么些功能却不常用,也不知道。

1. gdb

a.  .gdbinit

gdb运行时会首先加载 ~/.gdbinit文件

例如:我在debug时,每次都需要进行handle SIGBUS noprint pass来处理SIGBUS信号,这种情况就可以把它写入 .gdbinit文件。

在.gdbinit里也可以定义函

  eg:  在.gdbinit里定义print_regs
     def print_regs
        i r eax ebx ecx edx
     end

  (gdb) print_regs
  eax            0xbffff4a4    -1073744732
  ebx            0x28bff4    2670580
  ecx            0x902c5562    -1876142750
  edx            0x1    1

b. 在GDB中,可以使用命令up或down在栈中移动!上下移动栈,查询变量和内存的值。这个有什么好处呢?

看看如下的例子就知道了

test0(a){
    int m = GetNumber();
    test1(b);
}
test1(b){
    test3(c);
}

执行到test3(c)的时候,如果你想看看test0中的变量m的值是多少,怎么办?这时就可以使用up了,up到test0的栈时就可以直接print m的值了。很方便!

c. 设置临时断点 tbreak

d. 如果watch变量不好用,可以watch它的地址

e. return 和jump命令

  return <expr> :return 从函数退出,跳过剩下的语句。

  jump :跳过或重新执行当前函数中的语句。

f. shared library

可以显示哪些DLL已经载入,并且为尚未载入调试信息的DLL载入调试信息

g. 按下Ctrl + C,只是暂停程序,程序还可以继续运行。

h. 注意设置条件断点有可能会影响执行速度。

如果需要在某条执行特别频繁的语句上设置条件断点,则比较好的方法是在代码中直接插入源代码做判断,这样速度更快。

2.  strace

在进行以下高度时可以考虑使用strace:

a. 查明哪些文件被打开了

b. 在OS全程中未捕获的错误或中断。用strace查找返回的错误值,并再次核对源代码 是否处理了这些值

c. 调试性能问题,看OS调用的频率

d. 查看内存分配、释放、映射的情况。

3. gcc

gcc -E 可以观察预处理器的输出。这样,宏出错时可以看看为什么。

4. 设置LD_DEBUGS有点用


$ export LD_DEBUG=libs
$ ./a.out
      1715:    find library=libc.so.6 [0]; searching
      1715:     search cache=/etc/ld.so.cache
      1715:      trying file=/lib/i386-linux-gnu/libc.so.6
      1715:   
      1715:   
      1715:    calling init: /lib/i386-linux-gnu/libc.so.6
      1715:   
      1715:   
      1715:    initialize program: ./a.out
      1715:   
      1715:   
      1715:    transferring control: ./a.out
      1715:   
hello
      1715:   
      1715:    calling fini: ./a.out [0]
      1715:   
      1715:   
      1715:    calling fini: /lib/i386-linux-gnu/libc.so.6 [0]
      1715:   
$ export LD_DEBUG=help
$ ./a.out
Valid options for the LD_DEBUG environment variable are:

  libs        display library search paths
  reloc       display relocation processing
  files       display progress for input file
  symbols     display symbol table processing
  bindings    display information about symbol binding
  versions    display version dependencies
  all         all previous options combined
  statistics  display relocation statistics
  unused      determined unused DSOs
  help        display this help message and exit

To direct the debugging output into a file instead of standard output
a filename can be specified using the LD_DEBUG_OUTPUT environment variable.

posted on 2011-05-17 21:14 hex108 阅读(2545) 评论(3)  编辑 收藏 引用 所属分类: Program

评论:
# You’ve got it in one. Cuodln’t have put it better. 2011-05-25 21:10 | Bubber
You’ve got it in one. Cuodln’t have put it better.  回复  更多评论
  
# re: gdb,strace那些不常用的功能 2011-05-26 09:48 | hex108
@Bubber
They're short,so I put them together.  回复  更多评论
  

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理