annotate Tools/scripts/objgraph.py @ 58689:514b56efd89a 3.1

Merged revisions 77962 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r77962 | r.david.murray | 2010-02-04 11:41:57 -0500 (Thu, 04 Feb 2010) | 17 lines Merged revisions 77943,77959-77960 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77943 | r.david.murray | 2010-02-03 08:36:23 -0500 (Wed, 03 Feb 2010) | 2 lines Explicitly mention the default value for formatdate's usegmt parameter. ........ r77959 | nick.coghlan | 2010-02-04 07:43:58 -0500 (Thu, 04 Feb 2010) | 1 line Issue 6760: Clarify args handling for subprocess.Popen. Patch by Chris Rebert ........ r77960 | r.david.murray | 2010-02-04 11:33:31 -0500 (Thu, 04 Feb 2010) | 2 lines Add Chris Rebert to ACKS for issue 6760 Popen doc improvements. ........ ................
author R. David Murray <rdmurray@bitdance.com>
date Thu, 04 Feb 2010 16:44:31 +0000
parents 893a4dc17a91
children fcfe324663a6
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
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
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 #
37879
f731859e9b3b Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
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):
47100
893a4dc17a91 Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents: 42427
diff changeset
42 if key in dict:
15930
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:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
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():
47100
893a4dc17a91 Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents: 42427
diff changeset
89 flist = sorted(file2undef.keys())
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
90 for filename in flist:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
91 print(filename + ':')
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
92 elist = file2undef[filename]
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
93 elist.sort()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
94 for ext in elist:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
95 if len(ext) >= 8:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
96 tabs = '\t'
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
97 else:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
98 tabs = '\t\t'
47100
893a4dc17a91 Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents: 42427
diff changeset
99 if ext not in def2file:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
100 print('\t' + ext + tabs + ' *undefined')
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
101 else:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
102 print('\t' + ext + tabs + flat(def2file[ext]))
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
103
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 # 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
105 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 def printcaller():
47100
893a4dc17a91 Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents: 42427
diff changeset
107 files = sorted(file2def.keys())
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
108 for filename in files:
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
109 callers = []
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
110 for label in file2def[filename]:
47100
893a4dc17a91 Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents: 42427
diff changeset
111 if label in undef2file:
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
112 callers = callers + undef2file[label]
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
113 if callers:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
114 callers.sort()
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
115 print(filename + ':')
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
116 lastfn = ''
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
117 for fn in callers:
47100
893a4dc17a91 Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents: 42427
diff changeset
118 if fn != lastfn:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
119 print('\t' + fn)
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
120 lastfn = fn
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
121 else:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
122 print(filename + ': unused')
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
123
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
124 # Print undefined names and where they are used.
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 def printundef():
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
127 undefs = {}
47100
893a4dc17a91 Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents: 42427
diff changeset
128 for filename in list(file2undef.keys()):
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
129 for ext in file2undef[filename]:
47100
893a4dc17a91 Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents: 42427
diff changeset
130 if ext not in def2file:
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
131 store(undefs, ext, filename)
47100
893a4dc17a91 Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents: 42427
diff changeset
132 elist = sorted(undefs.keys())
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
133 for ext in elist:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
134 print(ext + ':')
47100
893a4dc17a91 Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents: 42427
diff changeset
135 flist = sorted(undefs[ext])
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
136 for filename in flist:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
137 print('\t' + filename)
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
138
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 # Print warning messages about names defined in more than one file.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 def warndups():
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
142 savestdout = sys.stdout
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
143 sys.stdout = sys.stderr
47100
893a4dc17a91 Ran 2to3 over scripts directory.
Georg Brandl <georg@python.org>
parents: 42427
diff changeset
144 names = sorted(def2file.keys())
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
145 for name in names:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
146 if len(def2file[name]) > 1:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
147 print('warning:', name, 'multiply defined:', end=' ')
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
148 print(flat(def2file[name]))
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
149 sys.stdout = savestdout
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
150
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 # Main program
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 #
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 def main():
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
154 try:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
155 optlist, args = getopt.getopt(sys.argv[1:], 'cdu')
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
156 except getopt.error:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
157 sys.stdout = sys.stderr
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
158 print('Usage:', os.path.basename(sys.argv[0]), end=' ')
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
159 print('[-cdu] [file] ...')
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
160 print('-c: print callers per objectfile')
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
161 print('-d: print callees per objectfile')
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
162 print('-u: print usage of undefined symbols')
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
163 print('If none of -cdu is specified, all are assumed.')
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
164 print('Use "nm -o" to generate the input (on IRIX: "nm -Bo"),')
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
165 print('e.g.: nm -o /lib/libc.a | objgraph')
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
166 return 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
167 optu = optc = optd = 0
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
168 for opt, void in optlist:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
169 if opt == '-u':
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
170 optu = 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
171 elif opt == '-c':
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
172 optc = 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
173 elif opt == '-d':
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
174 optd = 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
175 if optu == optc == optd == 0:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
176 optu = optc = optd = 1
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
177 if not args:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
178 args = ['-']
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
179 for filename in args:
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
180 if filename == '-':
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
181 readinput(sys.stdin)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
182 else:
29107
93c92f20b6bf Fix use of 'file' as a variable name.
Andrew M. Kuchling <amk@amk.ca>
parents: 25219
diff changeset
183 readinput(open(filename, 'r'))
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
184 #
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
185 warndups()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
186 #
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
187 more = (optu + optc + optd > 1)
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
188 if optd:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
189 if more:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
190 print('---------------All callees------------------')
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
191 printcallee()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
192 if optu:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
193 if more:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
194 print('---------------Undefined callees------------')
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
195 printundef()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
196 if optc:
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
197 if more:
42427
46625e6122e9 Convert print statements to function calls in Tools/.
Collin Winter <collinw@gmail.com>
parents: 37879
diff changeset
198 print('---------------All Callers------------------')
15930
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
199 printcaller()
14a27acc755a Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
200 return 0
274
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
201
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 # Call the main program.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 # Use its return value as exit status.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 # Catch interrupts to avoid stack trace.
12a64115a4ee Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 #
33074
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 29107
diff changeset
206 if __name__ == '__main__':
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 29107
diff changeset
207 try:
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 29107
diff changeset
208 sys.exit(main())
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 29107
diff changeset
209 except KeyboardInterrupt:
981fff7363b9 [Patch #1005491 ] use __name__ == '__main__' in scripts
Andrew M. Kuchling <amk@amk.ca>
parents: 29107
diff changeset
210 sys.exit(1)