Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3e1b85ea
Commit
3e1b85ea
authored
May 30, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a helper to display the various flags and components of code objects
(everything besides the actual code disassembly).
parent
dc089b6d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
0 deletions
+56
-0
Lib/dis.py
Lib/dis.py
+56
-0
No files found.
Lib/dis.py
View file @
3e1b85ea
...
...
@@ -55,6 +55,62 @@ def distb(tb=None):
while
tb
.
tb_next
:
tb
=
tb
.
tb_next
disassemble
(
tb
.
tb_frame
.
f_code
,
tb
.
tb_lasti
)
# XXX This duplicates information from code.h, also duplicated in inspect.py.
# XXX Maybe this ought to be put in a central location, like opcode.py?
flag2name
=
{
1
:
"OPTIMIZED"
,
2
:
"NEWLOCALS"
,
4
:
"VARARGS"
,
8
:
"VARKEYWORDS"
,
16
:
"NESTED"
,
32
:
"GENERATOR"
,
64
:
"NOFREE"
,
}
def
pretty_flags
(
flags
):
"""Return pretty representation of code flags."""
names
=
[]
for
i
in
range
(
32
):
flag
=
1
<<
i
if
flags
&
flag
:
names
.
append
(
flag2name
.
get
(
flag
,
hex
(
flag
)))
flags
^=
flag
if
not
flags
:
break
else
:
names
.
append
(
hex
(
flags
))
return
", "
.
join
(
names
)
def
show_code
(
co
):
"""Show details about a code object."""
print
(
"Name: "
,
co
.
co_name
)
print
(
"Filename: "
,
co
.
co_filename
)
print
(
"Argument count: "
,
co
.
co_argcount
)
print
(
"Kw-only arguments:"
,
co
.
co_kwonlyargcount
)
print
(
"Number of locals: "
,
co
.
co_nlocals
)
print
(
"Stack size: "
,
co
.
co_stacksize
)
print
(
"Flags: "
,
pretty_flags
(
co
.
co_flags
))
if
co
.
co_consts
:
print
(
"Constants:"
)
for
i_c
in
enumerate
(
co
.
co_consts
):
print
(
"%4d: %r"
%
i_c
)
if
co
.
co_names
:
print
(
"Names:"
)
for
i_n
in
enumerate
(
co
.
co_names
):
print
(
"%4d: %s"
%
i_n
)
if
co
.
co_varnames
:
print
(
"Variable names:"
)
for
i_n
in
enumerate
(
co
.
co_varnames
):
print
(
"%4d: %s"
%
i_n
)
if
co
.
co_freevars
:
print
(
"Free variables:"
)
for
i_n
in
enumerate
(
co
.
co_freevars
):
print
(
"%4d: %s"
%
i_n
)
if
co
.
co_cellvars
:
print
(
"Cell variables:"
)
for
i_n
in
enumerate
(
co
.
co_cellvars
):
print
(
"%4d: %s"
%
i_n
)
def
disassemble
(
co
,
lasti
=-
1
):
"""Disassemble a code object."""
code
=
co
.
co_code
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment