Skip to content

Commit 37fc8e6

Browse files
committed
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.
1 parent b530478 commit 37fc8e6

File tree

10 files changed

+68
-46
lines changed

10 files changed

+68
-46
lines changed

execve.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,28 +78,27 @@ printargv(struct tcb *const tcp, kernel_ulong_t addr)
7878
static void
7979
printargc(struct tcb *const tcp, kernel_ulong_t addr)
8080
{
81-
if (!addr || !verbose(tcp)) {
82-
printaddr(addr);
81+
printaddr(addr);
82+
83+
if (!addr || !verbose(tcp))
8384
return;
84-
}
8585

8686
bool unterminated = false;
8787
unsigned int count = 0;
8888
char *cp = NULL;
8989

9090
for (; addr; addr += current_wordsize, ++count) {
9191
if (umoven(tcp, addr, current_wordsize, &cp)) {
92-
if (count) {
93-
unterminated = true;
94-
break;
95-
}
96-
printaddr(addr);
97-
return;
92+
if (!count)
93+
return;
94+
95+
unterminated = true;
96+
break;
9897
}
9998
if (!cp)
10099
break;
101100
}
102-
tprintf("[/* %u var%s%s */]",
101+
tprintf(" /* %u var%s%s */",
103102
count, count == 1 ? "" : "s",
104103
unterminated ? ", unterminated" : "");
105104
}

tests/execve.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ main(void)
6262
#if VERBOSE
6363
", [\"%s\", \"%s\", %p, %p, %p, ???]"
6464
#else
65-
", [/* 5 vars, unterminated */]"
65+
", %p /* 5 vars, unterminated */"
6666
#endif
6767
") = -1 ENOENT (%m)\n",
6868
Q_FILENAME, q_argv[0], q_argv[1], q_argv[2],
6969
argv[3], argv[4], argv[5]
7070
#if VERBOSE
7171
, q_envp[0], q_envp[1], envp[2], envp[3], envp[4]
72+
#else
73+
, tail_envp
7274
#endif
7375
);
7476

@@ -80,12 +82,14 @@ main(void)
8082
#if VERBOSE
8183
", [\"%s\", \"%s\"]"
8284
#else
83-
", [/* 2 vars */]"
85+
", %p /* 2 vars */"
8486
#endif
8587
") = -1 ENOENT (%m)\n",
8688
Q_FILENAME, q_argv[0], q_argv[1], q_argv[2]
8789
#if VERBOSE
8890
, q_envp[0], q_envp[1]
91+
#else
92+
, tail_envp
8993
#endif
9094
);
9195

@@ -94,12 +98,14 @@ main(void)
9498
#if VERBOSE
9599
", [\"%s\"]"
96100
#else
97-
", [/* 1 var */]"
101+
", %p /* 1 var */"
98102
#endif
99103
") = -1 ENOENT (%m)\n",
100104
Q_FILENAME, q_argv[2]
101105
#if VERBOSE
102106
, q_envp[1]
107+
#else
108+
, tail_envp + 1
103109
#endif
104110
);
105111

@@ -112,9 +118,13 @@ main(void)
112118
#if VERBOSE
113119
", []"
114120
#else
115-
", [/* 0 vars */]"
121+
", %p /* 0 vars */"
116122
#endif
117-
") = -1 ENOENT (%m)\n", Q_FILENAME);
123+
") = -1 ENOENT (%m)\n", Q_FILENAME
124+
#if !VERBOSE
125+
, empty
126+
#endif
127+
);
118128

119129
char str_a[] = "012345678901234567890123456789012";
120130
char str_b[] = "_abcdefghijklmnopqrstuvwxyz()[]{}";
@@ -141,10 +151,11 @@ main(void)
141151
printf("], [\"%.*s\"...", DEFAULT_STRLEN, b[0]);
142152
for (i = 1; i <= DEFAULT_STRLEN; ++i)
143153
printf(", \"%s\"", b[i]);
154+
printf("]");
144155
#else
145-
printf("], [/* %u vars */", DEFAULT_STRLEN + 1);
156+
printf("], %p /* %u vars */", b, DEFAULT_STRLEN + 1);
146157
#endif
147-
printf("]) = -1 ENOENT (%m)\n");
158+
printf(") = -1 ENOENT (%m)\n");
148159

