Index: tools/find_runtime_symbols/reduce_debugline.py |
diff --git a/tools/find_runtime_symbols/reduce_debugline.py b/tools/find_runtime_symbols/reduce_debugline.py |
index 1a4efaa591e036e587b7ef28c87bee3b57228a99..75c8c8578d76c0d8e223f1409694ec7278b73b7a 100755 |
--- a/tools/find_runtime_symbols/reduce_debugline.py |
+++ b/tools/find_runtime_symbols/reduce_debugline.py |
@@ -2,23 +2,11 @@ |
# Copyright (c) 2013 The Chromium Authors. All rights reserved. |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
-"""Reduces result of 'readelf -wL' to just a set of address ranges per file. |
+"""Reduces result of 'readelf -wL' to just a list of starting addresses. |
-For example: |
- |
-CU: ../../chrome_main.cc: |
-File name Line number Starting address |
-chrome_main.cc 30 0xa3be90 |
-(an empty line) |
-chrome_main.cc 31 0xa3bea3 |
-chrome_main.cc 32 0xa3beaf |
-chrome_main.cc 34 0xa3bec9 |
-chrome_main.cc 32 0xa3bed1 |
-(an empty line) |
- |
-The example above is reduced into: |
-{'../../chrome_main.cc', [(0xa3be90, 0xa3be90), (0xa3bea3, 0xa3bed1)]} |
-where (0xa3bea3, 0xa3bed1) means an address range from 0xa3bea3 to 0xa3bed1. |
+It lists up all addresses where the corresponding source files change. The |
+list is sorted in ascending order. See tests/reduce_debugline_test.py for |
+examples. |
This script assumes that the result of 'readelf -wL' ends with an empty line. |
@@ -34,35 +22,32 @@ _FILENAME_PATTERN = re.compile('(CU: |)(.+)\:') |
def reduce_decoded_debugline(input_file): |
filename = '' |
- ranges_dict = {} |
- starting = None |
- ending = None |
+ starting_dict = {} |
+ started = False |
for line in input_file: |
line = line.strip() |
- |
- if line.endswith(':'): |
- matched = _FILENAME_PATTERN.match(line) |
- if matched: |
- filename = matched.group(2) |
- continue |
- |
unpacked = line.split(None, 2) |
- if len(unpacked) != 3 or not unpacked[2].startswith('0x'): |
- if starting: |
- ranges_dict.setdefault(filename, []).append((starting, ending)) |
- starting = None |
- ending = None |
- continue |
- |
- ending = int(unpacked[2], 16) |
- if not starting: |
- starting = ending |
- |
- if starting or ending: |
- raise ValueError('No new line at last.') |
- return ranges_dict |
+ if len(unpacked) == 3 and unpacked[2].startswith('0x'): |
+ if not started and filename: |
+ started = True |
+ starting_dict[int(unpacked[2], 16)] = filename |
+ else: |
+ started = False |
+ if line.endswith(':'): |
+ matched = _FILENAME_PATTERN.match(line) |
+ if matched: |
+ filename = matched.group(2) |
+ |
+ starting_list = [] |
+ prev_filename = '' |
+ for address in sorted(starting_dict): |
+ curr_filename = starting_dict[address] |
+ if prev_filename != curr_filename: |
+ starting_list.append((address, starting_dict[address])) |
+ prev_filename = curr_filename |
+ return starting_list |
def main(): |
@@ -70,15 +55,13 @@ def main(): |
print >> sys.stderr, 'Unsupported arguments' |
return 1 |
- ranges_dict = reduce_decoded_debugline(sys.stdin) |
- for filename, ranges in ranges_dict.iteritems(): |
- print filename + ':' |
- prev = (0, 0) |
- for address_range in sorted(ranges): |
- if address_range == prev: |
- continue |
- print ' %x-%x' % (address_range[0], address_range[1]) |
- prev = address_range |
+ starting_list = reduce_decoded_debugline(sys.stdin) |
+ bits64 = starting_list[-1][0] > 0xffffffff |
+ for address, filename in starting_list: |
+ if bits64: |
+ print '%016x %s' % (address, filename) |
+ else: |
+ print '%08x %s' % (address, filename) |
if __name__ == '__main__': |