]> granicus.if.org Git - strace/commitdiff
Make output of execve/execveat syscall parsers more structured
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 24 Apr 2017 19:22:11 +0000 (19:22 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 24 Apr 2017 19:22:11 +0000 (19:22 +0000)
* execve.c (printargc): Always print the address, format the number
of variables as a comment.
* tests/execve.c: Update expected output.
* tests/execveat.c: Likewise.
* tests/qual_syscall.test: Likewise.
* tests/strace-r.expected: Likewise.
* tests/strace-t.test: Likewise.
* tests/strace-tt.test: Likewise.
* tests/strace-ttt.test: Likewise.
* tests/threads-execve.c: Likewise.
* tests/threads-execve.test: Likewise.

execve.c
tests/execve.c
tests/execveat.c
tests/qual_syscall.test
tests/strace-r.expected
tests/strace-t.test
tests/strace-tt.test
tests/strace-ttt.test
tests/threads-execve.c
tests/threads-execve.test

index 6e45b11bf4639cd1ea795fe8453773f125b2285c..aa5303c3f44f5afc7c715afd092e0f4155cb7b26 100644 (file)
--- a/execve.c
+++ b/execve.c
@@ -78,10 +78,10 @@ printargv(struct tcb *const tcp, kernel_ulong_t addr)
 static void
 printargc(struct tcb *const tcp, kernel_ulong_t addr)
 {
-       if (!addr || !verbose(tcp)) {
-               printaddr(addr);
+       printaddr(addr);
+
+       if (!addr || !verbose(tcp))
                return;
-       }
 
        bool unterminated = false;
        unsigned int count = 0;
@@ -89,17 +89,16 @@ printargc(struct tcb *const tcp, kernel_ulong_t addr)
 
        for (; addr; addr += current_wordsize, ++count) {
                if (umoven(tcp, addr, current_wordsize, &cp)) {
-                       if (count) {
-                               unterminated = true;
-                               break;
-                       }
-                       printaddr(addr);
-                       return;
+                       if (!count)
+                               return;
+
+                       unterminated = true;
+                       break;
                }
                if (!cp)
                        break;
        }
-       tprintf("[/* %u var%s%s */]",
+       tprintf(" /* %u var%s%s */",
                count, count == 1 ? "" : "s",
                unterminated ? ", unterminated" : "");
 }
index d73a00da465950c6a444f1eaf6a23483aff25970..c50d065990b54f09ed73bf0022e3e3214b5b81e9 100644 (file)
@@ -62,13 +62,15 @@ main(void)
 #if VERBOSE
               ", [\"%s\", \"%s\", %p, %p, %p, ???]"
 #else
-              ", [/* 5 vars, unterminated */]"
+              ", %p /* 5 vars, unterminated */"
 #endif
               ") = -1 ENOENT (%m)\n",
               Q_FILENAME, q_argv[0], q_argv[1], q_argv[2],
               argv[3], argv[4], argv[5]
 #if VERBOSE
               , q_envp[0], q_envp[1], envp[2], envp[3], envp[4]
+#else
+              , tail_envp
 #endif
               );
 
@@ -80,12 +82,14 @@ main(void)
 #if VERBOSE
               ", [\"%s\", \"%s\"]"
 #else
-              ", [/* 2 vars */]"
+              ", %p /* 2 vars */"
 #endif
               ") = -1 ENOENT (%m)\n",
               Q_FILENAME, q_argv[0], q_argv[1], q_argv[2]
 #if VERBOSE
               , q_envp[0], q_envp[1]
+#else
+              , tail_envp
 #endif
               );
 
@@ -94,12 +98,14 @@ main(void)
 #if VERBOSE
               ", [\"%s\"]"
 #else
-              ", [/* 1 var */]"
+              ", %p /* 1 var */"
 #endif
               ") = -1 ENOENT (%m)\n",
               Q_FILENAME, q_argv[2]
 #if VERBOSE
               , q_envp[1]
+#else
+              , tail_envp + 1
 #endif
               );
 
@@ -112,9 +118,13 @@ main(void)
 #if VERBOSE
               ", []"
 #else
