Fix FullScreen crash in Webapp
[platform/framework/web/chromium-efl.git] / tools / find_runtime_symbols / reduce_debugline.py
1 #!/usr/bin/env python
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.
6
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
9 examples.
10
11 This script assumes that the result of 'readelf -wL' ends with an empty line.
12
13 Note: the option '-wL' has the same meaning with '--debug-dump=decodedline'.
14 """
15
16 from __future__ import print_function
17
18 import re
19 import sys
20
21
22 _FILENAME_PATTERN = re.compile('(CU: |)(.+)\:')
23
24
25 def reduce_decoded_debugline(input_file):
26   filename = ''
27   starting_dict = {}
28   started = False
29
30   for line in input_file:
31     line = line.strip()
32     unpacked = line.split(None, 2)
33
34     if len(unpacked) == 3 and unpacked[2].startswith('0x'):
35       if not started and filename:
36         started = True
37         starting_dict[int(unpacked[2], 16)] = filename
38     else:
39       started = False
40       if line.endswith(':'):
41         matched = _FILENAME_PATTERN.match(line)
42         if matched:
43           filename = matched.group(2)
44
45   starting_list = []
46   prev_filename = ''
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
52   return starting_list
53
54
55 def main():
56   if len(sys.argv) != 1:
57     print('Unsupported arguments', file=sys.stderr)
58     return 1
59
60   starting_list = reduce_decoded_debugline(sys.stdin)
61   bits64 = starting_list[-1][0] > 0xffffffff
62   for address, filename in starting_list:
63     if bits64:
64       print('%016x %s' % (address, filename))
65     else:
66       print('%08x %s' % (address, filename))
67   return 0
68
69
70 if __name__ == '__main__':
71   sys.exit(main())