Extract system call exit return value
[lttng-modules.git] / instrumentation / syscalls / lttng-syscalls-generate-headers.sh
1 #!/bin/sh
2
3 # Generate system call probe description macros from syscall metadata dump file.
4 # The resulting header will be written in the headers subdirectory, in a file name
5 # based on the name of the input file.
6 #
7 # example usage:
8 #
9 # lttng-syscalls-generate-headers.sh <type> <input_dir> <input_filename_in_dir> <bitness>
10 # lttng-syscalls-generate-headers.sh integers 3.0.4 x86-64-syscalls-3.0.4 64
11 # lttng-syscalls-generate-headers.sh pointers 3.0.4 x86-64-syscalls-3.0.4 64
12
13 CLASS=$1
14 INPUTDIR=$2
15 INPUTFILE=$3
16 BITNESS=$4
17 INPUT=${INPUTDIR}/${INPUTFILE}
18 SRCFILE=gen.tmp.0
19 TMPFILE=gen.tmp.1
20 HEADER=headers/${INPUTFILE}_${CLASS}.h
21
22 if [ x"$INPUTDIR" = x"" ]; then
23 echo "Error: Please specify input directory as second argument"
24 exit 1
25 fi
26
27 if [ x"$INPUTFILE" = x"" ]; then
28 echo "Error: Please specify input file as third argument"
29 exit 1
30 fi
31
32 if [ x"$BITNESS" != x"32" ] && [ x"$BITNESS" != x"64" ]; then
33 echo "Error: Please specify bitness as fourth argument (\"32\" or \"64\")"
34 exit 1
35 fi
36
37 cp ${INPUT} ${SRCFILE}
38
39 #Cleanup
40 perl -p -e 's/^\[.*\] //g' ${SRCFILE} > ${TMPFILE}
41 mv ${TMPFILE} ${SRCFILE}
42
43 perl -p -e 's/^syscall sys_([^ ]*)/syscall $1/g' ${SRCFILE} > ${TMPFILE}
44 mv ${TMPFILE} ${SRCFILE}
45
46 #Filter
47
48 if [ "$CLASS" = integers ]; then
49 #select integers and no-args.
50 CLASSCAP=INTEGERS
51 grep -v "\\*\|cap_user_header_t" ${SRCFILE} > ${TMPFILE}
52 mv ${TMPFILE} ${SRCFILE}
53 fi
54
55
56 if [ "$CLASS" = pointers ]; then
57 #select system calls using pointers.
58 CLASSCAP=POINTERS
59 grep "\\*\|cap_#user_header_t" ${SRCFILE} > ${TMPFILE}
60 mv ${TMPFILE} ${SRCFILE}
61 fi
62
63 if [ x"$CLASSCAP" = x"" ]; then
64 echo "Error: Please specify \"integers\" or \"pointers\" as first argument"
65 rm -f ${SRCFILE}
66 exit 1
67 fi
68
69 echo "/* THIS FILE IS AUTO-GENERATED. DO NOT EDIT */" > ${HEADER}
70
71 echo \
72 "#ifndef CREATE_SYSCALL_TABLE
73
74 #if !defined(_TRACE_SYSCALLS_${CLASSCAP}_H) || defined(TRACE_HEADER_MULTI_READ)
75 #define _TRACE_SYSCALLS_${CLASSCAP}_H
76
77 #include <linux/tracepoint.h>
78 #include <linux/syscalls.h>
79 #include \"${INPUTFILE}_${CLASS}_override.h\"
80 #include \"syscalls_${CLASS}_override.h\"
81 " >> ${HEADER}
82
83 if [ "$CLASS" = integers ]; then
84
85 NRARGS=0
86
87 printf \
88 '#ifdef SC_ENTER\n'\
89 >> ${HEADER}
90
91 printf \
92 'SC_DECLARE_EVENT_CLASS_NOARGS(syscalls_noargs,\n'\
93 ' TP_STRUCT__entry(),\n'\
94 ' TP_fast_assign(),\n'\
95 ' TP_printk()\n'\
96 ')\n'\
97 >> ${HEADER}
98
99 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
100 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
101 'types: \(([^)]*)\) '\
102 'args: \(([^)]*)\)/'\
103 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
104 'SC_DEFINE_EVENT_NOARGS(syscalls_noargs, sys_$1)\n'\
105 '#endif/g'\
106 ${TMPFILE} >> ${HEADER}
107
108 printf \
109 '#else /* #ifdef SC_ENTER */\n'\
110 >> ${HEADER}
111
112 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
113 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
114 'types: \(([^)]*)\) '\
115 'args: \(([^)]*)\)/'\
116 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
117 'SC_TRACE_EVENT(sys_$1,\n'\
118 ' TP_PROTO(sc_exit(long ret)),\n'\
119 ' TP_ARGS(sc_exit(ret)),\n'\
120 ' TP_STRUCT__entry(sc_exit(__field(long, ret))),\n'\
121 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret))),\n'\
122 ' TP_printk()\n'\
123 ')\n'\
124 '#endif/g'\
125 ${TMPFILE} >> ${HEADER}
126
127 printf \
128 '#endif /* else #ifdef SC_ENTER */\n'\
129 >> ${HEADER}
130
131 fi
132
133
134 # types: 4
135 # args 5
136
137 NRARGS=1
138 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
139 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
140 'types: \(([^)]*)\) '\
141 'args: \(([^)]*)\)/'\
142 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
143 'SC_TRACE_EVENT(sys_$1,\n'\
144 ' TP_PROTO(sc_exit(long ret,) $4 $5),\n'\
145 ' TP_ARGS(sc_exit(ret,) $5),\n'\
146 ' TP_STRUCT__entry(sc_exit(__field(long, ret)) __field($4, $5)),\n'\
147 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret)) tp_assign($4, $5, $5)),\n'\
148 ' TP_printk()\n'\
149 ')\n'\
150 '#endif/g'\
151 ${TMPFILE} >> ${HEADER}
152
153 # types: 4 5
154 # args 6 7
155
156 NRARGS=2
157 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
158 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
159 'types: \(([^,]*), ([^)]*)\) '\
160 'args: \(([^,]*), ([^)]*)\)/'\
161 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
162 'SC_TRACE_EVENT(sys_$1,\n'\
163 ' TP_PROTO(sc_exit(long ret,) $4 $6, $5 $7),\n'\
164 ' TP_ARGS(sc_exit(ret,) $6, $7),\n'\
165 ' TP_STRUCT__entry(sc_exit(__field(long, ret)) __field($4, $6) __field($5, $7)),\n'\
166 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret)) tp_assign($4, $6, $6) tp_assign($5, $7, $7)),\n'\
167 ' TP_printk()\n'\
168 ')\n'\
169 '#endif/g'\
170 ${TMPFILE} >> ${HEADER}
171
172 # types: 4 5 6
173 # args 7 8 9
174
175 NRARGS=3
176 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
177 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
178 'types: \(([^,]*), ([^,]*), ([^)]*)\) '\
179 'args: \(([^,]*), ([^,]*), ([^)]*)\)/'\
180 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
181 'SC_TRACE_EVENT(sys_$1,\n'\
182 ' TP_PROTO(sc_exit(long ret,) $4 $7, $5 $8, $6 $9),\n'\
183 ' TP_ARGS(sc_exit(ret,) $7, $8, $9),\n'\
184 ' TP_STRUCT__entry(sc_exit(__field(long, ret)) __field($4, $7) __field($5, $8) __field($6, $9)),\n'\
185 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret)) tp_assign($4, $7, $7) tp_assign($5, $8, $8) tp_assign($6, $9, $9)),\n'\
186 ' TP_printk()\n'\
187 ')\n'\
188 '#endif/g'\
189 ${TMPFILE} >> ${HEADER}
190
191
192 # types: 4 5 6 7
193 # args 8 9 10 11
194
195 NRARGS=4
196 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
197 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
198 'types: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
199 'args: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
200 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
201 'SC_TRACE_EVENT(sys_$1,\n'\
202 ' TP_PROTO(sc_exit(long ret,) $4 $8, $5 $9, $6 $10, $7 $11),\n'\
203 ' TP_ARGS(sc_exit(ret,) $8, $9, $10, $11),\n'\
204 ' TP_STRUCT__entry(sc_exit(__field(long, ret)) __field($4, $8) __field($5, $9) __field($6, $10) __field($7, $11)),\n'\
205 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret)) tp_assign($4, $8, $8) tp_assign($5, $9, $9) tp_assign($6, $10, $10) tp_assign($7, $11, $11)),\n'\
206 ' TP_printk()\n'\
207 ')\n'\
208 '#endif/g'\
209 ${TMPFILE} >> ${HEADER}
210
211 # types: 4 5 6 7 8
212 # args 9 10 11 12 13
213
214 NRARGS=5
215 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
216 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
217 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
218 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
219 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
220 'SC_TRACE_EVENT(sys_$1,\n'\
221 ' TP_PROTO(sc_exit(long ret,) $4 $9, $5 $10, $6 $11, $7 $12, $8 $13),\n'\
222 ' TP_ARGS(sc_exit(ret,) $9, $10, $11, $12, $13),\n'\
223 ' TP_STRUCT__entry(sc_exit(__field(long, ret)) __field($4, $9) __field($5, $10) __field($6, $11) __field($7, $12) __field($8, $13)),\n'\
224 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret)) tp_assign($4, $9, $9) tp_assign($5, $10, $10) tp_assign($6, $11, $11) tp_assign($7, $12, $12) tp_assign($8, $13, $13)),\n'\
225 ' TP_printk()\n'\
226 ')\n'\
227 '#endif/g'\
228 ${TMPFILE} >> ${HEADER}
229
230
231 # types: 4 5 6 7 8 9
232 # args 10 11 12 13 14 15
233
234 NRARGS=6
235 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
236 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
237 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\) '\
238 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\)/'\
239 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
240 'SC_TRACE_EVENT(sys_$1,\n'\
241 ' TP_PROTO(sc_exit(long ret,) $4 $10, $5 $11, $6 $12, $7 $13, $8 $14, $9 $15),\n'\
242 ' TP_ARGS(sc_exit(ret,) $10, $11, $12, $13, $14, $15),\n'\
243 ' TP_STRUCT__entry(sc_exit(__field(long, ret)) __field($4, $10) __field($5, $11) __field($6, $12) __field($7, $13) __field($8, $14) __field($9, $15)),\n'\
244 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret)) tp_assign($4, $10, $10) tp_assign($5, $11, $11) tp_assign($6, $12, $12) tp_assign($7, $13, $13) tp_assign($8, $14, $14) tp_assign($9, $15, $15)),\n'\
245 ' TP_printk()\n'\
246 ')\n'\
247 '#endif/g'\
248 ${TMPFILE} >> ${HEADER}
249
250 # Macro for tracing syscall table
251
252 echo \
253 "
254 #endif /* _TRACE_SYSCALLS_${CLASSCAP}_H */
255
256 /* This part must be outside protection */
257 #include \"../../../probes/define_trace.h\"
258
259 #else /* CREATE_SYSCALL_TABLE */
260
261 #include \"${INPUTFILE}_${CLASS}_override.h\"
262 #include \"syscalls_${CLASS}_override.h\"
263 " >> ${HEADER}
264
265 NRARGS=0
266
267 if [ "$CLASS" = integers ]; then
268 #noargs
269
270 printf \
271 '#ifdef SC_ENTER\n'\
272 >> ${HEADER}
273
274 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
275 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
276 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_sys_$1\n'\
277 'TRACE_SYSCALL_TABLE\(syscalls_noargs, sys_$1, $2, $3\)\n'\
278 '#endif/g'\
279 ${TMPFILE} >> ${HEADER}
280
281 printf \
282 '#else /* #ifdef SC_ENTER */\n'\
283 >> ${HEADER}
284
285 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
286 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
287 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_sys_$1\n'\
288 'TRACE_SYSCALL_TABLE(sys_$1, sys_$1, $2, $3)\n'\
289 '#endif/g'\
290 ${TMPFILE} >> ${HEADER}
291
292 printf \
293 '#endif /* else #ifdef SC_ENTER */\n'\
294 >> ${HEADER}
295
296 fi
297
298 #others.
299 grep -v "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
300 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
301 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_sys_$1\n'\
302 'TRACE_SYSCALL_TABLE(sys_$1, sys_$1, $2, $3)\n'\
303 '#endif/g'\
304 ${TMPFILE} >> ${HEADER}
305
306 echo -n \
307 "
308 #endif /* CREATE_SYSCALL_TABLE */
309 " >> ${HEADER}
310
311 #fields names: ...char * type with *name* or *file* or *path* or *root*
312 # or *put_old* or *type*
313 cp -f ${HEADER} ${TMPFILE}
314 rm -f ${HEADER}
315 perl -p -e 's/__field\(([^,)]*char \*), ([^\)]*)(name|file|path|root|put_old|type)([^\)]*)\)/__string_from_user($2$3$4, $2$3$4)/g'\
316 ${TMPFILE} >> ${HEADER}
317 cp -f ${HEADER} ${TMPFILE}
318 rm -f ${HEADER}
319 perl -p -e 's/tp_assign\(([^,)]*char \*), ([^,]*)(name|file|path|root|put_old|type)([^,]*), ([^\)]*)\)/tp_copy_string_from_user($2$3$4, $5)/g'\
320 ${TMPFILE} >> ${HEADER}
321
322 #prettify addresses heuristics.
323 #field names with addr or ptr
324 cp -f ${HEADER} ${TMPFILE}
325 rm -f ${HEADER}
326 perl -p -e 's/__field\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/__field_hex($1, $2$3)/g'\
327 ${TMPFILE} >> ${HEADER}
328
329 #field types ending with '*'
330 cp -f ${HEADER} ${TMPFILE}
331 rm -f ${HEADER}
332 perl -p -e 's/__field\(([^,)]*\*), ([^),]*)\)/__field_hex($1, $2)/g'\
333 ${TMPFILE} >> ${HEADER}
334
335 #strip the extra type information from tp_assign.
336 cp -f ${HEADER} ${TMPFILE}
337 rm -f ${HEADER}
338 perl -p -e 's/tp_assign\(([^,)]*), ([^,]*), ([^\)]*)\)/tp_assign($2, $3)/g'\
339 ${TMPFILE} >> ${HEADER}
340
341 rm -f ${INPUTFILE}.tmp
342 rm -f ${TMPFILE}
343 rm -f ${SRCFILE}
This page took 0.048112 seconds and 4 git commands to generate.