blob: 4ab9821852e47803f969af3055b275668b3951f9 [file] [log] [blame]
Jeremy Hyltonb769e802000-10-09 14:35:24 +00001#! /usr/bin/env python
2
3import marshal
4import dis
5import types
6
7def dump(obj):
8 print obj
9 for attr in dir(obj):
10 print "\t", attr, repr(getattr(obj, attr))
11
12def loadCode(path):
13 f = open(path)
14 f.read(8)
15 co = marshal.load(f)
16 f.close()
17 return co
18
19def walk(co, match=None):
20 if match is None or co.co_name == match:
21 dump(co)
22 print
23 dis.dis(co)
24 for obj in co.co_consts:
25 if type(obj) == types.CodeType:
26 walk(obj, match)
27
28def main(filename, codename=None):
29 co = loadCode(filename)
30 walk(co, codename)
31
32if __name__ == "__main__":
33 import sys
34 if len(sys.argv) == 3:
35 filename, codename = sys.argv[1:]
36 else:
37 filename = sys.argv[1]
38 codename = None
39 main(filename, codename)