]> granicus.if.org Git - strace/blob - mpers.awk
tests: add ftruncate64.test and truncate64.test
[strace] / mpers.awk
1 function compare_indices(i1, v1, i2, v2) {
2         c1 = strtonum(sprintf("%s", i1))
3         c2 = strtonum(sprintf("%s", i2))
4         if (c1 < c2)
5                 return -1
6         return (c1 != c2)
7 }
8 function what_is(what_idx, type_idx, special, item, \
9                  location, prev_location, prev_returned_size)
10 {
11         type_idx = array[what_idx]["type"]
12         special = array[what_idx]["special"]
13         switch (special) {
14         case "base_type":
15                 switch (array[what_idx]["encoding"]) {
16                 case 5: # signed
17                         printf("%s ", "int" \
18                         8*array[what_idx]["byte_size"] "_t")
19                         break
20                 case 7: # unsigned
21                         printf("%s ", "uint" \
22                         8*array[what_idx]["byte_size"] "_t")
23                         break
24                 default: # float, signed/unsigned char
25                         printf("%s ", array[what_idx]["name"])
26                         break
27                 }
28                 returned_size = array[what_idx]["byte_size"]
29                 break
30         case "enumeration_type":
31                 printf("%s ", "uint" 8*array[type_idx]["byte_size"] "_t")
32                 returned_size = array[what_idx]["byte_size"]
33                 break
34         case "pointer_type":
35                 printf("%s", "mpers_ptr_t ")
36                 returned_size = array[what_idx]["byte_size"]
37                 break
38         case "array_type":
39                 what_is(type_idx)
40                 to_return = array[what_idx]["upper_bound"]
41                 returned_size = array[what_idx]["upper_bound"] * returned_size
42                 return to_return
43                 break
44         case "structure_type":
45                 print "struct {"
46                 prev_location = 0
47                 location = 0
48                 returned_size = 0
49                 prev_returned_size = 0
50                 for (item in array) {
51                         if ("parent" in array[item] && \
52                                 array[item]["parent"] == what_idx) {
53                                 location = array[item]["location"]
54                                 loc_diff = location - prev_location - \
55                                         prev_returned_size
56                                 if (loc_diff != 0) {
57                                         printf("%s", \
58                                                 "unsigned char mpers_filler_" \
59                                                 item "[" loc_diff "];\n")
60                                 }
61                                 prev_location = location
62                                 returned = what_is(item)
63                                 prev_returned_size = returned_size
64                                 printf("%s", array[item]["name"])
65                                 if (returned) {
66                                         printf("%s", "[" returned "]")
67                                 }
68                                 print ";"
69                         }
70                 }
71                 returned_size = array[what_idx]["byte_size"]
72                 loc_diff = returned_size - prev_location - prev_returned_size
73                 if (loc_diff != 0) {
74                         printf("%s", "unsigned char mpers_end_filler_" \
75                                 item "[" loc_diff "];\n")
76                 }
77                 printf("%s", "} ATTRIBUTE_PACKED ")
78                 break
79         case "union_type":
80                 print "union {"
81                 for (item in array) {
82                         if ("parent" in array[item] && \
83                                 array[item]["parent"] == what_idx) {
84                                 returned = what_is(item)
85                                 printf("%s", array[item]["name"])
86                                 if (returned) {
87                                         printf("%s", "[" returned "]")
88                                 }
89                                 print ";"
90                         }
91                 }
92                 printf("%s", "} ")
93                 returned_size = array[what_idx]["byte_size"]
94                 break
95         case "typedef":
96                 return what_is(type_idx)
97                 break
98         case "member":
99                 return what_is(type_idx)
100                 break
101         default:
102                 what_is(type_idx)
103                 break
104         }
105         return 0
106 }
107 BEGIN {
108         print "#include <inttypes.h>"
109 }
110 /^<[[:xdigit:]]+>/ {
111         match($0, /([[:alnum:]]+)><([[:alnum:]]+)/, matches)
112         level = matches[1]
113         idx = "0x" matches[2]
114         array[idx]["idx"] = idx
115         parent[level] = idx
116         if (level > 1) {
117                 array[idx]["parent"] = parent[level-1]
118         }
119 }
120 /^DW_AT_data_member_location/ {
121         match($0, /[[:digit:]]+/, temparray)
122         array[idx]["location"] = temparray[0]
123 }
124 /^DW_AT_name/ {
125         match($0, /:[[:space:]]+([[:alpha:]_][[:alnum:]_[:space:]]*)/, \
126                 temparray)
127         array[idx]["name"] = temparray[1]
128 }
129 /^DW_AT_byte_size/ {
130         match($0, /[[:digit:]]+/, temparray)
131         array[idx]["byte_size"] = temparray[0]
132 }
133 /^DW_AT_encoding/ {
134         match($0, /[[:digit:]]+/, temparray)
135         array[idx]["encoding"] = temparray[0]
136 }
137 /^DW_AT_type/ {
138         match($0, /:[[:space:]]+<(0x[[:xdigit:]]*)>$/, temparray)
139         array[idx]["type"] = temparray[1]
140 }
141 /^DW_AT_upper_bound/ {
142         match($0, /[[:digit:]]+/, temparray)
143         array[parent[level-1]]["upper_bound"] = temparray[0] + 1
144 }
145 /^Abbrev Number:[^(]+\(DW_TAG_/ {
146         if (match($0, /typedef|union_type|structure_type|pointer_type\
147 |enumeration_type|array_type|base_type|member/, temparray)) {
148                 array[idx]["special"] = temparray[0]
149         }
150 }
151 END {
152         PROCINFO["sorted_in"] = "compare_indices"
153         for (item in array) {
154                 if (array[item]["special"] == "pointer_type") {
155                         print "typedef uint" \
156                                 8*array[item]["byte_size"] "_t mpers_ptr_t;"
157                         break
158                 }
159         }
160         for (item in array) {
161                 if (array[item]["name"] == VAR_NAME) {
162                         type=array[item]["type"]
163                         print "typedef"
164                         what_is(array[item]["type"])
165                         print ARCH_FLAG "_" array[type]["name"] ";"
166                         print "#define MPERS_" \
167                                 ARCH_FLAG "_" array[type]["name"] " " \
168                                 ARCH_FLAG "_" array[type]["name"]
169                         break
170                 }
171         }
172 }