Update to SPDX v3.0 identifiers
[lttng-modules.git] / instrumentation / syscalls / lttng-syscalls-generate-headers.sh
... / ...
CommitLineData
1#!/bin/bash
2
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.
6#
7# example usage:
8#
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
12
13CLASS=$1
14VERSIONDIR=$2
15INPUTFILE=$3
16BITNESS=$4
17INPUT=${VERSIONDIR}/${INPUTFILE}
18HEADER=headers/${INPUTFILE}_${CLASS}.h
19
20if [ x"$VERSIONDIR" = x"" ]; then
21 echo "Error: Please specify input directory as second argument" >&2
22 exit 1
23fi
24
25if [ x"$INPUTFILE" = x"" ]; then
26 echo "Error: Please specify input file as third argument" >&2
27 exit 1
28fi
29
30if [ x"$BITNESS" != x"32" ] && [ x"$BITNESS" != x"64" ]; then
31 echo "Error: Please specify bitness as fourth argument (\"32\" or \"64\")" >&2
32 exit 1
33fi
34
35# Abort on error and undefined variable
36set -eu
37
38# Create temp files
39SRCFILE=$(mktemp)
40TMPFILE=$(mktemp)
41
42# Delete temp files on exit
43trap 'rm -f "${SRCFILE}" "${TMPFILE}"' EXIT
44
45cp "${INPUT}" "${SRCFILE}"
46
47## Cleanup the input file
48# Remove the dmesg timestamp if present
49perl -pi -e 's/^\[.*\] //g' "${SRCFILE}"
50# Remove the 'sys_' prefix from syscall names
51perl -pi -e 's/^syscall sys_([^ ]*)/syscall $1/g' "${SRCFILE}"
52# Remove the user attribute from arguments
53sed -i 's/ __attribute__((user))//g' "${SRCFILE}"
54
55#Filter
56
57if [ "$CLASS" = integers ]; then
58 #select integers and no-args.
59 CLASSCAP=INTEGERS
60 grep -v "\\*\|cap_user_header_t" "${SRCFILE}" > "${TMPFILE}"
61 mv "${TMPFILE}" "${SRCFILE}"
62elif [ "$CLASS" = pointers ]; then
63 #select system calls using pointers.
64 CLASSCAP=POINTERS
65 grep "\\*\|cap_#user_header_t" "${SRCFILE}" > "${TMPFILE}"
66 mv "${TMPFILE}" "${SRCFILE}"
67else
68 echo "Error: Please specify \"integers\" or \"pointers\" as first argument" >&2
69 exit 1
70fi
71
72
73echo "/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) */
74
75/* THIS FILE IS AUTO-GENERATED. DO NOT EDIT */
76
77/* Generated from ${INPUTFILE} ${VERSIONDIR} */
78
79#ifndef CREATE_SYSCALL_TABLE
80
81#if !defined(_TRACE_SYSCALLS_${CLASSCAP}_H) || defined(TRACE_HEADER_MULTI_READ)
82#define _TRACE_SYSCALLS_${CLASSCAP}_H
83
84#include <probes/lttng-tracepoint-event.h>
85#include <linux/syscalls.h>
86#include \"${INPUTFILE}_${CLASS}_override.h\"
87#include \"syscalls_${CLASS}_override.h\"
88" > "${HEADER}"
89
90if [ "$CLASS" = integers ]; then
91
92 NRARGS=0
93
94 # shellcheck disable=SC2129
95 printf \
96'#ifdef SC_ENTER
97SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscalls_noargs,
98 TP_FIELDS()
99)
100' >> "${HEADER}"
101
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}"
110
111 printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}"
112
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'\
123')\n'\
124'#endif/g' >> "${HEADER}"
125
126 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
127
128fi
129
130
131# types: 4
132# args 5
133
134NRARGS=1
135grep "^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)
138
139 echo Syscall: "${SC_NAME}" "${ARG1}"
140
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'\
150')\n'\
151'#endif/g' >> "${HEADER}"
152done
153
154# types: 4 5
155# args 6 7
156
157NRARGS=2
158grep "^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)
162
163 echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}"
164
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'\
174')\n'\
175'#endif/g' >> "${HEADER}"
176done
177
178# types: 4 5 6
179# args 7 8 9
180
181NRARGS=3
182grep "^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)
187
188 echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}"
189
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'\
199')\n'\
200'#endif/g' >> "${HEADER}"
201done
202
203
204# types: 4 5 6 7
205# args 8 9 10 11
206
207NRARGS=4
208grep "^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)
214
215 echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}"
216
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'\
226')\n'\
227'#endif/g' >> "${HEADER}"
228done
229
230# types: 4 5 6 7 8
231# args 9 10 11 12 13
232
233NRARGS=5
234grep "^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)
241
242 echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}"
243
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'\
253')\n'\
254'#endif/g' >> "${HEADER}"
255done
256
257
258# types: 4 5 6 7 8 9
259# args 10 11 12 13 14 15
260
261NRARGS=6
262grep "^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)
270
271 echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}" "${ARG6}"
272
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'\
282')\n'\
283'#endif/g' >> "${HEADER}"
284done
285
286# Macro for tracing syscall table
287
288echo \
289"
290#endif /* _TRACE_SYSCALLS_${CLASSCAP}_H */
291
292/* This part must be outside protection */
293#include <probes/define_trace.h>
294
295#else /* CREATE_SYSCALL_TABLE */
296
297#include \"${INPUTFILE}_${CLASS}_override.h\"
298#include \"syscalls_${CLASS}_override.h\"
299" >> "${HEADER}"
300
301NRARGS=0
302
303if [ "$CLASS" = integers ]; then
304 #noargs
305
306 # shellcheck disable=SC2129
307 printf '#ifdef SC_ENTER\n' >> "${HEADER}"
308
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}"
315
316 printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}"
317
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}"
324
325 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
326fi
327
328#others.
329# shellcheck disable=SC2026
330grep -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}"
335
336printf '\n#endif /* CREATE_SYSCALL_TABLE */\n' >> "${HEADER}"
337
338#fields names: ...char * type with *name* or *file* or *path* or *root*
339# or *put_old* or *type*
340perl -pi -e 's/ctf_integer\(([^,)]*char \*), ([^\)]*)(name|file|path|root|put_old|type)([^\)]*)\)/ctf_user_string($2$3$4)/g' \
341 "${HEADER}"
342
343#prettify addresses heuristics.
344#field names with addr or ptr
345perl -pi -e 's/ctf_integer\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/ctf_integer_hex($1, $2$3, $2$3)/g' \
346 "${HEADER}"
347
348#field types ending with '*'
349perl -pi -e 's/ctf_integer\(([^,)]*\*), ([^),]*)\)/ctf_integer_hex($1, $2, $2)/g' "${HEADER}"
350
351# EOF
This page took 0.023713 seconds and 4 git commands to generate.