1 # Copyright 1997, 1999, 2007 Free Software Foundation, Inc.
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 2 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
24 if { ![isnative] } then {
31 set testfile "foll-exec"
32 set testfile2 "execd-prog"
33 set srcfile ${testfile}.c
34 set srcfile2 ${testfile2}.c
35 set binfile ${objdir}/${subdir}/${testfile}
36 set binfile2 ${objdir}/${subdir}/${testfile2}
38 # build the first test case
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
40 untested foll-exec.exp
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
45 untested foll-exec.exp
50 # Until "catch exec" is implemented on other targets...
52 if ![istarget "hppa*-hp-hpux*"] then {
62 -re ".*Kill the program being debugged.*y or n. $" {
64 send_gdb "file $binfile\n"
66 -re ".*Load new symbol table from.*y or n. $" {
69 -re "Reading symbols from.*$gdb_prompt $" {}
70 timeout { fail "loading symbols (timeout)"; return }
73 -re ".*gdb_prompt $" {}
74 timeout { fail "loading symbols (timeout)"; return }
77 -re ".*$gdb_prompt $" {}
78 timeout { fail "killing inferior (timeout)" ; return }
82 proc do_exec_tests {} {
90 # Start the program running, and stop at main.
92 if ![runto_main] then {
93 perror "Couldn't run ${testfile}"
97 # Verify that we can see various global and local variables
98 # in this program, and that they have expected values. Some
99 # of these variables are also declared in the program we'll
104 -re "20.*execlp.*$gdb_prompt $"\
105 {pass "step to exec call"}
106 -re "$gdb_prompt $" {fail "step to exec call"}
107 timeout {fail "(timeout) step to exec call"}
109 send_gdb "print global_i\n"
111 -re ".* = 100.*$gdb_prompt $"\
112 {pass "print follow-exec/global_i"}
113 -re "$gdb_prompt $" {fail "print follow-exec/global_i"}
114 timeout {fail "(timeout) print follow-exec/global_i"}
116 send_gdb "print local_j\n"
118 -re ".* = 101.*$gdb_prompt $"\
119 {pass "print follow-exec/local_j"}
120 -re "$gdb_prompt $" {fail "print follow-exec/local_j"}
121 timeout {fail "(timeout) print follow-exec/local_j"}
123 send_gdb "print local_k\n"
125 -re ".* = 102.*$gdb_prompt $"\
126 {pass "print follow-exec/local_k"}
127 -re "$gdb_prompt $" {fail "print follow-exec/local_k"}
128 timeout {fail "(timeout) print follow-exec/local_k"}
131 # Try stepping through an execlp call, without catching it.
132 # We should stop in execd-program, at its first statement.
136 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
137 {pass "step through execlp call"}
138 -re "$gdb_prompt $" {fail "step through execlp call"}
139 timeout {fail "(timeout) step through execlp call"}
142 # Verify that we can see the variables defined in the newly-exec'd
143 # program, and CANNOT see those defined in the exec'ing program.
147 -re "26.*printf.*$gdb_prompt $"\
148 {pass "step after execlp call"}
149 -re "$gdb_prompt $" {fail "step after execlp call"}
150 timeout {fail "(timeout) step after execlp call"}
152 send_gdb "print global_i\n"
154 -re ".* = 0.*$gdb_prompt $"\
155 {pass "print execd-program/global_i (after execlp)"}
156 -re "$gdb_prompt $" {fail "print execd-program/global_i (after execlp)"}
157 timeout {fail "(timeout) print execd-program/global_i (after execlp)"}
159 send_gdb "print local_j\n"
161 -re ".* = 2.*$gdb_prompt $"\
162 {pass "print execd-program/local_j (after execlp)"}
163 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execlp)"}
164 timeout {fail "(timeout) print execd-program/local_j (after execlp)"}
166 send_gdb "print local_k\n"
168 -re "No symbol \"local_k\" in current context.*$gdb_prompt $"\
169 {pass "print follow-exec/local_k (after execlp)"}
170 -re "$gdb_prompt $" {fail "print follow-exec/local_k (after execlp)"}
171 timeout {fail "(timeout) print follow-exec/local_k (after execlp)"}
174 # Explicitly kill this program, or a subsequent rerun actually runs
175 # the exec'd program, not the original program...
178 # Start the program running, and stop at main.
180 if ![runto_main] then {
181 perror "Couldn't run ${testfile} (2nd try)"
185 # Verify that we can catch an exec event, and then continue
186 # to follow through the exec. (Since there's a breakpoint on
187 # "main", it'll also be transferred to the exec'd program,
188 # and we expect to stop there.)
190 send_gdb "catch exec\n"
192 -re "Catchpoint .*(exec).*$gdb_prompt $"\
193 {pass "set catch exec"}
194 -re "$gdb_prompt $" {fail "set catch exec"}
195 timeout {fail "(timeout) set catch exec"}
198 # Verify that the catchpoint is mentioned in an "info breakpoints",
199 # and further that the catchpoint mentions no program name.
201 send_gdb "info breakpoints\n"
203 -re ".*catch exec.*keep y.*$gdb_prompt $"\
204 {pass "info shows catchpoint without exec pathname"}
205 -re ".*catch exec.*program \"\".*$gdb_prompt $"\
206 {fail "info shows catchpoint without exec pathname"}
207 -re "$gdb_prompt $" {fail "info shows catchpoint without exec pathname"}
208 timeout {fail "(timeout) info shows catchpoint without exec pathname"}
212 # PA64 doesn't know about $START$ in dld.sl at this point. It should.
214 setup_xfail hppa2.0w-hp-hpux* CLLbs16760
215 send_gdb "continue\n"
217 -re ".*Executing new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .START..*$gdb_prompt $"\
218 {pass "hit catch exec"}
219 -re "$gdb_prompt $" {fail "hit catch exec"}
220 timeout {fail "(timeout) hit catch exec"}
224 # test gets out of sync if previous test fails.
225 gdb_test "bt" ".*" "sync up after possible failure 1"
226 gdb_test "bt" "#0.*" "sync up after possible failure 2"
228 # Verify that the catchpoint is mentioned in an "info breakpoints",
229 # and further that the catchpoint managed to capture the exec'd
232 send_gdb "info breakpoints\n"
234 -re ".*catch exec .*program \".*${testfile2}\".*$gdb_prompt $"\
235 {pass "info shows catchpoint exec pathname"}
236 -re "$gdb_prompt $" {fail "info shows catchpoint exec pathname"}
237 timeout {fail "(timeout) info shows catchpoint exec pathname"}
240 # Verify that we can continue from the catchpoint, and land in the
241 # main of the newly-exec'd program.
243 send_gdb "continue\n"
245 -re ".*${srcfile2}:23.*$gdb_prompt $"\
246 {pass "continue after hit catch exec"}
247 -re "$gdb_prompt $" {fail "continue after hit catch exec"}
248 timeout {fail "(timeout) continue after hit catch exec"}
251 # Explicitly kill this program, or a subsequent rerun actually runs
252 # the exec'd program, not the original program...
255 # Start the program running, and stop at main.
257 if ![runto_main] then {
258 perror "Couldn't run ${testfile} (3rd try)"
262 # Verify that we can follow through follow an execl()
263 # call. (We must jump around earlier exec* calls.)
265 send_gdb "tbreak 27\n"
267 -re "Breakpoint .*file .*${srcfile}, line 27.*$gdb_prompt $"\
268 {pass "prepare to jump to execl call"}
269 -re "$gdb_prompt $" {fail "prepare to jump to execl call"}
270 timeout {fail "(timeout) prepare to jump to execl call"}
274 -re "main.* at .*${srcfile}:27.*$gdb_prompt $"\
275 {pass "jump to execl call"}
276 -re "$gdb_prompt $" {fail "jump to execl call"}
277 timeout {fail "(timeout) jump to execl call"}
279 # Note that stepping through an exec call causes the step-count
280 # to be reset to zero. I.e.: you may specify "next 2" at the
281 # call, but you'll actually stop at the first breakpoint set in
282 # the newly-exec'd program, not after the remaining step-count
287 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
288 {pass "step through execl call"}
289 -re "$gdb_prompt $" {fail "step through execl call"}
290 timeout {fail "(timeout) step through execl call"}
294 -re "26.*printf.*$gdb_prompt $"\
295 {pass "step after execl call"}
296 -re "$gdb_prompt $" {fail "step after execl call"}
297 timeout {fail "(timeout) step after execl call"}
300 # Verify that we can print a local variable (which happens to be
301 # assigned the value of main's argc).
303 send_gdb "print local_j\n"
305 -re ".* = 3.*$gdb_prompt $"\
306 {pass "print execd-program/local_j (after execl)"}
307 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execl)"}
308 timeout {fail "(timeout) print execd-program/local_j (after execl)"}
311 # Explicitly kill this program, or a subsequent rerun actually runs
312 # the exec'd program, not the original program...
315 # Start the program running, and stop at main.
317 if ![runto_main] then {
318 perror "Couldn't run ${testfile} (4th try)"
322 # Verify that we can follow through follow an execv()
323 # call. (We must jump around earlier exec* calls.)
325 send_gdb "tbreak 41\n"
327 -re "Breakpoint .*file .*${srcfile}, line 41.*$gdb_prompt $"\
328 {pass "prepare to jump to execv call"}
329 -re "$gdb_prompt $" {fail "prepare to jump to execv call"}
330 timeout {fail "(timeout) prepare to jump to execv call"}
334 -re "main.* at .*${srcfile}:41.*$gdb_prompt $"\
335 {pass "jump to execv call"}
336 -re "$gdb_prompt $" {fail "jump to execv call"}
337 timeout {fail "(timeout) jump to execv call"}
341 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
342 {pass "step through execv call"}
343 -re "$gdb_prompt $" {fail "step through execv call"}
344 timeout {fail "(timeout) step through execv call"}
348 -re "26.*printf.*$gdb_prompt $"\
349 {pass "step after execv call"}
350 -re "$gdb_prompt $" {fail "step after execv call"}
351 timeout {fail "(timeout) step after execv call"}
354 # Verify that we can print a local variable (which happens to be
355 # assigned the value of main's argc).
357 send_gdb "print local_j\n"
359 -re ".* = 2.*$gdb_prompt $"\
360 {pass "print execd-program/local_j (after execv)"}
361 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execv)"}
362 timeout {fail "(timeout) print execd-program/local_j (after execv)"}
365 # Explicitly kill this program, or a subsequent rerun actually runs
366 # the exec'd program, not the original program...
369 # Start the program running, and stop at main.
371 if ![runto_main] then {
372 perror "Couldn't run ${testfile} (5th try)"
376 # Verify that we can just continue and thereby follow through an
377 # exec call. (Since the breakpoint on "main" is reset, we should
378 # just stop in main of the newly-exec'd program.)
380 send_gdb "continue\n"
382 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
383 {pass "continue through exec"}
384 -re "$gdb_prompt $" {fail "continue through exec"}
385 timeout {fail "(timeout) continue through exec"}
389 # Start with a fresh gdb
393 gdb_reinitialize_dir $srcdir/$subdir
397 # This is a test of gdb's ability to follow a process through a
398 # Unix exec() system call.