Cleanup unused Makefile
[lttng-modules.git] / include / 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> <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
12
13CLASS=$1
14VERSIONDIR=$2
15INPUTFILE=$3
16ARCH_NAME=$4
17BITNESS=$5
18INPUT=${VERSIONDIR}/${INPUTFILE}
19HEADER=headers/${INPUTFILE}_${CLASS}.h
20
21if [ x"$VERSIONDIR" = x"" ]; then
22 echo "Error: Please specify input directory as second argument" >&2
23 exit 1
24fi
25
26if [ x"$INPUTFILE" = x"" ]; then
27 echo "Error: Please specify input file as third argument" >&2
28 exit 1
29fi
30
31if [ x"$BITNESS" != x"32" ] && [ x"$BITNESS" != x"64" ]; then
32 echo "Error: Please specify bitness as fourth argument (\"32\" or \"64\")" >&2
33 exit 1
34fi
35
36if [ x"$ARCH_NAME" = x"" ]; then
37 echo "Error: Please specify the architecture name as fourth argument" >&2
38 exit 1
39fi
40
41# Abort on error and undefined variable
42set -eu
43
44# Create temp files
45SRCFILE=$(mktemp)
46TMPFILE=$(mktemp)
47
48# Delete temp files on exit
49trap 'rm -f "${SRCFILE}" "${TMPFILE}"' EXIT
50
51cp "${INPUT}" "${SRCFILE}"
52
53## Cleanup the input file
54# Remove the dmesg timestamp if present
55perl -pi -e 's/^\[.*\] //g' "${SRCFILE}"
56# Remove the 'sys_' prefix from syscall names
57perl -pi -e 's/^syscall sys_([^ ]*)/syscall $1/g' "${SRCFILE}"
58# Remove the user attribute from arguments
59sed -i 's/ __attribute__((user))//g' "${SRCFILE}"
60
61#Filter
62
63if [ "$CLASS" = integers ]; then
64 #select integers and no-args.
65 CLASSCAP=INTEGERS
66 grep -v "\\*\|cap_user_header_t" "${SRCFILE}" > "${TMPFILE}"
67 mv "${TMPFILE}" "${SRCFILE}"
68elif [ "$CLASS" = pointers ]; then
69 #select system calls using pointers.
70 CLASSCAP=POINTERS
71 grep "\\*\|cap_#user_header_t" "${SRCFILE}" > "${TMPFILE}"
72 mv "${TMPFILE}" "${SRCFILE}"
73else
74 echo "Error: Please specify \"integers\" or \"pointers\" as first argument" >&2
75 exit 1
76fi
77
78
79echo "/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) */
80
81/* THIS FILE IS AUTO-GENERATED. DO NOT EDIT */
82
83/* Generated from ${INPUTFILE} ${VERSIONDIR} */
84
85#ifndef CREATE_SYSCALL_TABLE
86
87#if !defined(_TRACE_SYSCALLS_${CLASSCAP}_H) || defined(TRACE_HEADER_MULTI_READ)
88#define _TRACE_SYSCALLS_${CLASSCAP}_H
89
90#include <lttng/tracepoint-event.h>
91#include <linux/syscalls.h>
92#include \"${INPUTFILE}_${CLASS}_override.h\"
93#include \"syscalls_${CLASS}_override.h\"
94" > "${HEADER}"
95
96if [ "$CLASS" = integers ]; then
97
98 NRARGS=0
99
100 # shellcheck disable=SC2129
101 printf \
102'#ifdef SC_ENTER
103SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscalls_noargs,
104 TP_FIELDS()
105)
106' >> "${HEADER}"
107
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}"
116
117 printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}"
118
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'\
129')\n'\
130'#endif/g' >> "${HEADER}"
131
132 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
133
134fi
135
136
137# types: 4
138# args 5
139
140NRARGS=1
141grep "^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)
144
145 echo Syscall: "${SC_NAME}" "${ARG1}"
146
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'\
156')\n'\
157'#endif/g' >> "${HEADER}"
158done
159
160# types: 4 5
161# args 6 7
162
163NRARGS=2
164grep "^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)
168
169 echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}"
170
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'\
180')\n'\
181'#endif/g' >> "${HEADER}"
182done
183
184# types: 4 5 6
185# args 7 8 9
186
187NRARGS=3
188grep "^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)
193
194 echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}"
195
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'\
205')\n'\
206'#endif/g' >> "${HEADER}"
207done
208
209
210# types: 4 5 6 7
211# args 8 9 10 11
212
213NRARGS=4
214grep "^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)
220
221 echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}"
222
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'\
232')\n'\
233'#endif/g' >> "${HEADER}"
234done
235
236# types: 4 5 6 7 8
237# args 9 10 11 12 13
238
239NRARGS=5
240grep "^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)
247
248 echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}"
249
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'\
259')\n'\
260'#endif/g' >> "${HEADER}"
261done
262
263
264# types: 4 5 6 7 8 9
265# args 10 11 12 13 14 15
266
267NRARGS=6
268grep "^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)
276
277 echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}" "${ARG6}"
278
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'\
288')\n'\
289'#endif/g' >> "${HEADER}"
290done
291
292# Macro for tracing syscall table
293
294echo \
295"
296#endif /* _TRACE_SYSCALLS_${CLASSCAP}_H */
297
298/* This part must be outside protection */
299#include <lttng/define_trace.h>
300
301#else /* CREATE_SYSCALL_TABLE */
302
303#include \"${INPUTFILE}_${CLASS}_override.h\"
304#include \"syscalls_${CLASS}_override.h\"
305" >> "${HEADER}"
306
307NRARGS=0
308
309if [ "$CLASS" = integers ]; then
310 #noargs
311
312 # shellcheck disable=SC2129
313 printf '#ifdef SC_ENTER\n' >> "${HEADER}"
314
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}"
321
322 printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}"
323
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}"
330
331 printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}"
332fi
333
334#others.
335# shellcheck disable=SC2026
336grep -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}"
341
342printf '\n#endif /* CREATE_SYSCALL_TABLE */\n' >> "${HEADER}"
343
344#fields names: ...char * type with *name* or *file* or *path* or *root*
345# or *put_old* or *type*
346perl -pi -e 's/ctf_integer\(([^,)]*char \*), ([^\)]*)(name|file|path|root|put_old|type)([^\)]*)\)/ctf_user_string($2$3$4)/g' \
347 "${HEADER}"
348
349#prettify addresses heuristics.
350#field names with addr or ptr
351perl -pi -e 's/ctf_integer\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/ctf_integer_hex($1, $2$3, $2$3)/g' \
352 "${HEADER}"
353
354#field types ending with '*'
355perl -pi -e 's/ctf_integer\(([^,)]*\*), ([^),]*)\)/ctf_integer_hex($1, $2, $2)/g' "${HEADER}"
356
357# EOF
This page took 0.02479 seconds and 4 git commands to generate.