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> <arch_name> <bitness> <output_dir>
10 # lttng-syscalls-generate-headers.sh integers 3.0.4 x86 64 ../../include/instrumentation/syscalls/
11 # lttng-syscalls-generate-headers.sh pointers 3.0.4 x86 64 ../../include/instrumentation/syscalls/
18 ARCH_NAME
="$ARCH-$BITNESS"
19 INPUTFILE
="$ARCH_NAME-syscalls"
21 if [ "$VERSIONDIR" = "" ]; then
22 echo "Error: Please specify input directory as second argument" >&2
26 if [ "$INPUTFILE" = "" ]; then
27 echo "Error: Please specify input file as third argument" >&2
31 if [ "$BITNESS" != "32" ] && [ "$BITNESS" != "64" ]; then
32 echo "Error: Please specify bitness as fourth argument (\"32\" or \"64\")" >&2
36 if [ "$ARCH_NAME" = "" ]; then
37 echo "Error: Please specify the architecture name as fourth argument" >&2
41 if [ "$OUTPUTDIR" = "" ]; then
42 echo "Error: Please specify output directory as fifth argument" >&2
46 # Abort on error and undefined variable
49 INPUT
=${VERSIONDIR}/${INPUTFILE}
50 HEADER
="${OUTPUTDIR}/${INPUTFILE}_${CLASS}.h"
56 # Delete temp files on exit
57 trap 'rm -f "${SRCFILE}" "${TMPFILE}"' EXIT
59 cp "${INPUT}" "${SRCFILE}"
61 ## Cleanup the input file
62 # Remove the dmesg timestamp if present
63 perl
-pi -e 's/^\[.*\] //g' "${SRCFILE}"
64 # Remove the 'sys_' prefix from syscall names
65 perl
-pi -e 's/^syscall sys_([^ ]*)/syscall $1/g' "${SRCFILE}"
66 # Remove the user attribute from arguments
67 sed -i 's/ __attribute__((user))//g' "${SRCFILE}"
71 if [ "$CLASS" = integers
]; then
72 #select integers and no-args.
74 grep -v "\\*\|cap_user_header_t" "${SRCFILE}" > "${TMPFILE}"
75 mv "${TMPFILE}" "${SRCFILE}"
76 elif [ "$CLASS" = pointers
]; then
77 #select system calls using pointers.
79 grep "\\*\|cap_#user_header_t" "${SRCFILE}" > "${TMPFILE}"
80 mv "${TMPFILE}" "${SRCFILE}"
82 echo "Error: Please specify \"integers\" or \"pointers\" as first argument" >&2
87 echo "/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) */
88 /* SPDX-FileCopyrightText: $(date +%Y) EfficiOS Inc. */
90 /* THIS FILE IS AUTO-GENERATED. DO NOT EDIT */
92 /* Generated from ${INPUTFILE} ${VERSIONDIR} */
94 #ifndef CREATE_SYSCALL_TABLE
96 #if !defined(_TRACE_SYSCALLS_${CLASSCAP}_H) || defined(TRACE_HEADER_MULTI_READ)
97 #define _TRACE_SYSCALLS_${CLASSCAP}_H
99 #include <lttng/tracepoint-event.h>
100 #include <linux/syscalls.h>
101 #include \"${INPUTFILE}_${CLASS}_override.h\"
102 #include \"syscalls_${CLASS}_override.h\"
105 if [ "$CLASS" = integers
]; then
109 # shellcheck disable=SC2129
112 SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscalls_noargs,
117 # shellcheck disable=SC2026
118 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
119 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
120 'types: \(([^)]*)\) '\
121 'args: \(([^)]*)\)/'\
122 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
123 'SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscalls_noargs, $1)\n'\
124 '#endif/g' >> "${HEADER}"
126 printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}"
128 # shellcheck disable=SC2026
129 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
130 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
131 'types: \(([^)]*)\) '\
132 'args: \(([^)]*)\)/'\
133 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
134 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
135 ' TP_PROTO(sc_exit(long ret)),\n'\
136 ' TP_ARGS(sc_exit(ret)),\n'\
137 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)))\n'\
139 '#endif/g' >> "${HEADER}"
141 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
150 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
151 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
152 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 1)
154 echo Syscall
: "${SC_NAME}" "${ARG1}"
156 # shellcheck disable=SC2026
157 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
158 'types: \(([^)]*)\) '\
159 'args: \(([^)]*)\)/'\
160 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
161 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
162 ' TP_PROTO(sc_exit(long ret,) $4 $5),\n'\
163 ' TP_ARGS(sc_exit(ret,) $5),\n'\
164 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $5, $5)))\n'\
166 '#endif/g' >> "${HEADER}"
173 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
174 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
175 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 1)
176 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 2)
178 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}"
180 # shellcheck disable=SC2026
181 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
182 'types: \(([^,]*), ([^)]*)\) '\
183 'args: \(([^,]*), ([^)]*)\)/'\
184 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
185 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
186 ' TP_PROTO(sc_exit(long ret,) $4 $6, $5 $7),\n'\
187 ' TP_ARGS(sc_exit(ret,) $6, $7),\n'\
188 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $6, $6)) '"${ARG2}"'(ctf_integer($5, $7, $7)))\n'\
190 '#endif/g' >> "${HEADER}"
197 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
198 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
199 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 1)
200 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 2)
201 ARG3
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 3)
203 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}"
205 # shellcheck disable=SC2026
206 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
207 'types: \(([^,]*), ([^,]*), ([^)]*)\) '\
208 'args: \(([^,]*), ([^,]*), ([^)]*)\)/'\
209 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
210 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
211 ' TP_PROTO(sc_exit(long ret,) $4 $7, $5 $8, $6 $9),\n'\
212 ' TP_ARGS(sc_exit(ret,) $7, $8, $9),\n'\
213 ' 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'\
215 '#endif/g' >> "${HEADER}"
223 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
224 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
225 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 1)
226 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 2)
227 ARG3
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 3)
228 ARG4
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 4)
230 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}"
232 # shellcheck disable=SC2026
233 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
234 'types: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
235 'args: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
236 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
237 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
238 ' TP_PROTO(sc_exit(long ret,) $4 $8, $5 $9, $6 $10, $7 $11),\n'\
239 ' TP_ARGS(sc_exit(ret,) $8, $9, $10, $11),\n'\
240 ' 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'\
242 '#endif/g' >> "${HEADER}"
249 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
250 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
251 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 1)
252 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 2)
253 ARG3
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 3)
254 ARG4
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 4)
255 ARG5
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 5)
257 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}"
259 # shellcheck disable=SC2026
260 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
261 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
262 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
263 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
264 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
265 ' TP_PROTO(sc_exit(long ret,) $4 $9, $5 $10, $6 $11, $7 $12, $8 $13),\n'\
266 ' TP_ARGS(sc_exit(ret,) $9, $10, $11, $12, $13),\n'\
267 ' 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'\
269 '#endif/g' >> "${HEADER}"
274 # args 10 11 12 13 14 15
277 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
278 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
279 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 1)
280 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 2)
281 ARG3
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 3)
282 ARG4
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 4)
283 ARG5
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 5)
284 ARG6
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" "$NRARGS" 6)
286 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}" "${ARG6}"
288 # shellcheck disable=SC2026
289 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
290 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\) '\
291 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\)/'\
292 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
293 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
294 ' TP_PROTO(sc_exit(long ret,) $4 $10, $5 $11, $6 $12, $7 $13, $8 $14, $9 $15),\n'\
295 ' TP_ARGS(sc_exit(ret,) $10, $11, $12, $13, $14, $15),\n'\
296 ' 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'\
298 '#endif/g' >> "${HEADER}"
301 # Macro for tracing syscall table
305 #endif /* _TRACE_SYSCALLS_${CLASSCAP}_H */
307 /* This part must be outside protection */
308 #include <lttng/define_trace.h>
310 #else /* CREATE_SYSCALL_TABLE */
312 #include \"${INPUTFILE}_${CLASS}_override.h\"
313 #include \"syscalls_${CLASS}_override.h\"
318 if [ "$CLASS" = integers
]; then
321 # shellcheck disable=SC2129
322 printf '#ifdef SC_ENTER\n' >> "${HEADER}"
324 # shellcheck disable=SC2026
325 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
326 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
327 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
328 'TRACE_SYSCALL_TABLE\(syscalls_noargs, $1, $2, $3\)\n'\
329 '#endif/g' >> "${HEADER}"
331 printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}"
333 # shellcheck disable=SC2026
334 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
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' >> "${HEADER}"
340 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
344 # shellcheck disable=SC2026
345 grep -v "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
346 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
347 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
348 'TRACE_SYSCALL_TABLE($1, $1, $2, $3)\n'\
349 '#endif/g' >> "${HEADER}"
351 printf '\n#endif /* CREATE_SYSCALL_TABLE */\n' >> "${HEADER}"
353 #fields names: ...char * type with *name* or *file* or *path* or *root*
354 # or *put_old* or *type*
355 perl
-pi -e 's/ctf_integer\(([^,)]*char \*), ([^\)]*)(name|file|path|root|put_old|type)([^\)]*)\)/ctf_user_string($2$3$4)/g' \
358 #prettify addresses heuristics.
359 #field names with addr or ptr
360 perl
-pi -e 's/ctf_integer\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/ctf_integer_hex($1, $2$3, $2$3)/g' \
363 #field types ending with '*'
364 perl
-pi -e 's/ctf_integer\(([^,)]*\*), ([^),]*)\)/ctf_integer_hex($1, $2, $2)/g' "${HEADER}"