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