diff options
Diffstat (limited to 'Tools/scripts/objgraph.py')
-rwxr-xr-x | Tools/scripts/objgraph.py | 82 |
1 files changed, 43 insertions, 39 deletions
diff --git a/Tools/scripts/objgraph.py b/Tools/scripts/objgraph.py index add41e6..f74c2b6 100755 --- a/Tools/scripts/objgraph.py +++ b/Tools/scripts/objgraph.py @@ -1,9 +1,9 @@ -#! /usr/bin/env python3 +#! /usr/bin/env python # objgraph # -# Read "nm -o" input of a set of libraries or modules and print various -# interesting listings, such as: +# Read "nm -o" input (on IRIX: "nm -Bo") of a set of libraries or modules +# and print various interesting listings, such as: # # - which names are used but not defined in the set (and used where), # - which names are defined in the set (and where), @@ -15,7 +15,7 @@ # -d: print callees per objectfile # -u: print usage of undefined symbols # If none of -cdu is specified, all are assumed. -# Use "nm -o" to generate the input +# Use "nm -o" to generate the input (on IRIX: "nm -Bo"), # e.g.: nm -o /lib/libc.a | objgraph @@ -39,7 +39,7 @@ matcher = re.compile('(.*):\t?........ (.) (.*)$') # If there is no list for the key yet, it is created. # def store(dict, key, item): - if key in dict: + if dict.has_key(key): dict[key].append(item) else: dict[key] = [item] @@ -80,15 +80,16 @@ def readinput(fp): store(file2undef, fn, name) store(undef2file, name, fn) elif not type in ignore: - print(fn + ':' + name + ': unknown type ' + type) + print fn + ':' + name + ': unknown type ' + type # Print all names that were undefined in some module and where they are # defined. # def printcallee(): - flist = sorted(file2undef.keys()) + flist = file2undef.keys() + flist.sort() for filename in flist: - print(filename + ':') + print filename + ':' elist = file2undef[filename] elist.sort() for ext in elist: @@ -96,56 +97,60 @@ def printcallee(): tabs = '\t' else: tabs = '\t\t' - if ext not in def2file: - print('\t' + ext + tabs + ' *undefined') + if not def2file.has_key(ext): + print '\t' + ext + tabs + ' *undefined' else: - print('\t' + ext + tabs + flat(def2file[ext])) + print '\t' + ext + tabs + flat(def2file[ext]) # Print for each module the names of the other modules that use it. # def printcaller(): - files = sorted(file2def.keys()) + files = file2def.keys() + files.sort() for filename in files: callers = [] for label in file2def[filename]: - if label in undef2file: + if undef2file.has_key(label): callers = callers + undef2file[label] if callers: callers.sort() - print(filename + ':') + print filename + ':' lastfn = '' for fn in callers: - if fn != lastfn: - print('\t' + fn) + if fn <> lastfn: + print '\t' + fn lastfn = fn else: - print(filename + ': unused') + print filename + ': unused' # Print undefined names and where they are used. # def printundef(): undefs = {} - for filename in list(file2undef.keys()): + for filename in file2undef.keys(): for ext in file2undef[filename]: - if ext not in def2file: + if not def2file.has_key(ext): store(undefs, ext, filename) - elist = sorted(undefs.keys()) + elist = undefs.keys() + elist.sort() for ext in elist: - print(ext + ':') - flist = sorted(undefs[ext]) + print ext + ':' + flist = undefs[ext] + flist.sort() for filename in flist: - print('\t' + filename) + print '\t' + filename # Print warning messages about names defined in more than one file. # def warndups(): savestdout = sys.stdout sys.stdout = sys.stderr - names = sorted(def2file.keys()) + names = def2file.keys() + names.sort() for name in names: if len(def2file[name]) > 1: - print('warning:', name, 'multiply defined:', end=' ') - print(flat(def2file[name])) + print 'warning:', name, 'multiply defined:', + print flat(def2file[name]) sys.stdout = savestdout # Main program @@ -155,14 +160,14 @@ def main(): optlist, args = getopt.getopt(sys.argv[1:], 'cdu') except getopt.error: sys.stdout = sys.stderr - print('Usage:', os.path.basename(sys.argv[0]), end=' ') - print('[-cdu] [file] ...') - print('-c: print callers per objectfile') - print('-d: print callees per objectfile') - print('-u: print usage of undefined symbols') - print('If none of -cdu is specified, all are assumed.') - print('Use "nm -o" to generate the input') - print('e.g.: nm -o /lib/libc.a | objgraph') + print 'Usage:', os.path.basename(sys.argv[0]), + print '[-cdu] [file] ...' + print '-c: print callers per objectfile' + print '-d: print callees per objectfile' + print '-u: print usage of undefined symbols' + print 'If none of -cdu is specified, all are assumed.' + print 'Use "nm -o" to generate the input (on IRIX: "nm -Bo"),' + print 'e.g.: nm -o /lib/libc.a | objgraph' return 1 optu = optc = optd = 0 for opt, void in optlist: @@ -180,23 +185,22 @@ def main(): if filename == '-': readinput(sys.stdin) else: - with open(filename) as f: - readinput(f) + readinput(open(filename, 'r')) # warndups() # more = (optu + optc + optd > 1) if optd: if more: - print('---------------All callees------------------') + print '---------------All callees------------------' printcallee() if optu: if more: - print('---------------Undefined callees------------') + print '---------------Undefined callees------------' printundef() if optc: if more: - print('---------------All Callers------------------') + print '---------------All Callers------------------' printcaller() return 0 |