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