annotate Tools/scripts/objgraph.py @ 49955:878d40468c4e legacy-trunk

Issue #4384: Added logging integration with warnings module using captureWarnings(). This change includes a NullHandler which does nothing; it will be of use to library developers who want to avoid the "No handlers could be found for logger XXX" message which can appear if the library user doesn't configure logging.
author Vinay Sajip <vinay_sajip@yahoo.co.uk>
date Wed, 03 Dec 2008 23:22:58 +0000
parents 4727f260f6f8
children 46625e6122e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4573
73758db2f464 /usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents: 1105
diff changeset
1 #! /usr/bin/env python
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # objgraph
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 # Read "nm -o" input (on IRIX: "nm -Bo") of a set of libraries or modules
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 # and print various interesting listings, such as:
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 # - which names are used but not defined in the set (and used where),
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 # - which names are defined in the set (and where),
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 # - which modules use which other modules,
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 # - which modules are used by which other modules.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 # Usage: objgraph [-cdu] [file] ...
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 # -c: print callers per objectfile
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 # -d: print callees per objectfile
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 # -u: print usage of undefined symbols
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 # If none of -cdu is specified, all are assumed.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 # Use "nm -o" to generate the input (on IRIX: "nm -Bo"),
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 # e.g.: nm -o /lib/libc.a | objgraph
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
21
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 import sys
1105
6f2a6efd019e Adapt to modern times...
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
23 import os
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 import getopt
37021
4727f260f6f8 Remove regsub, reconvert, regex, regex_syntax and everything under lib-old.
Neal Norwitz <nnorwitz@gmail.com>
parents: 33074
diff changeset
25 import re
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 # Types of symbols.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 definitions = 'TRGDSBAEC'
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 externals = 'UV'
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 ignore = 'Nntrgdsbavuc'
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 # Regular expression to parse "nm -o" output.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #
37021
4727f260f6f8 Remove regsub, reconvert, regex, regex_syntax and everything under lib-old.
Neal Norwitz <nnorwitz@gmail.com>
parents: 33074
diff changeset
35 matcher = re.compile('(.*):\t?........ (.) (.*)$')
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 # Store "item" in "dict" under "key".
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 # The dictionary maps keys to lists of items.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 # If there is no list for the key yet, it is created.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 def store(dict, key, item):
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
42 if dict.has_key(key):
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
43 dict[key].append(item)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
44 else:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
45 dict[key] = [item]
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 # Return a flattened version of a list of strings: the concatenation
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 # of its elements with intervening spaces.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 def flat(list):
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
51 s = ''
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
52 for item in list:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
53 s = s + ' ' + item
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
54 return s[1:]
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 # Global variables mapping defined/undefined names to files and back.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 file2undef = {}
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 def2file = {}
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 file2def = {}
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 undef2file = {}
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
62
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 # Read one input file and merge the data into the tables.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 # Argument is an open file.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 #
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
66 def readinput(fp):
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
67 while 1:
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
68 s = fp.readline()
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
69 if not s:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
70 break
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
71 # If you get any output from this line,
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
72 # it is probably caused by an unexpected input line:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
73 if matcher.search(s) < 0: s; continue # Shouldn't happen
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
74 (ra, rb), (r1a, r1b), (r2a, r2b), (r3a, r3b) = matcher.regs[:4]
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
75 fn, name, type = s[r1a:r1b], s[r3a:r3b], s[r2a:r2b]
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
76 if type in definitions:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
77 store(def2file, name, fn)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
78 store(file2def, fn, name)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
79 elif type in externals:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
80 store(file2undef, fn, name)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
81 store(undef2file, name, fn)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
82 elif not type in ignore:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
83 print fn + ':' + name + ': unknown type ' + type
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 # Print all names that were undefined in some module and where they are
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 # defined.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 def printcallee():
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
89 flist = file2undef.keys()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
90 flist.sort()
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
91 for filename in flist:
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
92 print filename + ':'
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
93 elist = file2undef[filename]
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
94 elist.sort()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
95 for ext in elist:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
96 if len(ext) >= 8:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
97 tabs = '\t'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
98 else:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
99 tabs = '\t\t'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
100 if not def2file.has_key(ext):
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
101 print '\t' + ext + tabs + ' *undefined'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
102 else:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
103 print '\t' + ext + tabs + flat(def2file[ext])
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
104
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 # Print for each module the names of the other modules that use it.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 def printcaller():
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
108 files = file2def.keys()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
109 files.sort()
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
110 for filename in files:
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
111 callers = []
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
112 for label in file2def[filename]:
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
113 if undef2file.has_key(label):
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
114 callers = callers + undef2file[label]
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
115 if callers:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
116 callers.sort()
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
117 print filename + ':'
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
118 lastfn = ''
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
119 for fn in callers:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
120 if fn <> lastfn:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
121 print '\t' + fn
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
122 lastfn = fn
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
123 else:
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
124 print filename + ': unused'
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
125
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
126 # Print undefined names and where they are used.
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 def printundef():
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
129 undefs = {}
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
130 for filename in file2undef.keys():
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
131 for ext in file2undef[filename]:
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
132 if not def2file.has_key(ext):
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
133 store(undefs, ext, filename)
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
134 elist = undefs.keys()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
135 elist.sort()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
136 for ext in elist:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
137 print ext + ':'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
138 flist = undefs[ext]
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
139 flist.sort()
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
140 for filename in flist:
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
141 print '\t' + filename
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
142
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 # Print warning messages about names defined in more than one file.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 def warndups():
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
146 savestdout = sys.stdout
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
147 sys.stdout = sys.stderr
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
148 names = def2file.keys()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
149 names.sort()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
150 for name in names:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
151 if len(def2file[name]) > 1:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
152 print 'warning:', name, 'multiply defined:',
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
153 print flat(def2file[name])
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
154 sys.stdout = savestdout
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
155
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 # Main program
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 def main():
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
159 try:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
160 optlist, args = getopt.getopt(sys.argv[1:], 'cdu')
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
161 except getopt.error:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
162 sys.stdout = sys.stderr
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
163 print 'Usage:', os.path.basename(sys.argv[0]),
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
164 print '[-cdu] [file] ...'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
165 print '-c: print callers per objectfile'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
166 print '-d: print callees per objectfile'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
167 print '-u: print usage of undefined symbols'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
168 print 'If none of -cdu is specified, all are assumed.'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
169 print 'Use "nm -o" to generate the input (on IRIX: "nm -Bo"),'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
170 print 'e.g.: nm -o /lib/libc.a | objgraph'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
171 return 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
172 optu = optc = optd = 0
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
173 for opt, void in optlist:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
174 if opt == '-u':
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
175 optu = 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
176 elif opt == '-c':
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
177 optc = 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
178 elif opt == '-d':
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
179 optd = 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
180 if optu == optc == optd == 0:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
181 optu = optc = optd = 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
182 if not args:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
183 args = ['-']
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
184 for filename in args:
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
185 if filename == '-':
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
186 readinput(sys.stdin)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
187 else:
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
188 readinput(open(filename, 'r'))
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
189 #
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
190 warndups()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
191 #
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
192 more = (optu + optc + optd > 1)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
193 if optd:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
194 if more:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
195 print '---------------All callees------------------'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
196 printcallee()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
197 if optu:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
198 if more:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
199 print '---------------Undefined callees------------'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
200 printundef()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
201 if optc:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
202 if more:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
203 print '---------------All Callers------------------'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
204 printcaller()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
205 return 0
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
206
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 # Call the main program.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 # Use its return value as exit status.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 # Catch interrupts to avoid stack trace.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 #
33074
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 29107
diff changeset
211 if __name__ == '__main__':
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 29107
diff changeset
212 try:
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 29107
diff changeset
213 sys.exit(main())
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 29107
diff changeset
214 except KeyboardInterrupt:
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 29107
diff changeset
215 sys.exit(1)