Back to index

python3.2  3.2.2
Functions | Variables
objgraph Namespace Reference

Functions

def store
def flat
def readinput
def printcallee
def printcaller
def printundef
def warndups
def main

Variables

string definitions = 'TRGDSBAEC'
string externals = 'UV'
string ignore = 'Nntrgdsbavuc'
tuple matcher = re.compile('(.*):\t?........ (.) (.*)$')
dictionary file2undef = {}
dictionary def2file = {}
dictionary file2def = {}
dictionary undef2file = {}

Function Documentation

def objgraph.flat (   list)

Definition at line 50 of file objgraph.py.

00050 
00051 def flat(list):
00052     s = ''
00053     for item in list:
00054         s = s + ' ' + item
00055     return s[1:]
00056 
00057 # Global variables mapping defined/undefined names to files and back.
#

Here is the caller graph for this function:

def objgraph.main ( void  )

Definition at line 153 of file objgraph.py.

00153 
00154 def main():
00155     try:
00156         optlist, args = getopt.getopt(sys.argv[1:], 'cdu')
00157     except getopt.error:
00158         sys.stdout = sys.stderr
00159         print('Usage:', os.path.basename(sys.argv[0]), end=' ')
00160         print('[-cdu] [file] ...')
00161         print('-c: print callers per objectfile')
00162         print('-d: print callees per objectfile')
00163         print('-u: print usage of undefined symbols')
00164         print('If none of -cdu is specified, all are assumed.')
00165         print('Use "nm -o" to generate the input (on IRIX: "nm -Bo"),')
00166         print('e.g.: nm -o /lib/libc.a | objgraph')
00167         return 1
00168     optu = optc = optd = 0
00169     for opt, void in optlist:
00170         if opt == '-u':
00171             optu = 1
00172         elif opt == '-c':
00173             optc = 1
00174         elif opt == '-d':
00175             optd = 1
00176     if optu == optc == optd == 0:
00177         optu = optc = optd = 1
00178     if not args:
00179         args = ['-']
00180     for filename in args:
00181         if filename == '-':
00182             readinput(sys.stdin)
00183         else:
00184             readinput(open(filename, 'r'))
00185     #
00186     warndups()
00187     #
00188     more = (optu + optc + optd > 1)
00189     if optd:
00190         if more:
00191             print('---------------All callees------------------')
00192         printcallee()
00193     if optu:
00194         if more:
00195             print('---------------Undefined callees------------')
00196         printundef()
00197     if optc:
00198         if more:
00199             print('---------------All Callers------------------')
00200         printcaller()
00201     return 0
00202 
00203 # Call the main program.
00204 # Use its return value as exit status.
00205 # Catch interrupts to avoid stack trace.
#

Here is the call graph for this function:

Definition at line 88 of file objgraph.py.

00088 
00089 def printcallee():
00090     flist = sorted(file2undef.keys())
00091     for filename in flist:
00092         print(filename + ':')
00093         elist = file2undef[filename]
00094         elist.sort()
00095         for ext in elist:
00096             if len(ext) >= 8:
00097                 tabs = '\t'
00098             else:
00099                 tabs = '\t\t'
00100             if ext not in def2file:
00101                 print('\t' + ext + tabs + ' *undefined')
00102             else:
00103                 print('\t' + ext + tabs + flat(def2file[ext]))
00104 
00105 # Print for each module the names of the other modules that use it.
#

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 106 of file objgraph.py.

00106 
00107 def printcaller():
00108     files = sorted(file2def.keys())
00109     for filename in files:
00110         callers = []
00111         for label in file2def[filename]:
00112             if label in undef2file:
00113                 callers = callers + undef2file[label]
00114         if callers:
00115             callers.sort()
00116             print(filename + ':')
00117             lastfn = ''
00118             for fn in callers:
00119                 if fn != lastfn:
00120                     print('\t' + fn)
00121                 lastfn = fn
00122         else:
00123             print(filename + ': unused')
00124 
00125 # Print undefined names and where they are used.
#

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 126 of file objgraph.py.

00126 
00127 def printundef():
00128     undefs = {}
00129     for filename in list(file2undef.keys()):
00130         for ext in file2undef[filename]:
00131             if ext not in def2file:
00132                 store(undefs, ext, filename)
00133     elist = sorted(undefs.keys())
00134     for ext in elist:
00135         print(ext + ':')
00136         flist = sorted(undefs[ext])
00137         for filename in flist:
00138             print('\t' + filename)
00139 
00140 # Print warning messages about names defined in more than one file.
#

Here is the call graph for this function:

Here is the caller graph for this function:

def objgraph.readinput (   fp)

Definition at line 66 of file objgraph.py.

00066 
00067 def readinput(fp):
00068     while 1:
00069         s = fp.readline()
00070         if not s:
00071             break
00072         # If you get any output from this line,
00073         # it is probably caused by an unexpected input line:
00074         if matcher.search(s) < 0: s; continue # Shouldn't happen
00075         (ra, rb), (r1a, r1b), (r2a, r2b), (r3a, r3b) = matcher.regs[:4]
00076         fn, name, type = s[r1a:r1b], s[r3a:r3b], s[r2a:r2b]
00077         if type in definitions:
00078             store(def2file, name, fn)
00079             store(file2def, fn, name)
00080         elif type in externals:
00081             store(file2undef, fn, name)
00082             store(undef2file, name, fn)
00083         elif not type in ignore:
00084             print(fn + ':' + name + ': unknown type ' + type)
00085 
00086 # Print all names that were undefined in some module and where they are
00087 # defined.
#

Here is the call graph for this function:

Here is the caller graph for this function:

def objgraph.store (   dict,
  key,
  item 
)

Definition at line 41 of file objgraph.py.

00041 
00042 def store(dict, key, item):
00043     if key in dict:
00044         dict[key].append(item)
00045     else:
00046         dict[key] = [item]
00047 
00048 # Return a flattened version of a list of strings: the concatenation
00049 # of its elements with intervening spaces.
#

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 141 of file objgraph.py.

00141 
00142 def warndups():
00143     savestdout = sys.stdout
00144     sys.stdout = sys.stderr
00145     names = sorted(def2file.keys())
00146     for name in names:
00147         if len(def2file[name]) > 1:
00148             print('warning:', name, 'multiply defined:', end=' ')
00149             print(flat(def2file[name]))
00150     sys.stdout = savestdout
00151 
00152 # Main program
#

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 59 of file objgraph.py.

Definition at line 29 of file objgraph.py.

Definition at line 30 of file objgraph.py.

Definition at line 60 of file objgraph.py.

Definition at line 58 of file objgraph.py.

string objgraph.ignore = 'Nntrgdsbavuc'

Definition at line 31 of file objgraph.py.

tuple objgraph.matcher = re.compile('(.*):\t?........ (.) (.*)$')

Definition at line 35 of file objgraph.py.

Definition at line 61 of file objgraph.py.