summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-10-09 14:35:24 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-10-09 14:35:24 (GMT)
commitb769e80056908b4ea66a3e2f7c1ecb251dab4f04 (patch)
treefe19da954c1ed209f392fca11c103982bd94ea90
parentd92383102740bd143c5221a519433e64c4c9c498 (diff)
downloadcpython-b769e80056908b4ea66a3e2f7c1ecb251dab4f04.zip
cpython-b769e80056908b4ea66a3e2f7c1ecb251dab4f04.tar.gz
cpython-b769e80056908b4ea66a3e2f7c1ecb251dab4f04.tar.bz2
read in a .pyc file and disassemble the code objects
-rwxr-xr-xTools/compiler/dumppyc.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/Tools/compiler/dumppyc.py b/Tools/compiler/dumppyc.py
new file mode 100755
index 0000000..4ab9821
--- /dev/null
+++ b/Tools/compiler/dumppyc.py
@@ -0,0 +1,39 @@
+#! /usr/bin/env python
+
+import marshal
+import dis
+import types
+
+def dump(obj):
+ print obj
+ for attr in dir(obj):
+ print "\t", attr, repr(getattr(obj, attr))
+
+def loadCode(path):
+ f = open(path)
+ f.read(8)
+ co = marshal.load(f)
+ f.close()
+ return co
+
+def walk(co, match=None):
+ if match is None or co.co_name == match:
+ dump(co)
+ print
+ dis.dis(co)
+ for obj in co.co_consts:
+ if type(obj) == types.CodeType:
+ walk(obj, match)
+
+def main(filename, codename=None):
+ co = loadCode(filename)
+ walk(co, codename)
+
+if __name__ == "__main__":
+ import sys
+ if len(sys.argv) == 3:
+ filename, codename = sys.argv[1:]
+ else:
+ filename = sys.argv[1]
+ codename = None
+ main(filename, codename)