-              ", [/* 0 vars */]"
+              ", %p /* 0 vars */"
 #endif
-              ") = -1 ENOENT (%m)\n", Q_FILENAME);
+              ") = -1 ENOENT (%m)\n", Q_FILENAME
+#if !VERBOSE
+              , empty
+#endif
+              );
 
        char str_a[] = "012345678901234567890123456789012";
        char str_b[] = "_abcdefghijklmnopqrstuvwxyz()[]{}";
@@ -141,10 +151,11 @@ main(void)
        printf("], [\"%.*s\"...", DEFAULT_STRLEN, b[0]);
        for (i = 1; i <= DEFAULT_STRLEN; ++i)
                printf(", \"%s\"", b[i]);
+       printf("]");
 #else
-       printf("], [/* %u vars */", DEFAULT_STRLEN + 1);
+       printf("], %p /* %u vars */", b, DEFAULT_STRLEN + 1);
 #endif
-       printf("]) = -1 ENOENT (%m)\n");
+       printf(") = -1 ENOENT (%m)\n");
 
        execve(FILENAME, a + 1, b + 1);
        printf("execve(\"%s\", [\"%s\"", Q_FILENAME, a[1]);
@@ -154,10 +165,11 @@ main(void)
        printf("], [\"%s\"", b[1]);
        for (i = 2; i <= DEFAULT_STRLEN; ++i)
                printf(", \"%s\"", b[i]);
+       printf("]");
 #else
-       printf("], [/* %d vars */", DEFAULT_STRLEN);
+       printf("], %p /* %d vars */", b + 1, DEFAULT_STRLEN);
 #endif
-       printf("]) = -1 ENOENT (%m)\n");
+       printf(") = -1 ENOENT (%m)\n");
 
        execve(FILENAME, (char **) tail_argv[ARRAY_SIZE(q_argv)], efault);
        printf("execve(\"%s\", NULL, %p) = -1 ENOENT (%m)\n",
index e01fe4e60635f13f8dff4888245322ff5f47a40a..3e8fa3139bb01eb958201445dbc4a1d4ae64dd9d 100644 (file)
@@ -67,13 +67,15 @@ main(void)
 #if VERBOSE
               ", [\"%s\", \"%s\", %p, %p, %p, ???]"
 #else
-              ", [/* 5 vars, unterminated */]"
+              ", %p /* 5 vars, unterminated */"
 #endif
               ", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
               Q_FILENAME, q_argv[0], q_argv[1], q_argv[2],
               argv[3], argv[4], argv[5],
 #if VERBOSE
               q_envp[0], q_envp[1], envp[2], envp[3], envp[4],
+#else
+              tail_envp,
 #endif
               errno2name());
 
@@ -85,12 +87,14 @@ main(void)
 #if VERBOSE
               ", [\"%s\", \"%s\"]"
 #else
-              ", [/* 2 vars */]"
+              ", %p /* 2 vars */"
 #endif
               ", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
               Q_FILENAME, q_argv[0], q_argv[1], q_argv[2],
 #if VERBOSE
               q_envp[0], q_envp[1],
+#else
+              tail_envp,
 #endif
               errno2name());
 
@@ -99,12 +103,14 @@ main(void)
 #if VERBOSE
               ", [\"%s\"]"
 #else
-              ", [/* 1 var */]"
+              ", %p /* 1 var */"
 #endif
               ", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
               Q_FILENAME, q_argv[2],
 #if VERBOSE
               q_envp[1],
+#else
+              tail_envp + 1,
 #endif
               errno2name());
 
@@ -117,10 +123,14 @@ main(void)
 #if VERBOSE
               ", []"
 #else
-              ", [/* 0 vars */]"
+              ", %p /* 0 vars */"
 #endif
               ", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
-              Q_FILENAME, errno2name());
+              Q_FILENAME,
+#if !VERBOSE
+              empty,
+#endif
+              errno2name());
 
        char str_a[] = "012345678901234567890123456789012";
        char str_b[] = "_abcdefghijklmnopqrstuvwxyz()[]{}";
@@ -147,10 +157,11 @@ main(void)
        printf("], [\"%.*s\"...", DEFAULT_STRLEN, b[0]);
        for (i = 1; i <= DEFAULT_STRLEN; ++i)
                printf(", \"%s\"", b[i]);
