| 45 | |
| 46 | |
| 47 | class LineBreakpoint(object): |
| 48 | def __init__(self, breakpoint_id, line, condition, func_name, expression, suspend_policy="NONE", hit_condition=None, is_logpoint=False): |
| 49 | self.breakpoint_id = breakpoint_id |
| 50 | self.line = line |
| 51 | self.condition = condition |
| 52 | self.func_name = func_name |
| 53 | self.expression = expression |
| 54 | self.suspend_policy = suspend_policy |
| 55 | self.hit_condition = hit_condition |
| 56 | self._hit_count = 0 |
| 57 | self._hit_condition_lock = threading.Lock() |
| 58 | self.is_logpoint = is_logpoint |
| 59 | |
| 60 | @property |
| 61 | def has_condition(self): |
| 62 | return bool(self.condition) or bool(self.hit_condition) |
| 63 | |
| 64 | def handle_hit_condition(self, frame): |
| 65 | if not self.hit_condition: |
| 66 | return False |
| 67 | ret = False |
| 68 | with self._hit_condition_lock: |
| 69 | self._hit_count += 1 |
| 70 | expr = self.hit_condition.replace("@HIT@", str(self._hit_count)) |
| 71 | try: |
| 72 | ret = bool(eval(expr, frame.f_globals, frame.f_locals)) |
| 73 | except Exception: |
| 74 | ret = False |
| 75 | return ret |
| 76 | |
| 77 | |
| 78 | class FunctionBreakpoint(object): |