Skip to content

Commit

Permalink
exec()/eval() can be loaded via LOAD_GLOBAL
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Nov 23, 2024
1 parent 430efc5 commit 661fd6d
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions trepan/lib/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,23 +338,25 @@ def get_call_function_name(frame) -> Optional[str]:
# labels = dis.findlabels(code)
linestarts = dict(dis.findlinestarts(co))
offset = frame.f_lasti
last_LOAD_NAME_offset = -1
last_LOAD_offset = -1
is_load_global = None
while offset >= 0:
opcode = code[offset]
if opname[opcode] == "LOAD_NAME":
last_LOAD_NAME_offset = offset
if opname[opcode] in ("LOAD_NAME", "LOAD_GLOBAL"):
last_LOAD_offset = offset
is_load_global = opname[opcode] == "LOAD_GLOBAL"
if offset in linestarts:
break
offset -= 2
pass

if last_LOAD_NAME_offset != -1:
offset = last_LOAD_NAME_offset + 1
if last_LOAD_offset != -1:
offset = last_LOAD_offset + 1
arg = code[offset]

# FIXME: Calculate arg value with EXTENDED_ARG
extended_arg = 0
extended_arg_offset = last_LOAD_NAME_offset - 2
extended_arg_offset = last_LOAD_offset - 2
opcode = code[extended_arg_offset]
while extended_arg_offset >= 0 and opcode == opc.EXTENDED_ARG:
extended_arg_offset -= 2
Expand All @@ -371,6 +373,9 @@ def get_call_function_name(frame) -> Optional[str]:
opcode = code[extended_arg_offset]

arg += extended_arg
if PYTHON_VERSION_TRIPLE >= (3, 11):
if is_load_global:
arg >>= 1
if arg < len(co.co_names):
return co.co_names[arg]
return None
Expand All @@ -380,6 +385,7 @@ def print_stack_entry(proc_obj, i_stack: int, style="none", opts={}):
frame_lineno = proc_obj.stack[len(proc_obj.stack) - i_stack - 1]
frame, lineno = frame_lineno
intf = proc_obj.intf[-1]
name = "??"
if frame is proc_obj.curframe:
intf.msg_nocr(format_token(Arrow, "->", style=style))
else:
Expand Down

0 comments on commit 661fd6d

Please sign in to comment.