Skip to content

Commit 3d4d358

Browse files
committed
Small changes...
* Suggest import when a function is not found. * gcd.py better error message * info frame: change field name
1 parent 1c1c26b commit 3d4d358

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

test/example/gcd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def check_args():
1414
if len(sys.argv) != 3:
1515
# Rather than use sys.exit let's just raise an error
16-
raise Exception("Need to give two numbers")
16+
raise Exception(f"Need to give two numbers; got: {sys.argv}")
1717
for i in range(2):
1818
try:
1919
sys.argv[i+1] = int(sys.argv[i+1])

trepan/processor/command/info_subcmd/frame.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ def run(self, args):
154154
if f_lasti >= 0:
155155
opname = opc.opname[code.co_code[f_lasti]]
156156
opname_formatted = format_token(Keyword, opname, style=style)
157-
self.msg(f" last instruction: {frame.f_lasti} {opname_formatted}")
157+
self.msg(f" instruction offset and opname: {frame.f_lasti} {opname_formatted}")
158158
else:
159-
self.msg(f" last instruction: {frame.f_lasti}")
159+
self.msg(f" instruction offset: {frame.f_lasti}")
160160

161161
self.msg(f" code: {format_code(code, style)}")
162162
if frame.f_back:

trepan/processor/location.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,16 @@ def resolve_location(proc, location) -> Optional[Location]:
7979
return INVALID_LOCATION
8080

8181
if mod_func is None:
82-
msg = f"Object {location_method} is not known yet as a function, "
82+
# [1] DRY similar code [2] below
83+
msg = f"Object {location_method} is not known yet as a function."
8384
try:
8485
mod_func = eval(location_method, g, locals_dict)
8586
except Exception:
8687
proc.errmsg(msg)
88+
split_names = location_method.split(".")
89+
if len(split_names) > 1:
90+
proc.msg(f'Try importing {".".join(split_names[:-1])}?')
91+
8792
return INVALID_LOCATION
8893

8994
try:
@@ -202,10 +207,14 @@ def resolve_address_location(proc, location) -> Optional[Location]:
202207
if location.method:
203208
# Validate arguments that can't be done in parsing
204209
filename = offset = None
205-
msg = f"Object {location.method} is not known yet as a function, "
210+
msg = f"Object {location.method} is not known yet as a function."
211+
# [2] DRY simlar code above [1]
206212
try:
207213
mod_func = eval(location.method, g, locals_dict)
208214
except Exception:
215+
split_names = location_method.split(".")
216+
if len(split_names) > 1:
217+
proc.msg(f'Try importing {".".join(split_names[:-1])}?')
209218
proc.errmsg(msg)
210219
return INVALID_LOCATION
211220

0 commit comments

Comments
 (0)