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.
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
17 INPUT
=${INPUTDIR}/${INPUTFILE}
22 HEADER
=headers
/${INPUTFILE}_
${CLASS}.h
24 if [ x
"$INPUTDIR" = x
"" ]; then
25 echo "Error: Please specify input directory as second argument"
29 if [ x
"$INPUTFILE" = x
"" ]; then
30 echo "Error: Please specify input file as third argument"
34 if [ x
"$BITNESS" != x
"32" ] && [ x
"$BITNESS" != x
"64" ]; then
35 echo "Error: Please specify bitness as fourth argument (\"32\" or \"64\")"
39 cp ${INPUT} ${SRCFILE}
42 perl
-p -e 's/^\[.*\] //g' ${SRCFILE} > ${TMPFILE}
43 mv ${TMPFILE} ${SRCFILE}
45 perl
-p -e 's/^syscall sys_([^ ]*)/syscall $1/g' ${SRCFILE} > ${TMPFILE}
46 mv ${TMPFILE} ${SRCFILE}
50 if [ "$CLASS" = integers
]; then
51 #select integers and no-args.
53 grep -v "\\*\|cap_user_header_t" ${SRCFILE} > ${TMPFILE}
54 mv ${TMPFILE} ${SRCFILE}
58 if [ "$CLASS" = pointers
]; then
59 #select system calls using pointers.
61 grep "\\*\|cap_#user_header_t" ${SRCFILE} > ${TMPFILE}
62 mv ${TMPFILE} ${SRCFILE}
65 if [ x
"$CLASSCAP" = x
"" ]; then
66 echo "Error: Please specify \"integers\" or \"pointers\" as first argument"
71 echo "/* THIS FILE IS AUTO-GENERATED. DO NOT EDIT */" > ${HEADER}
74 "#ifndef CREATE_SYSCALL_TABLE
76 #if !defined(_TRACE_SYSCALLS_${CLASSCAP}_H) || defined(TRACE_HEADER_MULTI_READ)
77 #define _TRACE_SYSCALLS_${CLASSCAP}_H
79 #include <probes/lttng-tracepoint-event.h>
80 #include <linux/syscalls.h>
81 #include \"${INPUTFILE}_${CLASS}_override.h\"
82 #include \"syscalls_${CLASS}_override.h\"
85 if [ "$CLASS" = integers
]; then
94 'SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscalls_noargs,\n'\
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'\
106 ${TMPFILE} >> ${HEADER}
109 '#else /* #ifdef SC_ENTER */\n'\
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'\
123 ${TMPFILE} >> ${HEADER}
126 '#endif /* else #ifdef SC_ENTER */\n'\
136 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
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'\
154 ${TMPFILE2} >> ${HEADER}
161 grep "^syscall
[^
]* nr
[^
]* nbargs
${NRARGS} " ${SRCFILE} > ${TMPFILE}
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'\
180 ${TMPFILE2} >> ${HEADER}
187 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
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'\
207 ${TMPFILE2} >> ${HEADER}
215 grep "^syscall
[^
]* nr
[^
]* nbargs
${NRARGS} " ${SRCFILE} > ${TMPFILE}
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'\
236 ${TMPFILE2} >> ${HEADER}
243 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
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'\
265 ${TMPFILE2} >> ${HEADER}
270 # args 10 11 12 13 14 15
273 grep "^syscall
[^
]* nr
[^
]* nbargs
${NRARGS} " ${SRCFILE} > ${TMPFILE}
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'\
296 ${TMPFILE2} >> ${HEADER}
299 # Macro for tracing syscall table
303 #endif /* _TRACE_SYSCALLS_${CLASSCAP}_H */
305 /* This part must be outside protection */
306 #include <probes/define_trace.h>
308 #else /* CREATE_SYSCALL_TABLE */
310 #include \"${INPUTFILE}_${CLASS}_override.h\"
311 #include \"syscalls_${CLASS}_override.h\"
316 if [ "$CLASS" = integers
]; then
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'\
328 ${TMPFILE} >> ${HEADER}
331 '#else /* #ifdef SC_ENTER */\n'\
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'\
339 ${TMPFILE} >> ${HEADER}
342 '#endif /* else #ifdef SC_ENTER */\n'\
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'\
353 ${TMPFILE} >> ${HEADER}
357 #endif /* CREATE_SYSCALL_TABLE */
360 #fields names: ...char * type with *name* or *file* or *path* or *root*
361 # or *put_old* or *type*
362 cp -f ${HEADER} ${TMPFILE}
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}
367 #prettify addresses heuristics.
368 #field names with addr or ptr
369 cp -f ${HEADER} ${TMPFILE}
371 perl -p -e 's/ctf_integer\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/ctf_integer_hex($1, $2$3, $2$3)/g'\
372 ${TMPFILE} >> ${HEADER}
374 #field types ending with '*'
375 cp -f ${HEADER} ${TMPFILE}
377 perl -p -e 's/ctf_integer\(([^,)]*\*), ([^),]*)\)/ctf_integer_hex($1, $2, $2)/g'\
378 ${TMPFILE} >> ${HEADER}
380 rm -f ${INPUTFILE}.tmp