Skip to content

Commit 153fdc4

Browse files
committed
Adjust for addition of column numbers
1 parent 4ecb2fb commit 153fdc4

9 files changed

Lines changed: 76 additions & 42 deletions

File tree

test/data/highlight-310.right

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(gcd.py:1): <module>
1+
(gcd.py:1:0): <module>
22
-> 1 #!/usr/bin/env python3
33
Set basename is on.
44
Set event is on.

test/data/step-311.right

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
(gcd.py:1): <module>
1+
(gcd.py:1:0): <module>
22
-> 1 #!/usr/bin/env python3
33
Set basename is on.
44
Set event is on.
55
Set stopping is off.
66
Set confirmation is off.
77
line - gcd.py:2
8-
(gcd.py:2): <module>
8+
(gcd.py:2:0): <module>
99
-- 2 """Greatest Common Divisor
1010
2 -> """Greatest Common Divisor
1111
Set stopping is on.
1212
line - gcd.py:11
13-
(gcd.py:11): <module>
13+
(gcd.py:11:0): <module>
1414
-- 11 import sys
1515
11 -> import sys
1616
Set stopping is off.
1717
line - gcd.py:14
1818
line - gcd.py:29
1919
line - gcd.py:44
20-
(gcd.py:44): <module>
20+
(gcd.py:44:3): <module>
2121
-- 44 if __name__ == "__main__":
2222
44 -> if __name__ == "__main__":
2323
trepan3k: That's all, folks...

test/functional/fn_helper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def compare_output(right: list, d):
7575
pass
7676
pass
7777
pass
78+
if right != got:
79+
breakpoint()
7880
assert right == got
7981
return
8082

trepan/lib/stack.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import re
2626
from opcode import opname
2727
from reprlib import repr
28-
from types import FrameType
28+
from types import CodeType, FrameType
2929
from typing import Optional, Tuple
3030

3131
import xdis
@@ -77,18 +77,25 @@ def count_frames(frame: FrameType, count_start=0) -> int:
7777
return 1000
7878
return count
7979

80-
def get_column_start(frame: FrameType) -> int:
80+
def get_column_start_from_frame(frame: FrameType) -> int:
8181
"""
8282
Given a code frame, return the start column for that
8383
frame. (The line number is found in frame.f_lineno).
8484
If we can't find a column number, return -1.
8585
"""
86-
co_positions = frame.f_code.co_positions()
87-
instruction_number = frame.f_lasti // 2
86+
return get_column_start_from_code(frame.f_code, frame.f_lasti)
87+
88+
def get_column_start_from_code(code: CodeType, f_lasti: int) -> int:
89+
"""
90+
Given a code object, return the start column for that
91+
frame. (The line number is found in frame.f_lineno).
92+
If we can't find a column number, return -1.
93+
"""
94+
co_positions = code.co_positions()
95+
instruction_number = f_lasti // 2
8896
position_list = list(co_positions)
8997
position_tuple = position_list[instruction_number]
9098
if position_tuple is not None:
91-
assert position_tuple[0] == frame.f_lineno
9299
if position_tuple[2] is not None:
93100
return position_tuple[2]
94101
return -1

trepan/processor/cmdproc.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
# Note: the module name pre 3.2 is repr
2929
from reprlib import Repr
30+
from types import FrameType
3031
from typing import Optional, Set, Tuple
3132

3233
import pyficache
@@ -36,6 +37,7 @@
3637
import trepan.exception as Mexcept
3738
import trepan.lib.display as Mdisplay
3839
import trepan.lib.file as Mfile
40+
from trepan.lib.stack import get_column_start_from_frame
3941
import trepan.lib.thred as Mthread
4042
import trepan.misc as Mmisc
4143
from trepan.interfaces.script import ScriptInterface
@@ -77,15 +79,15 @@ def arg_split(s, posix=False):
7779
return args_list
7880

7981

80-
def get_stack(f, t, botframe, proc_obj=None) -> Tuple[list, int]:
82+
def get_stack(frame: FrameType, t, botframe, proc_obj=None) -> Tuple[list, int]:
8183
"""Return a stack of frames which the debugger will use for in
8284
showing backtraces and in frame switching. As such various frame
8385
that are really around may be excluded unless we are debugging the
8486
sebugger. Also we will add traceback frame on top if that
8587
exists."""
8688

87-
def false_fn(f):
88-
return false_fn
89+
def false_fn(_):
90+
return False
8991

