diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-10-09 14:35:24 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2000-10-09 14:35:24 (GMT) |
commit | b769e80056908b4ea66a3e2f7c1ecb251dab4f04 (patch) | |
tree | fe19da954c1ed209f392fca11c103982bd94ea90 /Tools/compiler | |
parent | d92383102740bd143c5221a519433e64c4c9c498 (diff) | |
download | cpython-b769e80056908b4ea66a3e2f7c1ecb251dab4f04.zip cpython-b769e80056908b4ea66a3e2f7c1ecb251dab4f04.tar.gz cpython-b769e80056908b4ea66a3e2f7c1ecb251dab4f04.tar.bz2 |
read in a .pyc file and disassemble the code objects
Diffstat (limited to 'Tools/compiler')
-rwxr-xr-x | Tools/compiler/dumppyc.py | 39 |
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) |