diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2023-11-22 22:36:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-22 22:36:55 (GMT) |
commit | 10e1a0c91613908757a5b97602834defbe575ab0 (patch) | |
tree | ff5f0696ab06839ba2b825caf731fd7eb8026467 /Doc | |
parent | 790db85c7737c2ebbb145f9a26f675a586c5f0d1 (diff) | |
download | cpython-10e1a0c91613908757a5b97602834defbe575ab0.zip cpython-10e1a0c91613908757a5b97602834defbe575ab0.tar.gz cpython-10e1a0c91613908757a5b97602834defbe575ab0.tar.bz2 |
gh-112137: change dis output to display labels instead of offsets (#112138)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/dis.rst | 36 | ||||
-rw-r--r-- | Doc/whatsnew/3.13.rst | 9 |
2 files changed, 36 insertions, 9 deletions
diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index e44fa46..7e97f1a 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -51,6 +51,11 @@ interpreter. transparent for forward jumps but needs to be taken into account when reasoning about backward jumps. + .. versionchanged:: 3.13 + The output shows logical labels rather than instruction offsets + for jump targets and exception handlers. The ``-O`` command line + option and the ``show_offsets`` argument were added. + Example: Given the function :func:`!myfunc`:: def myfunc(alist): @@ -62,12 +67,12 @@ the following command can be used to display the disassembly of .. doctest:: >>> dis.dis(myfunc) - 2 0 RESUME 0 + 2 RESUME 0 <BLANKLINE> - 3 2 LOAD_GLOBAL 1 (len + NULL) - 12 LOAD_FAST 0 (alist) - 14 CALL 1 - 22 RETURN_VALUE + 3 LOAD_GLOBAL 1 (len + NULL) + LOAD_FAST 0 (alist) + CALL 1 + RETURN_VALUE (The "2" is a line number). @@ -80,7 +85,7 @@ The :mod:`dis` module can be invoked as a script from the command line: .. code-block:: sh - python -m dis [-h] [-C] [infile] + python -m dis [-h] [-C] [-O] [infile] The following options are accepted: @@ -94,6 +99,10 @@ The following options are accepted: Show inline caches. +.. cmdoption:: -O, --show-offsets + + Show offsets of instructions. + If :file:`infile` is specified, its disassembled code will be written to stdout. Otherwise, disassembly is performed on compiled source code recieved from stdin. @@ -107,7 +116,7 @@ The bytecode analysis API allows pieces of Python code to be wrapped in a code. .. class:: Bytecode(x, *, first_line=None, current_offset=None,\ - show_caches=False, adaptive=False) + show_caches=False, adaptive=False, show_offsets=False) Analyse the bytecode corresponding to a function, generator, asynchronous generator, coroutine, method, string of source code, or a code object (as @@ -132,6 +141,9 @@ code. If *adaptive* is ``True``, :meth:`.dis` will display specialized bytecode that may be different from the original bytecode. + If *show_offsets* is ``True``, :meth:`.dis` will include instruction + offsets in the output. + .. classmethod:: from_traceback(tb, *, show_caches=False) Construct a :class:`Bytecode` instance from the given traceback, setting @@ -254,7 +266,8 @@ operation is being performed, so the intermediate analysis object isn't useful: Added the *show_caches* and *adaptive* parameters. -.. function:: distb(tb=None, *, file=None, show_caches=False, adaptive=False) +.. function:: distb(tb=None, *, file=None, show_caches=False, adaptive=False, + show_offset=False) Disassemble the top-of-stack function of a traceback, using the last traceback if none was passed. The instruction causing the exception is @@ -269,9 +282,12 @@ operation is being performed, so the intermediate analysis object isn't useful: .. versionchanged:: 3.11 Added the *show_caches* and *adaptive* parameters. + .. versionchanged:: 3.13 + Added the *show_offsets* parameter. .. function:: disassemble(code, lasti=-1, *, file=None, show_caches=False, adaptive=False) - disco(code, lasti=-1, *, file=None, show_caches=False, adaptive=False) + disco(code, lasti=-1, *, file=None, show_caches=False, adaptive=False, + show_offsets=False) Disassemble a code object, indicating the last instruction if *lasti* was provided. The output is divided in the following columns: @@ -296,6 +312,8 @@ operation is being performed, so the intermediate analysis object isn't useful: .. versionchanged:: 3.11 Added the *show_caches* and *adaptive* parameters. + .. versionchanged:: 3.13 + Added the *show_offsets* parameter. .. function:: get_instructions(x, *, first_line=None, show_caches=False, adaptive=False) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index fc5ae13..3fd0f5e 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -168,6 +168,15 @@ copy any user classes which define the :meth:`!__replace__` method. (Contributed by Serhiy Storchaka in :gh:`108751`.) +dis +--- + +* Change the output of :mod:`dis` module functions to show logical + labels for jump targets and exception handlers, rather than offsets. + The offsets can be added with the new ``-O`` command line option or + the ``show_offsets`` parameter. + (Contributed by Irit Katriel in :gh:`112137`.) + dbm --- |