Migrate syscall instrumentation to TP_FIELDS
[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 TMPFILE2=gen.tmp.2
21 TMPFILE3=gen.tmp.3
22 HEADER=headers/${INPUTFILE}_${CLASS}.h
23
24 if [ x"$INPUTDIR" = x"" ]; then
25 echo "Error: Please specify input directory as second argument"
26 exit 1
27 fi
28
29 if [ x"$INPUTFILE" = x"" ]; then
30 echo "Error: Please specify input file as third argument"
31 exit 1
32 fi
33
34 if [ x"$BITNESS" != x"32" ] && [ x"$BITNESS" != x"64" ]; then
35 echo "Error: Please specify bitness as fourth argument (\"32\" or \"64\")"
36 exit 1
37 fi
38
39 cp ${INPUT} ${SRCFILE}
40
41 #Cleanup
42 perl -p -e 's/^\[.*\] //g' ${SRCFILE} > ${TMPFILE}
43 mv ${TMPFILE} ${SRCFILE}
44
45 perl -p -e 's/^syscall sys_([^ ]*)/syscall $1/g' ${SRCFILE} > ${TMPFILE}
46 mv ${TMPFILE} ${SRCFILE}
47
48 #Filter
49
50 if [ "$CLASS" = integers ]; then
51 #select integers and no-args.
52 CLASSCAP=INTEGERS
53 grep -v "\\*\|cap_user_header_t" ${SRCFILE} > ${TMPFILE}
54 mv ${TMPFILE} ${SRCFILE}
55 fi
56
57
58 if [ "$CLASS" = pointers ]; then
59 #select system calls using pointers.
60 CLASSCAP=POINTERS
61 grep "\\*\|cap_#user_header_t" ${SRCFILE} > ${TMPFILE}
62 mv ${TMPFILE} ${SRCFILE}
63 fi
64
65 if [ x"$CLASSCAP" = x"" ]; then
66 echo "Error: Please specify \"integers\" or \"pointers\" as first argument"
67 rm -f ${SRCFILE}
68 exit 1
69 fi
70
71 echo "/* THIS FILE IS AUTO-GENERATED. DO NOT EDIT */" > ${HEADER}
72
73 echo \
74 "#ifndef CREATE_SYSCALL_TABLE
75
76 #if !defined(_TRACE_SYSCALLS_${CLASSCAP}_H) || defined(TRACE_HEADER_MULTI_READ)
77 #define _TRACE_SYSCALLS_${CLASSCAP}_H
78
79 #include \"../../../probes/lttng-tracepoint-event.h\"
80 #include <linux/syscalls.h>
81 #include \"${INPUTFILE}_${CLASS}_override.h\"
82 #include \"syscalls_${CLASS}_override.h\"
83 " >> ${HEADER}
84
85 if [ "$CLASS" = integers ]; then
86
87 NRARGS=0
88
89 printf \
90 '#ifdef SC_ENTER\n'\
91 >> ${HEADER}
92
93 printf \
94 'SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscalls_noargs,\n'\
95 ' TP_FIELDS()\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}"'_$1\n'\
104 'SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscalls_noargs, $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}"'_$1\n'\
117 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
118 ' TP_PROTO(sc_exit(long ret)),\n'\
119 ' TP_ARGS(sc_exit(ret)),\n'\
120 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)))\n'\
121 ')\n'\
122 '#endif/g'\
123 ${TMPFILE} >> ${HEADER}
124
125 printf \
126 '#endif /* else #ifdef SC_ENTER */\n'\
127 >> ${HEADER}
128
129 fi
130
131
132 # types: 4
133 # args 5
134
135 NRARGS=1
136 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
137
138 while read LINE; do
139 echo "${LINE}" > ${TMPFILE2}
140 perl -p -e 's/^syscall ([^ ]*) .*/$1/g' ${TMPFILE2} > ${TMPFILE3}
141 SC_NAME=$(cat ${TMPFILE3})
142 ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 1)
143 echo Syscall: ${SC_NAME} ${ARG1}
144 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
145 'types: \(([^)]*)\) '\
146 'args: \(([^)]*)\)/'\
147 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
148 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
149 ' TP_PROTO(sc_exit(long ret,) $4 $5),\n'\
150 ' TP_ARGS(sc_exit(ret,) $5),\n'\
151 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $5, $5)))\n'\
152 ')\n'\
153 '#endif/g'\
154 ${TMPFILE2} >> ${HEADER}
155 done < ${TMPFILE}
156
157 # types: 4 5
158 # args 6 7
159
160 NRARGS=2
161 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
162
163 while read LINE; do
164 echo "${LINE}" > ${TMPFILE2}
165 perl -p -e 's/^syscall ([^ ]*) .*/$1/g' ${TMPFILE2} > ${TMPFILE3}
166 SC_NAME=$(cat ${TMPFILE3})
167 ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 1)
168 ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 2)
169 echo Syscall: ${SC_NAME} ${ARG1} ${ARG2}
170 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
171 'types: \(([^,]*), ([^)]*)\) '\
172 'args: \(([^,]*), ([^)]*)\)/'\
173 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
174 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
175 ' TP_PROTO(sc_exit(long ret,) $4 $6, $5 $7),\n'\
176 ' TP_ARGS(sc_exit(ret,) $6, $7),\n'\
177 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $6, $6)) '"${ARG2}"'(ctf_integer($5, $7, $7)))\n'\
178 ')\n'\
179 '#endif/g'\
180 ${TMPFILE2} >> ${HEADER}
181 done < ${TMPFILE}
182
183 # types: 4 5 6
184 # args 7 8 9
185
186 NRARGS=3
187 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
188
189 while read LINE; do
190 echo "${LINE}" > ${TMPFILE2}
191 perl -p -e 's/^syscall ([^ ]*) .*/$1/g' ${TMPFILE2} > ${TMPFILE3}
192 SC_NAME=$(cat ${TMPFILE3})
193 ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 1)
194 ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 2)
195 ARG3=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 3)
196 echo Syscall: ${SC_NAME} ${ARG1} ${ARG2} ${ARG3}
197 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
198 'types: \(([^,]*), ([^,]*), ([^)]*)\) '\
199 'args: \(([^,]*), ([^,]*), ([^)]*)\)/'\
200 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
201 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
202 ' TP_PROTO(sc_exit(long ret,) $4 $7, $5 $8, $6 $9),\n'\
203 ' TP_ARGS(sc_exit(ret,) $7, $8, $9),\n'\
204 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $7, $7)) '"${ARG2}"'(ctf_integer($5, $8, $8)) '"${ARG3}"'(ctf_integer($6, $9, $9)))\n'\
205 ')\n'\
206 '#endif/g'\
207 ${TMPFILE2} >> ${HEADER}
208 done < ${TMPFILE}
209
210
211 # types: 4 5 6 7
212 # args 8 9 10 11
213
214 NRARGS=4
215 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
216
217 while read LINE; do
218 echo "${LINE}" > ${TMPFILE2}
219 perl -p -e 's/^syscall ([^ ]*) .*/$1/g' ${TMPFILE2} > ${TMPFILE3}
220 SC_NAME=$(cat ${TMPFILE3})
221 ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 1)
222 ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 2)
223 ARG3=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 3)
224 ARG4=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 4)
225 echo Syscall: ${SC_NAME} ${ARG1} ${ARG2} ${ARG3} ${ARG4}
226 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
227 'types: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
228 'args: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
229 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
230 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
231 ' TP_PROTO(sc_exit(long ret,) $4 $8, $5 $9, $6 $10, $7 $11),\n'\
232 ' TP_ARGS(sc_exit(ret,) $8, $9, $10, $11),\n'\
233 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $8, $8)) '"${ARG2}"'(ctf_integer($5, $9, $9)) '"${ARG3}"'(ctf_integer($6, $10, $10)) '"${ARG4}"'(ctf_integer($7, $11, $11)))\n'\
234 ')\n'\
235 '#endif/g'\
236 ${TMPFILE2} >> ${HEADER}
237 done < ${TMPFILE}
238
239 # types: 4 5 6 7 8
240 # args 9 10 11 12 13
241
242 NRARGS=5
243 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
244
245 while read LINE; do
246 echo "${LINE}" > ${TMPFILE2}
247 perl -p -e 's/^syscall ([^ ]*) .*/$1/g' ${TMPFILE2} > ${TMPFILE3}
248 SC_NAME=$(cat ${TMPFILE3})
249 ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 1)
250 ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 2)
251 ARG3=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 3)
252 ARG4=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 4)
253 ARG5=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 5)
254 echo Syscall: ${SC_NAME} ${ARG1} ${ARG2} ${ARG3} ${ARG4} ${ARG5}
255 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
256 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
257 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
258 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
259 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
260 ' TP_PROTO(sc_exit(long ret,) $4 $9, $5 $10, $6 $11, $7 $12, $8 $13),\n'\
261 ' TP_ARGS(sc_exit(ret,) $9, $10, $11, $12, $13),\n'\
262 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $9, $9)) '"${ARG2}"'(ctf_integer($5, $10, $10)) '"${ARG3}"'(ctf_integer($6, $11, $11)) '"${ARG4}"'(ctf_integer($7, $12, $12)) '"${ARG5}"'(ctf_integer($8, $13, $13)))\n'\
263 ')\n'\
264 '#endif/g'\
265 ${TMPFILE2} >> ${HEADER}
266 done < ${TMPFILE}
267
268
269 # types: 4 5 6 7 8 9
270 # args 10 11 12 13 14 15
271
272 NRARGS=6
273 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
274
275 while read LINE; do
276 echo "${LINE}" > ${TMPFILE2}
277 perl -p -e 's/^syscall ([^ ]*) .*/$1/g' ${TMPFILE2} > ${TMPFILE3}
278 SC_NAME=$(cat ${TMPFILE3})
279 ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 1)
280 ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 2)
281 ARG3=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 3)
282 ARG4=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 4)
283 ARG5=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 5)
284 ARG6=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 6)
285 echo Syscall: ${SC_NAME} ${ARG1} ${ARG2} ${ARG3} ${ARG4} ${ARG5} ${ARG6}
286 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
287 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\) '\
288 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\)/'\
289 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
290 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
291 ' TP_PROTO(sc_exit(long ret,) $4 $10, $5 $11, $6 $12, $7 $13, $8 $14, $9 $15),\n'\
292 ' TP_ARGS(sc_exit(ret,) $10, $11, $12, $13, $14, $15),\n'\
293 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $10, $10)) '"${ARG2}"'(ctf_integer($5, $11, $11)) '"${ARG3}"'(ctf_integer($6, $12, $12)) '"${ARG4}"'(ctf_integer($7, $13, $13)) '"${ARG5}"'(ctf_integer($8, $14, $14)) '"${ARG6}"'(ctf_integer($9, $15, $15)))\n'\
294 ')\n'\
295 '#endif/g'\
296 ${TMPFILE2} >> ${HEADER}
297 done < ${TMPFILE}
298
299 # Macro for tracing syscall table
300
301 echo \
302 "
303 #endif /* _TRACE_SYSCALLS_${CLASSCAP}_H */
304
305 /* This part must be outside protection */
306 #include \"../../../probes/define_trace.h\"
307
308 #else /* CREATE_SYSCALL_TABLE */
309
310 #include \"${INPUTFILE}_${CLASS}_override.h\"
311 #include \"syscalls_${CLASS}_override.h\"
312 " >> ${HEADER}
313
314 NRARGS=0
315
316 if [ "$CLASS" = integers ]; then
317 #noargs
318
319 printf \
320 '#ifdef SC_ENTER\n'\
321 >> ${HEADER}
322
323 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
324 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
325 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
326 'TRACE_SYSCALL_TABLE\(syscalls_noargs, $1, $2, $3\)\n'\
327 '#endif/g'\
328 ${TMPFILE} >> ${HEADER}
329
330 printf \
331 '#else /* #ifdef SC_ENTER */\n'\
332 >> ${HEADER}
333
334 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
335 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
336 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
337 'TRACE_SYSCALL_TABLE($1, $1, $2, $3)\n'\
338 '#endif/g'\
339 ${TMPFILE} >> ${HEADER}
340
341 printf \
342 '#endif /* else #ifdef SC_ENTER */\n'\
343 >> ${HEADER}
344
345 fi
346
347 #others.
348 grep -v "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
349 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
350 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
351 'TRACE_SYSCALL_TABLE($1, $1, $2, $3)\n'\
352 '#endif/g'\
353 ${TMPFILE} >> ${HEADER}
354
355 echo -n \
356 "
357 #endif /* CREATE_SYSCALL_TABLE */
358 " >> ${HEADER}
359
360 #fields names: ...char * type with *name* or *file* or *path* or *root*
361 # or *put_old* or *type*
362 cp -f ${HEADER} ${TMPFILE}
363 rm -f ${HEADER}
364 perl -p -e 's/ctf_integer\(([^,)]*char \*), ([^\)]*)(name|file|path|root|put_old|type)([^\)]*)\)/ctf_user_string($2$3$4)/g'\
365 ${TMPFILE} >> ${HEADER}
366
367 #prettify addresses heuristics.
368 #field names with addr or ptr
369 cp -f ${HEADER} ${TMPFILE}
370 rm -f ${HEADER}
371 perl -p -e 's/ctf_integer\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/ctf_integer_hex($1, $2$3, $2$3)/g'\
372 ${TMPFILE} >> ${HEADER}
373
374 #field types ending with '*'
375 cp -f ${HEADER} ${TMPFILE}
376 rm -f ${HEADER}
377 perl -p -e 's/ctf_integer\(([^,)]*\*), ([^),]*)\)/ctf_integer_hex($1, $2, $2)/g'\
378 ${TMPFILE} >> ${HEADER}
379
380 rm -f ${INPUTFILE}.tmp
381 rm -f ${TMPFILE3}
382 rm -f ${TMPFILE2}
383 rm -f ${TMPFILE}
384 rm -f ${SRCFILE}
This page took 0.039101 seconds and 4 git commands to generate.