149160
execve(FILENAME, a + 1, b + 1);
150161
printf("execve(\"%s\", [\"%s\"", Q_FILENAME, a[1]);
@@ -154,10 +165,11 @@ main(void)
154165
printf("], [\"%s\"", b[1]);
155166
for (i = 2; i <= DEFAULT_STRLEN; ++i)
156167
printf(", \"%s\"", b[i]);
168+
printf("]");
157169
#else
158-
printf("], [/* %d vars */", DEFAULT_STRLEN);
170+
printf("], %p /* %d vars */", b + 1, DEFAULT_STRLEN);
159171
#endif
160-
printf("]) = -1 ENOENT (%m)\n");
172+
printf(") = -1 ENOENT (%m)\n");
161173

162174
execve(FILENAME, (char **) tail_argv[ARRAY_SIZE(q_argv)], efault);
163175
printf("execve(\"%s\", NULL, %p) = -1 ENOENT (%m)\n",

tests/execveat.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ main(void)
6767
#if VERBOSE
6868
", [\"%s\", \"%s\", %p, %p, %p, ???]"
6969
#else
70-
", [/* 5 vars, unterminated */]"
70+
", %p /* 5 vars, unterminated */"
7171
#endif
7272
", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
7373
Q_FILENAME, q_argv[0], q_argv[1], q_argv[2],
7474
argv[3], argv[4], argv[5],
7575
#if VERBOSE
7676
q_envp[0], q_envp[1], envp[2], envp[3], envp[4],
77+
#else
78+
tail_envp,
7779
#endif
7880
errno2name());
7981

@@ -85,12 +87,14 @@ main(void)
8587
#if VERBOSE
8688
", [\"%s\", \"%s\"]"
8789
#else
88-
", [/* 2 vars */]"
90+
", %p /* 2 vars */"
8991
#endif
9092
", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
9193
Q_FILENAME, q_argv[0], q_argv[1], q_argv[2],
9294
#if VERBOSE
9395
q_envp[0], q_envp[1],
96+
#else
97+
tail_envp,
9498
#endif
9599
errno2name());
96100

@@ -99,12 +103,14 @@ main(void)
99103
#if VERBOSE
100104
", [\"%s\"]"
101105
#else
102-
", [/* 1 var */]"
106+
", %p /* 1 var */"
103107
#endif
104108
", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
105109
Q_FILENAME, q_argv[2],
106110
#if VERBOSE
107111
q_envp[1],
112+
#else
113+
tail_envp + 1,
108114
#endif
109115
errno2name());
110116

@@ -117,10 +123,14 @@ main(void)
117123
#if VERBOSE
118124
", []"
119125
#else
120-
", [/* 0 vars */]"
126+
", %p /* 0 vars */"
121127
#endif
122128
", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
123-
Q_FILENAME, errno2name());
129+
Q_FILENAME,
130+
#if !VERBOSE
131+
empty,
132+
#endif
133+
errno2name());
124134

