您使用/编写了哪些有用的GDB脚本?

nik*_*nik 28 debugging scripting gdb

人们使用gdb打开和关闭进行调试,当然在各种操作系统中有许多其他调试工具,有或没有GUI,可能还有其他奇特的IDE功能.

我想知道你编写和喜欢的有用的gdb脚本.
虽然,我并不是指在something.gdb您提供的文件中转储命令以提取大量数据,如果这样做了一天,请继续讨论它.

  • 让我们考虑条件处理,控制循环函数编写,以便更优雅和精致的编程进行调试,甚至可以用于白盒测试
  • 当您开始调试远程系统(例如,通过串行/以太网接口)时,事情变得有趣
  • 而且,如果目标是多处理器(和多线程)系统,该怎么办?

让我以一个简单的案例为例......
说,

在条目
上串行遍历的脚本,用于
在嵌入式平台上实现的大型哈希表中查找错误条目.

这帮我调试了一次破坏的哈希表.

Art*_*kii 10

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

非常棒.


mor*_*gil 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
Run Code Online (Sandbox Code Playgroud)