【问题标题】:Gdb conditional regex breakGdb 条件正则表达式中断
【发布时间】:2014-03-07 04:38:02
【问题描述】:

gdb 是否允许条件正则表达式中断?

我有一个源文件 timer.c、一个 int64_t 滴答声和一个返回它的函数 timer_ticks()。 都没有

rbreak timer.c:.如果滴答数 >= 24

也没有

rbreak timer.c:.如果 ticks_ticks() >= 24

放置任何断点。

如果我删除了正则表达式部分或条件部分,则会设置断点。

【问题讨论】:

    标签: c regex debugging gdb


    【解决方案1】:

    不幸的是,不,它没有。

    但是,有解决方法。

    您想有条件地破坏文件中的每个函数,不是吗?

    如果是,您可以使用此answer 作为起点,然后创建条件中断。

    所以,第一步:获取文件中的函数列表:

    nm a.out | grep ' T ' | addr2line  -fe a.out |
       grep -B1 'foo\.cpp' | grep -v 'foo\.cpp' > funclist
    

    下一步:创建一个创建中断的 gdb 脚本:

    sed 's/^/break /' funclist | sed 's/$/ if ticks>=24/' > stop-in-foo.gdb
    

    最后,在 gdb 中导入脚本:

    (gdb): source stop-in-foo.gdb
    

    【讨论】:

      【解决方案2】:

      这是完成它的一种方法。这需要几个步骤,并且需要对gdb 的输出进行一些目视检查。

      首先,运行rbreak 命令并记下它设置的断点编号。

      (gdb) rbreak f.c:.
      Breakpoint 1 at 0x80486a7: file f.c, line 41.
      int f();
      Breakpoint 2 at 0x80486ac: file f.c, line 42.
      int g();
      Breakpoint 3 at 0x80486b1: file f.c, line 43.
      int h();
      Breakpoint 4 at 0x8048569: file f.c, line 8.
      int main(int, char **);
      

      现在,遍历该范围的断点并使用cond 命令为每个断点添加条件:

      (gdb) set $i = 1
      (gdb) while ($i <= 4)
       >cond $i ticks >= 24
       >set $i = $i + 1
       >end
      (gdb) info breakpoints
      Num     Type           Disp Enb Address    What
      1       breakpoint     keep y   0x080486a7 in f at f.c:41
              stop only if ticks >= 24
      2       breakpoint     keep y   0x080486ac in g at f.c:42
              stop only if ticks >= 24
      3       breakpoint     keep y   0x080486b1 in h at f.c:43
              stop only if ticks >= 24
      4       breakpoint     keep y   0x08048569 in main at f.c:8
              stop only if ticks >= 24
      

      【讨论】:

      • 请注意,正如 here 所指出的,ada 模式要求分配为 :=
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-19
      • 1970-01-01
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多