125135
char str_a[] = "012345678901234567890123456789012";
126136
char str_b[] = "_abcdefghijklmnopqrstuvwxyz()[]{}";
@@ -147,10 +157,11 @@ main(void)
147157
printf("], [\"%.*s\"...", DEFAULT_STRLEN, b[0]);
148158
for (i = 1; i <= DEFAULT_STRLEN; ++i)
149159
printf(", \"%s\"", b[i]);
160+
printf("]");
150161
#else
151-
printf("], [/* %u vars */", DEFAULT_STRLEN + 1);
162+
printf("], %p /* %u vars */", b, DEFAULT_STRLEN + 1);
152163
#endif
153-
printf("], AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
164+
printf(", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
154165
errno2name());
155166

156167
syscall(__NR_execveat, -100, FILENAME, a + 1, b + 1, 0x1100);
@@ -161,10 +172,11 @@ main(void)
161172
printf("], [\"%s\"", b[1]);
162173
for (i = 2; i <= DEFAULT_STRLEN; ++i)
163174
printf(", \"%s\"", b[i]);
175+
printf("]");
164176
#else
165-
printf("], [/* %d vars */", DEFAULT_STRLEN);
177+
printf("], %p /* %d vars */", b + 1, DEFAULT_STRLEN);
166178
#endif
167-
printf("], AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
179+
printf(", AT_SYMLINK_NOFOLLOW|AT_EMPTY_PATH) = -1 %s (%m)\n",
168180
errno2name());
169181

170182
syscall(__NR_execveat, -100, FILENAME, NULL, efault, 0x1100);

tests/qual_syscall.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
. "${srcdir=.}/init.sh"
77

88
run_prog ../umovestr
9-
pattern_abbrev_verbose='execve("\.\./umovestr", \["\.\./umovestr"\], \[/\* [[:digit:]]* vars \*/\]) = 0'
9+
pattern_abbrev_verbose='execve("\.\./umovestr", \["\.\./umovestr"\], 0x[[:xdigit:]]* /\* [[:digit:]]* vars \*/) = 0'
1010
pattern_nonabbrev_verbose='execve("\.\./umovestr", \["\.\./umovestr"\], \[".*\"\(\.\.\.\)\?\]) = 0'
1111
pattern_nonverbose='execve("\.\./umovestr", 0x[[:xdigit:]]*, 0x[[:xdigit:]]*) = 0'
1212
pattern_raw='execve(0x[[:xdigit:]]*, 0x[[:xdigit:]]*, 0x[[:xdigit:]]*) = 0'

tests/strace-r.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
[ ]{5}0\.0{6} execve\("\.\./sleep", \["\.\./sleep", "1"\], \[/\* [[:digit:]]+ vars \*/\]\) = 0
1+
[ ]{5}0\.0{6} execve\("\.\./sleep", \["\.\./sleep", "1"\], 0x[[:xdigit:]]* /\* [[:digit:]]* vars \*/\) = 0
22
[ ]{5}(1\.[01]|0\.9)[[:digit:]]{5} \+\+\+ exited with 0 \+\+\+

tests/strace-t.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ run_strace -t -eexecve $args
1212
t1="$(date +%T)"
1313

1414
cat > "$EXP" << __EOF__
15-
($t0|$t1) execve\\("\\.\\./sleep", \\["\\.\\./sleep", "0"\\], \\[/\\* [[:digit:]]+ vars \\*/\\]\\) = 0
15+
($t0|$t1) execve\\("\\.\\./sleep", \\["\\.\\./sleep", "0"\\], 0x[[:xdigit:]]* /\\* [[:digit:]]* vars \\*/\\) = 0
1616
__EOF__
1717

1818
match_grep "$LOG" "$EXP"

tests/strace-tt.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ while [ "$s" -le "$s1" ]; do
2121
done
2222

2323
cat > "$EXP" << __EOF__
24-
($t_reg)\\.[[:digit:]]{6} execve\\("\\.\\./sleep", \\["\\.\\./sleep", "0"\\], \\[/\\* [[:digit:]]+ vars \\*/\\]\\) = 0
24+
($t_reg)\\.[[:digit:]]{6} execve\\("\\.\\./sleep", \\["\\.\\./sleep", "0"\\], 0x[[:xdigit:]]* /\\* [[:digit:]]* vars \\*/\\) = 0
2525
__EOF__
2626

2727
match_grep "$LOG" "$EXP"

tests/strace-ttt.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ while [ "$s" -le "$s1" ]; do
1919
done
2020

2121
cat > "$EXP" << __EOF__
22-
($t_reg)\\.[[:digit:]]{6} execve\\("\\.\\./sleep", \\["\\.\\./sleep", "0"\\], \\[/\\* [[:digit:]]+ vars \\*/\\]\\) = 0
22+
($t_reg)\\.[[:digit:]]{6} execve\\("\\.\\./sleep", \\["\\.\\./sleep", "0"\\], 0x[[:xdigit:]]* /\\* [[:digit:]]+ vars \\*/\\) = 0
2323
__EOF__
2424

2525
match_grep "$LOG" "$EXP"

tests/threads-execve.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,25 +136,25 @@ thread(void *arg)
136136
switch (action % NUMBER_OF_ACTIONS) {
137137
case ACTION_exit:
138138
printf("%-5d execve(\"%s\", [\"%s\", \"%s\", \"%s\"]"
139-
", [/* %u vars */] <pid changed to %u ...>\n",
139+
", %p /* %u vars */ <pid changed to %u ...>\n",
140140
tid, argv[0], argv[0], argv[1], argv[2],
141-
arglen(environ), leader);
141+
environ, arglen(environ), leader);
142142
break;
143143
case ACTION_rt_sigsuspend:
144144
printf("%-5d execve(\"%s\", [\"%s\", \"%s\", \"%s\"]"
145-
", [/* %u vars */] <unfinished ...>\n"
145+
", %p /* %u vars */ <unfinished ...>\n"
146146
"%-5d <... rt_sigsuspend resumed>) = ?\n",
147147
tid, argv[0], argv[0], argv[1], argv[2],
148-
arglen(environ),
148+
environ, arglen(environ),
149149
leader);
150150
break;
151151
case ACTION_nanosleep:
152152
printf("%-5d execve(\"%s\", [\"%s\", \"%s\", \"%s\"]"
153-
", [/* %u vars */] <unfinished ...>\n"
153+
", %p /* %u vars */ <unfinished ...>\n"
154154
"%-5d <... nanosleep resumed> <unfinished ...>)"
155155
" = ?\n",
156156
tid, argv[0], argv[0], argv[1], argv[2],
157-
arglen(environ),
157+
environ, arglen(environ),
158158
leader);
159159
break;
160160
}
@@ -180,18 +180,15 @@ main(int ac, char **av)
180180
if (clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL))
181181
perror_msg_and_skip("clock_nanosleep CLOCK_REALTIME");
182182

