2 # SPDX-License-Identifier: GPL-2.0
4 # Usage: unwcheck.py FILE
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.
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.
18 if len(sys
.argv
) != 2:
19 print "Usage: %s FILE" % sys
.argv
[0]
22 readelf
= os
.getenv("READELF", "readelf")
24 start_pattern
= re
.compile("<([^>]*)>: \[0x([0-9a-f]+)-0x([0-9a-f]+)\]")
25 rlen_pattern
= re
.compile(".*rlen=([0-9]+)")
27 def check_func (func
, slots
, rlen_sum
):
31 if not func
: func
= "[%#x-%#x]" % (start
, end
)
32 print "ERROR: %s: %lu slots, total region length = %lu" % (func
, slots
, rlen_sum
)
40 for line
in os
.popen("%s -u %s" % (readelf
, sys
.argv
[1])):
41 m
= start_pattern
.match(line
)
43 check_func(func
, slots
, rlen_sum
)
46 start
= long(m
.group(2), 16)
47 end
= long(m
.group(3), 16)
48 slots
= 3 * (end
- start
) / 16
52 m
= rlen_pattern
.match(line
)
54 rlen_sum
+= long(m
.group(1))
55 check_func(func
, slots
, rlen_sum
)
58 print "No errors detected in %u functions." % num_funcs
64 print "%u %s detected in %u functions." % (num_errors
, err
, num_funcs
)