Skip to content

Commit 2cb0182

Browse files
committed
Improve stepi
Correct resetting opcode tracing when going from stepi to step or next Respect set-different behavior when going from line event to opcode
1 parent 2e08659 commit 2cb0182

5 files changed

Lines changed: 14 additions & 7 deletions

File tree

trepan/lib/core.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ def get_option(key: str) -> Any:
116116
self.stop_on_finish = False
117117

118118
self.last_lineno = None
119+
self.last_offset = None
119120
self.last_filename = None
120-
self.different_line = None
121+
self.different_line = True
121122

122123
# The reason we have stopped, e.g. 'breakpoint hit', 'next',
123124
# 'finish', 'step', or 'exception'.
@@ -344,7 +345,7 @@ def matches_condition(self, frame):
344345
return val
345346

346347
def is_stop_here(self, frame, event):
347-
"""Does the magic to determine if we stop here and run a
348+
"""Do the magic to determine if we stop here and run a
348349
command processor or not. If so, return True and set
349350
self.stop_reason; if not, return False.
350351
@@ -362,13 +363,16 @@ def is_stop_here(self, frame, event):
362363
# Do we want a different line and if so,
363364
# do we have one?
364365
lineno = frame.f_lineno
366+
offset = frame.f_lasti
365367
filename = frame.f_code.co_filename
366-
if self.different_line and event == "line":
368+
if self.different_line and event in ("line", "opcode"):
367369
if self.last_lineno == lineno and self.last_filename == filename:
368-
# print("is_stop_here(): not different")
369-
return False
370+
if event != "opcode" or self.last_offset == offset:
371+
# print("is_stop_here(): not different")
372+
return False
370373
pass
371374
self.last_lineno = lineno
375+
self.last_offset = offset
372376
self.last_filename = filename
373377

374378
if self.stop_level is not None:

trepan/processor/command/next.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def run(self, args):
5959
self.core.different_line = want_different_line(
6060
args[0], self.debugger.settings["different"]
6161
)
62+
if self.proc.frame is not None:
63+
self.proc.frame.f_trace_opcodes = False
6264
self.core.set_next(self.proc.frame, step_ignore)
6365
self.proc.continue_running = True # Break out of command read loop
6466
return True

trepan/processor/command/step.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def run(self, args):
125125
self.core.different_line = want_different_line(
126126
args[0], self.settings["different"]
127127
)
128+
if self.proc.frame is not None:
129+
self.proc.frame.f_trace_opcodes = False
128130
self.core.stop_level = None
129131
self.core.last_frame = None
130132
self.core.stop_on_finish = False

trepan/processor/command/stepi.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def run(self, args):
6767

6868
self.core.step_events = None
6969

70-
self.core.different_line = False
7170
# print("XXX", self.proc.frame)
7271
if self.proc.frame is not None:
7372
self.proc.frame.f_trace_opcodes = True

trepan/processor/print.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def prefix_for_source_text(source_text: str, maxwidth: int) -> str:
302302
is_pyasm = pyficache.is_python_assembly_file(remapped_file or filename)
303303
if is_pyasm:
304304
line, remapped_line_number = pyficache.get_pyasm_line(
305-
filename, line_number, is_source_line=True
305+
filename, line_number, is_source_line=True, offset=frame.f_lasti,
306306
)
307307
if remapped_line_number >= 0:
308308
# FIXME: +1 is because getlines is 0 origin.

0 commit comments

Comments
 (0)