Jens Wiklander | 5976a0a | 2017-05-25 07:48:20 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
Jerome Forissier | 1bb9298 | 2017-12-15 14:27:02 +0100 | [diff] [blame] | 2 | # SPDX-License-Identifier: BSD-2-Clause |
Jens Wiklander | 5976a0a | 2017-05-25 07:48:20 +0200 | [diff] [blame] | 3 | # |
| 4 | # Copyright (c) 2017, Linaro Limited |
Jens Wiklander | 5976a0a | 2017-05-25 07:48:20 +0200 | [diff] [blame] | 5 | # |
Jens Wiklander | 5976a0a | 2017-05-25 07:48:20 +0200 | [diff] [blame] | 6 | |
| 7 | import sys |
| 8 | import re |
| 9 | |
| 10 | def usage(): |
Andrew F. Davis | 85ab358 | 2017-09-22 10:51:26 -0500 | [diff] [blame] | 11 | print "Usage: {0} <section reg exp match> [<skip section>...]".format( \ |
Jens Wiklander | 5976a0a | 2017-05-25 07:48:20 +0200 | [diff] [blame] | 12 | sys.argv[0]) |
| 13 | sys.exit (1) |
| 14 | |
| 15 | def 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. Davis | 85ab358 | 2017-09-22 10:51:26 -0500 | [diff] [blame] | 58 | print '\t*({0})'.format(sect_name) |
Jens Wiklander | 5976a0a | 2017-05-25 07:48:20 +0200 | [diff] [blame] | 59 | |
| 60 | if __name__ == "__main__": |
| 61 | main() |