183-
printf("%-5d execve(\"%s\", [\"%s\"], [/* %u vars */]) = 0\n",
184-
leader, av[0], av[0], arglen(environ));
185-
186183
get_sigsetsize();
187184
static char buf[sizeof(sigsetsize) * 3];
188185
sprintf(buf, "%u", sigsetsize);
189186

190187
char *argv[] = { av[0], buf, (char *) "0", NULL };
191188
printf("%-5d execve(\"%s\", [\"%s\", \"%s\", \"%s\"]"
192-
", [/* %u vars */]) = 0\n",
189+
", %p /* %u vars */) = 0\n",
193190
leader, argv[0], argv[0], argv[1], argv[2],
194-
arglen(environ));
191+
environ, arglen(environ));
195192
execve(argv[0], argv, environ);
196193
perror_msg_and_fail("execve");
197194
}

tests/threads-execve.test

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ set -- -a21 -f -esignal=none -e trace=execve,exit,nanosleep,rt_sigsuspend $args
4040

4141
# Due to probabilistic nature of the test, try it several times.
4242
i=0
43-
while [ $i -le 9 ]; do
43+
while [ $i -le 19 ]; do
44+
i="$(($i+1))"
4445
run_strace "$@" > "$EXP"
45-
diff -- "$EXP" "$LOG" || continue
46+
sed 1d < "$LOG" > "$OUT"
47+
diff -- "$EXP" "$OUT" || continue
4648
exit 0
4749
done
4850

0 commit comments

Comments
 (0)