Skip to content

Commit d1d4e6a

Browse files
committed
pyasm and exec/eval handling improvements
1 parent 6d80039 commit d1d4e6a

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

trepan/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def write_wrapper(*args, **kwargs):
212212
info = disassemble_file(
213213
mainpyfile,
214214
outstream=fd,
215-
asm_format="extended-bytes",
215+
asm_format="extended",
216216
show_source=False,
217217
)
218218
code_module = info[1]

trepan/processor/command/list.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def run(self, args):
143143
return
144144

145145
if last > max_line:
146-
self.msg("End position changed from %d to last line %d " % (last, max_line))
146+
# self.msg("End position changed from %d to last line %d " % (last, max_line))
147147
last = max_line
148148

149149
bplist = self.core.bpmgr.bplist
@@ -160,6 +160,8 @@ def run(self, args):
160160
try:
161161
if is_pyasm:
162162
lineno = first
163+
opts["strip_nl"] = True
164+
163165
# FIXME add approximate
164166
line, pyasm_line_index = pyficache.get_pyasm_line(filename, lineno, is_source_line=True, opts=opts)
165167
proc.list_lineno = lineno
@@ -243,7 +245,7 @@ def doit(cmd, args):
243245

244246
# doit(lcmd, ['list', "python3-trepan/test/example/00_chained-compare-cpython-314.pyasm:3"])
245247

246-
# Note: osp is defined abouve
248+
# Note: osp is defined above
247249
doit(lcmd, ['list', "osp:1"])
248250
# print('--' * 10)
249251

trepan/processor/print.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def print_source_line(msg, lineno, line, event_str=None, is_pyasm: bool = False)
8383
"""Print out a source line of text , e.g. the second
8484
line in:
8585
(/tmp.py:2): <module>
86-
L -- 2 import sys,os
86+
-- 2 import sys,os
8787
(trepan3k)
8888
8989
We define this method
@@ -106,16 +106,21 @@ def print_source_location_info(
106106
fn_name=None,
107107
f_lasti=None,
108108
remapped_file=None,
109+
remapped_line_number: int=-1,
110+
remapped_column_number: int=-1,
109111
):
110-
"""Print out a source location , e.g. the first line in
112+
"""Print out a source location, e.g. the first line in
111113
line in:
112114
(/tmp.py:2:4 @21): <module>
113-
L -- 2 import sys,os
115+
-- 2 import sys,os
114116
(trepan3k)
115117
"""
116118
col_str = f":{column_number}" if column_number >= 0 else ""
117119
if remapped_file and filename != remapped_file:
118-
mess = f"({remapped_file}:{line_number}{col_str} remapped {filename}"
120+
if remapped_line_number != -1:
121+
mess = f"({remapped_file}:{remapped_line_number} remapped {filename}:{line_number}"
122+
else:
123+
mess = f"({remapped_file}:{line_number}{col_str} remapped {filename}"
119124
else:
120125
mess = f"({filename}:{line_number}{col_str}"
121126
if f_lasti and f_lasti != -1:
@@ -202,6 +207,10 @@ def prefix_for_source_text(source_text: str, maxwidth: int) -> str:
202207
if "<string>" == filename:
203208
if remapped_file := pyficache.main.code2tempfile.get(frame.f_code):
204209
filename = remapped_file
210+
_, remapped_line_number = pyficache.unmap_file_line(
211+
remapped_file, line_number
212+
)
213+
205214
elif dbgr_obj.eval_string:
206215
remapped_file = filename
207216
filename = pyficache.unmap_file(filename)
@@ -238,7 +247,6 @@ def prefix_for_source_text(source_text: str, maxwidth: int) -> str:
238247
deparsed.text,
239248
tempdir=proc_obj.settings("tempdir"),
240249
)
241-
# FIXME: pyficache remaps seems backwards
242250
filename = remapped_file
243251

244252
else:
@@ -288,13 +296,13 @@ def prefix_for_source_text(source_text: str, maxwidth: int) -> str:
288296

289297
pyficache.update_cache(filename)
290298

291-
is_pyasm = filename.endswith(".pyasm")
299+
is_pyasm = pyficache.is_python_assembly_file(remapped_file or filename)
292300
if is_pyasm:
293-
opts = opts.copy()
294-
line, _ = pyficache.get_pyasm_line(
295-
filename, line_number, is_source_line=True, opts=opts
301+
line, remapped_line_number = pyficache.get_pyasm_line(
302+
filename, line_number, is_source_line=True
296303
)
297304
else:
305+
remapped_line_number = -1 # -1 means no remapping
298306
line = pyficache.getline(filename, line_number, opts)
299307

300308
if not line:
@@ -326,7 +334,7 @@ def prefix_for_source_text(source_text: str, maxwidth: int) -> str:
326334
# try with good ol linecache and consider fixing pyficache
327335
lines = linecache.getlines(filename)
328336
temp_name = filename
329-
if lines and not filename.endswith(".pyasm"):
337+
if lines and not pyficache.is_python_assembly_file(filename):
330338
# FIXME: DRY code with version in cmdproc.py print_location
331339
prefix = osp.basename(temp_name).split(".")[0] + "-"
332340
fd = NamedTemporaryFile(
@@ -397,8 +405,9 @@ def prefix_for_source_text(source_text: str, maxwidth: int) -> str:
397405
line_number,
398406
column_number,
399407
fn_name,
400-
remapped_file=remapped_file,
401408
f_lasti=last_i,
409+
remapped_file=remapped_file,
410+
remapped_line_number=remapped_line_number,
402411
)
403412
if line and len(line.strip()) != 0:
404413
if proc_obj.event:

0 commit comments

Comments
 (0)