+       printf("]");
 #else
-       printf("], [/* %u vars */", DEFAULT_STRLEN + 1);
+       printf("], %p /* %u vars */", b, DEFAULT_STRLEN + 1);
 #endif
-       printf("], AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
+       printf(", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
               errno2name());
 
        syscall(__NR_execveat, -100, FILENAME, a + 1, b + 1, 0x1100);
@@ -161,10 +172,11 @@ main(void)
        printf("], [\"%s\"", b[1]);
        for (i = 2; i <= DEFAULT_STRLEN; ++i)
                printf(", \"%s\"", b[i]);
+       printf("]");
 #else
-       printf("], [/* %d vars */", DEFAULT_STRLEN);
+       printf("], %p /* %d vars */", b + 1, DEFAULT_STRLEN);
 #endif
-       printf("], AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
+       printf(", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
               errno2name());
 
        syscall(__NR_execveat, -100, FILENAME, NULL, efault, 0x1100);
index 4c2a25a6189985e81d82cb331dc4570010780ba1..1524405a316b6ac7d7a2d6abc591eb49f26e5ade 100755 (executable)
@@ -6,7 +6,7 @@
 . "${srcdir=.}/init.sh"
 
 run_prog ../umovestr
-pattern_abbrev_verbose='execve("\.\./umovestr", \["\.\./umovestr"\], \[/\* [[:digit:]]* vars \*/\]) = 0'
+pattern_abbrev_verbose='execve("\.\./umovestr", \["\.\./umovestr"\], 0x[[:xdigit:]]* /\* [[: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'
index a3d09079d82d594ba9374d2430656e3f1f10e452..2a5b9773349ba6efaedf40d62ccb7810412e08f7 100644 (file)
@@ -1,2 +1,2 @@
-[ ]{5}0\.0{6} execve\("\.\./sleep", \["\.\./sleep", "1"\], \[/\* [[:digit:]]+ vars \*/\]\) = 0
+[ ]{5}0\.0{6} execve\("\.\./sleep", \["\.\./sleep", "1"\], 0x[[:xdigit:]]* /\* [[:digit:]]* vars \*/\) = 0
 [ ]{5}(1\.[01]|0\.9)[[:digit:]]{5} \+\+\+ exited with 0 \+\+\+
index d7fc742026dfcf31216c545a10d6d8907f622f3f..38070f30764ea382258fcf7da6aa1ac2c80c3fe4 100755 (executable)
@@ -12,7 +12,7 @@ run_strace -t -eexecve $args
 t1="$(date +%T)"
 
 cat > "$EXP" << __EOF__
-($t0|$t1) execve\\("\\.\\./sleep", \\["\\.\\./sleep", "0"\\], \\[/\\* [[:digit:]]+ vars \\*/\\]\\) = 0
+($t0|$t1) execve\\("\\.\\./sleep", \\["\\.\\./sleep", "0"\\], 0x[[:xdigit:]]* /\\* [[:digit:]]* vars \\*/\\) = 0
 __EOF__
 
 match_grep "$LOG" "$EXP"
index c7fea700fc436829ab78e9967f9b2217ae2ea4e2..328565599d1d3fc6434846aba245ac5143887fe7 100755 (executable)
@@ -21,7 +21,7 @@ while [ "$s" -le "$s1" ]; do
 done
 
 cat > "$EXP" << __EOF__
-($t_reg)\\.[[:digit:]]{6} execve\\("\\.\\./sleep", \\["\\.\\./sleep", "0"\\], \\[/\\* [[:digit:]]+ vars \\*/\\]\\) = 0
+($t_reg)\\.[[:digit:]]{6} execve\\("\\.\\./sleep", \\["\\.\\./sleep", "0"\\], 0x[[:xdigit:]]* /\\* [[:digit:]]* vars \\*/\\) = 0
 __EOF__
 
 match_grep "$LOG" "$EXP"
index 039442b704ebb4d51013ae93debd3bc369794ae1..7d4435beb319d81f6637a31ac6a302862fb926b0 100755 (executable)
@@ -19,7 +19,7 @@ while [ "$s" -le "$s1" ]; do
 done
 
 cat > "$EXP" << __EOF__
-($t_reg)\\.[[:digit:]]{6} execve\\("\\.\\./sleep", \\["\\.\\./sleep", "0"\\], \\[/\\* [[:digit:]]+ vars \\*/\\]\\) = 0
+($t_reg)\\.[[:digit:]]{6} execve\\("\\.\\./sleep", \\["\\.\\./sleep", "0"\\], 0x[[:xdigit:]]* /\\* [[:digit:]]+ vars \\*/\\) = 0
 __EOF__
 
 match_grep "$LOG" "$EXP"
index 853645ffa10ea541aeda721743b19f3e2997377c..f4d9722d41b68fcf75a580a621161f4d4b1549a6 100644 (file)
@@ -136,25 +136,25 @@ thread(void *arg)
        switch (action % NUMBER_OF_ACTIONS) {
                case ACTION_exit:
                        printf("%-5d execve(\"%s\", [\"%s\", \"%s\", \"%s\"]"
-                              ", [/* %u vars */] <pid changed to %u ...>\n",
+                              ", %p /* %u vars */ <pid changed to %u ...>\n",
                               tid, argv[0], argv[0], argv[1], argv[2],
-                              arglen(environ), leader);
+                              environ, arglen(environ), leader);
                        break;
                case ACTION_rt_sigsuspend:
                        printf("%-5d execve(\"%s\", [\"%s\", \"%s\", \"%s\"]"
-                              ", [/* %u vars */] <unfinished ...>\n"
+                              ", %p /* %u vars */ <unfinished ...>\n"
                               "%-5d <... rt_sigsuspend resumed>) = ?\n",
                               tid, argv[0], argv[0], argv[1], argv[2],
-                              arglen(environ),
+                              environ, arglen(environ),
                               leader);
                        break;
                case ACTION_nanosleep:
                        printf("%-5d execve(\"%s\", [\"%s\", \"%s\", \"%s\"]"
-                              ", [/* %u vars */] <unfinished ...>\n"
+                              ", %p /* %u vars */ <unfinished ...>\n"
                               "%-5d <... nanosleep resumed> <unfinished ...>)"
                               " = ?\n",
                               tid, argv[0], argv[0], argv[1], argv[2],
-                              arglen(environ),
+                              environ, arglen(environ),
                               leader);
                        break;
        }
@@ -180,18 +180,15 @@ main(int ac, char **av)
                if (clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL))
                        perror_msg_and_skip("clock_nanosleep CLOCK_REALTIME");
 
