| 1 | #!/bin/sh |
| 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-3.0.4 64 |
| 11 | # lttng-syscalls-generate-headers.sh pointers 3.0.4 x86-64-syscalls-3.0.4 64 |
| 12 | |
| 13 | CLASS=$1 |
| 14 | INPUTDIR=$2 |
| 15 | INPUTFILE=$3 |
| 16 | BITNESS=$4 |
| 17 | INPUT=${INPUTDIR}/${INPUTFILE} |
| 18 | SRCFILE=gen.tmp.0 |
| 19 | TMPFILE=gen.tmp.1 |
| 20 | HEADER=headers/${INPUTFILE}_${CLASS}.h |
| 21 | |
| 22 | if [ x"$INPUTDIR" = x"" ]; then |
| 23 | echo "Error: Please specify input directory as second argument" |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
| 27 | if [ x"$INPUTFILE" = x"" ]; then |
| 28 | echo "Error: Please specify input file as third argument" |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | if [ x"$BITNESS" != x"32" ] && [ x"$BITNESS" != x"64" ]; then |
| 33 | echo "Error: Please specify bitness as fourth argument (\"32\" or \"64\")" |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
| 37 | cp ${INPUT} ${SRCFILE} |
| 38 | |
| 39 | #Cleanup |
| 40 | perl -p -e 's/^\[.*\] //g' ${SRCFILE} > ${TMPFILE} |
| 41 | mv ${TMPFILE} ${SRCFILE} |
| 42 | |
| 43 | perl -p -e 's/^syscall sys_([^ ]*)/syscall $1/g' ${SRCFILE} > ${TMPFILE} |
| 44 | mv ${TMPFILE} ${SRCFILE} |
| 45 | |
| 46 | #Filter |
| 47 | |
| 48 | if [ "$CLASS" = integers ]; then |
| 49 | #select integers and no-args. |
| 50 | CLASSCAP=INTEGERS |
| 51 | grep -v "\\*\|cap_user_header_t" ${SRCFILE} > ${TMPFILE} |
| 52 | mv ${TMPFILE} ${SRCFILE} |
| 53 | fi |
| 54 | |
| 55 | |
| 56 | if [ "$CLASS" = pointers ]; then |
| 57 | #select system calls using pointers. |
| 58 | CLASSCAP=POINTERS |
| 59 | grep "\\*\|cap_#user_header_t" ${SRCFILE} > ${TMPFILE} |
| 60 | mv ${TMPFILE} ${SRCFILE} |
| 61 | fi |
| 62 | |
| 63 | if [ x"$CLASSCAP" = x"" ]; then |
| 64 | echo "Error: Please specify \"integers\" or \"pointers\" as first argument" |
| 65 | rm -f ${SRCFILE} |
| 66 | exit 1 |
| 67 | fi |
| 68 | |
| 69 | echo "/* THIS FILE IS AUTO-GENERATED. DO NOT EDIT */" > ${HEADER} |
| 70 | |
| 71 | echo \ |
| 72 | "#ifndef CREATE_SYSCALL_TABLE |
| 73 | |
| 74 | #if !defined(_TRACE_SYSCALLS_${CLASSCAP}_H) || defined(TRACE_HEADER_MULTI_READ) |
| 75 | #define _TRACE_SYSCALLS_${CLASSCAP}_H |
| 76 | |
| 77 | #include <linux/tracepoint.h> |
| 78 | #include <linux/syscalls.h> |
| 79 | #include \"${INPUTFILE}_${CLASS}_override.h\" |
| 80 | #include \"syscalls_${CLASS}_override.h\" |
| 81 | " >> ${HEADER} |
| 82 | |
| 83 | if [ "$CLASS" = integers ]; then |
| 84 | |
| 85 | NRARGS=0 |
| 86 | |
| 87 | printf \ |
| 88 | 'SC_DECLARE_EVENT_CLASS_NOARGS(syscalls_noargs,\n'\ |
| 89 | ' TP_STRUCT__entry(),\n'\ |
| 90 | ' TP_fast_assign(),\n'\ |
| 91 | ' TP_printk()\n'\ |
| 92 | ')\n'\ |
| 93 | >> ${HEADER} |
| 94 | |
| 95 | grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} |
| 96 | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ |
| 97 | 'types: \(([^)]*)\) '\ |
| 98 | 'args: \(([^)]*)\)/'\ |
| 99 | '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\ |
| 100 | 'SC_DEFINE_EVENT_NOARGS(syscalls_noargs, sys_$1)\n'\ |
| 101 | '#endif/g'\ |
| 102 | ${TMPFILE} >> ${HEADER} |
| 103 | |
| 104 | fi |
| 105 | |
| 106 | |
| 107 | # types: 4 |
| 108 | # args 5 |
| 109 | |
| 110 | NRARGS=1 |
| 111 | grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} |
| 112 | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ |
| 113 | 'types: \(([^)]*)\) '\ |
| 114 | 'args: \(([^)]*)\)/'\ |
| 115 | '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\ |
| 116 | 'SC_TRACE_EVENT(sys_$1,\n'\ |
| 117 | ' TP_PROTO($4 $5),\n'\ |
| 118 | ' TP_ARGS($5),\n'\ |
| 119 | ' TP_STRUCT__entry(__field($4, $5)),\n'\ |
| 120 | ' TP_fast_assign(tp_assign($4, $5, $5)),\n'\ |
| 121 | ' TP_printk()\n'\ |
| 122 | ')\n'\ |
| 123 | '#endif/g'\ |
| 124 | ${TMPFILE} >> ${HEADER} |
| 125 | |
| 126 | # types: 4 5 |
| 127 | # args 6 7 |
| 128 | |
| 129 | NRARGS=2 |
| 130 | grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} |
| 131 | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ |
| 132 | 'types: \(([^,]*), ([^)]*)\) '\ |
| 133 | 'args: \(([^,]*), ([^)]*)\)/'\ |
| 134 | '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\ |
| 135 | 'SC_TRACE_EVENT(sys_$1,\n'\ |
| 136 | ' TP_PROTO($4 $6, $5 $7),\n'\ |
| 137 | ' TP_ARGS($6, $7),\n'\ |
| 138 | ' TP_STRUCT__entry(__field($4, $6) __field($5, $7)),\n'\ |
| 139 | ' TP_fast_assign(tp_assign($4, $6, $6) tp_assign($5, $7, $7)),\n'\ |
| 140 | ' TP_printk()\n'\ |
| 141 | ')\n'\ |
| 142 | '#endif/g'\ |
| 143 | ${TMPFILE} >> ${HEADER} |
| 144 | |
| 145 | # types: 4 5 6 |
| 146 | # args 7 8 9 |
| 147 | |
| 148 | NRARGS=3 |
| 149 | grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} |
| 150 | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ |
| 151 | 'types: \(([^,]*), ([^,]*), ([^)]*)\) '\ |
| 152 | 'args: \(([^,]*), ([^,]*), ([^)]*)\)/'\ |
| 153 | '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\ |
| 154 | 'SC_TRACE_EVENT(sys_$1,\n'\ |
| 155 | ' TP_PROTO($4 $7, $5 $8, $6 $9),\n'\ |
| 156 | ' TP_ARGS($7, $8, $9),\n'\ |
| 157 | ' TP_STRUCT__entry(__field($4, $7) __field($5, $8) __field($6, $9)),\n'\ |
| 158 | ' TP_fast_assign(tp_assign($4, $7, $7) tp_assign($5, $8, $8) tp_assign($6, $9, $9)),\n'\ |
| 159 | ' TP_printk()\n'\ |
| 160 | ')\n'\ |
| 161 | '#endif/g'\ |
| 162 | ${TMPFILE} >> ${HEADER} |
| 163 | |
| 164 | |
| 165 | # types: 4 5 6 7 |
| 166 | # args 8 9 10 11 |
| 167 | |
| 168 | NRARGS=4 |
| 169 | grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} |
| 170 | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ |
| 171 | 'types: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\ |
| 172 | 'args: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\ |
| 173 | '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\ |
| 174 | 'SC_TRACE_EVENT(sys_$1,\n'\ |
| 175 | ' TP_PROTO($4 $8, $5 $9, $6 $10, $7 $11),\n'\ |
| 176 | ' TP_ARGS($8, $9, $10, $11),\n'\ |
| 177 | ' TP_STRUCT__entry(__field($4, $8) __field($5, $9) __field($6, $10) __field($7, $11)),\n'\ |
| 178 | ' TP_fast_assign(tp_assign($4, $8, $8) tp_assign($5, $9, $9) tp_assign($6, $10, $10) tp_assign($7, $11, $11)),\n'\ |
| 179 | ' TP_printk()\n'\ |
| 180 | ')\n'\ |
| 181 | '#endif/g'\ |
| 182 | ${TMPFILE} >> ${HEADER} |
| 183 | |
| 184 | # types: 4 5 6 7 8 |
| 185 | # args 9 10 11 12 13 |
| 186 | |
| 187 | NRARGS=5 |
| 188 | grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} |
| 189 | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ |
| 190 | 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\ |
| 191 | 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\ |
| 192 | '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\ |
| 193 | 'SC_TRACE_EVENT(sys_$1,\n'\ |
| 194 | ' TP_PROTO($4 $9, $5 $10, $6 $11, $7 $12, $8 $13),\n'\ |
| 195 | ' TP_ARGS($9, $10, $11, $12, $13),\n'\ |
| 196 | ' TP_STRUCT__entry(__field($4, $9) __field($5, $10) __field($6, $11) __field($7, $12) __field($8, $13)),\n'\ |
| 197 | ' TP_fast_assign(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'\ |
| 198 | ' TP_printk()\n'\ |
| 199 | ')\n'\ |
| 200 | '#endif/g'\ |
| 201 | ${TMPFILE} >> ${HEADER} |
| 202 | |
| 203 | |
| 204 | # types: 4 5 6 7 8 9 |
| 205 | # args 10 11 12 13 14 15 |
| 206 | |
| 207 | NRARGS=6 |
| 208 | grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} |
| 209 | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ |
| 210 | 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\) '\ |
| 211 | 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\)/'\ |
| 212 | '#ifndef OVERRIDE_'"${BITNESS}"'_sys_$1\n'\ |
| 213 | 'SC_TRACE_EVENT(sys_$1,\n'\ |
| 214 | ' TP_PROTO($4 $10, $5 $11, $6 $12, $7 $13, $8 $14, $9 $15),\n'\ |
| 215 | ' TP_ARGS($10, $11, $12, $13, $14, $15),\n'\ |
| 216 | ' TP_STRUCT__entry(__field($4, $10) __field($5, $11) __field($6, $12) __field($7, $13) __field($8, $14) __field($9, $15)),\n'\ |
| 217 | ' TP_fast_assign(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'\ |
| 218 | ' TP_printk()\n'\ |
| 219 | ')\n'\ |
| 220 | '#endif/g'\ |
| 221 | ${TMPFILE} >> ${HEADER} |
| 222 | |
| 223 | # Macro for tracing syscall table |
| 224 | |
| 225 | echo \ |
| 226 | " |
| 227 | #endif /* _TRACE_SYSCALLS_${CLASSCAP}_H */ |
| 228 | |
| 229 | /* This part must be outside protection */ |
| 230 | #include \"../../../probes/define_trace.h\" |
| 231 | |
| 232 | #else /* CREATE_SYSCALL_TABLE */ |
| 233 | |
| 234 | #include \"${INPUTFILE}_${CLASS}_override.h\" |
| 235 | #include \"syscalls_${CLASS}_override.h\" |
| 236 | " >> ${HEADER} |
| 237 | |
| 238 | NRARGS=0 |
| 239 | |
| 240 | if [ "$CLASS" = integers ]; then |
| 241 | #noargs |
| 242 | grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} |
| 243 | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\ |
| 244 | '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_sys_$1\n'\ |
| 245 | 'TRACE_SYSCALL_TABLE\(syscalls_noargs, sys_$1, $2, $3\)\n'\ |
| 246 | '#endif/g'\ |
| 247 | ${TMPFILE} >> ${HEADER} |
| 248 | fi |
| 249 | |
| 250 | #others. |
| 251 | grep -v "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} |
| 252 | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\ |
| 253 | '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_sys_$1\n'\ |
| 254 | 'TRACE_SYSCALL_TABLE(sys_$1, sys_$1, $2, $3)\n'\ |
| 255 | '#endif/g'\ |
| 256 | ${TMPFILE} >> ${HEADER} |
| 257 | |
| 258 | echo -n \ |
| 259 | " |
| 260 | #endif /* CREATE_SYSCALL_TABLE */ |
| 261 | " >> ${HEADER} |
| 262 | |
| 263 | #fields names: ...char * type with *name* or *file* or *path* or *root* |
| 264 | # or *put_old* or *type* |
| 265 | cp -f ${HEADER} ${TMPFILE} |
| 266 | rm -f ${HEADER} |
| 267 | perl -p -e 's/__field\(([^,)]*char \*), ([^\)]*)(name|file|path|root|put_old|type)([^\)]*)\)/__string_from_user($2$3$4, $2$3$4)/g'\ |
| 268 | ${TMPFILE} >> ${HEADER} |
| 269 | cp -f ${HEADER} ${TMPFILE} |
| 270 | rm -f ${HEADER} |
| 271 | perl -p -e 's/tp_assign\(([^,)]*char \*), ([^,]*)(name|file|path|root|put_old|type)([^,]*), ([^\)]*)\)/tp_copy_string_from_user($2$3$4, $5)/g'\ |
| 272 | ${TMPFILE} >> ${HEADER} |
| 273 | |
| 274 | #prettify addresses heuristics. |
| 275 | #field names with addr or ptr |
| 276 | cp -f ${HEADER} ${TMPFILE} |
| 277 | rm -f ${HEADER} |
| 278 | perl -p -e 's/__field\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/__field_hex($1, $2$3)/g'\ |
| 279 | ${TMPFILE} >> ${HEADER} |
| 280 | |
| 281 | #field types ending with '*' |
| 282 | cp -f ${HEADER} ${TMPFILE} |
| 283 | rm -f ${HEADER} |
| 284 | perl -p -e 's/__field\(([^,)]*\*), ([^),]*)\)/__field_hex($1, $2)/g'\ |
| 285 | ${TMPFILE} >> ${HEADER} |
| 286 | |
| 287 | #strip the extra type information from tp_assign. |
| 288 | cp -f ${HEADER} ${TMPFILE} |
| 289 | rm -f ${HEADER} |
| 290 | perl -p -e 's/tp_assign\(([^,)]*), ([^,]*), ([^\)]*)\)/tp_assign($2, $3)/g'\ |
| 291 | ${TMPFILE} >> ${HEADER} |
| 292 | |
| 293 | rm -f ${INPUTFILE}.tmp |
| 294 | rm -f ${TMPFILE} |
| 295 | rm -f ${SRCFILE} |