9092
def fn_is_ignored(f):
9193
return proc_obj.core.ignore_filter.is_excluded(f)
@@ -98,20 +100,23 @@ def fn_is_ignored(f):
98100
pass
99101
pass
100102
stack = []
101-
if t and t.tb_frame is f:
103+
if t and t.tb_frame is frame:
102104
t = t.tb_next
103-
while f is not None:
104-
if exclude_frame(f):
105+
curframe = frame
106+
while curframe is not None:
107+
if exclude_frame(curframe):
105108
break # See commented alternative below
106-
stack.append((f, f.f_lineno))
109+
column_number = get_column_start_from_frame(curframe)
110+
stack.append((frame, frame.f_lineno, column_number))
107111
# bdb has:
108112
# if f is botframe: break
109-
f = f.f_back
113+
curframe = curframe.f_back
110114
pass
111115
stack.reverse()
112116
i = max(0, len(stack) - 1)
113117
while t is not None:
114-
stack.append((t.tb_frame, t.tb_lineno))
118+
column_number = get_column_start_from_frame(t.tb_frame)
119+
stack.append((t.tb_frame, t.tb_lineno, column_number))
115120
t = t.tb_next
116121
pass
117122
return stack, i
@@ -744,14 +749,20 @@ def setup(self):
744749
None,
745750
) # NOQA
746751
pass
752+
self.column_number = -1
747753
if self.frame or exc_traceback:
748754
self.stack, self.curindex = get_stack(self.frame, exc_traceback, None, self)
749755
self.curframe = self.stack[self.curindex][0]
750756
self.thread_name = Mthread.current_thread_name()
757+
self.list_offset = self.curframe.f_lasti
758+
self.list_object = self.curframe
759+
self.column_number = get_column_start_from_frame(self.curframe)
751760
if exc_traceback:
752761
self.list_lineno = traceback.extract_tb(exc_traceback, 1)[0][1]
753-
self.list_offset = self.curframe.f_lasti
754-
self.list_object = self.curframe
762+
# FIXME: Do any other fields need to be changed?
763+
else:
764+
self.list_lineno = self.curframe.f_lineno
765+
pass
755766
else:
756767
self.stack = self.curframe = self.botframe = None
757768
pass

trepan/processor/command/info_subcmd/threads.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import sys
1818
import threading
1919

20-
from trepan.lib.stack import format_stack_entry, get_column_start
20+
from trepan.lib.stack import format_stack_entry, get_column_start_from_frame
2121
from trepan.lib import thred as Mthread
2222

2323
# Our local modules
@@ -63,7 +63,7 @@ def stack_trace(self, frame):
6363
self.core.ignore_filter.is_excluded(frame)
6464
or self.settings["dbg_trepan"]
6565
):
66-
column_start = get_column_start(frame)
66+
column_start = get_column_start_from_frame(frame)
6767
s = format_stack_entry(self, (frame, frame.f_lineno, column_start))
6868
self.msg(" " * 4 + s)
6969
pass
@@ -177,7 +177,7 @@ def run(self, args):
177177
s += " thread id: %d" % thread_id
178178
pass
179179
s += "\n "
180-
column_start = get_column_start(frame)
180+
column_start = get_column_start_from_frame(frame)
181181
s += format_stack_entry(
182182
self,
183183
(frame, frame.f_lineno, column_start),

trepan/processor/command/jump.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright (C) 2009, 2013, 2015, 2020, 2023-2024 Rocky Bernstein
3+
# Copyright (C) 2009, 2013, 2015, 2020, 2023-2025 Rocky Bernstein
44
#
55
# This program is free software: you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
@@ -21,6 +21,7 @@
2121
from trepan.processor.cmdproc import print_location
2222

2323
# Our local modules
24+
from trepan.lib.stack import get_column_start_from_frame
2425
from trepan.processor.command.base_cmd import DebuggerCommand
2526

2627

@@ -91,9 +92,11 @@ def run(self, args):
9192
# Set to change position, update our copy of the stack,
9293
# and display the new position
9394
self.proc.curframe.f_lineno = lineno
95+
column = get_column_start_from_frame(self.proc.curframe)
9496
self.proc.stack[self.proc.curindex] = (
9597
self.proc.stack[self.proc.curindex][0],
9698
lineno,
99+
column,
97100
)
98101
print_location(self.proc)
99102
except ValueError as e:

trepan/processor/command/skip.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2009, 2013, 2015, 2020, 2024 Rocky Bernstein
2+
# Copyright (C) 2009, 2013, 2015, 2020, 2024-2025 Rocky Bernstein
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
@@ -15,6 +15,7 @@
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
# Our local modules
18+
from trepan.lib.stack import get_column_start_from_frame
1819
from trepan.processor.command.base_cmd import DebuggerCommand
1920
from trepan.processor.cmdproc import print_location
2021
from trepan.lib.bytecode import next_linestart
@@ -69,9 +70,11 @@ def run(self, args):
6970
# Set to change position, update our copy of the stack,
7071
# and display the new position
7172
self.proc.curframe.f_lineno = lineno
73+
column = get_column_start_from_frame(self.proc.curframe)
7274
self.proc.stack[self.proc.curindex] = (
7375
self.proc.stack[self.proc.curindex][0],
7476
lineno,
77+
column,
7578
)
7679
print_location(self.proc)
7780
self.proc.continue_running = True # Break out of command read loop

trepan/processor/print.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,25 @@ def print_source_line(msg, lineno, line, event_str=None, is_pyasm: bool = False)
9494

9595

9696
def print_source_location_info(
97-
print_fn, filename, lineno, fn_name=None, f_lasti=None, remapped_file=None
97+
print_fn,
98+
filename,
99+
line_number: int,
100+
column_number: int,
101+
fn_name=None,
102+
f_lasti=None,
103+
remapped_file=None,
98104
):
99105
"""Print out a source location , e.g. the first line in
100106
line in:
101-
(/tmp.py:2 @21): <module>
107+
(/tmp.py:2:4 @21): <module>
102108
L -- 2 import sys,os
103109
(trepan3k)
104110
"""
111+
col_str = f":{column_number}" if column_number >= 0 else ""
105112
if remapped_file and filename != remapped_file:
106-
mess = f"({remapped_file}:{lineno} remapped {filename}"
113+
mess = f"({remapped_file}:{line_number}{col_str} remapped {filename}"
107114
else:
108-
mess = f"({filename}:{lineno}"
115+
mess = f"({filename}:{line_number}{col_str}"
109116
if f_lasti and f_lasti != -1:
110117
mess += " @%d" % f_lasti
111118
pass
@@ -152,13 +159,13 @@ def prefix_for_filename(deparsed_text: str) -> str:
152159
eval_kind = None
153160
i_stack = min(i_stack, len(proc_obj.stack) - 1)
154161
while i_stack >= 0:
155-
frame, lineno = proc_obj.stack[i_stack]
162+
frame, line_number, column_number = proc_obj.stack[i_stack]
156163

157164
# Before starting a program a location for a module with
158165
# line number 0 may be reported. Treat that as though
159166
# we were on the first line.
160-
if frame.f_code.co_name == "<module>" and lineno == 0:
161-
lineno = 1
167+
if frame.f_code.co_name == "<module>" and line_number == 0:
168+
line_number = 1
162169

163170
i_stack -= 1
164171

@@ -181,7 +188,7 @@ def prefix_for_filename(deparsed_text: str) -> str:
181188
tempdir=proc_obj.settings("tempdir"),
182189
)
183190
pyficache.remap_file(filename, remapped_file)
184-
filename, lineno = pyficache.unmap_file_line(filename, lineno)
191+
filename, line_number = pyficache.unmap_file_line(filename, line_number)
185192
pass
186193
pass
187194
elif "<string>" == filename:
@@ -250,7 +257,7 @@ def prefix_for_filename(deparsed_text: str) -> str:
250257
opts["style"] = "plain"
251258
opts["output"] = "plain"
252259

