]>
Commit | Line | Data |
---|---|---|
94a47083 | 1 | #!/usr/bin/python |
b2441318 | 2 | # SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
3 | # |
4 | # Usage: unwcheck.py FILE | |
5 | # | |
6 | # This script checks the unwind info of each function in file FILE | |
7 | # and verifies that the sum of the region-lengths matches the total | |
8 | # length of the function. | |
9 | # | |
10 | # Based on a shell/awk script originally written by Harish Patil, | |
11 | # which was converted to Perl by Matthew Chapman, which was converted | |
12 | # to Python by David Mosberger. | |
13 | # | |
14 | import os | |
15 | import re | |
16 | import sys | |
17 | ||
18 | if len(sys.argv) != 2: | |
bd5edbe6 | 19 | print("Usage: %s FILE" % sys.argv[0]) |
1da177e4 LT |
20 | sys.exit(2) |
21 | ||
22 | readelf = os.getenv("READELF", "readelf") | |
23 | ||
24 | start_pattern = re.compile("<([^>]*)>: \[0x([0-9a-f]+)-0x([0-9a-f]+)\]") | |
25 | rlen_pattern = re.compile(".*rlen=([0-9]+)") | |
26 | ||
27 | def check_func (func, slots, rlen_sum): | |
28 | if slots != rlen_sum: | |
29 | global num_errors | |
30 | num_errors += 1 | |
31 | if not func: func = "[%#x-%#x]" % (start, end) | |
bd5edbe6 | 32 | print("ERROR: %s: %lu slots, total region length = %lu" % (func, slots, rlen_sum)) |
1da177e4 LT |
33 | return |
34 | ||
35 | num_funcs = 0 | |
36 | num_errors = 0 | |
37 | func = False | |
38 | slots = 0 | |
39 | rlen_sum = 0 | |
40 | for line in os.popen("%s -u %s" % (readelf, sys.argv[1])): | |
41 | m = start_pattern.match(line) | |
42 | if m: | |
43 | check_func(func, slots, rlen_sum) | |
44 | ||
45 | func = m.group(1) | |
bd5edbe6 CL |
46 | start = int(m.group(2), 16) |
47 | end = int(m.group(3), 16) | |
1da177e4 | 48 | slots = 3 * (end - start) / 16 |
bd5edbe6 | 49 | rlen_sum = 0 |
1da177e4 LT |
50 | num_funcs += 1 |
51 | else: | |
52 | m = rlen_pattern.match(line) | |
53 | if m: | |
bd5edbe6 | 54 | rlen_sum += int(m.group(1)) |
1da177e4 LT |
55 | check_func(func, slots, rlen_sum) |
56 | ||
57 | if num_errors == 0: | |
bd5edbe6 | 58 | print("No errors detected in %u functions." % num_funcs) |
1da177e4 LT |
59 | else: |
60 | if num_errors > 1: | |
61 | err="errors" | |
62 | else: | |
63 | err="error" | |
bd5edbe6 | 64 | print("%u %s detected in %u functions." % (num_errors, err, num_funcs)) |
1da177e4 | 65 | sys.exit(1) |