]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/foll-exec.exp
GDB copyright headers update after running GDB's copyright.py script.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / foll-exec.exp
1 # Copyright 1997-2016 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # This is a test of gdb's ability to follow a process through a
17 # Unix exec() system call.
18
19 # Until "catch exec" is implemented on other targets...
20 #
21 if { ![istarget "*-linux*"] } then {
22 continue
23 }
24
25 standard_testfile foll-exec.c
26
27 set testfile2 "execd-prog"
28 set srcfile2 ${testfile2}.c
29 set binfile2 [standard_output_file ${testfile2}]
30
31 set compile_options debug
32 set dirname [relative_filename [pwd] [file dirname $binfile]]
33 lappend compile_options "additional_flags=-DBASEDIR=\"$dirname\""
34
35 # build the first test case
36 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $compile_options] != "" } {
37 untested foll-exec.exp
38 return -1
39 }
40
41 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $compile_options] != "" } {
42 untested foll-exec.exp
43 return -1
44 }
45
46 proc do_exec_tests {} {
47 global binfile srcfile srcfile2 testfile testfile2
48 global gdb_prompt
49
50 # Start the program running, and stop at main.
51 #
52 if ![runto_main] then {
53 fail "Couldn't run ${testfile}"
54 return
55 }
56
57 # Verify that the system supports "catch exec".
58 gdb_test "catch exec" "Catchpoint \[0-9\]* \\(exec\\)" "insert first exec catchpoint"
59 set has_exec_catchpoints 0
60 gdb_test_multiple "continue" "continue to first exec catchpoint" {
61 -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
62 unsupported "continue to first exec catchpoint"
63 }
64 -re ".*Catchpoint.*$gdb_prompt $" {
65 set has_exec_catchpoints 1
66 pass "continue to first exec catchpoint"
67 }
68 }
69
70 if {$has_exec_catchpoints == 0} {
71 unsupported "exec catchpoints"
72 return
73 }
74
75 clean_restart $binfile
76
77 # Start the program running, and stop at main.
78 #
79 if ![runto_main] then {
80 fail "Couldn't run ${testfile}"
81 return
82 }
83
84 # Verify that we can see various global and local variables
85 # in this program, and that they have expected values. Some
86 # of these variables are also declared in the program we'll
87 # exec in a moment.
88 #
89 send_gdb "next 3\n"
90 gdb_expect {
91 -re "execlp \\(.*$gdb_prompt $"\
92 {pass "step to exec call"}
93 -re "$gdb_prompt $" {fail "step to exec call"}
94 timeout {fail "(timeout) step to exec call"}
95 }
96 send_gdb "print global_i\n"
97 gdb_expect {
98 -re ".* = 100.*$gdb_prompt $"\
99 {pass "print follow-exec/global_i"}
100 -re "$gdb_prompt $" {fail "print follow-exec/global_i"}
101 timeout {fail "(timeout) print follow-exec/global_i"}
102 }
103 send_gdb "print local_j\n"
104 gdb_expect {
105 -re ".* = 101.*$gdb_prompt $"\
106 {pass "print follow-exec/local_j"}
107 -re "$gdb_prompt $" {fail "print follow-exec/local_j"}
108 timeout {fail "(timeout) print follow-exec/local_j"}
109 }
110 send_gdb "print local_k\n"
111 gdb_expect {
112 -re ".* = 102.*$gdb_prompt $"\
113 {pass "print follow-exec/local_k"}
114 -re "$gdb_prompt $" {fail "print follow-exec/local_k"}
115 timeout {fail "(timeout) print follow-exec/local_k"}
116 }
117
118 # Try stepping through an execlp call, without catching it.
119 # We should stop in execd-program, at its first statement.
120 #
121 set execd_line [gdb_get_line_number "after-exec" $srcfile2]
122 send_gdb "next\n"
123 gdb_expect {
124 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
125 {pass "step through execlp call"}
126 -re "$gdb_prompt $" {fail "step through execlp call"}
127 timeout {fail "(timeout) step through execlp call"}
128 }
129
130 # Verify that we can see the variables defined in the newly-exec'd
131 # program, and CANNOT see those defined in the exec'ing program.
132 #
133 send_gdb "next\n"
134 gdb_expect {
135 -re "printf \\(.Hello .*$gdb_prompt $"\
136 {pass "step after execlp call"}
137 -re "$gdb_prompt $" {fail "step after execlp call"}
138 timeout {fail "(timeout) step after execlp call"}
139 }
140 send_gdb "print global_i\n"
141 gdb_expect {
142 -re ".* = 0.*$gdb_prompt $"\
143 {pass "print execd-program/global_i (after execlp)"}
144 -re "$gdb_prompt $" {fail "print execd-program/global_i (after execlp)"}
145 timeout {fail "(timeout) print execd-program/global_i (after execlp)"}
146 }
147 send_gdb "print local_j\n"
148 gdb_expect {
149 -re ".* = 2.*$gdb_prompt $"\
150 {pass "print execd-program/local_j (after execlp)"}
151 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execlp)"}
152 timeout {fail "(timeout) print execd-program/local_j (after execlp)"}
153 }
154 send_gdb "print local_k\n"
155 gdb_expect {
156 -re "No symbol \"local_k\" in current context.*$gdb_prompt $"\
157 {pass "print follow-exec/local_k (after execlp)"}
158 -re "$gdb_prompt $" {fail "print follow-exec/local_k (after execlp)"}
159 timeout {fail "(timeout) print follow-exec/local_k (after execlp)"}
160 }
161
162 # Explicitly kill this program, or a subsequent rerun actually runs
163 # the exec'd program, not the original program...
164 clean_restart $binfile
165
166 # Start the program running, and stop at main.
167 #
168 if ![runto_main] then {
169 fail "Couldn't run ${testfile} (2nd try)"
170 return
171 }
172
173 # Verify that we can catch an exec event, and then continue
174 # to follow through the exec. (Since there's a breakpoint on
175 # "main", it'll also be transferred to the exec'd program,
176 # and we expect to stop there.)
177 #
178 send_gdb "catch exec\n"
179 gdb_expect {
180 -re "Catchpoint .*(exec).*$gdb_prompt $"\
181 {pass "set catch exec"}
182 -re "$gdb_prompt $" {fail "set catch exec"}
183 timeout {fail "(timeout) set catch exec"}
184 }
185
186 # Verify that the catchpoint is mentioned in an "info breakpoints",
187 # and further that the catchpoint mentions no program name.
188 #
189 set msg "info shows catchpoint without exec pathname"
190 gdb_test_multiple "info breakpoints" $msg {
191 -re ".*catchpoint.*keep y.*exec\[\n\r\]+$gdb_prompt $" {
192 pass $msg
193 }
194 }
195
196 send_gdb "continue\n"
197 gdb_expect {
198 -re ".*xecuting new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .*$gdb_prompt $"\
199 {pass "hit catch exec"}
200 -re "$gdb_prompt $" {fail "hit catch exec"}
201 timeout {fail "(timeout) hit catch exec"}
202 }
203
204 # DTS CLLbs16760
205 # test gets out of sync if previous test fails.
206 gdb_test "bt" ".*" "sync up after possible failure 1"
207 gdb_test "bt" "#0.*" "sync up after possible failure 2"
208
209 # Verify that the catchpoint is mentioned in an "info breakpoints",
210 # and further that the catchpoint managed to capture the exec'd
211 # program's name.
212 #
213 set msg "info shows catchpoint exec pathname"
214 gdb_test_multiple "info breakpoints" $msg {
215 -re ".*catchpoint.*keep y.*exec, program \".*${testfile2}\".*$gdb_prompt $" {
216 pass $msg
217 }
218 }
219
220 # Verify that we can continue from the catchpoint, and land in the
221 # main of the newly-exec'd program.
222 #
223 send_gdb "continue\n"
224 gdb_expect {
225 -re ".*${srcfile2}:${execd_line}.*$gdb_prompt $"\
226 {pass "continue after hit catch exec"}
227 -re "$gdb_prompt $" {fail "continue after hit catch exec"}
228 timeout {fail "(timeout) continue after hit catch exec"}
229 }
230
231 # Explicitly kill this program, or a subsequent rerun actually runs
232 # the exec'd program, not the original program...
233 clean_restart $binfile
234
235 # Start the program running, and stop at main.
236 #
237 if ![runto_main] then {
238 fail "Couldn't run ${testfile} (3rd try)"
239 return
240 }
241
242 # Verify that we can follow through follow an execl()
243 # call. (We must jump around earlier exec* calls.)
244 #
245 set tbreak_line [gdb_get_line_number "tbreak-execl" $srcfile]
246 send_gdb "tbreak ${tbreak_line}\n"
247 gdb_expect {
248 -re "Temporary breakpoint .*file .*${srcfile}, line ${tbreak_line}.*$gdb_prompt $"\
249 {pass "prepare to jump to execl call"}
250 -re "$gdb_prompt $" {fail "prepare to jump to execl call"}
251 timeout {fail "(timeout) prepare to jump to execl call"}
252 }
253 send_gdb "jump ${tbreak_line}\n"
254 gdb_expect {
255 -re "main.* at .*${srcfile}:${tbreak_line}.*$gdb_prompt $"\
256 {pass "jump to execl call"}
257 -re "$gdb_prompt $" {fail "jump to execl call"}
258 timeout {fail "(timeout) jump to execl call"}
259 }
260 # Note that stepping through an exec call causes the step-count
261 # to be reset to zero. I.e.: you may specify "next 2" at the
262 # call, but you'll actually stop at the first breakpoint set in
263 # the newly-exec'd program, not after the remaining step-count
264 # reaches zero.
265 #
266 send_gdb "next 2\n"
267 gdb_expect {
268 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
269 {pass "step through execl call"}
270 -re "$gdb_prompt $" {fail "step through execl call"}
271 timeout {fail "(timeout) step through execl call"}
272 }
273 send_gdb "next\n"
274 gdb_expect {
275 -re "printf \\(.Hello .*$gdb_prompt $"\
276 {pass "step after execl call"}
277 -re "$gdb_prompt $" {fail "step after execl call"}
278 timeout {fail "(timeout) step after execl call"}
279 }
280
281 # Verify that we can print a local variable (which happens to be
282 # assigned the value of main's argc).
283 #
284 send_gdb "print local_j\n"
285 gdb_expect {
286 -re ".* = 3.*$gdb_prompt $"\
287 {pass "print execd-program/local_j (after execl)"}
288 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execl)"}
289 timeout {fail "(timeout) print execd-program/local_j (after execl)"}
290 }
291
292 # Explicitly kill this program, or a subsequent rerun actually runs
293 # the exec'd program, not the original program...
294 clean_restart $binfile
295
296 # Start the program running, and stop at main.
297 #
298 if ![runto_main] then {
299 fail "Couldn't run ${testfile} (4th try)"
300 return
301 }
302
303 # Verify that we can follow through follow an execv()
304 # call. (We must jump around earlier exec* calls.)
305 #
306 set tbreak_line [gdb_get_line_number "tbreak-execv"]
307 send_gdb "tbreak ${tbreak_line}\n"
308 gdb_expect {
309 -re "Temporary breakpoint .*file .*${srcfile}, line ${tbreak_line}.*$gdb_prompt $"\
310 {pass "prepare to jump to execv call"}
311 -re "$gdb_prompt $" {fail "prepare to jump to execv call"}
312 timeout {fail "(timeout) prepare to jump to execv call"}
313 }
314 send_gdb "jump ${tbreak_line}\n"
315 gdb_expect {
316 -re "main.* at .*${srcfile}:${tbreak_line}.*$gdb_prompt $"\
317 {pass "jump to execv call"}
318 -re "$gdb_prompt $" {fail "jump to execv call"}
319 timeout {fail "(timeout) jump to execv call"}
320 }
321 send_gdb "next\n"
322 gdb_expect {
323 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
324 {pass "step through execv call"}
325 -re "$gdb_prompt $" {fail "step through execv call"}
326 timeout {fail "(timeout) step through execv call"}
327 }
328 send_gdb "next\n"
329 gdb_expect {
330 -re "printf \\(.Hello .*$gdb_prompt $"\
331 {pass "step after execv call"}
332 -re "$gdb_prompt $" {fail "step after execv call"}
333 timeout {fail "(timeout) step after execv call"}
334 }
335
336 # Verify that we can print a local variable (which happens to be
337 # assigned the value of main's argc).
338 #
339 send_gdb "print local_j\n"
340 gdb_expect {
341 -re ".* = 2.*$gdb_prompt $"\
342 {pass "print execd-program/local_j (after execv)"}
343 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execv)"}
344 timeout {fail "(timeout) print execd-program/local_j (after execv)"}
345 }
346
347 # Explicitly kill this program, or a subsequent rerun actually runs
348 # the exec'd program, not the original program...
349 clean_restart $binfile
350
351 # Start the program running, and stop at main.
352 #
353 if ![runto_main] then {
354 fail "Couldn't run ${testfile} (5th try)"
355 return
356 }
357
358 # Verify that we can just continue and thereby follow through an
359 # exec call. (Since the breakpoint on "main" is reset, we should
360 # just stop in main of the newly-exec'd program.)
361 #
362 send_gdb "continue\n"
363 gdb_expect {
364 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
365 {pass "continue through exec"}
366 -re "$gdb_prompt $" {fail "continue through exec"}
367 timeout {fail "(timeout) continue through exec"}
368 }
369 }
370
371 # Start with a fresh gdb
372
373 gdb_exit
374 clean_restart $binfile
375
376 do_exec_tests
377
378 return 0