253-
line = pyficache.getline(filename, lineno, opts)
260+
line = pyficache.getline(filename, line_number, opts)
254261

255262
if not line:
256263
if (
@@ -266,8 +273,8 @@ def prefix_for_filename(deparsed_text: str) -> str:
266273
temp_filename, _ = deparse_and_cache(
267274
co, proc_obj.errmsg, tempdir=tempdir
268275
)
269-
lineno = 1
270-
# _, lineno = pyficache.unmap_file_line(temp_filename, lineno, True)
276+
line_number = 1
277+
# _, line_number = pyficache.unmap_file_line(temp_filename, line_number, True)
271278
if temp_filename:
272279
filename = temp_filename
273280
pass
@@ -299,7 +306,7 @@ def prefix_for_filename(deparsed_text: str) -> str:
299306

300307
pass
301308

302-
line = linecache.getline(filename, lineno, proc_obj.curframe.f_globals)
309+
line = linecache.getline(filename, line_number, proc_obj.curframe.f_globals)
303310
if not line:
304311
m = re.search("^<frozen (.*)>", filename)
305312
if m and m.group(1):
@@ -313,13 +320,13 @@ def prefix_for_filename(deparsed_text: str) -> str:
313320
remapped_file = sys.modules[remapped_file].__file__
314321
pyficache.remap_file(filename, remapped_file)
315322
line = linecache.getline(
316-
remapped_file, lineno, proc_obj.curframe.f_globals
323+
remapped_file, line_number, proc_obj.curframe.f_globals
317324
)
318325
else:
319326
remapped_file = m.group(1)
320327
code = proc_obj.curframe.f_code
321328
filename, line = cmdfns.deparse_getline(
322-
code, remapped_file, lineno, opts
329+
code, remapped_file, line_number, opts
323330
)
324331
pass
325332
pass
@@ -342,7 +349,8 @@ def prefix_for_filename(deparsed_text: str) -> str:
342349
print_source_location_info(
343350
intf_obj.msg,
344351
filename,
345-
lineno,
352+
line_number,
353+
column_number,
346354
fn_name,
347355
remapped_file=remapped_file,
348356
f_lasti=last_i,
@@ -351,7 +359,7 @@ def prefix_for_filename(deparsed_text: str) -> str:
351359
if proc_obj.event:
352360
print_source_line(
353361
intf_obj.msg,
354-
lineno,
362+
line_number,
355363
line,
356364
proc_obj.event2short[proc_obj.event],
357365
is_pyasm,

0 commit comments

Comments
 (0)