2009-07-07 76 views
27

人们使用gdb打开和关闭调试, 当然还有很多其他调试工具 横跨各种不同的操作系统,with and without GUI and, maybe other fancy IDE features您使用/编写了哪些有用的GDB脚本?

我想知道what useful gdb scripts you have written and liked
虽然,我并不是指在something.gdb文件中存在一个命令转储,您可以从中获取大量数据,如果这样做会让您有一天的时间,请继续谈论它。

  • 让我们觉得条件处理控制回路功能更多的优雅和精致的编程写入调试和,甚至为白盒测试,当你开始debugging remote systems
  • 事情变得有趣(比如,通过串行/以太网接口)
  • 而且,如果目标是多处理器(和多线程)系统会怎么样?

让我把一个简单的情况为例...
说,

是连续走过了条目
定位在一个大的哈希表
被实现在一个糟糕的条目的脚本一个嵌入式平台。

这帮助我调试一个破碎的散列表。

回答

3

1.当试图获得一些第三方闭源DLL在Mono下使用我们的项目时,它给出了毫无意义的错误。因此,我使用Mono project的脚本。

2.我也有可能放弃它自己的信息标准输出在GDB使用,所以在断点处,我可以运行的功能,然后切正粘贴其输出到GDB的项目。

[编辑]

我的大多数海合会/ G ++的使用已经有一段时间,但我还记得使用宏,以充分利用GDB知道一些不透明的成员的事实的优点我有数据(该库是用调试编译的)。这非常有帮助。

4.我刚刚也发现了这个。它转储一个对象列表(来自全局“headMeterFix”SLL),其中包含另一个对象类型的动态数组。其中几次我用嵌套循环在宏:

define showFixes 
    set $i= headMeterFix 
    set $n = 0 
    while ($i != 0) 
    set $p = $i->resolved_list 
    set $x = $i->resolved_cnt 
    set $j = 0 
    printf "%08x [%d] = {", $i, $x 
    printf "%3d [%3d] %08x->%08x (D/R): %3d/%-3d - %3d/%-3d {", $n, $i, $x, $i->fix, $i->depend_cnt, dynArySizeDepList($i->depend_list), $i->resolved_cnt, dynArySizeDepList($i->resolved_list) 
    while ($j < $x) 
     printf " %08x", $p[$j] 
     set $j=$j+1 
    end 
    printf " }\n" 
    set $i = $i->next 
    set $n = $n+1 
    end 
end 
+0

Mono的gdb的参考是很好的 - 不知道。不确定我是否正确地获得了第二部分,是否描述了一个集成到项目构建中的函数,以便从GDB中的断点调用?这是一个很好的技巧,并且在我的一个项目中,对于慢速串行线调试接口很有用。 – nik 2009-09-19 04:26:32

+0

W.r.t第二部分,很久以前。但是,是的,它只是在GDB的一个断点处被调用的源代码。我认为这是一个试图在* __ builtin_frame_address(n)*帮助下追踪一些堆栈损坏的情况 - 这是一个宏,不能从GDB调用。 – NVRAM 2009-09-21 20:30:48

5

当调试AOLserver的SIGSEGV崩溃,我用下面的脚本来检查从GDB的TCL级调用堆栈:

define tcl_stack_dump 
    set $interp = *(Interp*)interp 
    set $frame = $interp->framePtr 
    while (0 != (CallFrame *)$frame->callerPtr != 0) 
    set $i = 0 

    if 0 != $frame->objv 
     while ($i < $frame->objc) 
     if (0 != $frame->objv[$i] && 0 != $frame->objv[$i]->bytes) 
      printf " %s", (char *)(CallFrame *)$frame->objv[$i]->bytes 
     end 

     set $i = $i + 1 
     end 
     printf "\n" 
    end 

    set $frame = (CallFrame *)$frame->callerPtr 
    end 
end 

document tcl_stack_dump 
    Print a list of TCL procs and arguments currently being called in an 
    interpreter. Most TCL C API functions beginning with Tcl[^_] will have a 
    Tcl_Interp parameter. Assumes the `interp' local C variable holds a 
    Tcl_Interp which is represented internally as an Interp struct. 

    See: 
    ptype Interp 
    ptype CallFrame 
    ptype Proc 
    ptype Command 
    ptype Namespace 
    ptype Tcl_Obj 
end