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
18 INPUT
=${VERSIONDIR}/${INPUTFILE}
19 HEADER
=headers
/${INPUTFILE}_
${CLASS}.h
21 if [ x
"$VERSIONDIR" = x
"" ]; then
22 echo "Error: Please specify input directory as second argument" >&2
26 if [ x
"$INPUTFILE" = x
"" ]; then
27 echo "Error: Please specify input file as third argument" >&2
31 if [ x
"$BITNESS" != x
"32" ] && [ x
"$BITNESS" != x
"64" ]; then
32 echo "Error: Please specify bitness as fourth argument (\"32\" or \"64\")" >&2
36 if [ x
"$ARCH_NAME" = x
"" ]; then
37 echo "Error: Please specify the architecture name as fourth argument" >&2
41 # Abort on error and undefined variable
48 # Delete temp files on exit
49 trap 'rm -f "${SRCFILE}" "${TMPFILE}"' EXIT
51 cp "${INPUT}" "${SRCFILE}"
53 ## Cleanup the input file
54 # Remove the dmesg timestamp if present
55 perl
-pi -e 's/^\[.*\] //g' "${SRCFILE}"
56 # Remove the 'sys_' prefix from syscall names
57 perl
-pi -e 's/^syscall sys_([^ ]*)/syscall $1/g' "${SRCFILE}"
58 # Remove the user attribute from arguments
59 sed -i 's/ __attribute__((user))//g' "${SRCFILE}"
63 if [ "$CLASS" = integers
]; then
64 #select integers and no-args.
66 grep -v "\\*\|cap_user_header_t" "${SRCFILE}" > "${TMPFILE}"
67 mv "${TMPFILE}" "${SRCFILE}"
68 elif [ "$CLASS" = pointers
]; then
69 #select system calls using pointers.
71 grep "\\*\|cap_#user_header_t" "${SRCFILE}" > "${TMPFILE}"
72 mv "${TMPFILE}" "${SRCFILE}"
74 echo "Error: Please specify \"integers\" or \"pointers\" as first argument" >&2
79 echo "/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) */
81 /* THIS FILE IS AUTO-GENERATED. DO NOT EDIT */
83 /* Generated from ${INPUTFILE} ${VERSIONDIR} */
85 #ifndef CREATE_SYSCALL_TABLE
87 #if !defined(_TRACE_SYSCALLS_${CLASSCAP}_H) || defined(TRACE_HEADER_MULTI_READ)
88 #define _TRACE_SYSCALLS_${CLASSCAP}_H
90 #include <lttng/tracepoint-event.h>
91 #include <linux/syscalls.h>
92 #include \"${INPUTFILE}_${CLASS}_override.h\"
93 #include \"syscalls_${CLASS}_override.h\"
96 if [ "$CLASS" = integers
]; then
100 # shellcheck disable=SC2129
103 SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscalls_noargs,
108 # shellcheck disable=SC2026
109 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
110 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
111 'types: \(([^)]*)\) '\
112 'args: \(([^)]*)\)/'\
113 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
114 'SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscalls_noargs, $1)\n'\
115 '#endif/g' >> "${HEADER}"
117 printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}"
119 # shellcheck disable=SC2026
120 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
121 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
122 'types: \(([^)]*)\) '\
123 'args: \(([^)]*)\)/'\
124 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
125 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
126 ' TP_PROTO(sc_exit(long ret)),\n'\
127 ' TP_ARGS(sc_exit(ret)),\n'\
128 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)))\n'\
130 '#endif/g' >> "${HEADER}"
132 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
141 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
142 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
143 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 1)
145 echo Syscall
: "${SC_NAME}" "${ARG1}"
147 # shellcheck disable=SC2026
148 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
149 'types: \(([^)]*)\) '\
150 'args: \(([^)]*)\)/'\
151 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
152 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
153 ' TP_PROTO(sc_exit(long ret,) $4 $5),\n'\
154 ' TP_ARGS(sc_exit(ret,) $5),\n'\
155 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $5, $5)))\n'\
157 '#endif/g' >> "${HEADER}"
164 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
165 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
166 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 1)
167 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 2)
169 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}"
171 # shellcheck disable=SC2026
172 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
173 'types: \(([^,]*), ([^)]*)\) '\
174 'args: \(([^,]*), ([^)]*)\)/'\
175 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
176 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
177 ' TP_PROTO(sc_exit(long ret,) $4 $6, $5 $7),\n'\
178 ' TP_ARGS(sc_exit(ret,) $6, $7),\n'\
179 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $6, $6)) '"${ARG2}"'(ctf_integer($5, $7, $7)))\n'\
181 '#endif/g' >> "${HEADER}"
188 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
189 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
190 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 1)
191 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 2)
192 ARG3
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 3)
194 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}"
196 # shellcheck disable=SC2026
197 echo "${LINE}" | 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'\
206 '#endif/g' >> "${HEADER}"
214 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
215 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
216 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 1)
217 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 2)
218 ARG3
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 3)
219 ARG4
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 4)
221 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}"
223 # shellcheck disable=SC2026
224 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
225 'types: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
226 'args: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
227 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
228 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
229 ' TP_PROTO(sc_exit(long ret,) $4 $8, $5 $9, $6 $10, $7 $11),\n'\
230 ' TP_ARGS(sc_exit(ret,) $8, $9, $10, $11),\n'\
231 ' 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'\
233 '#endif/g' >> "${HEADER}"
240 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
241 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
242 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 1)
243 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 2)
244 ARG3
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 3)
245 ARG4
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 4)
246 ARG5
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 5)
248 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}"
250 # shellcheck disable=SC2026
251 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
252 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
253 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
254 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
255 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
256 ' TP_PROTO(sc_exit(long ret,) $4 $9, $5 $10, $6 $11, $7 $12, $8 $13),\n'\
257 ' TP_ARGS(sc_exit(ret,) $9, $10, $11, $12, $13),\n'\
258 ' 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'\
260 '#endif/g' >> "${HEADER}"
265 # args 10 11 12 13 14 15
268 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
269 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
270 ARG1
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 1)
271 ARG2
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 2)
272 ARG3
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 3)
273 ARG4
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 4)
274 ARG5
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 5)
275 ARG6
=$
(.
/lttng-get-syscall-inout.sh
"${ARCH_NAME}" "${SC_NAME}" 6)
277 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}" "${ARG6}"
279 # shellcheck disable=SC2026
280 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
281 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\) '\
282 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\)/'\
283 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
284 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
285 ' TP_PROTO(sc_exit(long ret,) $4 $10, $5 $11, $6 $12, $7 $13, $8 $14, $9 $15),\n'\
286 ' TP_ARGS(sc_exit(ret,) $10, $11, $12, $13, $14, $15),\n'\
287 ' 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'\
289 '#endif/g' >> "${HEADER}"
292 # Macro for tracing syscall table
296 #endif /* _TRACE_SYSCALLS_${CLASSCAP}_H */
298 /* This part must be outside protection */
299 #include <lttng/define_trace.h>
301 #else /* CREATE_SYSCALL_TABLE */
303 #include \"${INPUTFILE}_${CLASS}_override.h\"
304 #include \"syscalls_${CLASS}_override.h\"
309 if [ "$CLASS" = integers
]; then
312 # shellcheck disable=SC2129
313 printf '#ifdef SC_ENTER\n' >> "${HEADER}"
315 # shellcheck disable=SC2026
316 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
317 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
318 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
319 'TRACE_SYSCALL_TABLE\(syscalls_noargs, $1, $2, $3\)\n'\
320 '#endif/g' >> "${HEADER}"
322 printf '#else /* #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($1, $1, $2, $3)\n'\
329 '#endif/g' >> "${HEADER}"
331 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
335 # shellcheck disable=SC2026
336 grep -v "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
337 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
338 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
339 'TRACE_SYSCALL_TABLE($1, $1, $2, $3)\n'\
340 '#endif/g' >> "${HEADER}"
342 printf '\n#endif /* CREATE_SYSCALL_TABLE */\n' >> "${HEADER}"
344 #fields names: ...char * type with *name* or *file* or *path* or *root*
345 # or *put_old* or *type*
346 perl
-pi -e 's/ctf_integer\(([^,)]*char \*), ([^\)]*)(name|file|path|root|put_old|type)([^\)]*)\)/ctf_user_string($2$3$4)/g' \
349 #prettify addresses heuristics.
350 #field names with addr or ptr
351 perl
-pi -e 's/ctf_integer\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/ctf_integer_hex($1, $2$3, $2$3)/g' \
354 #field types ending with '*'
355 perl
-pi -e 's/ctf_integer\(([^,)]*\*), ([^),]*)\)/ctf_integer_hex($1, $2, $2)/g' "${HEADER}"