Skip to content

Commit e56048b

Browse files
committed
Extend "set patsub"; sync with trepan2
1 parent 82141a1 commit e56048b

4 files changed

Lines changed: 22 additions & 11 deletions

File tree

trepan/lib/core.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import os.path as osp
2828

2929
# External packages
30+
import pyficache
3031
import tracer
3132

3233
# Our local modules
@@ -174,6 +175,8 @@ def canonic(self, filename):
174175
pass
175176
canonic = osp.realpath(osp.normcase(canonic))
176177
self.filename_cache[filename] = canonic
178+
canonic = pyficache.unmap_file(canonic)
179+
177180
return canonic
178181

179182
def canonic_filename(self, frame):

trepan/lib/stack.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,7 @@ def format_stack_entry(
109109
s = format_token(Mformat.Function, funcname, highlight=color)
110110

111111
args, varargs, varkw, local_vars = inspect.getargvalues(frame)
112-
if "<module>" == funcname and ([], None, None,) == (
113-
args,
114-
varargs,
115-
varkw,
116-
):
112+
if "<module>" == funcname and ([], None, None,) == (args, varargs, varkw,):
117113
is_module = True
118114
if is_exec_stmt(frame):
119115
fn_name = format_token(Mformat.Function, "exec", highlight=color)
@@ -229,9 +225,12 @@ def check_path_with_frame(frame, path):
229225
if bc_size and bc_size != my_size:
230226
return False, "bytecode and local files mismatch"
231227
if fs_size and fs_size != my_size:
232-
return False, (
233-
"frame file size, %d bytes, and local file size, %d bytes, on file %s mismatch"
234-
% (fs_size, my_size, path)
228+
return (
229+
False,
230+
(
231+
"frame file size, %d bytes, and local file size, %d bytes, on file %s mismatch"
232+
% (fs_size, my_size, path)
233+
),
235234
)
236235
return True, None
237236

trepan/processor/cmdproc.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ def print_location(proc_obj):
229229
remapped_file = None
230230
pass
231231
pass
232+
elif pyficache.main.remap_re_hash:
233+
remapped_file = pyficache.remap_file_pat(filename, pyficache.main.remap_re_hash)
232234
elif m and m.group(1) in sys.modules:
233235
remapped_file = m.group(1)
234236
pyficache.remap_file(filename, remapped_file)
@@ -390,6 +392,7 @@ def __init__(self, core_obj, opts=None):
390392

391393
self.preloop_hooks = []
392394
self.postcmd_hooks = []
395+
self.remap_file_re = None
393396

394397
self._populate_cmd_lists()
395398

@@ -443,6 +446,13 @@ def add_preloop_hook(self, hook, position=-1, nodups=True):
443446
self.preloop_hooks.insert(position, hook)
444447
return True
445448

449+
def add_remap_pat(self, pat, replace, clear_remap=True):
450+
self.remap_re_hash[re.compile(pat)] = (pat, replace)
451+
pyficache.main.add_remap_pat(pat, replace, clear_remap)
452+
if clear_remap:
453+
self.file2file_remap = {}
454+
pyficache.file2file_remap = {}
455+
446456
# To be overridden in derived debuggers
447457
def defaultFile(self):
448458
"""Produce a reasonable default."""

trepan/processor/command/set_subcmd/patsub.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ class SetPatSub(Mbase_subcmd.DebuggerSubcommand):
3838
"""
3939

4040
in_list = True
41+
max_args = 2
4142
min_abbrev = len("pats")
43+
min_args = 2
4244
short_help = "Set pattern substitution rule"
4345

4446
def run(self, args):
45-
if len(args) != 2:
46-
self.errmsg("Expecting two arguments; got %d." % len(args))
47-
return
4847
self.proc.add_remap_pat(args[0], args[1])
4948

5049
pass

0 commit comments

Comments
 (0)