0

I am using the GDB Python interface to handle Breakpoints

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

This works as expected. The hit_count is increased after the "stop" method returns.

Now when I want to use a conditional breakpoint:

bp.condition="some_value==2"

it is not working as expected. The stop method is always executed regardless whether the condition is true or false. If the stop method returns "True" the breakpoint will only halt the program if the condition is also true. The hit_count is increased after the Stop method returns and the condition holds.

So it seems as if GDB is only applying the condition check after the Stop method was called.

How can I ensure that the Stop method is only called when the condition holds?

1 Answer 1

1

How can I ensure that the Stop method is only called when the condition holds?

Currently, you can't. See bpstat_check_breakpoint_conditions() in gdb/breakpoint.c

Relevant portions:

  /* 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);
      ...
    }

So the python stop method is always called before the condition is evaluated. You can implement your condition in python though, e.g. using gdb.parse_and_eval, if you want to write expressions in the source language.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.