blob: c5dc3a7b6c1ad036ae1ba8ae60614ca3cd83cdda [file] [log] [blame]
Jens Wiklander5976a0a2017-05-25 07:48:20 +02001#!/usr/bin/env python
Jerome Forissier1bb92982017-12-15 14:27:02 +01002# SPDX-License-Identifier: BSD-2-Clause
Jens Wiklander5976a0a2017-05-25 07:48:20 +02003#
4# Copyright (c) 2017, Linaro Limited
Jens Wiklander5976a0a2017-05-25 07:48:20 +02005#
Jens Wiklander5976a0a2017-05-25 07:48:20 +02006
7import sys
8import re
9
10def usage():
Andrew F. Davis85ab3582017-09-22 10:51:26 -050011 print "Usage: {0} <section reg exp match> [<skip section>...]".format( \
Jens Wiklander5976a0a2017-05-25 07:48:20 +020012 sys.argv[0])
13 sys.exit (1)
14
15def main():
16 if len(sys.argv) < 2 :
17 usage()
18
19 in_shdr = False
20 section_headers = re.compile("Section Headers:")
21 key_to_flags = re.compile("Key to Flags:")
22 match_rule = re.compile(sys.argv[1])
23 skip_sections = sys.argv[2:]
24
25 for line in sys.stdin:
26 if section_headers.match(line) :
27 in_shdr = True;
28 continue
29 if key_to_flags.match(line) :
30 in_shdr = False;
31 continue
32
33 if not in_shdr :
34 continue
35
36 words = line.split()
37
38 if len(words) < 3 :
39 continue
40
41 if words[0] == "[" :
42 name_offs = 2
43 else :
44 name_offs = 1;
45
46 sect_name = words[name_offs]
47 sect_type = words[name_offs + 1]
48
49 if sect_type != "PROGBITS" :
50 continue
51
52 if not match_rule.match(sect_name) :
53 continue
54
55 if sect_name in skip_sections :
56 continue
57
Andrew F. Davis85ab3582017-09-22 10:51:26 -050058 print '\t*({0})'.format(sect_name)
Jens Wiklander5976a0a2017-05-25 07:48:20 +020059
60if __name__ == "__main__":
61 main()