2 # Usage: unwcheck.sh <executable_file_name>
3 # Pre-requisite: readelf [from Gnu binutils package]
4 # Purpose: Check the following invariant
5 # For each code range in the input binary:
6 # Sum[ lengths of unwind regions] = Number of slots in code range.
7 # Author : Harish Patil
8 # First version: January 2002
10 # Modified : 3/15/2002: duplicate detection
11 readelf
-u $1 | gawk
'\
12 function todec(hexstr){
15 for (i = 1; i <= l; i++)
17 c = substr(hexstr, i, 1);
35 BEGIN { first = 1; sum_rlen = 0; no_slots = 0; errors=0; no_code_ranges=0; }
37 if (NF==5 && $3=="info")
42 if (sum_rlen != no_slots)
44 print full_code_range;
45 print " ", "lo = ", lo, " hi =", hi;
46 print " ", "sum_rlen = ", sum_rlen, "no_slots = " no_slots;
47 print " "," ", "*******ERROR ***********";
48 print " "," ", "sum_rlen:", sum_rlen, " != no_slots:" no_slots;
55 gsub("..$", "", code_range);
56 gsub("^.", "", code_range);
57 split(code_range, addr, "-");
58 lo = toupper(addr[1]);
60 code_range_lo[no_code_ranges] = addr[1];
62 full_range[addr[1]] = $0;
64 gsub("0X.[0]*", "", lo);
65 hi = toupper(addr[2]);
66 gsub("0X.[0]*", "", hi);
67 no_slots = (todec(hi) - todec(lo))/ 16*3
70 if (index($0,"rlen") > 0 )
72 rlen_str = substr($0, index($0,"rlen"));
74 gsub("rlen=", "", rlen);
76 sum_rlen = sum_rlen + rlen;
82 if (sum_rlen != no_slots)
84 print "code_range=", code_range;
85 print " ", "lo = ", lo, " hi =", hi;
86 print " ", "sum_rlen = ", sum_rlen, "no_slots = " no_slots;
87 print " "," ", "*******ERROR ***********";
88 print " "," ", "sum_rlen:", sum_rlen, " != no_slots:" no_slots;
93 for (i=1; i<=no_code_ranges; i++)
95 cr = code_range_lo[i];
96 if (reported_cr[cr]==1) continue;
100 print "Code range low ", code_range_lo[i], ":", full_range[cr], " occurs: ", occurs[cr], " times.";
105 print "======================================"
106 print "Total errors:", errors, "/", no_code_ranges, " duplicates:", no_duplicates;
107 print "======================================"