1 # Copyright (C) 1997 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
27 set testfile "foll-exec"
28 set testfile2 "execd-prog"
29 set srcfile ${testfile}.c
30 set srcfile2 ${testfile2}.c
31 set binfile ${objdir}/${subdir}/${testfile}
32 set binfile2 ${objdir}/${subdir}/${testfile2}
34 # build the first test case
35 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
36 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
44 # Until "catch exec" is implemented on other targets...
46 if ![istarget "hppa*-hp-hpux*"] then {
56 -re ".*Kill the program being debugged.*y or n. $" {
58 send_gdb "file $binfile\n"
60 -re ".*Load new symbol table from.*y or n. $" {
63 -re "Reading symbols from.*$gdb_prompt $" {}
64 timeout { fail "loading symbols (timeout)"; return }
67 -re ".*gdb_prompt $" {}
68 timeout { fail "loading symbols (timeout)"; return }
71 -re ".*$gdb_prompt $" {}
72 timeout { fail "killing inferior (timeout)" ; return }
76 proc do_exec_tests {} {
84 # Start the program running, and stop at main.
86 if ![runto_main] then {
87 perror "Couldn't run ${testfile}"
91 # Verify that we can see various global and local variables
92 # in this program, and that they have expected values. Some
93 # of these variables are also declared in the program we'll
98 -re "20.*execlp.*$gdb_prompt $"\
99 {pass "step to exec call"}
100 -re "$gdb_prompt $" {fail "step to exec call"}
101 timeout {fail "(timeout) step to exec call"}
103 send_gdb "print global_i\n"
105 -re ".* = 100.*$gdb_prompt $"\
106 {pass "print follow-exec/global_i"}
107 -re "$gdb_prompt $" {fail "print follow-exec/global_i"}
108 timeout {fail "(timeout) print follow-exec/global_i"}
110 send_gdb "print local_j\n"
112 -re ".* = 101.*$gdb_prompt $"\
113 {pass "print follow-exec/local_j"}
114 -re "$gdb_prompt $" {fail "print follow-exec/local_j"}
115 timeout {fail "(timeout) print follow-exec/local_j"}
117 send_gdb "print local_k\n"
119 -re ".* = 102.*$gdb_prompt $"\
120 {pass "print follow-exec/local_k"}
121 -re "$gdb_prompt $" {fail "print follow-exec/local_k"}
122 timeout {fail "(timeout) print follow-exec/local_k"}
125 # Try stepping through an execlp call, without catching it.
126 # We should stop in execd-program, at its first statement.
130 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
131 {pass "step through execlp call"}
132 -re "$gdb_prompt $" {fail "step through execlp call"}
133 timeout {fail "(timeout) step through execlp call"}
136 # Verify that we can see the variables defined in the newly-exec'd
137 # program, and CANNOT see those defined in the exec'ing program.
141 -re "26.*printf.*$gdb_prompt $"\
142 {pass "step after execlp call"}
143 -re "$gdb_prompt $" {fail "step after execlp call"}
144 timeout {fail "(timeout) step after execlp call"}
146 send_gdb "print global_i\n"
148 -re ".* = 0.*$gdb_prompt $"\
149 {pass "print execd-program/global_i (after execlp)"}
150 -re "$gdb_prompt $" {fail "print execd-program/global_i (after execlp)"}
151 timeout {fail "(timeout) print execd-program/global_i (after execlp)"}
153 send_gdb "print local_j\n"
155 -re ".* = 2.*$gdb_prompt $"\
156 {pass "print execd-program/local_j (after execlp)"}
157 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execlp)"}
158 timeout {fail "(timeout) print execd-program/local_j (after execlp)"}
160 send_gdb "print local_k\n"
162 -re "No symbol \"local_k\" in current context.*$gdb_prompt $"\
163 {pass "print follow-exec/local_k (after execlp)"}
164 -re "$gdb_prompt $" {fail "print follow-exec/local_k (after execlp)"}
165 timeout {fail "(timeout) print follow-exec/local_k (after execlp)"}
168 # Explicitly kill this program, or a subsequent rerun actually runs
169 # the exec'd program, not the original program...
172 # Start the program running, and stop at main.
174 if ![runto_main] then {
175 perror "Couldn't run ${testfile} (2nd try)"
179 # Verify that we can catch an exec event, and then continue
180 # to follow through the exec. (Since there's a breakpoint on
181 # "main", it'll also be transferred to the exec'd program,
182 # and we expect to stop there.)
184 send_gdb "catch exec\n"
186 -re "Catchpoint .*(exec).*$gdb_prompt $"\
187 {pass "set catch exec"}
188 -re "$gdb_prompt $" {fail "set catch exec"}
189 timeout {fail "(timeout) set catch exec"}
192 # Verify that the catchpoint is mentioned in an "info breakpoints",
193 # and further that the catchpoint mentions no program name.
195 send_gdb "info breakpoints\n"
197 -re ".*catch exec.*keep y.*$gdb_prompt $"\
198 {pass "info shows catchpoint without exec pathname"}
199 -re ".*catch exec.*program \"\".*$gdb_prompt $"\
200 {fail "info shows catchpoint without exec pathname"}
201 -re "$gdb_prompt $" {fail "info shows catchpoint without exec pathname"}
202 timeout {fail "(timeout) info shows catchpoint without exec pathname"}
206 # PA64 doesn't know about $START$ in dld.sl at this point. It should.
208 setup_xfail hppa2.0w-hp-hpux*
209 send_gdb "continue\n"
211 -re ".*Executing new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .START..*$gdb_prompt $"\
212 {pass "hit catch exec"}
213 -re "$gdb_prompt $" {fail "hit catch exec"}
214 timeout {fail "(timeout) hit catch exec"}
218 # test gets out of sync if previous test fails.
219 gdb_test "bt" ".*" "sync up after possible failure 1"
220 gdb_test "bt" "#0.*" "sync up after possible failure 2"
222 # Verify that the catchpoint is mentioned in an "info breakpoints",
223 # and further that the catchpoint managed to capture the exec'd
226 send_gdb "info breakpoints\n"
228 -re ".*catch exec .*program \".*${testfile2}\".*$gdb_prompt $"\
229 {pass "info shows catchpoint exec pathname"}
230 -re "$gdb_prompt $" {fail "info shows catchpoint exec pathname"}
231 timeout {fail "(timeout) info shows catchpoint exec pathname"}
234 # Verify that we can continue from the catchpoint, and land in the
235 # main of the newly-exec'd program.
237 send_gdb "continue\n"
239 -re ".*${srcfile2}:23.*$gdb_prompt $"\
240 {pass "continue after hit catch exec"}
241 -re "$gdb_prompt $" {fail "continue after hit catch exec"}
242 timeout {fail "(timeout) continue after hit catch exec"}
245 # Explicitly kill this program, or a subsequent rerun actually runs
246 # the exec'd program, not the original program...
249 # Start the program running, and stop at main.
251 if ![runto_main] then {
252 perror "Couldn't run ${testfile} (3rd try)"
256 # Verify that we can follow through follow an execl()
257 # call. (We must jump around earlier exec* calls.)
259 send_gdb "tbreak 27\n"
261 -re "Breakpoint .*file .*${srcfile}, line 27.*$gdb_prompt $"\
262 {pass "prepare to jump to execl call"}
263 -re "$gdb_prompt $" {fail "prepare to jump to execl call"}
264 timeout {fail "(timeout) prepare to jump to execl call"}
268 -re "main.* at .*${srcfile}:27.*$gdb_prompt $"\
269 {pass "jump to execl call"}
270 -re "$gdb_prompt $" {fail "jump to execl call"}
271 timeout {fail "(timeout) jump to execl call"}
273 # Note that stepping through an exec call causes the step-count
274 # to be reset to zero. I.e.: you may specify "next 2" at the
275 # call, but you'll actually stop at the first breakpoint set in
276 # the newly-exec'd program, not after the remaining step-count
281 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
282 {pass "step through execl call"}
283 -re "$gdb_prompt $" {fail "step through execl call"}
284 timeout {fail "(timeout) step through execl call"}
288 -re "26.*printf.*$gdb_prompt $"\
289 {pass "step after execl call"}
290 -re "$gdb_prompt $" {fail "step after execl call"}
291 timeout {fail "(timeout) step after execl call"}
294 # Verify that we can print a local variable (which happens to be
295 # assigned the value of main's argc).
297 send_gdb "print local_j\n"
299 -re ".* = 3.*$gdb_prompt $"\
300 {pass "print execd-program/local_j (after execl)"}
301 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execl)"}
302 timeout {fail "(timeout) print execd-program/local_j (after execl)"}
305 # Explicitly kill this program, or a subsequent rerun actually runs
306 # the exec'd program, not the original program...
309 # Start the program running, and stop at main.
311 if ![runto_main] then {
312 perror "Couldn't run ${testfile} (4th try)"
316 # Verify that we can follow through follow an execv()
317 # call. (We must jump around earlier exec* calls.)
319 send_gdb "tbreak 41\n"
321 -re "Breakpoint .*file .*${srcfile}, line 41.*$gdb_prompt $"\
322 {pass "prepare to jump to execv call"}
323 -re "$gdb_prompt $" {fail "prepare to jump to execv call"}
324 timeout {fail "(timeout) prepare to jump to execv call"}
328 -re "main.* at .*${srcfile}:41.*$gdb_prompt $"\
329 {pass "jump to execv call"}
330 -re "$gdb_prompt $" {fail "jump to execv call"}
331 timeout {fail "(timeout) jump to execv call"}
335 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
336 {pass "step through execv call"}
337 -re "$gdb_prompt $" {fail "step through execv call"}
338 timeout {fail "(timeout) step through execv call"}
342 -re "26.*printf.*$gdb_prompt $"\
343 {pass "step after execv call"}
344 -re "$gdb_prompt $" {fail "step after execv call"}
345 timeout {fail "(timeout) step after execv call"}
348 # Verify that we can print a local variable (which happens to be
349 # assigned the value of main's argc).
351 send_gdb "print local_j\n"
353 -re ".* = 2.*$gdb_prompt $"\
354 {pass "print execd-program/local_j (after execv)"}
355 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execv)"}
356 timeout {fail "(timeout) print execd-program/local_j (after execv)"}
359 # Explicitly kill this program, or a subsequent rerun actually runs
360 # the exec'd program, not the original program...
363 # Start the program running, and stop at main.
365 if ![runto_main] then {
366 perror "Couldn't run ${testfile} (5th try)"
370 # Verify that we can just continue and thereby follow through an
371 # exec call. (Since the breakpoint on "main" is reset, we should
372 # just stop in main of the newly-exec'd program.)
374 send_gdb "continue\n"
376 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
377 {pass "continue through exec"}
378 -re "$gdb_prompt $" {fail "continue through exec"}
379 timeout {fail "(timeout) continue through exec"}
383 # Start with a fresh gdb
387 gdb_reinitialize_dir $srcdir/$subdir
391 # This is a test of gdb's ability to follow a process through a
392 # Unix exec() system call.