diff options
author | Dmitry V. Levin <ldv@strace.io> | 2022-01-16 08:00:00 +0000 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2022-01-16 08:00:00 +0000 |
commit | e71f3095a92fcce771c02296b8f87ed40e0ef39b (patch) | |
tree | a093985d4de1d4d1e2ff31660c94d7f0acc7d40f | |
parent | e23ddffdcb6845aacd745ed33d37700201c110fb (diff) | |
download | strace-e71f3095a92fcce771c02296b8f87ed40e0ef39b.tar.gz |
Extend personality designation syntax to support all@pers
* NEWS: Mention this.
* src/basic_filters.c (lookup_class): Change to support zero flags,
handle "all" as a class with zero flags.
(qualify_syscall_class): Update to new lookup_class semantics.
* src/strace.c (usage): Update --trace description.
* doc/strace.1.in (.SS Filtering): Likewise.
* tests/filtering_syscall-syntax.test: Update expected output.
* tests/qualify_personality_all.sh: New file.
* tests/Makefile.am (EXTRA_DIST): Add it.
* tests/gen_tests.in (trace_personality_all_32,
trace_personality_all_64, trace_personality_all_x32): New tests.
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | doc/strace.1.in | 3 | ||||
-rw-r--r-- | src/basic_filters.c | 17 | ||||
-rw-r--r-- | src/strace.c | 4 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rwxr-xr-x | tests/filtering_syscall-syntax.test | 3 | ||||
-rw-r--r-- | tests/gen_tests.in | 3 | ||||
-rw-r--r-- | tests/qualify_personality_all.sh | 91 |
8 files changed, 113 insertions, 11 deletions
@@ -4,7 +4,7 @@ Noteworthy changes in release ?.?? (????-??-??) * Improvements * Added 64-bit LoongArch architecture support. * Extended personality designation syntax of syscall specification expressions - to support %class@pers. + to support all@pers and %class@pers. * Bug fixes diff --git a/doc/strace.1.in b/doc/strace.1.in index 9ae53faf6..0e5bfa61b 100644 --- a/doc/strace.1.in +++ b/doc/strace.1.in @@ -502,6 +502,9 @@ Limit the syscall specification described by .I value to x32 personality. .TP +.B all +Trace all system calls. +.TP .BI / regex Trace only those system calls that match the .IR regex . diff --git a/src/basic_filters.c b/src/basic_filters.c index 50142bc55..d6e552889 100644 --- a/src/basic_filters.c +++ b/src/basic_filters.c @@ -102,8 +102,8 @@ qualify_syscall_regex(const char *str, unsigned int p, struct number_set *set) return found; } -static unsigned int -lookup_class(const char *s) +static bool +lookup_class(const char *s, unsigned int *v) { static const struct { const char *name; @@ -128,6 +128,7 @@ lookup_class(const char *s) { "%pure", TRACE_PURE }, { "%clock", TRACE_CLOCK }, /* legacy class names */ + { "all", 0 }, { "desc", TRACE_DESC }, { "file", TRACE_FILE }, { "memory", TRACE_MEMORY }, @@ -138,18 +139,20 @@ lookup_class(const char *s) }; for (unsigned int i = 0; i < ARRAY_SIZE(syscall_class); ++i) { - if (strcmp(s, syscall_class[i].name) == 0) - return syscall_class[i].value; + if (strcmp(s, syscall_class[i].name) == 0) { + *v = syscall_class[i].value; + return true; + } } - return 0; + return false; } static bool qualify_syscall_class(const char *str, unsigned int p, struct number_set *set) { - const unsigned int n = lookup_class(str); - if (!n) + unsigned int n; + if (!lookup_class(str, &n)) return false; for (unsigned int i = 0; i < nsyscall_vec[p]; ++i) { diff --git a/src/strace.c b/src/strace.c index b4631bdcc..8c2c1818d 100644 --- a/src/strace.c +++ b/src/strace.c @@ -317,8 +317,8 @@ Tracing:\n\ (useful to make 'strace -o FILE PROG' not stop on ^Z)\n\ \n\ Filtering:\n\ - -e trace=[!][?]{{SYSCALL|GROUP|/REGEX}[@64|@32|@x32]|all|none},\n\ - --trace=[!][?]{{SYSCALL|GROUP|/REGEX}[@64|@32|@x32]|all|none}\n\ + -e trace=[!][?]{{SYSCALL|GROUP|all|/REGEX}[@64|@32|@x32]|none},\n\ + --trace=[!][?]{{SYSCALL|GROUP|all|/REGEX}[@64|@32|@x32]|none}\n\ trace only specified syscalls.\n\ groups: %%clock, %%creds, %%desc, %%file, %%fstat, %%fstatfs %%ipc, %%lstat,\n\ %%memory, %%net, %%process, %%pure, %%signal, %%stat, %%%%stat,\n\ diff --git a/tests/Makefile.am b/tests/Makefile.am index 859a912f6..9623e672d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -665,6 +665,7 @@ EXTRA_DIST = \ qual_inject-error-signal.expected \ qual_inject-signal.expected \ qualify_personality.sh \ + qualify_personality_all.sh \ qualify_personality_empty.in \ quotactl.h \ regex.in \ diff --git a/tests/filtering_syscall-syntax.test b/tests/filtering_syscall-syntax.test index b5f8526e2..81813bad1 100755 --- a/tests/filtering_syscall-syntax.test +++ b/tests/filtering_syscall-syntax.test @@ -89,7 +89,7 @@ for arg in -1 -2 -3 -4 -5 \ check_syscall "$arg@$pers" "$arg@$pers" done -for arg in '!chdir' none all; do +for arg in '!chdir' none; do check_syscall "$arg" "1,$arg" done @@ -101,6 +101,7 @@ for arg in %desc \ %network \ chdir \ 1 \ + all \ ?32767 \ ?invalid \ ?%not_a_class \ diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 1509dc08a..4b16f9bff 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -1000,6 +1000,9 @@ trace_fstatfs test_trace_expr '' -e%fstatfs trace_lstat test_trace_expr '' -e%lstat -v -P stat.sample -P /dev/full trace_personality_32 +qualify_personality.sh 32 'getcwd' 'fsync-y|poke' trace_personality_64 +qualify_personality.sh 64 'getcwd' 'fsync-y|poke' +trace_personality_all_32 +qualify_personality_all.sh 32 +trace_personality_all_64 +qualify_personality_all.sh 64 +trace_personality_all_x32 +qualify_personality_all.sh x32 trace_personality_number_32 +qualify_personality.sh 32 "$(${srcdir=.}/print_scno_getcwd.sh)" 'fsync-y|poke' trace_personality_number_64 +qualify_personality.sh 64 "$(${srcdir=.}/print_scno_getcwd.sh)" 'fsync-y|poke' trace_personality_number_x32 +qualify_personality.sh x32 "$(${srcdir=.}/print_scno_getcwd.sh)" 'fsync-y|poke' diff --git a/tests/qualify_personality_all.sh b/tests/qualify_personality_all.sh new file mode 100644 index 000000000..d3fc95253 --- /dev/null +++ b/tests/qualify_personality_all.sh @@ -0,0 +1,91 @@ +#! /bin/sh -efu +# +# Common code for strace --trace=all@pers tests. +# +# Copyright (c) 2018-2022 The strace developers. +# All rights reserved. +# +# SPDX-License-Identifier: GPL-2.0-or-later + +. "${srcdir=.}/init.sh" + +[ "$#" -eq 1 ] || + fail_ 'No personality designation ("64", "32", "x32") specified' + +target_pers="$1" +shift + +trace_expr="all@$target_pers" + +case "$STRACE_NATIVE_ARCH" in +x86_64) + native_pers='64' + supported_pers='64 32 x32' + ;; +x32) + native_pers='x32' + supported_pers='x32 32' + ;; +aarch64|powerpc64|s390x|sparc64|tile) + native_pers='64' + supported_pers='64 32' + ;; +*) + native_pers=$(($SIZEOF_LONG * 8)) + supported_pers=$native_pers + ;; +esac + +pers_found= +for i in $supported_pers; do + if [ "$target_pers" = "$i" ]; then + pers_found=1 + break + fi +done + +[ -n "$pers_found" ] || + skip_ "Personality '$target_pers' is not supported on architecture" \ + "'$STRACE_NATIVE_ARCH' (supported personalities: $supported_pers)" + +cur_pers=$(print_current_personality_designator) +if [ "$target_pers" = "$cur_pers" ]; then + skip_ "$trace_expr would match all syscalls on $STRACE_ARCH" +fi + +if [ "$target_pers" != "$native_pers" ]; then + # reset $NAME, so that "$NAME.in" used by test_trace_expr + # would point to an empty file. + NAME=qualify_personality_empty + + test_trace_expr '' --trace="$trace_expr" + exit +fi + +if [ "$cur_pers:$target_pers" = 'x32:64' ]; then + skip_ "x32 executables may invoke $STRACE_NATIVE_ARCH syscalls" +fi + +# $trace_expr would match the native execve +cat > "$EXP" <<'__EOF__' +execve(at)?\(.* +__EOF__ + +check_prog head +check_prog tail + +while read -r t; do { + # skip lines beginning with "#" symbol + case "$t" in + ''|'#'*) continue ;; + esac + + try_run_prog "../$t" || continue + run_strace -qq -esignal=none --trace="$trace_expr" "../$t" > /dev/null + + head -n1 < "$LOG" > "$OUT" + match_grep "$OUT" "$EXP" + + tail -n +2 < "$LOG" > "$OUT" + match_diff "$OUT" /dev/null +} < /dev/null; done < "$srcdir/pure_executables.list" |