summaryrefslogtreecommitdiffstats
path: root/Lib/dis.py
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@gmail.com>2022-05-06 14:18:09 (GMT)
committerGitHub <noreply@github.com>2022-05-06 14:18:09 (GMT)
commit93a666b5a56919a3633a3897dfdb9bddfb9614f0 (patch)
tree3567f32fdf0aa2787c06e1aa5bac3cd2237339e9 /Lib/dis.py
parenta79001ee16b3ea8b5d0fad595c969d9e1b7627f3 (diff)
downloadcpython-93a666b5a56919a3633a3897dfdb9bddfb9614f0.zip
cpython-93a666b5a56919a3633a3897dfdb9bddfb9614f0.tar.gz
cpython-93a666b5a56919a3633a3897dfdb9bddfb9614f0.tar.bz2
gh-90997: Show cached inline values in `dis` output (#92360)
Diffstat (limited to 'Lib/dis.py')
-rw-r--r--Lib/dis.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/Lib/dis.py b/Lib/dis.py
index c0e5367..53c6269 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -6,8 +6,14 @@ import collections
import io
from opcode import *
-from opcode import __all__ as _opcodes_all
-from opcode import _nb_ops, _inline_cache_entries, _specializations, _specialized_instructions
+from opcode import (
+ __all__ as _opcodes_all,
+ _cache_format,
+ _inline_cache_entries,
+ _nb_ops,
+ _specializations,
+ _specialized_instructions,
+)
__all__ = ["code_info", "dis", "disassemble", "distb", "disco",
"findlinestarts", "findlabels", "show_code",
@@ -437,9 +443,6 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
cache_counter = 0
for offset, op, arg in _unpack_opargs(code):
if cache_counter > 0:
- if show_caches:
- yield Instruction("CACHE", 0, None, None, '',
- offset, None, False, None)
cache_counter -= 1
continue
if linestarts is not None:
@@ -494,6 +497,17 @@ def _get_instructions_bytes(code, varname_from_oparg=None,
yield Instruction(_all_opname[op], op,
arg, argval, argrepr,
offset, starts_line, is_jump_target, positions)
+ if show_caches and cache_counter:
+ for name, caches in _cache_format[opname[deop]].items():
+ data = code[offset + 2: offset + 2 + caches * 2]
+ argrepr = f"{name}: {int.from_bytes(data, sys.byteorder)}"
+ for _ in range(caches):
+ offset += 2
+ yield Instruction(
+ "CACHE", 0, 0, None, argrepr, offset, None, False, None
+ )
+ # Only show the actual value for the first cache entry:
+ argrepr = ""
def disassemble(co, lasti=-1, *, file=None, show_caches=False, adaptive=False):
"""Disassemble a code object."""