Skip to content

Commit 6d80039

Browse files
committed
Improve setting line number when switching frames
1 parent 36e94f0 commit 6d80039

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

test/example/fib-exec.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ def fib(x: int) -> int:
33
return 1
44
return fib(x-1) + fib(x-2)
55

6-
command = "print(fib(2))"
7-
exec(command)
6+
exec_command = "print(fib(2))"
7+
8+
# Show that trepan3k can figure out what is getting called when exec is used:
9+
exec(exec_command)
10+
11+
# Show that trepan3k can figure out what is getting called when eval is used:
12+
eval_command = "fib(0)"
13+
print(eval(eval_command))
14+
15+
816
print("fib(2)= %d, fib(3) = %d, fib(4) = %d\n" % (fib(2), fib(3), fib(4)))

trepan/processor/command/frame.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def find_and_set_debugged_frame(self, frame, thread_id):
102102
self.stack, self.curindex = get_stack(frame, None, self.proc)
103103
self.proc.stack, self.proc.curindex = self.stack, self.curindex
104104
self.proc.frame_thread_name = thread_name
105+
self.proc.curframe = frame
106+
self.proc.list_lineno = self.curframe.f_lineno - 1
107+
self.proc.list_offset = self.curframe.f_lasti
105108
return
106109

107110
def one_arg_run(self, position_str):

trepan/processor/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def adjust_frame(proc_obj, pos: int, is_absolute_pos: bool):
7878
proc_obj.curindex = pos
7979
proc_obj.curframe = proc_obj.stack[proc_obj.curindex][0]
8080
proc_obj.location()
81-
proc_obj.list_lineno = None
81+
proc_obj.list_lineno = proc_obj.curframe.f_lineno - 1
8282
proc_obj.list_offset = proc_obj.curframe.f_lasti
8383
proc_obj.list_object = proc_obj.curframe
8484
proc_obj.list_filename = proc_obj.curframe.f_code.co_filename

0 commit comments

Comments
 (0)