@@ -51,6 +51,11 @@ interpreter.
51
51
transparent for forward jumps but needs to be taken into account when
52
52
reasoning about backward jumps.
53
53
54
+ .. versionchanged :: 3.13
55
+ The output shows logical labels rather than instruction offsets
56
+ for jump targets and exception handlers. The ``-O `` command line
57
+ option and the ``show_offsets `` argument were added.
58
+
54
59
Example: Given the function :func: `!myfunc `::
55
60
56
61
def myfunc(alist):
@@ -62,12 +67,12 @@ the following command can be used to display the disassembly of
62
67
.. doctest ::
63
68
64
69
>>> dis.dis(myfunc)
65
- 2 0 RESUME 0
70
+ 2 RESUME 0
66
71
<BLANKLINE>
67
- 3 2 LOAD_GLOBAL 1 (len + NULL)
68
- 12 LOAD_FAST 0 (alist)
69
- 14 CALL 1
70
- 22 RETURN_VALUE
72
+ 3 LOAD_GLOBAL 1 (len + NULL)
73
+ LOAD_FAST 0 (alist)
74
+ CALL 1
75
+ RETURN_VALUE
71
76
72
77
(The "2" is a line number).
73
78
@@ -80,7 +85,7 @@ The :mod:`dis` module can be invoked as a script from the command line:
80
85
81
86
.. code-block :: sh
82
87
83
- python -m dis [-h] [-C] [infile]
88
+ python -m dis [-h] [-C] [-O] [ infile]
84
89
85
90
The following options are accepted:
86
91
@@ -94,6 +99,10 @@ The following options are accepted:
94
99
95
100
Show inline caches.
96
101
102
+ .. cmdoption :: -O, --show-offsets
103
+
104
+ Show offsets of instructions.
105
+
97
106
If :file: `infile ` is specified, its disassembled code will be written to stdout.
98
107
Otherwise, disassembly is performed on compiled source code recieved from stdin.
99
108
@@ -107,7 +116,7 @@ The bytecode analysis API allows pieces of Python code to be wrapped in a
107
116
code.
108
117
109
118
.. class :: Bytecode(x, *, first_line=None, current_offset=None,\
110
- show_caches=False, adaptive=False)
119
+ show_caches=False, adaptive=False, show_offsets=False )
111
120
112
121
Analyse the bytecode corresponding to a function, generator, asynchronous
113
122
generator, coroutine, method, string of source code, or a code object (as
@@ -132,6 +141,9 @@ code.
132
141
If *adaptive * is ``True ``, :meth: `.dis ` will display specialized bytecode
133
142
that may be different from the original bytecode.
134
143
144
+ If *show_offsets * is ``True ``, :meth: `.dis ` will include instruction
145
+ offsets in the output.
146
+
135
147
.. classmethod :: from_traceback(tb, *, show_caches=False)
136
148
137
149
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:
254
266
Added the *show_caches * and *adaptive * parameters.
255
267
256
268
257
- .. function :: distb(tb=None, *, file=None, show_caches=False, adaptive=False)
269
+ .. function :: distb(tb=None, *, file=None, show_caches=False, adaptive=False,
270
+ show_offset=False)
258
271
259
272
Disassemble the top-of-stack function of a traceback, using the last
260
273
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:
269
282
.. versionchanged :: 3.11
270
283
Added the *show_caches * and *adaptive * parameters.
271
284
285
+ .. versionchanged :: 3.13
286
+ Added the *show_offsets * parameter.
272
287
273
288
.. function :: disassemble(code, lasti=-1, *, file=None, show_caches=False, adaptive=False)
274
- disco(code, lasti=-1, *, file=None, show_caches=False, adaptive=False)
289
+ disco(code, lasti=-1, *, file=None, show_caches=False, adaptive=False,
290
+ show_offsets=False)
275
291
276
292
Disassemble a code object, indicating the last instruction if *lasti * was
277
293
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:
296
312
.. versionchanged :: 3.11
297
313
Added the *show_caches * and *adaptive * parameters.
298
314
315
+ .. versionchanged :: 3.13
316
+ Added the *show_offsets * parameter.
299
317
300
318
.. function :: get_instructions(x, *, first_line=None, show_caches=False, adaptive=False)
301
319
0 commit comments