Skip to content

Commit fa8469b

Browse files
committed
Allow modules in list and disasm for a filename
1 parent 8809bf2 commit fa8469b

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

trepan/processor/command/disassemble.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ def run(self, args):
173173
opts["end_line"] = last = None
174174
do_parse = False
175175
bytecode_file = None
176+
elif inspect.ismodule(obj):
177+
proc.current_command = proc.current_command.replace(args[1], __file__, 1)
178+
args[1] = __file__
176179

177180
if do_parse:
178181
(
@@ -271,6 +274,11 @@ def doit(cmd, args):
271274
command = DisassembleCommand(cp)
272275
prefix = "-" * 20 + " disassemble "
273276

277+
# FIXME
278+
# Note osp has already been imported
279+
print(prefix + "osp")
280+
doit(command, ["disassemble", "osp"])
281+
274282
print(prefix + 'doit')
275283
doit(command, ['disassemble', 'doit()'])
276284

@@ -279,10 +287,6 @@ def doit(cmd, args):
279287

280288
doit(command, ["disassemble", f"{doit_return_line}, {doit_return_line+2}"])
281289

282-
# FIXME
283-
# print(prefix + "os.path")
284-
# doit(command, ["disassemble", "os.path"])
285-
286290
print(prefix + "cp.errmsg()")
287291
doit(command, ["disassemble", "cp.errmsg()"])
288292

trepan/processor/command/list.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class ListCommand(DebuggerCommand):
6363
list foo.py:5 # List starting from line 5 of file foo.py
6464
list foo() # List starting from function foo
6565
list os.path:5 # List starting from line 5 of module os.path
66+
# Note: os.path should have been imported
6667
list os.path:5, 6 # list lines 5 and 6 of os.path
6768
list os.path:5, +1 # Same as above. +1 is an offset
6869
list os.path:5, 1 # Same as above, since 1 < 5.
@@ -93,7 +94,23 @@ def run(self, args):
9394
curframe = proc.curframe
9495
if filename is None:
9596
return
96-
filename = pyficache.unmap_file(pyficache.resolve_name_to_path(filename))
97+
resolved_name = pyficache.resolve_name_to_path(filename)
98+
if not osp.exists(resolved_name):
99+
# See of resuled_filename is a module name:
100+
# START HERE with try: eval, except
101+
try:
102+
obj = self.proc.eval(filename, show_error=False)
103+
except Exception:
104+
self.errmsg(f"File {filename} not found")
105+
return
106+
else:
107+
if inspect.ismodule(obj):
108+
resolved_name = pyficache.resolve_name_to_path(obj.__file__)
109+
else:
110+
self.errmsg(f"Can't use {obj} as a file-like object")
111+
return
112+
113+
filename = pyficache.unmap_file(resolved_name)
97114
is_pyasm = filename.endswith(".pyasm")
98115

99116
# We now have range information. Do the listing.
@@ -207,6 +224,10 @@ def doit(cmd, args):
207224
cmdproc.setup()
208225
lcmd = ListCommand(cmdproc)
209226

227+
# Note: osp is defined abouve
228+
doit(lcmd, ['list', "osp:1"])
229+
# print('--' * 10)
230+
210231
print("--" * 10)
211232
# doit(lcmd, ['list'])
212233

0 commit comments

Comments
 (0)