Skip to content

Commit 1996215

Browse files
committed
"info frame" understands eval/exec better
1 parent ea0bce1 commit 1996215

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

  • trepan/processor/command/info_subcmd

trepan/processor/command/info_subcmd/frame.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2015, 2023-2025 Rocky Bernstein <rocky@gnu.org>
2+
# Copyright (C) 2015, 2023-2026 Rocky Bernstein <rocky@gnu.org>
33
#
44
# This program is free software: you can redistribute it and/or modify
55
# it under the terms of the GNU General Public License as published by
@@ -21,7 +21,12 @@
2121
from trepan.lib.complete import complete_token
2222
from trepan.lib.disassemble import PYTHON_OPCODES as python_opcodes
2323
from trepan.lib.format import Function, Keyword, format_token
24-
from trepan.lib.stack import format_function_name, get_column_start_from_frame
24+
from trepan.lib.stack import (
25+
format_function_name,
26+
get_column_start_from_frame,
27+
get_exec_or_eval_string,
28+
is_eval_or_exec_stmt
29+
)
2530
from trepan.lib.thred import current_thread_name
2631
from trepan.processor import frame as Mframe
2732
from trepan.processor.print import format_code, format_frame
@@ -123,9 +128,12 @@ def run(self, args):
123128
function_name, formatted_func_name = format_function_name(frame, style=style)
124129
if function_name is None:
125130
formatted_func_name = "??"
126-
f_args, f_varargs, f_keywords, f_locals = inspect.getargvalues(frame)
127131
self.msg(f" function name: {formatted_func_name}")
128-
func_args = inspect.formatargvalues(f_args, f_varargs, f_keywords, f_locals)
132+
if is_eval_or_exec_stmt(frame):
133+
func_args = get_exec_or_eval_string(frame)
134+
else:
135+
f_args, f_varargs, f_keywords, f_locals = inspect.getargvalues(frame)
136+
func_args = inspect.formatargvalues(f_args, f_varargs, f_keywords, f_locals)
129137
formatted_func_signature = highlight_string(func_args, style=style).strip()
130138
self.msg(f" function args: {formatted_func_signature}")
131139

@@ -161,7 +169,9 @@ def run(self, args):
161169
if f_lasti >= 0:
162170
opname = python_opcodes.opname[code.co_code[f_lasti]]
163171
opname_formatted = format_token(Keyword, opname, style=style)
164-
self.msg(f" instruction offset and opname: {frame.f_lasti} {opname_formatted}")
172+
self.msg(
173+
f" instruction offset and opname: {frame.f_lasti} {opname_formatted}"
174+
)
165175
else:
166176
self.msg(f" instruction offset: {frame.f_lasti}")
167177

0 commit comments

Comments
 (0)