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}
18 HEADER
=headers
/${INPUTFILE}_
${CLASS}.h
20 if [ x
"$INPUTDIR" = x
"" ]; then
21 echo "Error: Please specify input directory as second argument" >&2
25 if [ x
"$INPUTFILE" = x
"" ]; then
26 echo "Error: Please specify input file as third argument" >&2
30 if [ x
"$BITNESS" != x
"32" ] && [ x
"$BITNESS" != x
"64" ]; then
31 echo "Error: Please specify bitness as fourth argument (\"32\" or \"64\")" >&2
35 # Abort on error and undefined variable
42 # Delete temp files on exit
43 trap 'rm -f "${SRCFILE}" "${TMPFILE}"' EXIT
45 cp "${INPUT}" "${SRCFILE}"
47 ## Cleanup the input file
48 # Remove the dmesg timestamp if present
49 perl
-pi -e 's/^\[.*\] //g' "${SRCFILE}"
50 # Remove the 'sys_' prefix from syscall names
51 perl
-pi -e 's/^syscall sys_([^ ]*)/syscall $1/g' "${SRCFILE}"
52 # Remove the user attribute from arguments
53 sed -i 's/ __attribute__((user))//g' "${SRCFILE}"
57 if [ "$CLASS" = integers
]; then
58 #select integers and no-args.
60 grep -v "\\*\|cap_user_header_t" "${SRCFILE}" > "${TMPFILE}"
61 mv "${TMPFILE}" "${SRCFILE}"
62 elif [ "$CLASS" = pointers
]; then
63 #select system calls using pointers.
65 grep "\\*\|cap_#user_header_t" "${SRCFILE}" > "${TMPFILE}"
66 mv "${TMPFILE}" "${SRCFILE}"
68 echo "Error: Please specify \"integers\" or \"pointers\" as first argument" >&2
73 echo "/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) */
75 /* THIS FILE IS AUTO-GENERATED. DO NOT EDIT */
77 #ifndef CREATE_SYSCALL_TABLE
79 #if !defined(_TRACE_SYSCALLS_${CLASSCAP}_H) || defined(TRACE_HEADER_MULTI_READ)
80 #define _TRACE_SYSCALLS_${CLASSCAP}_H
82 #include <probes/lttng-tracepoint-event.h>
83 #include <linux/syscalls.h>
84 #include \"${INPUTFILE}_${CLASS}_override.h\"
85 #include \"syscalls_${CLASS}_override.h\"
88 if [ "$CLASS" = integers
]; then
92 # shellcheck disable=SC2129
95 SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscalls_noargs,
100 # shellcheck disable=SC2026
101 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
102 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
103 'types: \(([^)]*)\) '\
104 'args: \(([^)]*)\)/'\
105 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
106 'SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscalls_noargs, $1)\n'\
107 '#endif/g' >> "${HEADER}"
109 printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}"
111 # shellcheck disable=SC2026
112 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
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'\
122 '#endif/g' >> "${HEADER}"
124 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
133 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
134 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
135 ARG1
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 1)
137 echo Syscall
: "${SC_NAME}" "${ARG1}"
139 # shellcheck disable=SC2026
140 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
141 'types: \(([^)]*)\) '\
142 'args: \(([^)]*)\)/'\
143 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
144 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
145 ' TP_PROTO(sc_exit(long ret,) $4 $5),\n'\
146 ' TP_ARGS(sc_exit(ret,) $5),\n'\
147 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $5, $5)))\n'\
149 '#endif/g' >> "${HEADER}"
156 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
157 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
158 ARG1
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 1)
159 ARG2
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 2)
161 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}"
163 # shellcheck disable=SC2026
164 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
165 'types: \(([^,]*), ([^)]*)\) '\
166 'args: \(([^,]*), ([^)]*)\)/'\
167 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
168 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
169 ' TP_PROTO(sc_exit(long ret,) $4 $6, $5 $7),\n'\
170 ' TP_ARGS(sc_exit(ret,) $6, $7),\n'\
171 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $6, $6)) '"${ARG2}"'(ctf_integer($5, $7, $7)))\n'\
173 '#endif/g' >> "${HEADER}"
180 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
181 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
182 ARG1
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 1)
183 ARG2
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 2)
184 ARG3
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 3)
186 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}"
188 # shellcheck disable=SC2026
189 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
190 'types: \(([^,]*), ([^,]*), ([^)]*)\) '\
191 'args: \(([^,]*), ([^,]*), ([^)]*)\)/'\
192 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
193 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
194 ' TP_PROTO(sc_exit(long ret,) $4 $7, $5 $8, $6 $9),\n'\
195 ' TP_ARGS(sc_exit(ret,) $7, $8, $9),\n'\
196 ' 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'\
198 '#endif/g' >> "${HEADER}"
206 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
207 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
208 ARG1
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 1)
209 ARG2
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 2)
210 ARG3
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 3)
211 ARG4
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 4)
213 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}"
215 # shellcheck disable=SC2026
216 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
217 'types: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
218 'args: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
219 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
220 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
221 ' TP_PROTO(sc_exit(long ret,) $4 $8, $5 $9, $6 $10, $7 $11),\n'\
222 ' TP_ARGS(sc_exit(ret,) $8, $9, $10, $11),\n'\
223 ' 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'\
225 '#endif/g' >> "${HEADER}"
232 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
233 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
234 ARG1
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 1)
235 ARG2
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 2)
236 ARG3
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 3)
237 ARG4
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 4)
238 ARG5
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 5)
240 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}"
242 # shellcheck disable=SC2026
243 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
244 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
245 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
246 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
247 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
248 ' TP_PROTO(sc_exit(long ret,) $4 $9, $5 $10, $6 $11, $7 $12, $8 $13),\n'\
249 ' TP_ARGS(sc_exit(ret,) $9, $10, $11, $12, $13),\n'\
250 ' 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'\
252 '#endif/g' >> "${HEADER}"
257 # args 10 11 12 13 14 15
260 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
261 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
262 ARG1
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 1)
263 ARG2
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 2)
264 ARG3
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 3)
265 ARG4
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 4)
266 ARG5
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 5)
267 ARG6
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 6)
269 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}" "${ARG6}"
271 # shellcheck disable=SC2026
272 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
273 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\) '\
274 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\)/'\
275 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
276 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
277 ' TP_PROTO(sc_exit(long ret,) $4 $10, $5 $11, $6 $12, $7 $13, $8 $14, $9 $15),\n'\
278 ' TP_ARGS(sc_exit(ret,) $10, $11, $12, $13, $14, $15),\n'\
279 ' 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'\
281 '#endif/g' >> "${HEADER}"
284 # Macro for tracing syscall table
288 #endif /* _TRACE_SYSCALLS_${CLASSCAP}_H */
290 /* This part must be outside protection */
291 #include <probes/define_trace.h>
293 #else /* CREATE_SYSCALL_TABLE */
295 #include \"${INPUTFILE}_${CLASS}_override.h\"
296 #include \"syscalls_${CLASS}_override.h\"
301 if [ "$CLASS" = integers
]; then
304 # shellcheck disable=SC2129
305 printf '#ifdef SC_ENTER\n' >> "${HEADER}"
307 # shellcheck disable=SC2026
308 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
309 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
310 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
311 'TRACE_SYSCALL_TABLE\(syscalls_noargs, $1, $2, $3\)\n'\
312 '#endif/g' >> "${HEADER}"
314 printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}"
316 # shellcheck disable=SC2026
317 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
318 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
319 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
320 'TRACE_SYSCALL_TABLE($1, $1, $2, $3)\n'\
321 '#endif/g' >> "${HEADER}"
323 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
327 # shellcheck disable=SC2026
328 grep -v "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
329 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
330 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
331 'TRACE_SYSCALL_TABLE($1, $1, $2, $3)\n'\
332 '#endif/g' >> "${HEADER}"
334 printf '\n#endif /* CREATE_SYSCALL_TABLE */\n' >> "${HEADER}"
336 #fields names: ...char * type with *name* or *file* or *path* or *root*
337 # or *put_old* or *type*
338 perl
-pi -e 's/ctf_integer\(([^,)]*char \*), ([^\)]*)(name|file|path|root|put_old|type)([^\)]*)\)/ctf_user_string($2$3$4)/g' \
341 #prettify addresses heuristics.
342 #field names with addr or ptr
343 perl
-pi -e 's/ctf_integer\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/ctf_integer_hex($1, $2$3, $2$3)/g' \
346 #field types ending with '*'
347 perl
-pi -e 's/ctf_integer\(([^,)]*\*), ([^),]*)\)/ctf_integer_hex($1, $2, $2)/g' "${HEADER}"