diff options
author | Brandt Bucher <brandtbucher@microsoft.com> | 2022-06-17 17:26:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-17 17:26:20 (GMT) |
commit | 05d83a706c320792246cb4a06a1153c26475a578 (patch) | |
tree | 501919fb37ccd508c31747f8b28464d830fd0228 /Lib/dis.py | |
parent | 1353b8a4bcef22d985a0b6a186c96439fd540ea8 (diff) | |
download | cpython-05d83a706c320792246cb4a06a1153c26475a578.zip cpython-05d83a706c320792246cb4a06a1153c26475a578.tar.gz cpython-05d83a706c320792246cb4a06a1153c26475a578.tar.bz2 |
GH-91389: Fix dis position information for CACHEs (GH-93663) (GH-93921)
(cherry picked from commit f8e576be0a7cd38f753f31cf4178db81a602fc32)
Diffstat (limited to 'Lib/dis.py')
-rw-r--r-- | Lib/dis.py | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -492,17 +492,29 @@ 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 _inline_cache_entries[deop]: - 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: + caches = _inline_cache_entries[deop] + if not caches: + continue + if not show_caches: + # We still need to advance the co_positions iterator: + for _ in range(caches): + next(co_positions, ()) + continue + for name, size in _cache_format[opname[deop]].items(): + for i in range(size): + offset += 2 + # Only show the fancy argrepr for a CACHE instruction when it's + # the first entry for a particular cache value and the + # instruction using it is actually quickened: + if i == 0 and op != deop: + data = code[offset: offset + 2 * size] + argrepr = f"{name}: {int.from_bytes(data, sys.byteorder)}" + else: argrepr = "" + yield Instruction( + "CACHE", CACHE, 0, None, argrepr, offset, None, False, + Positions(*next(co_positions, ())) + ) def disassemble(co, lasti=-1, *, file=None, show_caches=False, adaptive=False): """Disassemble a code object.""" |