|
54 | 54 | #DEBUG = False |
55 | 55 | DEBUG = True |
56 | 56 |
|
| 57 | +BREAKPOINT_STR = '#break' |
| 58 | + |
57 | 59 |
|
58 | 60 | # simple sandboxing scheme: |
59 | 61 | # |
@@ -329,6 +331,13 @@ def __init__(self, cumulative_mode, heap_primitives, finalizer_func, disable_sec |
329 | 331 |
|
330 | 332 | self.executed_script = None # Python script to be executed! |
331 | 333 |
|
| 334 | + # if there is at least one line that ends with BREAKPOINT_STR, |
| 335 | + # then activate "breakpoint mode", where execution should stop |
| 336 | + # ONLY at breakpoint lines. |
| 337 | + self.breakpoints = [] |
| 338 | + |
| 339 | + self.prev_lineno = -1 # keep track of previous line just executed |
| 340 | + |
332 | 341 |
|
333 | 342 | def get_frame_id(self, cur_frame): |
334 | 343 | return self.frame_ordered_ids[cur_frame] |
@@ -470,6 +479,15 @@ def interaction(self, frame, traceback, event_type): |
470 | 479 | top_frame = tos[0] |
471 | 480 | lineno = tos[1] |
472 | 481 |
|
| 482 | + # stop at both the breakpoint line and the next executed line, |
| 483 | + # so that if you set only ONE breakpoint, OPT shows the state |
| 484 | + # before and after that line gets executed. |
| 485 | + if self.breakpoints: |
| 486 | + if not ((lineno in self.breakpoints) or (self.prev_lineno in self.breakpoints)): |
| 487 | + return |
| 488 | + |
| 489 | + self.prev_lineno = lineno |
| 490 | + |
473 | 491 |
|
474 | 492 | # debug ... |
475 | 493 | ''' |
@@ -854,6 +872,12 @@ def create_encoded_stack_entry(cur_frame): |
854 | 872 | def _runscript(self, script_str): |
855 | 873 | self.executed_script = script_str |
856 | 874 |
|
| 875 | + for (i, line) in enumerate(self.executed_script.splitlines()): |
| 876 | + line_no = i + 1 |
| 877 | + if line.endswith(BREAKPOINT_STR): |
| 878 | + self.breakpoints.append(line_no) |
| 879 | + |
| 880 | + |
857 | 881 | # When bdb sets tracing, a number of call and line events happens |
858 | 882 | # BEFORE debugger even reaches user's code (and the exact sequence of |
859 | 883 | # events depends on python version). So we take special measures to |
|
0 commit comments