summaryrefslogtreecommitdiffstats
path: root/tools/linux
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 01:01:14 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 01:01:14 +0000
commit0ecff4259f65f5e920eff998e53e503cf0b2f446 (patch)
tree8ed153e6046125ea37c402122d5e5be13a5b87f6 /tools/linux
parent595bd0c88b0a93040ffbdf31daa5bba84c352acf (diff)
downloadchromium_src-0ecff4259f65f5e920eff998e53e503cf0b2f446.zip
chromium_src-0ecff4259f65f5e920eff998e53e503cf0b2f446.tar.gz
chromium_src-0ecff4259f65f5e920eff998e53e503cf0b2f446.tar.bz2
dump-static-initializers: Add a --size option to just print out the total static initializers size.
BUG=none TEST=none Review URL: http://codereview.chromium.org/8188003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104414 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/linux')
-rwxr-xr-xtools/linux/dump-static-initializers.py62
1 files changed, 40 insertions, 22 deletions
diff --git a/tools/linux/dump-static-initializers.py b/tools/linux/dump-static-initializers.py
index 3a30641..894e58e 100755
--- a/tools/linux/dump-static-initializers.py
+++ b/tools/linux/dump-static-initializers.py
@@ -26,6 +26,7 @@ they reference.
import optparse
import re
import subprocess
+import sys
# A map of symbol => informative text about it.
NOTES = {
@@ -93,26 +94,43 @@ def ExtractSymbolReferences(binary, start, end):
yield ref
-parser = optparse.OptionParser(usage='%prog filename')
-opts, args = parser.parse_args()
-if len(args) != 1:
- parser.error('missing filename argument')
-binary = args[0]
-
-demangler = Demangler()
-for addr, size, filename in ParseNm(binary):
- if size == 2:
- # 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
-
- print '%s (initializer offset 0x%x size 0x%x)' % (filename, addr, size)
- for ref in ExtractSymbolReferences(binary, addr, addr+size):
- ref = demangler.Demangle(ref)
- if ref in NOTES:
- print ' ', '%s [%s]' % (ref, NOTES[ref])
- else:
- print ' ', ref
- print
+def main():
+ parser = optparse.OptionParser(usage='%prog filename')
+ parser.add_option('-i', '--instances', dest='calculate_instances',
+ action='store_true', default=False,
+ help='Only print out the number of static initializers')
+ 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:
+ # 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.calculate_instances):
+ static_initializers_count += 1
+ continue
+
+ print '%s (initializer offset 0x%x size 0x%x)' % (filename, addr, size)
+ for ref in ExtractSymbolReferences(binary, addr, addr+size):
+ ref = demangler.Demangle(ref)
+ if ref in NOTES:
+ print ' ', '%s [%s]' % (ref, NOTES[ref])
+ else:
+ print ' ', ref
+ print
+
+ if opts.calculate_instances:
+ print static_initializers_count
+ return 0
+
+if '__main__' == __name__:
+ sys.exit(main())