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 3 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, see <http://www.gnu.org/licenses/>. */
16 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
23 if { ![isnative] } then {
30 set testfile "foll-exec"
31 set testfile2 "execd-prog"
32 set srcfile ${testfile}.c
33 set srcfile2 ${testfile2}.c
34 set binfile ${objdir}/${subdir}/${testfile}
35 set binfile2 ${objdir}/${subdir}/${testfile2}
37 # build the first test case
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
39 untested foll-exec.exp
43 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
44 untested foll-exec.exp
49 # Until "catch exec" is implemented on other targets...
51 if ![istarget "hppa*-hp-hpux*"] then {
61 -re ".*Kill the program being debugged.*y or n. $" {
63 send_gdb "file $binfile\n"
65 -re ".*Load new symbol table from.*y or n. $" {
68 -re "Reading symbols from.*$gdb_prompt $" {}
69 timeout { fail "loading symbols (timeout)"; return }
72 -re ".*gdb_prompt $" {}
73 timeout { fail "loading symbols (timeout)"; return }
76 -re ".*$gdb_prompt $" {}
77 timeout { fail "killing inferior (timeout)" ; return }
81 proc do_exec_tests {} {
89 # Start the program running, and stop at main.
91 if ![runto_main] then {
92 perror "Couldn't run ${testfile}"
96 # Verify that we can see various global and local variables
97 # in this program, and that they have expected values. Some
98 # of these variables are also declared in the program we'll
103 -re "20.*execlp.*$gdb_prompt $"\
104 {pass "step to exec call"}
105 -re "$gdb_prompt $" {fail "step to exec call"}
106 timeout {fail "(timeout) step to exec call"}
108 send_gdb "print global_i\n"
110 -re ".* = 100.*$gdb_prompt $"\
111 {pass "print follow-exec/global_i"}
112 -re "$gdb_prompt $" {fail "print follow-exec/global_i"}
113 timeout {fail "(timeout) print follow-exec/global_i"}
115 send_gdb "print local_j\n"
117 -re ".* = 101.*$gdb_prompt $"\
118 {pass "print follow-exec/local_j"}
119 -re "$gdb_prompt $" {fail "print follow-exec/local_j"}
120 timeout {fail "(timeout) print follow-exec/local_j"}
122 send_gdb "print local_k\n"
124 -re ".* = 102.*$gdb_prompt $"\
125 {pass "print follow-exec/local_k"}
126 -re "$gdb_prompt $" {fail "print follow-exec/local_k"}
127 timeout {fail "(timeout) print follow-exec/local_k"}
130 # Try stepping through an execlp call, without catching it.
131 # We should stop in execd-program, at its first statement.
135 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
136 {pass "step through execlp call"}
137 -re "$gdb_prompt $" {fail "step through execlp call"}
138 timeout {fail "(timeout) step through execlp call"}
141 # Verify that we can see the variables defined in the newly-exec'd
142 # program, and CANNOT see those defined in the exec'ing program.
146 -re "26.*printf.*$gdb_prompt $"\
147 {pass "step after execlp call"}
148 -re "$gdb_prompt $" {fail "step after execlp call"}
149 timeout {fail "(timeout) step after execlp call"}
151 send_gdb "print global_i\n"
153 -re ".* = 0.*$gdb_prompt $"\
154 {pass "print execd-program/global_i (after execlp)"}
155 -re "$gdb_prompt $" {fail "print execd-program/global_i (after execlp)"}
156 timeout {fail "(timeout) print execd-program/global_i (after execlp)"}
158 send_gdb "print local_j\n"
160 -re ".* = 2.*$gdb_prompt $"\
161 {pass "print execd-program/local_j (after execlp)"}
162 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execlp)"}
163 timeout {fail "(timeout) print execd-program/local_j (after execlp)"}
165 send_gdb "print local_k\n"
167 -re "No symbol \"local_k\" in current context.*$gdb_prompt $"\
168 {pass "print follow-exec/local_k (after execlp)"}
169 -re "$gdb_prompt $" {fail "print follow-exec/local_k (after execlp)"}
170 timeout {fail "(timeout) print follow-exec/local_k (after execlp)"}
173 # Explicitly kill this program, or a subsequent rerun actually runs
174 # the exec'd program, not the original program...
177 # Start the program running, and stop at main.
179 if ![runto_main] then {
180 perror "Couldn't run ${testfile} (2nd try)"
184 # Verify that we can catch an exec event, and then continue
185 # to follow through the exec. (Since there's a breakpoint on
186 # "main", it'll also be transferred to the exec'd program,
187 # and we expect to stop there.)
189 send_gdb "catch exec\n"
191 -re "Catchpoint .*(exec).*$gdb_prompt $"\
192 {pass "set catch exec"}
193 -re "$gdb_prompt $" {fail "set catch exec"}
194 timeout {fail "(timeout) set catch exec"}
197 # Verify that the catchpoint is mentioned in an "info breakpoints",
198 # and further that the catchpoint mentions no program name.
200 send_gdb "info breakpoints\n"
202 -re ".*catch exec.*keep y.*$gdb_prompt $"\
203 {pass "info shows catchpoint without exec pathname"}
204 -re ".*catch exec.*program \"\".*$gdb_prompt $"\
205 {fail "info shows catchpoint without exec pathname"}
206 -re "$gdb_prompt $" {fail "info shows catchpoint without exec pathname"}
207 timeout {fail "(timeout) info shows catchpoint without exec pathname"}
211 # PA64 doesn't know about $START$ in dld.sl at this point. It should.
213 setup_xfail hppa2.0w-hp-hpux* CLLbs16760
214 send_gdb "continue\n"
216 -re ".*Executing new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .START..*$gdb_prompt $"\
217 {pass "hit catch exec"}
218 -re "$gdb_prompt $" {fail "hit catch exec"}
219 timeout {fail "(timeout) hit catch exec"}
223 # test gets out of sync if previous test fails.
224 gdb_test "bt" ".*" "sync up after possible failure 1"
225 gdb_test "bt" "#0.*" "sync up after possible failure 2"
227 # Verify that the catchpoint is mentioned in an "info breakpoints",
228 # and further that the catchpoint managed to capture the exec'd
231 send_gdb "info breakpoints\n"
233 -re ".*catch exec .*program \".*${testfile2}\".*$gdb_prompt $"\
234 {pass "info shows catchpoint exec pathname"}
235 -re "$gdb_prompt $" {fail "info shows catchpoint exec pathname"}
236 timeout {fail "(timeout) info shows catchpoint exec pathname"}
239 # Verify that we can continue from the catchpoint, and land in the
240 # main of the newly-exec'd program.
242 send_gdb "continue\n"
244 -re ".*${srcfile2}:23.*$gdb_prompt $"\
245 {pass "continue after hit catch exec"}
246 -re "$gdb_prompt $" {fail "continue after hit catch exec"}
247 timeout {fail "(timeout) continue after hit catch exec"}
250 # Explicitly kill this program, or a subsequent rerun actually runs
251 # the exec'd program, not the original program...
254 # Start the program running, and stop at main.
256 if ![runto_main] then {
257 perror "Couldn't run ${testfile} (3rd try)"
261 # Verify that we can follow through follow an execl()
262 # call. (We must jump around earlier exec* calls.)
264 send_gdb "tbreak 27\n"
266 -re "Breakpoint .*file .*${srcfile}, line 27.*$gdb_prompt $"\
267 {pass "prepare to jump to execl call"}
268 -re "$gdb_prompt $" {fail "prepare to jump to execl call"}
269 timeout {fail "(timeout) prepare to jump to execl call"}
273 -re "main.* at .*${srcfile}:27.*$gdb_prompt $"\
274 {pass "jump to execl call"}
275 -re "$gdb_prompt $" {fail "jump to execl call"}
276 timeout {fail "(timeout) jump to execl call"}
278 # Note that stepping through an exec call causes the step-count
279 # to be reset to zero. I.e.: you may specify "next 2" at the
280 # call, but you'll actually stop at the first breakpoint set in
281 # the newly-exec'd program, not after the remaining step-count
286 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
287 {pass "step through execl call"}
288 -re "$gdb_prompt $" {fail "step through execl call"}
289 timeout {fail "(timeout) step through execl call"}
293 -re "26.*printf.*$gdb_prompt $"\
294 {pass "step after execl call"}
295 -re "$gdb_prompt $" {fail "step after execl call"}
296 timeout {fail "(timeout) step after execl call"}
299 # Verify that we can print a local variable (which happens to be
300 # assigned the value of main's argc).
302 send_gdb "print local_j\n"
304 -re ".* = 3.*$gdb_prompt $"\
305 {pass "print execd-program/local_j (after execl)"}
306 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execl)"}
307 timeout {fail "(timeout) print execd-program/local_j (after execl)"}
310 # Explicitly kill this program, or a subsequent rerun actually runs
311 # the exec'd program, not the original program...
314 # Start the program running, and stop at main.
316 if ![runto_main] then {
317 perror "Couldn't run ${testfile} (4th try)"
321 # Verify that we can follow through follow an execv()
322 # call. (We must jump around earlier exec* calls.)
324 send_gdb "tbreak 41\n"
326 -re "Breakpoint .*file .*${srcfile}, line 41.*$gdb_prompt $"\
327 {pass "prepare to jump to execv call"}
328 -re "$gdb_prompt $" {fail "prepare to jump to execv call"}
329 timeout {fail "(timeout) prepare to jump to execv call"}
333 -re "main.* at .*${srcfile}:41.*$gdb_prompt $"\
334 {pass "jump to execv call"}
335 -re "$gdb_prompt $" {fail "jump to execv call"}
336 timeout {fail "(timeout) jump to execv call"}
340 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
341 {pass "step through execv call"}
342 -re "$gdb_prompt $" {fail "step through execv call"}
343 timeout {fail "(timeout) step through execv call"}
347 -re "26.*printf.*$gdb_prompt $"\
348 {pass "step after execv call"}
349 -re "$gdb_prompt $" {fail "step after execv call"}
350 timeout {fail "(timeout) step after execv call"}
353 # Verify that we can print a local variable (which happens to be
354 # assigned the value of main's argc).
356 send_gdb "print local_j\n"
358 -re ".* = 2.*$gdb_prompt $"\
359 {pass "print execd-program/local_j (after execv)"}
360 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execv)"}
361 timeout {fail "(timeout) print execd-program/local_j (after execv)"}
364 # Explicitly kill this program, or a subsequent rerun actually runs
365 # the exec'd program, not the original program...
368 # Start the program running, and stop at main.
370 if ![runto_main] then {
371 perror "Couldn't run ${testfile} (5th try)"
375 # Verify that we can just continue and thereby follow through an
376 # exec call. (Since the breakpoint on "main" is reset, we should
377 # just stop in main of the newly-exec'd program.)
379 send_gdb "continue\n"
381 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
382 {pass "continue through exec"}
383 -re "$gdb_prompt $" {fail "continue through exec"}
384 timeout {fail "(timeout) continue through exec"}
388 # Start with a fresh gdb
392 gdb_reinitialize_dir $srcdir/$subdir
396 # This is a test of gdb's ability to follow a process through a
397 # Unix exec() system call.