]> granicus.if.org Git - strace/commitdiff
Enhance -e abbrev=set, -e raw=set, and -e verbose=set
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 30 Sep 2016 00:35:35 +0000 (00:35 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 30 Sep 2016 13:43:48 +0000 (13:43 +0000)
Enhance abbrev=, raw=, and verbose= to accept the same syntax as trace=.
For example, this allows such syntax as -e verbose=file.

* syscall.c (lookup_class): Define before qual_syscall.
(qualify): Move the loop based on lookup_class ...
(qual_syscall): ... here.
* tests/qual_syscall.test: Check it.

syscall.c
tests/qual_syscall.test

index f649a9076321e6b3aa5ad3f2029074fbc2f89ead..a43ff43f278a6d5df9d3e1483680cddba546fb7a 100644 (file)
--- a/syscall.c
+++ b/syscall.c
@@ -418,13 +418,45 @@ qualify_one(const unsigned int n, unsigned int bitflag, const int not, const int
        }
 }
 
+static int
+lookup_class(const char *s)
+{
+       if (strcmp(s, "file") == 0)
+               return TRACE_FILE;
+       if (strcmp(s, "ipc") == 0)
+               return TRACE_IPC;
+       if (strcmp(s, "network") == 0)
+               return TRACE_NETWORK;
+       if (strcmp(s, "process") == 0)
+               return TRACE_PROCESS;
+       if (strcmp(s, "signal") == 0)
+               return TRACE_SIGNAL;
+       if (strcmp(s, "desc") == 0)
+               return TRACE_DESC;
+       if (strcmp(s, "memory") == 0)
+               return TRACE_MEMORY;
+       return -1;
+}
+
 static int
 qual_syscall(const char *s, const unsigned int bitflag, const int not)
 {
-       int p;
+       unsigned int p;
        unsigned int i;
+       int n;
        int rc = -1;
 
+       if ((n = lookup_class(s)) >= 0) {
+               for (p = 0; p < SUPPORTED_PERSONALITIES; ++p) {
+                       for (i = 0; i < nsyscall_vec[p]; ++i) {
+                               if ((sysent_vec[p][i].sys_flags & n) == n) {
+                                       qualify_one(i, bitflag, not, p);
+                               }
+                       }
+               }
+               return 0;
+       }
+
        if (*s >= '0' && *s <= '9') {
                i = string_to_uint(s);
                if (i >= MAX_NSYSCALLS)
@@ -483,26 +515,6 @@ qual_desc(const char *s, const unsigned int bitflag, const int not)
        return -1;
 }
 
-static int
-lookup_class(const char *s)
-{
-       if (strcmp(s, "file") == 0)
-               return TRACE_FILE;
-       if (strcmp(s, "ipc") == 0)
-               return TRACE_IPC;
-       if (strcmp(s, "network") == 0)
-               return TRACE_NETWORK;
-       if (strcmp(s, "process") == 0)
-               return TRACE_PROCESS;
-       if (strcmp(s, "signal") == 0)
-               return TRACE_SIGNAL;
-       if (strcmp(s, "desc") == 0)
-               return TRACE_DESC;
-       if (strcmp(s, "memory") == 0)
-               return TRACE_MEMORY;
-       return -1;
-}
-
 void
 qualify(const char *s)
 {
@@ -544,16 +556,6 @@ qualify(const char *s)
        }
        copy = xstrdup(s);
        for (p = strtok(copy, ","); p; p = strtok(NULL, ",")) {
-               int n;
-               if (opt->bitflag == QUAL_TRACE && (n = lookup_class(p)) > 0) {
-                       unsigned pers;
-                       for (pers = 0; pers < SUPPORTED_PERSONALITIES; pers++) {
-                               for (i = 0; i < nsyscall_vec[pers]; i++)
-                                       if (sysent_vec[pers][i].sys_flags & n)
-                                               qualify_one(i, opt->bitflag, not, pers);
-                       }
-                       continue;
-               }
                if (opt->qualify(p, opt->bitflag, not)) {
                        error_msg_and_die("invalid %s '%s'",
                                opt->argument_name, p);
index 0b4fa42e8aae8f916c1ece4ce483f36dad783da8..49245dd76170c113641c38dd2f8bb8a7b2f96097 100755 (executable)
@@ -1,11 +1,15 @@
 #!/bin/sh
 
-# Ensure that strace -e trace=set works.
+# Check how strace -e abbrev=set, -e raw=set, -e trace=set,
+# and -e verbose=set work.
 
 . "${srcdir=.}/init.sh"
 
 run_prog ./umovestr
 pattern_abbrev_verbose='execve("\./umovestr", \["\./umovestr"\], \[/\* [[:digit:]]* vars \*/\]) = 0'
+pattern_nonabbrev_verbose='execve("\./umovestr", \["\./umovestr"\], \[".*\"\]) = 0'
+pattern_nonverbose='execve("\./umovestr", 0x[[:xdigit:]]*, 0x[[:xdigit:]]*) = 0'
+pattern_raw='execve(0x[[:xdigit:]]*, 0x[[:xdigit:]]*, 0x[[:xdigit:]]*) = 0'
 
 check_output_mismatch()
 {
@@ -29,4 +33,24 @@ run_strace -e 42 ./umovestr
 LC_ALL=C grep '^[[:alnum:]_]*(' > /dev/null &&
        dump_log_and_fail_with "$STRACE $args unexpected output"
 
+for a in execve \!chdir all \!none \
+        file process \!desc \!ipc \!memory \!network \!signal; do
+       check_output_mismatch \
+               "$pattern_abbrev_verbose" -e abbrev="$a" -e execve
+       check_output_mismatch \
+               "$pattern_raw" -a22 -e raw="$a" -e execve
+       check_output_mismatch \
+               "$pattern_abbrev_verbose" -e verbose="$a" -e execve
+done
+
+for a in \!execve chdir 42 \!all none \
+        \!file \!process desc ipc memory network signal; do
+       check_output_mismatch \
+               "$pattern_nonabbrev_verbose" -e abbrev="$a" -e execve
+       check_output_mismatch \
+               "$pattern_abbrev_verbose" -e raw="$a" -e execve
+       check_output_mismatch \
+               "$pattern_nonverbose" -a31 -e verbose="$a" -e execve
+done
+
 exit 0