From 2879dbbcd21397431ed3621b925a5a154f91c09b Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Fri, 14 Feb 2020 16:38:27 -0500 Subject: [PATCH] Cleanup: Syscall headers scripts shellcheck warnings Change-Id: Ia616724d942f43f5fde2186bff28446120b17c43 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- .../syscalls/lttng-get-syscall-inout.sh | 73 ++-- .../lttng-syscalls-generate-headers.sh | 343 ++++++++---------- 2 files changed, 195 insertions(+), 221 deletions(-) diff --git a/instrumentation/syscalls/lttng-get-syscall-inout.sh b/instrumentation/syscalls/lttng-get-syscall-inout.sh index 5d1df8f2..34aef00e 100755 --- a/instrumentation/syscalls/lttng-get-syscall-inout.sh +++ b/instrumentation/syscalls/lttng-get-syscall-inout.sh @@ -1,4 +1,5 @@ #!/bin/bash +# SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) # example usage: # lttng-get-syscall-inout.sh table-syscall-inout.txt select 1 @@ -6,81 +7,89 @@ FILENAME=$1 SYSCALL_NAME=$2 ARG_NR=$3 -TMPFILE=inout.tmp.1 -TMPFILE2=inout.tmp.2 +TMPFILE=$(mktemp) + +# Delete temp file on exit +trap 'rm -f "$TMPFILE"' EXIT + if [ x"${FILENAME}" = x"" ]; then - echo "Error: Please specify input file name as first argument" + echo "Error: Please specify input file name as first argument" >&2 exit 1 fi if [ x"${SYSCALL_NAME}" = x"" ]; then - echo "Error: Please specify system call name as second argument" + echo "Error: Please specify system call name as second argument" >&2 exit 1 fi if [[ x"${ARG_NR}" = x"" || ${ARG_NR} == 0 ]]; then - echo "Error: Please specify argument number larger than 0 as 3rd argument" + echo "Error: Please specify argument number larger than 0 as third argument" >&2 exit 1 fi -grep "syscall ${SYSCALL_NAME} " ${FILENAME} > ${TMPFILE} -perl -p -e 's/^syscall ([^ ]*) nbargs ([^ ]*) .*/'\ -'$2/g' ${TMPFILE} > ${TMPFILE2} +# Abort on error and undefined variable +set -eu + +# Get the required syscall +grep "syscall ${SYSCALL_NAME} " "${FILENAME}" > "${TMPFILE}" || true -NR_MATCH=$(wc -l ${TMPFILE} | perl -p -e 's/^([^ ])*.*/$1/g') -if [ ${NR_MATCH} -gt 1 ]; then - echo "Error: more than one system call match" +# Error out if we got more than one syscall +NR_MATCH=$(wc -l < "${TMPFILE}") +if [ "${NR_MATCH}" -gt 1 ]; then + echo "Error: more than one system call match" >&2 exit 1 fi -if [ ${NR_MATCH} -eq 0 ]; then +# Default to sc_inout for unknown syscalls +if [ "${NR_MATCH}" -eq 0 ]; then + echo "Warning: no match for syscall '${SYSCALL_NAME}', set to 'inout'" >&2 # no match, default to inout echo "sc_inout" exit 0 fi -SC_ARGS=$(cat ${TMPFILE2}) +# Get the number of argument +SC_ARGS=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) .*/\2/g' "${TMPFILE}") -if [ ${ARG_NR} -gt ${SC_ARGS} ]; then - echo "Error: argument number (${ARG_NR}) is larger than number of syscall arguments (${SC_ARGS})" +if [ "${ARG_NR}" -gt "${SC_ARGS}" ]; then + echo "Error: argument number (${ARG_NR}) is larger than number of syscall arguments (${SC_ARGS})" >&2 exit 1 fi -if [ ${ARG_NR} == 1 ]; then - perl -p -e 's/^syscall ([^ ]*) nbargs ([^ ]*) rw: \(([^,\)]*).*/$3/g' ${TMPFILE} > ${TMPFILE2} +if [ "${ARG_NR}" == 1 ]; then + SC_ARG_TYPE=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: (\([^,)]*\).*/\3/g' "${TMPFILE}") fi -if [ ${ARG_NR} == 2 ]; then - perl -p -e 's/^syscall ([^ ]*) nbargs ([^ ]*) rw: \([^,]*, ([^,\)]*).*/$3/g' ${TMPFILE} > ${TMPFILE2} +if [ "${ARG_NR}" == 2 ]; then + SC_ARG_TYPE=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}") fi -if [ ${ARG_NR} == 3 ]; then - perl -p -e 's/^syscall ([^ ]*) nbargs ([^ ]*) rw: \([^,]*, [^,]*, ([^,\)]*).*/$3/g' ${TMPFILE} > ${TMPFILE2} +if [ "${ARG_NR}" == 3 ]; then + SC_ARG_TYPE=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}") fi -if [ ${ARG_NR} == 4 ]; then - perl -p -e 's/^syscall ([^ ]*) nbargs ([^ ]*) rw: \([^,]*, [^,]*, [^,]*, ([^,\)]*).*/$3/g' ${TMPFILE} > ${TMPFILE2} +if [ "${ARG_NR}" == 4 ]; then + SC_ARG_TYPE=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}") fi -if [ ${ARG_NR} == 5 ]; then - perl -p -e 's/^syscall ([^ ]*) nbargs ([^ ]*) rw: \([^,]*, [^,]*, [^,]*, [^,]*, ([^,\)]*).*/$3/g' ${TMPFILE} > ${TMPFILE2} +if [ "${ARG_NR}" == 5 ]; then + SC_ARG_TYPE=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}") fi -if [ ${ARG_NR} == 6 ]; then - perl -p -e 's/^syscall ([^ ]*) nbargs ([^ ]*) rw: \([^,]*, [^,]*, [^,]*, [^,]*, [^,]*, ([^,\)]*).*/$3/g' ${TMPFILE} > ${TMPFILE2} +if [ "${ARG_NR}" == 6 ]; then + SC_ARG_TYPE=$(sed 's/^syscall \([^ ]*\) nbargs \([^ ]*\) rw: ([^,]*, [^,]*, [^,]*, [^,]*, [^,]*, \([^,)]*\).*/\3/g' "${TMPFILE}") fi -SC_ARG_TYPE=$(cat ${TMPFILE2}) -if [ ${SC_ARG_TYPE} = "r" ]; then +if [ "${SC_ARG_TYPE}" = "r" ]; then echo "sc_in" fi -if [ ${SC_ARG_TYPE} = "w" ]; then +if [ "${SC_ARG_TYPE}" = "w" ]; then echo "sc_out" fi -if [ ${SC_ARG_TYPE} = "rw" ]; then +if [ "${SC_ARG_TYPE}" = "rw" ]; then echo "sc_inout" fi -rm -f ${TMPFILE} ${TMPFILE2} +# EOF diff --git a/instrumentation/syscalls/lttng-syscalls-generate-headers.sh b/instrumentation/syscalls/lttng-syscalls-generate-headers.sh index 4b601b49..0096c69b 100755 --- a/instrumentation/syscalls/lttng-syscalls-generate-headers.sh +++ b/instrumentation/syscalls/lttng-syscalls-generate-headers.sh @@ -1,8 +1,8 @@ -#!/bin/sh +#!/bin/bash # Generate system call probe description macros from syscall metadata dump file. # The resulting header will be written in the headers subdirectory, in a file name -# based on the name of the input file. +# based on the name of the input file. # # example usage: # @@ -15,63 +15,66 @@ INPUTDIR=$2 INPUTFILE=$3 BITNESS=$4 INPUT=${INPUTDIR}/${INPUTFILE} -SRCFILE=gen.tmp.0 -TMPFILE=gen.tmp.1 -TMPFILE2=gen.tmp.2 -TMPFILE3=gen.tmp.3 HEADER=headers/${INPUTFILE}_${CLASS}.h if [ x"$INPUTDIR" = x"" ]; then - echo "Error: Please specify input directory as second argument" + echo "Error: Please specify input directory as second argument" >&2 exit 1 fi if [ x"$INPUTFILE" = x"" ]; then - echo "Error: Please specify input file as third argument" + echo "Error: Please specify input file as third argument" >&2 exit 1 fi if [ x"$BITNESS" != x"32" ] && [ x"$BITNESS" != x"64" ]; then - echo "Error: Please specify bitness as fourth argument (\"32\" or \"64\")" + echo "Error: Please specify bitness as fourth argument (\"32\" or \"64\")" >&2 exit 1 fi -cp ${INPUT} ${SRCFILE} +# Abort on error and undefined variable +set -eu -#Cleanup -perl -p -e 's/^\[.*\] //g' ${SRCFILE} > ${TMPFILE} -mv ${TMPFILE} ${SRCFILE} +# Create temp files +SRCFILE=$(mktemp) +TMPFILE=$(mktemp) -perl -p -e 's/^syscall sys_([^ ]*)/syscall $1/g' ${SRCFILE} > ${TMPFILE} -mv ${TMPFILE} ${SRCFILE} +# Delete temp files on exit +trap 'rm -f "${SRCFILE}" "${TMPFILE}"' EXIT + +cp "${INPUT}" "${SRCFILE}" + +## Cleanup the input file +# Remove the dmesg timestamp if present +perl -pi -e 's/^\[.*\] //g' "${SRCFILE}" +# Remove the 'sys_' prefix from syscall names +perl -pi -e 's/^syscall sys_([^ ]*)/syscall $1/g' "${SRCFILE}" +# Remove the user attribute from arguments +sed -i 's/ __attribute__((user))//g' "${SRCFILE}" #Filter if [ "$CLASS" = integers ]; then #select integers and no-args. CLASSCAP=INTEGERS - grep -v "\\*\|cap_user_header_t" ${SRCFILE} > ${TMPFILE} - mv ${TMPFILE} ${SRCFILE} -fi - - -if [ "$CLASS" = pointers ]; then + grep -v "\\*\|cap_user_header_t" "${SRCFILE}" > "${TMPFILE}" + mv "${TMPFILE}" "${SRCFILE}" +elif [ "$CLASS" = pointers ]; then #select system calls using pointers. CLASSCAP=POINTERS - grep "\\*\|cap_#user_header_t" ${SRCFILE} > ${TMPFILE} - mv ${TMPFILE} ${SRCFILE} -fi - -if [ x"$CLASSCAP" = x"" ]; then - echo "Error: Please specify \"integers\" or \"pointers\" as first argument" - rm -f ${SRCFILE} + grep "\\*\|cap_#user_header_t" "${SRCFILE}" > "${TMPFILE}" + mv "${TMPFILE}" "${SRCFILE}" +else + echo "Error: Please specify \"integers\" or \"pointers\" as first argument" >&2 exit 1 fi -echo "/* THIS FILE IS AUTO-GENERATED. DO NOT EDIT */" > ${HEADER} -echo \ -"#ifndef CREATE_SYSCALL_TABLE +echo "/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) */ + +/* THIS FILE IS AUTO-GENERATED. DO NOT EDIT */ + +#ifndef CREATE_SYSCALL_TABLE #if !defined(_TRACE_SYSCALLS_${CLASSCAP}_H) || defined(TRACE_HEADER_MULTI_READ) #define _TRACE_SYSCALLS_${CLASSCAP}_H @@ -80,37 +83,34 @@ echo \ #include #include \"${INPUTFILE}_${CLASS}_override.h\" #include \"syscalls_${CLASS}_override.h\" -" >> ${HEADER} +" > "${HEADER}" if [ "$CLASS" = integers ]; then -NRARGS=0 - -printf \ -'#ifdef SC_ENTER\n'\ - >> ${HEADER} + NRARGS=0 -printf \ -'SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscalls_noargs,\n'\ -' TP_FIELDS()\n'\ -')\n'\ - >> ${HEADER} + # shellcheck disable=SC2129 + printf \ +'#ifdef SC_ENTER +SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscalls_noargs, + TP_FIELDS() +) +' >> "${HEADER}" -grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} -perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ + # shellcheck disable=SC2026 + grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \ + perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ 'types: \(([^)]*)\) '\ 'args: \(([^)]*)\)/'\ '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\ 'SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscalls_noargs, $1)\n'\ -'#endif/g'\ - ${TMPFILE} >> ${HEADER} +'#endif/g' >> "${HEADER}" -printf \ -'#else /* #ifdef SC_ENTER */\n'\ - >> ${HEADER} + printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}" -grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} -perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ + # shellcheck disable=SC2026 + grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \ + perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ 'types: \(([^)]*)\) '\ 'args: \(([^)]*)\)/'\ '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\ @@ -119,12 +119,9 @@ perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ ' TP_ARGS(sc_exit(ret)),\n'\ ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)))\n'\ ')\n'\ -'#endif/g'\ - ${TMPFILE} >> ${HEADER} +'#endif/g' >> "${HEADER}" -printf \ -'#endif /* else #ifdef SC_ENTER */\n'\ - >> ${HEADER} + printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}" fi @@ -133,15 +130,14 @@ fi # args 5 NRARGS=1 -grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} - -while read LINE; do - echo "${LINE}" > ${TMPFILE2} - perl -p -e 's/^syscall ([^ ]*) .*/$1/g' ${TMPFILE2} > ${TMPFILE3} - SC_NAME=$(cat ${TMPFILE3}) - ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 1) - echo Syscall: ${SC_NAME} ${ARG1} - perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ +grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | while read -r LINE; do + SC_NAME=$(echo "${LINE}" | perl -p -e 's/^syscall ([^ ]*) .*/$1/g') + ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 1) + + echo Syscall: "${SC_NAME}" "${ARG1}" + + # shellcheck disable=SC2026 + echo "${LINE}" | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ 'types: \(([^)]*)\) '\ 'args: \(([^)]*)\)/'\ '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\ @@ -150,24 +146,22 @@ while read LINE; do ' TP_ARGS(sc_exit(ret,) $5),\n'\ ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $5, $5)))\n'\ ')\n'\ -'#endif/g'\ - ${TMPFILE2} >> ${HEADER} -done < ${TMPFILE} +'#endif/g' >> "${HEADER}" +done # types: 4 5 # args 6 7 NRARGS=2 -grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} - -while read LINE; do - echo "${LINE}" > ${TMPFILE2} - perl -p -e 's/^syscall ([^ ]*) .*/$1/g' ${TMPFILE2} > ${TMPFILE3} - SC_NAME=$(cat ${TMPFILE3}) - ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 1) - ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 2) - echo Syscall: ${SC_NAME} ${ARG1} ${ARG2} - perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ +grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | while read -r LINE; do + SC_NAME=$(echo "${LINE}" | perl -p -e 's/^syscall ([^ ]*) .*/$1/g') + ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 1) + ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 2) + + echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}" + + # shellcheck disable=SC2026 + echo "${LINE}" | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ 'types: \(([^,]*), ([^)]*)\) '\ 'args: \(([^,]*), ([^)]*)\)/'\ '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\ @@ -176,25 +170,23 @@ while read LINE; do ' TP_ARGS(sc_exit(ret,) $6, $7),\n'\ ' TP_FIELDS(sc_exit(ctf_integer(long, ret, ret)) '"${ARG1}"'(ctf_integer($4, $6, $6)) '"${ARG2}"'(ctf_integer($5, $7, $7)))\n'\ ')\n'\ -'#endif/g'\ - ${TMPFILE2} >> ${HEADER} -done < ${TMPFILE} +'#endif/g' >> "${HEADER}" +done # types: 4 5 6 # args 7 8 9 NRARGS=3 -grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} - -while read LINE; do - echo "${LINE}" > ${TMPFILE2} - perl -p -e 's/^syscall ([^ ]*) .*/$1/g' ${TMPFILE2} > ${TMPFILE3} - SC_NAME=$(cat ${TMPFILE3}) - ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 1) - ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 2) - ARG3=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 3) - echo Syscall: ${SC_NAME} ${ARG1} ${ARG2} ${ARG3} - perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ +grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | while read -r LINE; do + SC_NAME=$(echo "${LINE}" | perl -p -e 's/^syscall ([^ ]*) .*/$1/g') + ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 1) + ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 2) + ARG3=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 3) + + echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" + + # shellcheck disable=SC2026 + echo "${LINE}" | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ 'types: \(([^,]*), ([^,]*), ([^)]*)\) '\ 'args: \(([^,]*), ([^,]*), ([^)]*)\)/'\ '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\ @@ -203,27 +195,25 @@ while read LINE; do ' TP_ARGS(sc_exit(ret,) $7, $8, $9),\n'\ ' 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'\ ')\n'\ -'#endif/g'\ - ${TMPFILE2} >> ${HEADER} -done < ${TMPFILE} +'#endif/g' >> "${HEADER}" +done # types: 4 5 6 7 # args 8 9 10 11 NRARGS=4 -grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} - -while read LINE; do - echo "${LINE}" > ${TMPFILE2} - perl -p -e 's/^syscall ([^ ]*) .*/$1/g' ${TMPFILE2} > ${TMPFILE3} - SC_NAME=$(cat ${TMPFILE3}) - ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 1) - ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 2) - ARG3=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 3) - ARG4=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 4) - echo Syscall: ${SC_NAME} ${ARG1} ${ARG2} ${ARG3} ${ARG4} - perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ +grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | while read -r LINE; do + SC_NAME=$(echo "${LINE}" | perl -p -e 's/^syscall ([^ ]*) .*/$1/g') + ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 1) + ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 2) + ARG3=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 3) + ARG4=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 4) + + echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" + + # shellcheck disable=SC2026 + echo "${LINE}" | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ 'types: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\ 'args: \(([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\ '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\ @@ -232,27 +222,25 @@ while read LINE; do ' TP_ARGS(sc_exit(ret,) $8, $9, $10, $11),\n'\ ' 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'\ ')\n'\ -'#endif/g'\ - ${TMPFILE2} >> ${HEADER} -done < ${TMPFILE} +'#endif/g' >> "${HEADER}" +done # types: 4 5 6 7 8 # args 9 10 11 12 13 NRARGS=5 -grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} - -while read LINE; do - echo "${LINE}" > ${TMPFILE2} - perl -p -e 's/^syscall ([^ ]*) .*/$1/g' ${TMPFILE2} > ${TMPFILE3} - SC_NAME=$(cat ${TMPFILE3}) - ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 1) - ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 2) - ARG3=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 3) - ARG4=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 4) - ARG5=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 5) - echo Syscall: ${SC_NAME} ${ARG1} ${ARG2} ${ARG3} ${ARG4} ${ARG5} - perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ +grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | while read -r LINE; do + SC_NAME=$(echo "${LINE}" | perl -p -e 's/^syscall ([^ ]*) .*/$1/g') + ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 1) + ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 2) + ARG3=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 3) + ARG4=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 4) + ARG5=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 5) + + echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}" + + # shellcheck disable=SC2026 + echo "${LINE}" | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\) '\ 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^)]*)\)/'\ '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\ @@ -261,29 +249,27 @@ while read LINE; do ' TP_ARGS(sc_exit(ret,) $9, $10, $11, $12, $13),\n'\ ' 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'\ ')\n'\ -'#endif/g'\ - ${TMPFILE2} >> ${HEADER} -done < ${TMPFILE} +'#endif/g' >> "${HEADER}" +done # types: 4 5 6 7 8 9 # args 10 11 12 13 14 15 NRARGS=6 -grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} - -while read LINE; do - echo "${LINE}" > ${TMPFILE2} - perl -p -e 's/^syscall ([^ ]*) .*/$1/g' ${TMPFILE2} > ${TMPFILE3} - SC_NAME=$(cat ${TMPFILE3}) - ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 1) - ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 2) - ARG3=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 3) - ARG4=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 4) - ARG5=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 5) - ARG6=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt ${SC_NAME} 6) - echo Syscall: ${SC_NAME} ${ARG1} ${ARG2} ${ARG3} ${ARG4} ${ARG5} ${ARG6} - perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ +grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | while read -r LINE; do + SC_NAME=$(echo "${LINE}" | perl -p -e 's/^syscall ([^ ]*) .*/$1/g') + ARG1=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 1) + ARG2=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 2) + ARG3=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 3) + ARG4=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 4) + ARG5=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 5) + ARG6=$(./lttng-get-syscall-inout.sh table-syscall-inout.txt "${SC_NAME}" 6) + + echo Syscall: "${SC_NAME}" "${ARG1}" "${ARG2}" "${ARG3}" "${ARG4}" "${ARG5}" "${ARG6}" + + # shellcheck disable=SC2026 + echo "${LINE}" | perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) '\ 'types: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\) '\ 'args: \(([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^,]*), ([^\)]*)\)/'\ '#ifndef OVERRIDE_'"${BITNESS}"'_$1\n'\ @@ -292,9 +278,8 @@ while read LINE; do ' TP_ARGS(sc_exit(ret,) $10, $11, $12, $13, $14, $15),\n'\ ' 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'\ ')\n'\ -'#endif/g'\ - ${TMPFILE2} >> ${HEADER} -done < ${TMPFILE} +'#endif/g' >> "${HEADER}" +done # Macro for tracing syscall table @@ -309,76 +294,56 @@ echo \ #include \"${INPUTFILE}_${CLASS}_override.h\" #include \"syscalls_${CLASS}_override.h\" -" >> ${HEADER} +" >> "${HEADER}" NRARGS=0 if [ "$CLASS" = integers ]; then -#noargs + #noargs -printf \ -'#ifdef SC_ENTER\n'\ - >> ${HEADER} + # shellcheck disable=SC2129 + printf '#ifdef SC_ENTER\n' >> "${HEADER}" -grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} -perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\ + # shellcheck disable=SC2026 + grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \ + perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\ '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\ 'TRACE_SYSCALL_TABLE\(syscalls_noargs, $1, $2, $3\)\n'\ -'#endif/g'\ - ${TMPFILE} >> ${HEADER} +'#endif/g' >> "${HEADER}" -printf \ -'#else /* #ifdef SC_ENTER */\n'\ - >> ${HEADER} + printf '#else /* #ifdef SC_ENTER */\n' >> "${HEADER}" -grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} -perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\ + # shellcheck disable=SC2026 + grep "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \ + perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\ '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\ 'TRACE_SYSCALL_TABLE($1, $1, $2, $3)\n'\ -'#endif/g'\ - ${TMPFILE} >> ${HEADER} - -printf \ -'#endif /* else #ifdef SC_ENTER */\n'\ - >> ${HEADER} +'#endif/g' >> "${HEADER}" + printf '#endif /* else #ifdef SC_ENTER */\n' >> "${HEADER}" fi #others. -grep -v "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " ${SRCFILE} > ${TMPFILE} -perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\ +# shellcheck disable=SC2026 +grep -v "^syscall [^ ]* nr [^ ]* nbargs ${NRARGS} " "${SRCFILE}" | \ + perl -p -e 's/^syscall ([^ ]*) nr ([^ ]*) nbargs ([^ ]*) .*$/'\ '#ifndef OVERRIDE_TABLE_'"${BITNESS}"'_$1\n'\ 'TRACE_SYSCALL_TABLE($1, $1, $2, $3)\n'\ -'#endif/g'\ - ${TMPFILE} >> ${HEADER} +'#endif/g' >> "${HEADER}" -echo -n \ -" -#endif /* CREATE_SYSCALL_TABLE */ -" >> ${HEADER} +printf '\n#endif /* CREATE_SYSCALL_TABLE */\n' >> "${HEADER}" #fields names: ...char * type with *name* or *file* or *path* or *root* # or *put_old* or *type* -cp -f ${HEADER} ${TMPFILE} -rm -f ${HEADER} -perl -p -e 's/ctf_integer\(([^,)]*char \*), ([^\)]*)(name|file|path|root|put_old|type)([^\)]*)\)/ctf_user_string($2$3$4)/g'\ - ${TMPFILE} >> ${HEADER} +perl -pi -e 's/ctf_integer\(([^,)]*char \*), ([^\)]*)(name|file|path|root|put_old|type)([^\)]*)\)/ctf_user_string($2$3$4)/g' \ + "${HEADER}" #prettify addresses heuristics. #field names with addr or ptr -cp -f ${HEADER} ${TMPFILE} -rm -f ${HEADER} -perl -p -e 's/ctf_integer\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/ctf_integer_hex($1, $2$3, $2$3)/g'\ - ${TMPFILE} >> ${HEADER} +perl -pi -e 's/ctf_integer\(([^,)]*), ([^,)]*addr|[^,)]*ptr)([^),]*)\)/ctf_integer_hex($1, $2$3, $2$3)/g' \ + "${HEADER}" #field types ending with '*' -cp -f ${HEADER} ${TMPFILE} -rm -f ${HEADER} -perl -p -e 's/ctf_integer\(([^,)]*\*), ([^),]*)\)/ctf_integer_hex($1, $2, $2)/g'\ - ${TMPFILE} >> ${HEADER} - -rm -f ${INPUTFILE}.tmp -rm -f ${TMPFILE3} -rm -f ${TMPFILE2} -rm -f ${TMPFILE} -rm -f ${SRCFILE} +perl -pi -e 's/ctf_integer\(([^,)]*\*), ([^),]*)\)/ctf_integer_hex($1, $2, $2)/g' "${HEADER}" + +# EOF -- 2.34.1