2 # Copyright 2013 The Chromium Authors
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5 """Reduces result of 'readelf -wL' to just a list of starting addresses.
7 It lists up all addresses where the corresponding source files change. The
8 list is sorted in ascending order. See tests/reduce_debugline_test.py for
11 This script assumes that the result of 'readelf -wL' ends with an empty line.
13 Note: the option '-wL' has the same meaning with '--debug-dump=decodedline'.
16 from __future__ import print_function
22 _FILENAME_PATTERN = re.compile('(CU: |)(.+)\:')
25 def reduce_decoded_debugline(input_file):
30 for line in input_file:
32 unpacked = line.split(None, 2)
34 if len(unpacked) == 3 and unpacked[2].startswith('0x'):
35 if not started and filename:
37 starting_dict[int(unpacked[2], 16)] = filename
40 if line.endswith(':'):
41 matched = _FILENAME_PATTERN.match(line)
43 filename = matched.group(2)
47 for address in sorted(starting_dict):
48 curr_filename = starting_dict[address]
49 if prev_filename != curr_filename:
50 starting_list.append((address, starting_dict[address]))
51 prev_filename = curr_filename
56 if len(sys.argv) != 1:
57 print('Unsupported arguments', file=sys.stderr)
60 starting_list = reduce_decoded_debugline(sys.stdin)
61 bits64 = starting_list[-1][0] > 0xffffffff
62 for address, filename in starting_list:
64 print('%016x %s' % (address, filename))
66 print('%08x %s' % (address, filename))
70 if __name__ == '__main__':