Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Unified Diff: tools/linux/dump-static-initializers.py

Issue 9169074: Add '-d' flag to dump-static-initializers.py (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: "" Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/linux/dump-static-initializers.py
diff --git a/tools/linux/dump-static-initializers.py b/tools/linux/dump-static-initializers.py
index 14fe46994a89a4aa3d017e174ccbce290a1484b9..412c77f1320e31940fa62a0dda1d925a4bc22217 100755
--- a/tools/linux/dump-static-initializers.py
+++ b/tools/linux/dump-static-initializers.py
@@ -96,14 +96,18 @@ def QualifyFilename(filename, symbol):
# 0000000001919920 0000000000000008 b _ZN12_GLOBAL__N_119g_nine_box_prelightE
nm_re = re.compile(r'(\S+) (\S+) t _GLOBAL__I_(.*)')
def ParseNm(binary):
- """Given a binary, yield static initializers as (start, size, file) pairs."""
+ """Given a binary, yield static initializers as (file, start, size) tuples."""
Tyler Breisacher (Chromium) 2012/01/26 22:36:33 I switched the order so that it would always be so
nm = subprocess.Popen(['nm', '-S', binary], stdout=subprocess.PIPE)
+ files = []
Lei Zhang 2012/01/27 19:18:38 This defeats the purpose of having the yield().
Tyler Breisacher (Chromium) 2012/01/30 23:28:16 Done. Also at line 135 in patchset 4.
for line in nm.stdout:
match = nm_re.match(line)
if match:
addr, size, filename = match.groups()
- yield int(addr, 16), int(size, 16), filename
+ files.append((filename, int(addr, 16), int(size, 16)))
+
+ for f in sorted(files):
Evan Martin 2012/01/27 19:52:09 I'd weakly prefer for this function to remain unso
Tyler Breisacher (Chromium) 2012/01/30 23:28:16 Done.
+ yield f
# Regex matching objdump output for the symbols we're interested in.
@@ -132,54 +136,76 @@ def ExtractSymbolReferences(binary, start, end):
# Probably a relative jump within this function.
continue
refs.add(ref)
- continue
for ref in sorted(refs):
yield ref
-
def main():
- parser = optparse.OptionParser(usage='%prog filename')
- parser.add_option('-i', '--instances', dest='calculate_instances',
+ parser = optparse.OptionParser(usage='%prog [option] filename')
+ parser.add_option('-f', '--files', dest='count_files',
+ action='store_true', default=False,
+ help='Print out the number of files containing static '
+ 'initializers')
+ parser.add_option('-i', '--instances', dest='count_initializers',
+ action='store_true', default=False,
+ help='Print out the number of static initializers')
+ parser.add_option('-d', '--diffable', dest='diffable',
action='store_true', default=False,
- help='Only print out the number of static initializers')
+ help='Prints the filename on each line, for more easily '
+ 'diff-able output.')
opts, args = parser.parse_args()
if len(args) != 1:
parser.error('missing filename argument')
return 1
binary = args[0]
- demangler = Demangler()
- static_initializers_count = 0
- for addr, size, filename in ParseNm(binary):
- if size == 2:
Tyler Breisacher (Chromium) 2012/01/26 22:36:33 I discussed this with fischman@ and he said that w
Lei Zhang 2012/01/27 19:18:38 From the comment, it sounds like many of these are
Tyler Breisacher (Chromium) 2012/01/27 19:44:19 But we can make sure they're not called at load ti
Evan Martin 2012/01/27 19:52:09 Yes, that is my belief. Removing them will make t
- # gcc generates a two-byte 'repz retq' initializer when there is nothing
- # to do. jyasskin tells me this is fixed in gcc 4.6.
- # Two bytes is too small to do anything, so just ignore it.
- continue
+ if opts.count_files and opts.count_initializers:
+ parser.error('-f and -i are mutually exclusive')
+ return 1
+
+ if opts.diffable and (opts.count_initializers or opts.count_files):
+ parser.error('-d cannot be used with -f or -i')
+ return 1
- if (opts.calculate_instances):
- static_initializers_count += 1
+ demangler = Demangler()
+ file_count = 0
+ initializer_count = 0
+ for filename, addr, size in ParseNm(binary):
+ if opts.count_files:
+ file_count += 1
Lei Zhang 2012/01/27 19:18:38 Isn't this going to count a given file multiple ti
Tyler Breisacher (Chromium) 2012/01/27 19:44:19 I don't think so, because of the |continue| after
continue
- ref_output = ''
+ ref_output = []
qualified_filename = QualifyFilenameAsProto(filename)
for ref in ExtractSymbolReferences(binary, addr, addr+size):
+ if opts.count_initializers:
+ initializer_count += 1
+ continue
+
ref = demangler.Demangle(ref)
if qualified_filename == filename:
qualified_filename = QualifyFilename(filename, ref)
if ref in NOTES:
- ref_output = ref_output + ' %s [%s]\n' % (ref, NOTES[ref])
+ ref_output.append(' %s [%s]' % (ref, NOTES[ref]))
else:
- ref_output = ref_output + ' ' + ref + '\n'
- print '%s (initializer offset 0x%x size 0x%x)' % (qualified_filename,
- addr, size)
- print ref_output
+ ref_output.append(' ' + ref)
- if opts.calculate_instances:
- print static_initializers_count
- return 0
+ if opts.count_initializers:
+ continue
+
+ if opts.diffable:
+ print '\n'.join(qualified_filename + r for r in ref_output)
+ else:
+ print '%s (initializer offset 0x%x size 0x%x)' % (qualified_filename,
+ addr, size)
+ print '\n'.join(ref_output) + '\n'
+ if opts.count_files:
+ print file_count
+
+ if opts.count_initializers:
+ print initializer_count
+ return 0
if '__main__' == __name__:
sys.exit(main())
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698