diff options
author | Brandt Bucher <brandtbucher@microsoft.com> | 2022-06-16 20:49:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-16 20:49:32 (GMT) |
commit | f8e576be0a7cd38f753f31cf4178db81a602fc32 (patch) | |
tree | 71702a3e03a5d7c32ddda31096349a2dcfef03a4 /Lib/dis.py | |
parent | 4f85cec9e2077681b3dacc3108e646d509b720bf (diff) | |
download | cpython-f8e576be0a7cd38f753f31cf4178db81a602fc32.zip cpython-f8e576be0a7cd38f753f31cf4178db81a602fc32.tar.gz cpython-f8e576be0a7cd38f753f31cf4178db81a602fc32.tar.bz2 |
GH-91389: Fix dis position information for CACHEs (GH-93663)
Diffstat (limited to 'Lib/dis.py')
-rw-r--r-- | Lib/dis.py | 32 |
1 files changed, 22 insertions, 10 deletions
@@ -497,17 +497,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.""" |