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}
20 HEADER
=headers
/${INPUTFILE}_
${CLASS}.h
22 if [ x
"$INPUTDIR" = x
"" ]; then
23 echo "Error: Please specify input directory as second argument"
27 if [ x
"$INPUTFILE" = x
"" ]; then
28 echo "Error: Please specify input file as third argument"
32 if [ x
"$BITNESS" != x
"32" ] && [ x
"$BITNESS" != x
"64" ]; then
33 echo "Error: Please specify bitness as fourth argument (\"32\" or \"64\")"
37 cp ${INPUT} ${SRCFILE}
40 perl
-p -e 's/^\[.*\] //g' ${SRCFILE} > ${TMPFILE}
41 mv ${TMPFILE} ${SRCFILE}
43 perl
-p -e 's/^syscall sys_([^ ]*)/syscall $1/g' ${SRCFILE} > ${TMPFILE}
44 mv ${TMPFILE} ${SRCFILE}
48 if [ "$CLASS" = integers
]; then
49 #select integers and no-args.
51 grep -v "\\*\|cap_user_header_t" ${SRCFILE} > ${TMPFILE}
52 mv ${TMPFILE} ${SRCFILE}
56 if [ "$CLASS" = pointers
]; then
57 #select system calls using pointers.
59 grep "\\*\|cap_#user_header_t" ${SRCFILE} > ${TMPFILE}
60 mv ${TMPFILE} ${SRCFILE}
63 if [ x
"$CLASSCAP" = x
"" ]; then
64 echo "Error: Please specify \"integers\" or \"pointers\" as first argument"
69 echo "/* THIS FILE IS AUTO-GENERATED. DO NOT EDIT */" > ${HEADER}
72 "#ifndef CREATE_SYSCALL_TABLE
74 #if !defined(_TRACE_SYSCALLS_${CLASSCAP}_H) || defined(TRACE_HEADER_MULTI_READ)
75 #define _TRACE_SYSCALLS_${CLASSCAP}_H
77 #include <linux/tracepoint.h>
78 #include <linux/syscalls.h>
79 #include \"${INPUTFILE}_${CLASS}_override.h\"
80 #include \"syscalls_${CLASS}_override.h\"
83 if [ "$CLASS" = integers
]; then
92 'SC_DECLARE_EVENT_CLASS_NOARGS(syscalls_noargs,\n'\
93 ' TP_STRUCT__entry(),\n'\
94 ' TP_fast_assign(),\n'\
99 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
100 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
101 'types: \(([^)]*)\) '\
102 'args: \(([^)]*)\)/'\
103 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
104 'SC_DEFINE_EVENT_NOARGS(syscalls_noargs, sys_$1)\n'\
106 ${TMPFILE} >> ${HEADER}
109 '#else /* #ifdef SC_ENTER */\n'\
112 grep "^syscall
[^
]* nr
[^
]* nbargs
${NRARGS} " ${SRCFILE} > ${TMPFILE}
113 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
114 'types: \(([^)]*)\) '\
115 'args: \(([^)]*)\)/'\
116 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
117 'SC_TRACE_EVENT(sys_$1,\n'\
118 ' TP_PROTO(sc_exit(long ret)),\n'\
119 ' TP_ARGS(sc_exit(ret)),\n'\
120 ' TP_STRUCT__entry(sc_exit(__field(long, ret))),\n'\
121 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret))),\n'\
125 ${TMPFILE} >> ${HEADER}
128 '#endif /* else #ifdef SC_ENTER */\n'\
138 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
139 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
140 'types: \(([^)]*)\) '\
141 'args: \(([^)]*)\)/'\
142 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
143 'SC_TRACE_EVENT(sys_$1,\n'\
144 ' TP_PROTO(sc_exit(long ret,) $4 $5),\n'\
145 ' TP_ARGS(sc_exit(ret,) $5),\n'\
146 ' TP_STRUCT__entry(sc_exit(__field(long, ret)) __field($4, $5)),\n'\
147 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret)) tp_assign($4, $5, $5)),\n'\
151 ${TMPFILE} >> ${HEADER}
157 grep "^syscall
[^
]* nr
[^
]* nbargs
${NRARGS} " ${SRCFILE} > ${TMPFILE}
158 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
159 'types: \(([^,]*), ([^)]*)\) '\
160 'args: \(([^,]*), ([^)]*)\)/'\
161 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
162 'SC_TRACE_EVENT(sys_$1,\n'\
163 ' TP_PROTO(sc_exit(long ret,) $4 $6, $5 $7),\n'\
164 ' TP_ARGS(sc_exit(ret,) $6, $7),\n'\
165 ' TP_STRUCT__entry(sc_exit(__field(long, ret)) __field($4, $6) __field($5, $7)),\n'\
166 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret)) tp_assign($4, $6, $6) tp_assign($5, $7, $7)),\n'\
170 ${TMPFILE} >> ${HEADER}
176 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
177 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
178 'types: \(([^,]*), ([^,]*), ([^)]*)\) '\
179 'args: \(([^,]*), ([^,]*), ([^)]*)\)/'\
180 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
181 'SC_TRACE_EVENT(sys_$1,\n'\
182 ' TP_PROTO(sc_exit(long ret,) $4 $7, $5 $8, $6 $9),\n'\
183 ' TP_ARGS(sc_exit(ret,) $7, $8, $9),\n'\
184 ' TP_STRUCT__entry(sc_exit(__field(long, ret)) __field($4, $7) __field($5, $8) __field($6, $9)),\n'\
185 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret)) tp_assign($4, $7, $7) tp_assign($5, $8, $8) tp_assign($6, $9, $9)),\n'\
189 ${TMPFILE} >> ${HEADER}
196 grep "^syscall
[^
]* nr
[^
]* nbargs
${NRARGS} " ${SRCFILE} > ${TMPFILE}
197 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
198 'types: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
199 'args: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
200 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
201 'SC_TRACE_EVENT(sys_$1,\n'\
202 ' TP_PROTO(sc_exit(long ret,) $4 $8, $5 $9, $6 $10, $7 $11),\n'\
203 ' TP_ARGS(sc_exit(ret,) $8, $9, $10, $11),\n'\
204 ' TP_STRUCT__entry(sc_exit(__field(long, ret)) __field($4, $8) __field($5, $9) __field($6, $10) __field($7, $11)),\n'\
205 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret)) tp_assign($4, $8, $8) tp_assign($5, $9, $9) tp_assign($6, $10, $10) tp_assign($7, $11, $11)),\n'\
209 ${TMPFILE} >> ${HEADER}
215 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
216 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
217 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\
218 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\
219 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
220 'SC_TRACE_EVENT(sys_$1,\n'\
221 ' TP_PROTO(sc_exit(long ret,) $4 $9, $5 $10, $6 $11, $7 $12, $8 $13),\n'\
222 ' TP_ARGS(sc_exit(ret,) $9, $10, $11, $12, $13),\n'\
223 ' TP_STRUCT__entry(sc_exit(__field(long, ret)) __field($4, $9) __field($5, $10) __field($6, $11) __field($7, $12) __field($8, $13)),\n'\
224 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret)) tp_assign($4, $9, $9) tp_assign($5, $10, $10) tp_assign($6, $11, $11) tp_assign($7, $12, $12) tp_assign($8, $13, $13)),\n'\
228 ${TMPFILE} >> ${HEADER}
232 # args 10 11 12 13 14 15
235 grep "^syscall
[^
]* nr
[^
]* nbargs
${NRARGS} " ${SRCFILE} > ${TMPFILE}
236 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\
237 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\) '\
238 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\)/'\
239 '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\
240 'SC_TRACE_EVENT(sys_$1,\n'\
241 ' TP_PROTO(sc_exit(long ret,) $4 $10, $5 $11, $6 $12, $7 $13, $8 $14, $9 $15),\n'\
242 ' TP_ARGS(sc_exit(ret,) $10, $11, $12, $13, $14, $15),\n'\
243 ' TP_STRUCT__entry(sc_exit(__field(long, ret)) __field($4, $10) __field($5, $11) __field($6, $12) __field($7, $13) __field($8, $14) __field($9, $15)),\n'\
244 ' TP_fast_assign(sc_exit(tp_assign(long, ret, ret)) tp_assign($4, $10, $10) tp_assign($5, $11, $11) tp_assign($6, $12, $12) tp_assign($7, $13, $13) tp_assign($8, $14, $14) tp_assign($9, $15, $15)),\n'\
248 ${TMPFILE} >> ${HEADER}
250 # Macro for tracing syscall table
254 #endif /* _TRACE_SYSCALLS_${CLASSCAP}_H */
256 /* This part must be outside protection */
257 #include \"../../../probes/define_trace.h\"
259 #else /* CREATE_SYSCALL_TABLE */
261 #include \"${INPUTFILE}_${CLASS}_override.h\"
262 #include \"syscalls_${CLASS}_override.h\"
267 if [ "$CLASS" = integers
]; then
274 grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
275 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
276 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_sys_$1\n'\
277 'TRACE_SYSCALL_TABLE\(syscalls_noargs, sys_$1, $2, $3\)\n'\
279 ${TMPFILE} >> ${HEADER}
282 '#else /* #ifdef SC_ENTER */\n'\
285 grep "^syscall
[^
]* nr
[^
]* nbargs
${NRARGS} " ${SRCFILE} > ${TMPFILE}
286 perl
-p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
287 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_sys_$1\n'\
288 'TRACE_SYSCALL_TABLE(sys_$1, sys_$1, $2, $3)\n'\
290 ${TMPFILE} >> ${HEADER}
293 '#endif /* else #ifdef SC_ENTER */\n'\
299 grep -v "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE}
300 perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\
301 '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_sys_$1\n'\
302 'TRACE_SYSCALL_TABLE(sys_$1, sys_$1, $2, $3)\n'\
304 ${TMPFILE} >> ${HEADER}
308 #endif /* CREATE_SYSCALL_TABLE */
311 #fields names: ...char * type with *name* or *file* or *path* or *root*
312 # or *put_old* or *type*
313 cp -f ${HEADER} ${TMPFILE}
315 perl -p -e 's/__field\(([^,)]*char \*), ([^\)]*)(name|file|path|root|put_old|type)([^\)]*)\)/__string_from_user($2$3$4, $2$3$4)/g'\
316 ${TMPFILE} >> ${HEADER}
317 cp -f ${HEADER} ${TMPFILE}
319 perl -p -e 's/tp_assign\(([^,)]*char \*), ([^,]*)(name|file|path|root|put_old|type)([^,]*), ([^\)]*)\)/tp_copy_string_from_user($2$3$4, $5)/g'\
320 ${TMPFILE} >> ${HEADER}
322 #prettify addresses heuristics.
323 #field names with addr or ptr
324 cp -f ${HEADER} ${TMPFILE}
326 perl -p -e 's/__field\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/__field_hex($1, $2$3)/g'\
327 ${TMPFILE} >> ${HEADER}
329 #field types ending with '*'
330 cp -f ${HEADER} ${TMPFILE}
332 perl -p -e 's/__field\(([^,)]*\*), ([^),]*)\)/__field_hex($1, $2)/g'\
333 ${TMPFILE} >> ${HEADER}
335 #strip the extra type information from tp_assign.
336 cp -f ${HEADER} ${TMPFILE}
338 perl -p -e 's/tp_assign\(([^,)]*), ([^,]*), ([^\)]*)\)/tp_assign($2, $3)/g'\
339 ${TMPFILE} >> ${HEADER}
341 rm -f ${INPUTFILE}.tmp
This page took 0.064438 seconds and 5 git commands to generate.