【问题标题】:What useful GDB scripts have you used/written?您使用/编写过哪些有用的 GDB 脚本?
【发布时间】:2009-07-07 19:14:54
【问题描述】:

人们使用gdb打开和关闭进行调试, 当然还有很多其他的调试工具 跨各种操作系统,with and without GUI and, maybe other fancy IDE features

我想知道what useful gdb scripts you have written and liked
虽然,我并不是指在 something.gdb 文件中转储命令以提取大量数据,如果这让你很开心,请继续讨论它。

  • 让我们考虑一下条件处理控制循环函数,它们是为了更优雅和更精细的编程来调试甚至可能用于白盒测试而编写的
  • 当您启动 debugging remote systems(例如,通过串行/以太网接口)时,事情会变得有趣
  • 如果目标是多处理器(和多线程)系统,该怎么办

让我举一个简单的案例作为例子......
说吧,

连续遍历条目的脚本
在大型哈希表中查找错误条目
这是在嵌入式平台上实现的。

这帮助我调试了一次损坏的哈希表。

【问题讨论】:

    标签: debugging scripting gdb


    【解决方案1】:

    这个脚本,不是我写的,漂亮地打印 STL 容器,例如矢量、地图等:http://www.yolinux.com/TUTORIALS/src/dbinit_stl_views-1.03.txt

    太棒了。

    【讨论】:

    • 这还有必要吗?
    【解决方案2】:

    在调试 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
    

    【讨论】:

      【解决方案3】:

      1. 当试图让一些 3rd 方闭源 DLL 在 Mono 下与我们的项目一起工作时,它给出了毫无意义的错误。因此,我求助于Mono project 的脚本。

      2. 我还有一个项目可以将自己的信息转储到 stdout 以在 GDB 中使用,所以在断点处,我可以运行该函数,然后剪切-n-将其输出粘贴到 GDB 中。

      [编辑]

      3. 我的大部分 GCC/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 
      

      【讨论】:

      • Mono gdb 参考很好——不知道。不确定我是否正确理解了您的第二部分,您是否描述了一个集成到项目构建中以从 GDB 中的断点调用的函数?这是一个很好的技巧,并且在我的一个项目中对慢速串行线路调试接口很有用。
      • W.r.t 第二部分,很久以前了。但是,是的,它是源代码,只能在 GDB 中的断点处调用。我认为这是试图在 __builtin_frame_address(n) 的帮助下追踪一些堆栈损坏——这是一个宏,不能从 GDB 调用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-30
      • 1970-01-01
      • 2010-10-05
      • 1970-01-01
      • 2011-01-11
      • 1970-01-01
      相关资源
      最近更新 更多