2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
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'.
20 _FILENAME_PATTERN
= re
.compile('(CU: |)(.+)\:')
23 def reduce_decoded_debugline(input_file
):
28 for line
in input_file
:
30 unpacked
= line
.split(None, 2)
32 if len(unpacked
) == 3 and unpacked
[2].startswith('0x'):
33 if not started
and filename
:
35 starting_dict
[int(unpacked
[2], 16)] = filename
38 if line
.endswith(':'):
39 matched
= _FILENAME_PATTERN
.match(line
)
41 filename
= matched
.group(2)
45 for address
in sorted(starting_dict
):
46 curr_filename
= starting_dict
[address
]
47 if prev_filename
!= curr_filename
:
48 starting_list
.append((address
, starting_dict
[address
]))
49 prev_filename
= curr_filename
54 if len(sys
.argv
) != 1:
55 print >> sys
.stderr
, 'Unsupported arguments'
58 starting_list
= reduce_decoded_debugline(sys
.stdin
)
59 bits64
= starting_list
[-1][0] > 0xffffffff
60 for address
, filename
in starting_list
:
62 print '%016x %s' % (address
, filename
)
64 print '%08x %s' % (address
, filename
)
67 if __name__
== '__main__':