Support per-architecture syscall in/out parameter descriptions
[lttng-modules.git] / include / instrumentation / syscalls / lttng-get-syscall-inout.sh
index 8ddaad8d0e57c400f99b6a304d6b709bad879ac6..61bd86a42e2a68a1dc70258c1866fade2428185a 100755 (executable)
@@ -4,16 +4,16 @@
 # example usage:
 # lttng-get-syscall-inout.sh table-syscall-inout.txt select 1
 
-FILENAME=$1
+ARCH_NAME=$1
 SYSCALL_NAME=$2
 ARG_NR=$3
 TMPFILE=$(mktemp)
+GENERIC_INOUT_DESCRIPTION_FILE="$(dirname "$0")/table-syscall-inout.txt"
 
 # Delete temp file on exit
 trap 'rm -f "$TMPFILE"' EXIT
 
-
-if [ x"${FILENAME}" = x"" ]; then
+if [ x"${GENERIC_INOUT_DESCRIPTION_FILE}" = x"" ]; then
        echo "Error: Please specify input file name as first argument" >&2
        exit 1
 fi
@@ -28,21 +28,48 @@ if [[ x"${ARG_NR}" = x"" || ${ARG_NR} == 0 ]]; then
        exit 1
 fi
 
+# Search for the in/out description of a syscall. This function attempts to find
+# a matching description in the per-architecture description override file (if it exists)
+# and falls back to the generic description file otherwise.
+#
+# Returns 0 if a description was found and written to the output file, 1 otherwise.
+function write_inout_description ()
+{
+       local arch_name=$1
+       local syscall_name=$2
+       local output_file=$3
+       local description_files=("$(dirname "$0")/table-syscall-inout-${arch_name}-override.txt" "$GENERIC_INOUT_DESCRIPTION_FILE")
+       local found=0
+
+       for file in ${description_files[@]}; do
+               if [ ! -f "$file" ]; then
+                       continue
+               fi
+
+               # Look for the syscall's in/out description
+               grep "syscall ${syscall_name} " "${file}" > "${output_file}" || true
+
+               # Error out if we got more than one syscall
+               local match_count=$(wc -l < "${output_file}")
+               if [ "${match_count}" -gt 1 ]; then
+                       # Fatal error; invalid description file
+                       echo "Error: more than one system call match" >&2
+                       exit 1
+               elif [ "${match_count}" -eq 1 ]; then
+                       # Description found
+                       return 0
+               fi
+       done
+
+       return 1
+}
+
 # Abort on error and undefined variable
 set -eu
 
-# Get the required syscall
-grep "syscall ${SYSCALL_NAME} " "${FILENAME}" > "${TMPFILE}" || true
-
-# 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
 
 # Default to sc_inout for unknown syscalls
-if [ "${NR_MATCH}" -eq 0 ]; then
+if ! write_inout_description "$ARCH_NAME" "$SYSCALL_NAME" "$TMPFILE"; then
        echo "Warning: no match for syscall '${SYSCALL_NAME}', set to 'inout'" >&2
        # no match, default to inout
        echo "sc_inout"
This page took 0.024551 seconds and 4 git commands to generate.