Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-pickletools.html" /> | |
13 | <link rel="prev" href="module-compileall.html" /> | |
14 | <link rel="parent" href="language.html" /> | |
15 | <link rel="next" href="bytecodes.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>18.10 dis -- Disassembler for Python byte code</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="18.9 compileall " | |
25 | href="module-compileall.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="18. Python Language Services" | |
28 | href="language.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="18.10.1 Python Byte Code" | |
31 | href="bytecodes.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-compileall.html">18.9 compileall </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="language.html">18. Python Language Services</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="bytecodes.html">18.10.1 Python Byte Code</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION00201000000000000000000"> | |
56 | 18.10 <tt class="module">dis</tt> -- | |
57 | Disassembler for Python byte code</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-dis"></A> | |
62 | ||
63 | <P> | |
64 | The <tt class="module">dis</tt> module supports the analysis of Python byte code by | |
65 | disassembling it. Since there is no Python assembler, this module | |
66 | defines the Python assembly language. The Python byte code which | |
67 | this module takes as an input is defined in the file | |
68 | <span class="file">Include/opcode.h</span> and used by the compiler and the interpreter. | |
69 | ||
70 | <P> | |
71 | Example: Given the function <tt class="function">myfunc</tt>: | |
72 | ||
73 | <P> | |
74 | <div class="verbatim"><pre> | |
75 | def myfunc(alist): | |
76 | return len(alist) | |
77 | </pre></div> | |
78 | ||
79 | <P> | |
80 | the following command can be used to get the disassembly of | |
81 | <tt class="function">myfunc()</tt>: | |
82 | ||
83 | <P> | |
84 | <div class="verbatim"><pre> | |
85 | >>> dis.dis(myfunc) | |
86 | 2 0 LOAD_GLOBAL 0 (len) | |
87 | 3 LOAD_FAST 0 (alist) | |
88 | 6 CALL_FUNCTION 1 | |
89 | 9 RETURN_VALUE | |
90 | 10 LOAD_CONST 0 (None) | |
91 | 13 RETURN_VALUE | |
92 | </pre></div> | |
93 | ||
94 | <P> | |
95 | (The ``2'' is a line number). | |
96 | ||
97 | <P> | |
98 | The <tt class="module">dis</tt> module defines the following functions and constants: | |
99 | ||
100 | <P> | |
101 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
102 | <td><nobr><b><tt id='l2h-5001' xml:id='l2h-5001' class="function">dis</tt></b>(</nobr></td> | |
103 | <td><var></var><big>[</big><var>bytesource</var><big>]</big><var></var>)</td></tr></table></dt> | |
104 | <dd> | |
105 | Disassemble the <var>bytesource</var> object. <var>bytesource</var> can denote | |
106 | either a module, a class, a method, a function, or a code object. | |
107 | For a module, it disassembles all functions. For a class, | |
108 | it disassembles all methods. For a single code sequence, it prints | |
109 | one line per byte code instruction. If no object is provided, it | |
110 | disassembles the last traceback. | |
111 | </dl> | |
112 | ||
113 | <P> | |
114 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
115 | <td><nobr><b><tt id='l2h-5002' xml:id='l2h-5002' class="function">distb</tt></b>(</nobr></td> | |
116 | <td><var></var><big>[</big><var>tb</var><big>]</big><var></var>)</td></tr></table></dt> | |
117 | <dd> | |
118 | Disassembles the top-of-stack function of a traceback, using the last | |
119 | traceback if none was passed. The instruction causing the exception | |
120 | is indicated. | |
121 | </dl> | |
122 | ||
123 | <P> | |
124 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
125 | <td><nobr><b><tt id='l2h-5003' xml:id='l2h-5003' class="function">disassemble</tt></b>(</nobr></td> | |
126 | <td><var>code</var><big>[</big><var>, lasti</var><big>]</big><var></var>)</td></tr></table></dt> | |
127 | <dd> | |
128 | Disassembles a code object, indicating the last instruction if <var>lasti</var> | |
129 | was provided. The output is divided in the following columns: | |
130 | ||
131 | <P> | |
132 | ||
133 | <OL> | |
134 | <LI>the line number, for the first instruction of each line | |
135 | </LI> | |
136 | <LI>the current instruction, indicated as "<tt class="samp">--></tt>", | |
137 | </LI> | |
138 | <LI>a labelled instruction, indicated with "<tt class="samp">><code>></code></tt>", | |
139 | </LI> | |
140 | <LI>the address of the instruction, | |
141 | </LI> | |
142 | <LI>the operation code name, | |
143 | </LI> | |
144 | <LI>operation parameters, and | |
145 | </LI> | |
146 | <LI>interpretation of the parameters in parentheses. | |
147 | </LI> | |
148 | </OL> | |
149 | ||
150 | <P> | |
151 | The parameter interpretation recognizes local and global | |
152 | variable names, constant values, branch targets, and compare | |
153 | operators. | |
154 | </dl> | |
155 | ||
156 | <P> | |
157 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
158 | <td><nobr><b><tt id='l2h-5004' xml:id='l2h-5004' class="function">disco</tt></b>(</nobr></td> | |
159 | <td><var>code</var><big>[</big><var>, lasti</var><big>]</big><var></var>)</td></tr></table></dt> | |
160 | <dd> | |
161 | A synonym for disassemble. It is more convenient to type, and kept | |
162 | for compatibility with earlier Python releases. | |
163 | </dl> | |
164 | ||
165 | <P> | |
166 | <dl><dt><b><tt id='l2h-5005' xml:id='l2h-5005'>opname</tt></b></dt> | |
167 | <dd> | |
168 | Sequence of operation names, indexable using the byte code. | |
169 | </dd></dl> | |
170 | ||
171 | <P> | |
172 | <dl><dt><b><tt id='l2h-5006' xml:id='l2h-5006'>cmp_op</tt></b></dt> | |
173 | <dd> | |
174 | Sequence of all compare operation names. | |
175 | </dd></dl> | |
176 | ||
177 | <P> | |
178 | <dl><dt><b><tt id='l2h-5007' xml:id='l2h-5007'>hasconst</tt></b></dt> | |
179 | <dd> | |
180 | Sequence of byte codes that have a constant parameter. | |
181 | </dd></dl> | |
182 | ||
183 | <P> | |
184 | <dl><dt><b><tt id='l2h-5008' xml:id='l2h-5008'>hasfree</tt></b></dt> | |
185 | <dd> | |
186 | Sequence of byte codes that access a free variable. | |
187 | </dd></dl> | |
188 | ||
189 | <P> | |
190 | <dl><dt><b><tt id='l2h-5009' xml:id='l2h-5009'>hasname</tt></b></dt> | |
191 | <dd> | |
192 | Sequence of byte codes that access an attribute by name. | |
193 | </dd></dl> | |
194 | ||
195 | <P> | |
196 | <dl><dt><b><tt id='l2h-5010' xml:id='l2h-5010'>hasjrel</tt></b></dt> | |
197 | <dd> | |
198 | Sequence of byte codes that have a relative jump target. | |
199 | </dd></dl> | |
200 | ||
201 | <P> | |
202 | <dl><dt><b><tt id='l2h-5011' xml:id='l2h-5011'>hasjabs</tt></b></dt> | |
203 | <dd> | |
204 | Sequence of byte codes that have an absolute jump target. | |
205 | </dd></dl> | |
206 | ||
207 | <P> | |
208 | <dl><dt><b><tt id='l2h-5012' xml:id='l2h-5012'>haslocal</tt></b></dt> | |
209 | <dd> | |
210 | Sequence of byte codes that access a local variable. | |
211 | </dd></dl> | |
212 | ||
213 | <P> | |
214 | <dl><dt><b><tt id='l2h-5013' xml:id='l2h-5013'>hascompare</tt></b></dt> | |
215 | <dd> | |
216 | Sequence of byte codes of Boolean operations. | |
217 | </dd></dl> | |
218 | ||
219 | <P> | |
220 | ||
221 | <p><br /></p><hr class='online-navigation' /> | |
222 | <div class='online-navigation'> | |
223 | <!--Table of Child-Links--> | |
224 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> | |
225 | ||
226 | <UL CLASS="ChildLinks"> | |
227 | <LI><A href="bytecodes.html">18.10.1 Python Byte Code Instructions</a> | |
228 | </ul> | |
229 | <!--End of Table of Child-Links--> | |
230 | </div> | |
231 | ||
232 | <DIV CLASS="navigation"> | |
233 | <div class='online-navigation'> | |
234 | <p></p><hr /> | |
235 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
236 | <tr> | |
237 | <td class='online-navigation'><a rel="prev" title="18.9 compileall " | |
238 | href="module-compileall.html"><img src='../icons/previous.png' | |
239 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
240 | <td class='online-navigation'><a rel="parent" title="18. Python Language Services" | |
241 | href="language.html"><img src='../icons/up.png' | |
242 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
243 | <td class='online-navigation'><a rel="next" title="18.10.1 Python Byte Code" | |
244 | href="bytecodes.html"><img src='../icons/next.png' | |
245 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
246 | <td align="center" width="100%">Python Library Reference</td> | |
247 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
248 | href="contents.html"><img src='../icons/contents.png' | |
249 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
250 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
251 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
252 | <td class='online-navigation'><a rel="index" title="Index" | |
253 | href="genindex.html"><img src='../icons/index.png' | |
254 | border='0' height='32' alt='Index' width='32' /></A></td> | |
255 | </tr></table> | |
256 | <div class='online-navigation'> | |
257 | <b class="navlabel">Previous:</b> | |
258 | <a class="sectref" rel="prev" href="module-compileall.html">18.9 compileall </A> | |
259 | <b class="navlabel">Up:</b> | |
260 | <a class="sectref" rel="parent" href="language.html">18. Python Language Services</A> | |
261 | <b class="navlabel">Next:</b> | |
262 | <a class="sectref" rel="next" href="bytecodes.html">18.10.1 Python Byte Code</A> | |
263 | </div> | |
264 | </div> | |
265 | <hr /> | |
266 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
267 | </DIV> | |
268 | <!--End of Navigation Panel--> | |
269 | <ADDRESS> | |
270 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
271 | </ADDRESS> | |
272 | </BODY> | |
273 | </HTML> |