代码之家  ›  专栏  ›  技术社区  ›  TCSGrad

如何在每次命中特定brkpt时执行的gdb脚本中编写命令?

gdb
  •  3
  • TCSGrad  · 技术社区  · 15 年前

    每次调用gdb时,我都需要调试一组特定的命令,所以我决定将它们放在.gdbinit中。一切都很好,直到我决定使用 commands (每次点击某个brkpt时执行一组gdb命令)。我的脚本如下:

    
    define setup
       handle SIGTRAP noprint nostop
       br 'Class1::Fun1(void)'
       run
       br 'Class2::Run(void)'
       c
       br Function2
       commands 3
         return 0 
         c
       end
    end
    

    Problem is , whenever I execute them one by one , it behaves perfectly , but when i source the script and run setup

    ,它在执行命令后的行为异常(不执行以前执行的操作)。

    有人能帮忙吗?

    1 回复  |  直到 15 年前
        1
  •  1
  •   alesplin    15 年前

    您可能没有将命令放在您认为是的断点上。

    如果我是你,我会将脚本修改为以下内容:

    define setup
       handle SIGTRAP noprint nostop
       br 'Class1::Fun1(void)'
       run
       br 'Class2::Run(void)'
       c
       br Function2
       commands
         return 0 
         c
       end
    end
    

    如果没有给定断点目标, commands 与最近的断点关联。这样,无论您的gdb会话中有什么其他断点,您的命令都将与函数2中的断点相关联。