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 64
11 # lttng-syscalls-generate-headers.sh pointers 3.0.4 x86-64-syscalls 64
17 INPUT
=${VERSIONDIR}/${INPUTFILE}
18 HEADER
=headers
/${INPUTFILE}_
${CLASS}.h
20 if [ x
"$VERSIONDIR" = 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 /* Generated from ${INPUTFILE} ${VERSIONDIR} */
79 #ifndef CREATE_SYSCALL_TABLE
81 #if !defined(_TRACE_SYSCALLS_${CLASSCAP}_H) || defined(TRACE_HEADER_MULTI_READ)
82 #define _TRACE_SYSCALLS_${CLASSCAP}_H
84 #include <probes/lttng-tracepoint-event.h>
85 #include <linux/syscalls.h>
86 #include \"${INPUTFILE}_${CLASS}_override.h\"
87 #include \"syscalls_${CLASS}_override.h\"
90 if [ "$CLASS" = integers
]; then
94 # shellcheck disable=SC2129
97 SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscalls_noargs,
102 # shellcheck disable=SC2026
103 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
104 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
105 'types: \(([^)]*)\) '\
106 'args: \(([^)]*)\)/'\
107 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
108 'SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscalls_noargs, $1)\n'\
109 '#endif/g' >> "${HEADER}"
111 printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}"
113 # shellcheck disable=SC2026
114 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
115 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
116 'types: \(([^)]*)\) '\
117 'args: \(([^)]*)\)/'\
118 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
119 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
120 ' TP_PROTO(sc_exit(long ret)),\n'\
121 ' TP_ARGS(sc_exit(ret)),\n'\
122 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)))\n'\
124 '#endif/g' >> "${HEADER}"
126 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
135 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
136 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
137 ARG1
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 1)
139 echo Syscall
: "${SC_NAME}" "${ARG1}"
141 # shellcheck disable=SC2026
142 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
143 'types: \(([^)]*)\) '\
144 'args: \(([^)]*)\)/'\
145 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
146 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
147 ' TP_PROTO(sc_exit(long ret,) $4 $5),\n'\
148 ' TP_ARGS(sc_exit(ret,) $5),\n'\
149 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $5, $5)))\n'\
151 '#endif/g' >> "${HEADER}"
158 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
159 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
160 ARG1
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 1)
161 ARG2
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 2)
163 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}"
165 # shellcheck disable=SC2026
166 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
167 'types: \(([^,]*), ([^)]*)\) '\
168 'args: \(([^,]*), ([^)]*)\)/'\
169 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
170 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
171 ' TP_PROTO(sc_exit(long ret,) $4 $6, $5 $7),\n'\
172 ' TP_ARGS(sc_exit(ret,) $6, $7),\n'\
173 ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $6, $6)) '"${ARG2}"'(ctf_integer($5, $7, $7)))\n'\
175 '#endif/g' >> "${HEADER}"
182 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
183 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
184 ARG1
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 1)
185 ARG2
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 2)
186 ARG3
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 3)
188 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}"
190 # shellcheck disable=SC2026
191 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
192 'types: \(([^,]*), ([^,]*), ([^)]*)\) '\
193 'args: \(([^,]*), ([^,]*), ([^)]*)\)/'\
194 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
195 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
196 ' TP_PROTO(sc_exit(long ret,) $4 $7, $5 $8, $6 $9),\n'\
197 ' TP_ARGS(sc_exit(ret,) $7, $8, $9),\n'\
198 ' 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'\
200 '#endif/g' >> "${HEADER}"
208 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
209 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
210 ARG1
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 1)
211 ARG2
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 2)
212 ARG3
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 3)
213 ARG4
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 4)
215 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}"
217 # shellcheck disable=SC2026
218 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
219 'types: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
220 'args: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
221 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
222 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
223 ' TP_PROTO(sc_exit(long ret,) $4 $8, $5 $9, $6 $10, $7 $11),\n'\
224 ' TP_ARGS(sc_exit(ret,) $8, $9, $10, $11),\n'\
225 ' 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'\
227 '#endif/g' >> "${HEADER}"
234 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
235 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
236 ARG1
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 1)
237 ARG2
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 2)
238 ARG3
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 3)
239 ARG4
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 4)
240 ARG5
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 5)
242 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}"
244 # shellcheck disable=SC2026
245 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
246 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
247 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
248 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
249 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
250 ' TP_PROTO(sc_exit(long ret,) $4 $9, $5 $10, $6 $11, $7 $12, $8 $13),\n'\
251 ' TP_ARGS(sc_exit(ret,) $9, $10, $11, $12, $13),\n'\
252 ' 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'\
254 '#endif/g' >> "${HEADER}"
259 # args 10 11 12 13 14 15
262 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" |
while read -r LINE
; do
263 SC_NAME
=$
(echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) .*/$1/g')
264 ARG1
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 1)
265 ARG2
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 2)
266 ARG3
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 3)
267 ARG4
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 4)
268 ARG5
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 5)
269 ARG6
=$
(.
/lttng-get-syscall-inout.sh table-syscall-inout.txt
"${SC_NAME}" 6)
271 echo Syscall
: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}" "${ARG6}"
273 # shellcheck disable=SC2026
274 echo "${LINE}" | perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
275 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\) '\
276 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\)/'\
277 '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\
278 'SC_LTTNG_TRACEPOINT_EVENT($1,\n'\
279 ' TP_PROTO(sc_exit(long ret,) $4 $10, $5 $11, $6 $12, $7 $13, $8 $14, $9 $15),\n'\
280 ' TP_ARGS(sc_exit(ret,) $10, $11, $12, $13, $14, $15),\n'\
281 ' 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'\
283 '#endif/g' >> "${HEADER}"
286 # Macro for tracing syscall table
290 #endif /* _TRACE_SYSCALLS_${CLASSCAP}_H */
292 /* This part must be outside protection */
293 #include <probes/define_trace.h>
295 #else /* CREATE_SYSCALL_TABLE */
297 #include \"${INPUTFILE}_${CLASS}_override.h\"
298 #include \"syscalls_${CLASS}_override.h\"
303 if [ "$CLASS" = integers
]; then
306 # shellcheck disable=SC2129
307 printf '#ifdef SC_ENTER\n' >> "${HEADER}"
309 # shellcheck disable=SC2026
310 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
311 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
312 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
313 'TRACE_SYSCALL_TABLE\(syscalls_noargs, $1, $2, $3\)\n'\
314 '#endif/g' >> "${HEADER}"
316 printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}"
318 # shellcheck disable=SC2026
319 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
320 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
321 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
322 'TRACE_SYSCALL_TABLE($1, $1, $2, $3)\n'\
323 '#endif/g' >> "${HEADER}"
325 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
329 # shellcheck disable=SC2026
330 grep -v "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \
331 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
332 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\
333 'TRACE_SYSCALL_TABLE($1, $1, $2, $3)\n'\
334 '#endif/g' >> "${HEADER}"
336 printf '\n#endif /* CREATE_SYSCALL_TABLE */\n' >> "${HEADER}"
338 #fields names: ...char * type with *name* or *file* or *path* or *root*
339 # or *put_old* or *type*
340 perl
-pi -e 's/ctf_integer\(([^,)]*char \*), ([^\)]*)(name|file|path|root|put_old|type)([^\)]*)\)/ctf_user_string($2$3$4)/g' \
343 #prettify addresses heuristics.
344 #field names with addr or ptr
345 perl
-pi -e 's/ctf_integer\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/ctf_integer_hex($1, $2$3, $2$3)/g' \
348 #field types ending with '*'
349 perl
-pi -e 's/ctf_integer\(([^,)]*\*), ([^),]*)\)/ctf_integer_hex($1, $2, $2)/g' "${HEADER}"