GDB Python断点类接口和条件断点



我正在使用GDB Python接口来处理断点

import gdb
class MyBP(gdb.Breakpoint):
    def stop(self):
        print("stop called "+str(self.hit_count))
        return True
bp = MyBP("test.c:22")

这是按预期工作的。"停止"方法返回后,hit_count增加了。

现在我想使用有条件的断点:

bp.condition="some_value==2"

它无法正常工作。无论条件是正确还是错误,停止方法始终执行。如果停止方法返回" true",则只有在条件也是正确的情况下,断点才会停止程序。停止方法返回并保持条件保持后,hit_count增加了。

因此,似乎GDB仅在调用停止方法之后应用条件检查。

如何确保仅在条件持有时才调用停止方法?

如何确保仅在条件保持时才调用停止方法?

目前,您不能。请参阅 gdb/breakpoint.c

中的bpstat_check_breakpoint_conditions((

相关部分:

  /* Evaluate extension language breakpoints that have a "stop" method
     implemented.  */
  bs->stop = breakpoint_ext_lang_cond_says_stop (b);
  ...
          condition_result = breakpoint_cond_eval (cond);
  ...
  if (cond && !condition_result)
    {
      bs->stop = 0;
    }
  else if (b->ignore_count > 0)
    {
      ...
      ++(b->hit_count);
      ...
    }

因此,在评估条件之前,总是调用Python停止方法。您可以在Python中实现您的状况,例如使用gdb.parse_and_eval,如果要以源语言编写表达式。

最新更新