From: Dmitry V. Levin Date: Mon, 24 Apr 2017 19:22:11 +0000 (+0000) Subject: Make output of execve/execveat syscall parsers more structured X-Git-Tag: v4.17~35 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=37fc8e673a78a281cfc28a1fa23e7c4f542007f4;p=strace Make output of execve/execveat syscall parsers more structured * 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. --- diff --git a/execve.c b/execve.c index 6e45b11b..aa5303c3 100644 --- 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" : ""); } diff --git a/tests/execve.c b/tests/execve.c index d73a00da..c50d0659 100644 --- a/tests/execve.c +++ b/tests/execve.c @@ -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", diff --git a/tests/execveat.c b/tests/execveat.c index e01fe4e6..3e8fa313 100644 --- a/tests/execveat.c +++ b/tests/execveat.c @@ -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); diff --git a/tests/qual_syscall.test b/tests/qual_syscall.test index 4c2a25a6..1524405a 100755 --- a/tests/qual_syscall.test +++ b/tests/qual_syscall.test @@ -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' diff --git a/tests/strace-r.expected b/tests/strace-r.expected index a3d09079..2a5b9773 100644 --- a/tests/strace-r.expected +++ b/tests/strace-r.expected @@ -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 \+\+\+ diff --git a/tests/strace-t.test b/tests/strace-t.test index d7fc7420..38070f30 100755 --- a/tests/strace-t.test +++ b/tests/strace-t.test @@ -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" diff --git a/tests/strace-tt.test b/tests/strace-tt.test index c7fea700..32856559 100755 --- a/tests/strace-tt.test +++ b/tests/strace-tt.test @@ -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" diff --git a/tests/strace-ttt.test b/tests/strace-ttt.test index 039442b7..7d4435be 100755 --- a/tests/strace-ttt.test +++ b/tests/strace-ttt.test @@ -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" diff --git a/tests/threads-execve.c b/tests/threads-execve.c index 853645ff..f4d9722d 100644 --- a/tests/threads-execve.c +++ b/tests/threads-execve.c @@ -136,25 +136,25 @@ thread(void *arg) switch (action % NUMBER_OF_ACTIONS) { case ACTION_exit: printf("%-5d execve(\"%s\", [\"%s\", \"%s\", \"%s\"]" - ", [/* %u vars */] \n", + ", %p /* %u vars */ \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 */] \n" + ", %p /* %u vars */ \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 */] \n" + ", %p /* %u vars */ \n" "%-5d <... nanosleep resumed> )" " = ?\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"); } diff --git a/tests/threads-execve.test b/tests/threads-execve.test index 830856d2..62d70a77 100755 --- a/tests/threads-execve.test +++ b/tests/threads-execve.test @@ -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