-               printf("%-5d execve(\"%s\", [\"%s\"], [/* %u vars */]) = 0\n",
-                      leader, av[0], av[0], arglen(environ));
-
                get_sigsetsize();
                static char buf[sizeof(sigsetsize) * 3];
                sprintf(buf, "%u", sigsetsize);
 
                char *argv[] = { av[0], buf, (char *) "0", NULL };
                printf("%-5d execve(\"%s\", [\"%s\", \"%s\", \"%s\"]"
-                      ", [/* %u vars */]) = 0\n",
+                      ", %p /* %u vars */) = 0\n",
                       leader, argv[0], argv[0], argv[1], argv[2],
-                      arglen(environ));
+                      environ, arglen(environ));
                execve(argv[0], argv, environ);
                perror_msg_and_fail("execve");
        }
index 830856d2015cd51793f400538ee55eba82bd78eb..62d70a7757f51bd25dd2da26f05932ece8c32fb0 100755 (executable)
@@ -40,9 +40,11 @@ set -- -a21 -f -esignal=none -e trace=execve,exit,nanosleep,rt_sigsuspend $args
 
 # Due to probabilistic nature of the test, try it several times.
 i=0
-while [ $i -le 9 ]; do
+while [ $i -le 19 ]; do
+       i="$(($i+1))"
        run_strace "$@" > "$EXP"
-       diff -- "$EXP" "$LOG" || continue
+       sed 1d < "$LOG" > "$OUT"
+       diff -- "$EXP" "$OUT" || continue
        exit 0
 done