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> <arch_name> <bitness>
10 # lttng-syscalls-generate-headers.sh integers 3.0.4 x86-64-syscalls x86-64 64
11 # lttng-syscalls-generate-headers.sh pointers 3.0.4 x86-64-syscalls x86-64 64
20 if [ "$VERSIONDIR" = "" ]; then
21 echo "Error: Please specify input directory as second argument" >&2
25 if [ "$INPUTFILE" = "" ]; then
26 echo "Error: Please specify input file as third argument" >&2
30 if [ "$BITNESS" != "32" ] && [ "$BITNESS" != "64" ]; then
31 echo "Error: Please specify bitness as fourth argument (\"32\" or \"64\")" >&2
35 if [ "$ARCH_NAME" = "" ]; then
36 echo "Error: Please specify the architecture name as fourth argument" >&2
40 if [ "$OUTPUTDIR" = "" ]; then
41 echo "Error: Please specify output directory as fifth argument" >&2
45 # Abort on error and undefined variable
48 INPUT
=${VERSIONDIR}/${INPUTFILE}
49 HEADER
="${OUTPUTDIR}/${INPUTFILE}_${CLASS}.h"
55 # Delete temp files on exit
56 trap 'rm -f "${SRCFILE}" "${TMPFILE}"' EXIT
58 cp "${INPUT}" "${SRCFILE}"
60 ## Cleanup the input file
61 # Remove the dmesg timestamp if present
62 perl
-pi -e 's/^\[.*\] //g' "${SRCFILE}"
63 # Remove the 'sys_' prefix from syscall names
64 perl
-pi -e 's/^syscall sys_([^ ]*)/syscall $1/g' "${SRCFILE}"
65 # Remove the user attribute from arguments
66 sed -i 's/ __attribute__((user))//g' "${SRCFILE}"
70 if [ "$CLASS" = integers
]; then
71 #select integers and no-args.
73 grep -v "\\*\|cap_user_header_t" "${SRCFILE}" > "${TMPFILE}"
74 mv "${TMPFILE}" "${SRCFILE}"
75 elif [ "$CLASS" = pointers
]; then
76 #select system calls using pointers.
78 grep "\\*\|cap_#user_header_t" "${SRCFILE}" > "${TMPFILE}"
79 mv "${TMPFILE}" "${SRCFILE}"
81 echo "Error: Please specify \"integers\" or \"pointers\" as first argument" >&2
86 echo "/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) */
87 /* SPDX-FileCopyrightText: $(date +%Y) EfficiOS Inc. */
89 /* THIS FILE IS AUTO-GENERATED. DO NOT EDIT */
91 /* Generated from ${INPUTFILE} ${VERSIONDIR} */
93 #ifndef CREATE_SYSCALL_TABLE
95 #if !defined(_TRACE_SYSCALLS_${CLASSCAP}_H) || defined(TRACE_HEADER_MULTI_READ)
96 #define _TRACE_SYSCALLS_${CLASSCAP}_H
98 #include <lttng/tracepoint-event.h>
99 #include <linux/syscalls.h>
100 #include \"${INPUTFILE}_${CLASS}_override.h\"
101 #include \"syscalls_${CLASS}_override.h\"
104 if [ "$CLASS" = integers
]; then
108 # shellcheck disable=SC2129
111 SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscalls_noargs,
116 # shellcheck disable=SC2026
117 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
118 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
119 'types: \(([^)]*)\) '\
120 'args: \(([^)]*)\)/'\
121 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
122 'SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscalls_noargs, $1)\n'\
123 '#endif/g' >> "${HEADER}"
125 printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}"
127 # shellcheck disable=SC2026
128 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
129 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
130 'types: \(([^)]*)\) '\
131 'args: \(([^)]*)\)/'\
132 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
133 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
134 ' TP_PROTO(sc_exit(long ret)),\n'\
135 ' TP_ARGS(sc_exit(ret)),\n'\
136 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)))\n'\
138 '#endif/g' >> "${HEADER}"
140 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
149 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
150 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
151 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 1)
153 echo Syscall
: "${SC_NAME}" "${ARG1}"
155 # shellcheck disable=SC2026
156 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
157 'types: \(([^)]*)\) '\
158 'args: \(([^)]*)\)/'\
159 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
160 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
161 ' TP_PROTO(sc_exit(long ret,) $4 $5),\n'\
162 ' TP_ARGS(sc_exit(ret,) $5),\n'\
163 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $5, $5)))\n'\
165 '#endif/g' >> "${HEADER}"
172 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
173 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
174 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 1)
175 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 2)
177 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}"
179 # shellcheck disable=SC2026
180 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
181 'types: \(([^,]*), ([^)]*)\) '\
182 'args: \(([^,]*), ([^)]*)\)/'\
183 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
184 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
185 ' TP_PROTO(sc_exit(long ret,) $4 $6, $5 $7),\n'\
186 ' TP_ARGS(sc_exit(ret,) $6, $7),\n'\
187 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $6, $6)) '"${ARG2}"'(ctf_integer($5, $7, $7)))\n'\
189 '#endif/g' >> "${HEADER}"
196 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
197 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
198 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 1)
199 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 2)
200 ARG3
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 3)
202 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}"
204 # shellcheck disable=SC2026
205 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
206 'types: \(([^,]*), ([^,]*), ([^)]*)\) '\
207 'args: \(([^,]*), ([^,]*), ([^)]*)\)/'\
208 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
209 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
210 ' TP_PROTO(sc_exit(long ret,) $4 $7, $5 $8, $6 $9),\n'\
211 ' TP_ARGS(sc_exit(ret,) $7, $8, $9),\n'\
212 ' 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'\
214 '#endif/g' >> "${HEADER}"
222 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
223 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
224 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 1)
225 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 2)
226 ARG3
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 3)
227 ARG4
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 4)
229 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}"
231 # shellcheck disable=SC2026
232 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
233 'types: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
234 'args: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
235 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
236 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
237 ' TP_PROTO(sc_exit(long ret,) $4 $8, $5 $9, $6 $10, $7 $11),\n'\
238 ' TP_ARGS(sc_exit(ret,) $8, $9, $10, $11),\n'\
239 ' 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'\
241 '#endif/g' >> "${HEADER}"
248 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
249 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
250 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 1)
251 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 2)
252 ARG3
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 3)
253 ARG4
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 4)
254 ARG5
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 5)
256 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}"
258 # shellcheck disable=SC2026
259 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
260 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
261 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
262 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
263 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
264 ' TP_PROTO(sc_exit(long ret,) $4 $9, $5 $10, $6 $11, $7 $12, $8 $13),\n'\
265 ' TP_ARGS(sc_exit(ret,) $9, $10, $11, $12, $13),\n'\
266 ' 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'\
268 '#endif/g' >> "${HEADER}"
273 # args 10 11 12 13 14 15
276 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
277 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
278 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 1)
279 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 2)
280 ARG3
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 3)
281 ARG4
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 4)
282 ARG5
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 5)
283 ARG6
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 6)
285 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}" "${ARG6}"
287 # shellcheck disable=SC2026
288 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
289 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\) '\
290 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\)/'\
291 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
292 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
293 ' TP_PROTO(sc_exit(long ret,) $4 $10, $5 $11, $6 $12, $7 $13, $8 $14, $9 $15),\n'\
294 ' TP_ARGS(sc_exit(ret,) $10, $11, $12, $13, $14, $15),\n'\
295 ' 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'\
297 '#endif/g' >> "${HEADER}"
300 # Macro for tracing syscall table
304 #endif /* _TRACE_SYSCALLS_${CLASSCAP}_H */
306 /* This part must be outside protection */
307 #include <lttng/define_trace.h>
309 #else /* CREATE_SYSCALL_TABLE */
311 #include \"${INPUTFILE}_${CLASS}_override.h\"
312 #include \"syscalls_${CLASS}_override.h\"
317 if [ "$CLASS" = integers
]; then
320 # shellcheck disable=SC2129
321 printf '#ifdef SC_ENTER\n' >> "${HEADER}"
323 # shellcheck disable=SC2026
324 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
325 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
326 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
327 'TRACE_SYSCALL_TABLE\(syscalls_noargs, $1, $2, $3\)\n'\
328 '#endif/g' >> "${HEADER}"
330 printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}"
332 # shellcheck disable=SC2026
333 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
334 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
335 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
336 'TRACE_SYSCALL_TABLE($1, $1, $2, $3)\n'\
337 '#endif/g' >> "${HEADER}"
339 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
343 # shellcheck disable=SC2026
344 grep -v "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
345 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
346 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
347 'TRACE_SYSCALL_TABLE($1, $1, $2, $3)\n'\
348 '#endif/g' >> "${HEADER}"
350 printf '\n#endif /* CREATE_SYSCALL_TABLE */\n' >> "${HEADER}"
352 #fields names: ...char * type with *name* or *file* or *path* or *root*
353 # or *put_old* or *type*
354 perl
-pi -e 's/ctf_integer\(([^,)]*char \*), ([^\)]*)(name|file|path|root|put_old|type)([^\)]*)\)/ctf_user_string($2$3$4)/g' \
357 #prettify addresses heuristics.
358 #field names with addr or ptr
359 perl
-pi -e 's/ctf_integer\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/ctf_integer_hex($1, $2$3, $2$3)/g' \
362 #field types ending with '*'
363 perl
-pi -e 's/ctf_integer\(([^,)]*\*), ([^),]*)\)/ctf_integer_hex($1, $2, $2)/g' "${HEADER}"