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 # are we on a target board
32 if {![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"]} {
37 set testfile "foll-exec"
38 set testfile2 "execd-program"
39 set srcfile ${testfile}.c
40 set srcfile2 ${testfile2}.c
41 set binfile ${objdir}/${subdir}/${testfile}
42 set binfile2 ${objdir}/${subdir}/${testfile2}
44 # build the first test case
45 #if { [compile "-g -DNO_PROTOTYPES ${srcdir}/${subdir}/${srcfile2} -o ${binfile2} "] != "" } {
46 # perror "Couldn't compile ${srcfile2}"
49 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
50 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
53 #if { [compile "-g ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } {
54 # execute_anywhere "rm -f ${objdir}/${subdir}/${testfile}.tmp"
55 # built the second test case since we can't use prototypes
56 # warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES"
57 # execute_anywhere "echo set prototypes 0 > ${objdir}/${subdir}/${testfile}.tmp"
58 # if { [compile "-g -DNO_PROTOTYPES ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } {
59 # perror "Couldn't compile ${testfile}.c"
64 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
65 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
69 # Until "catch exec" is implemented on other targets...
71 if ![istarget "hppa*-hp-hpux*"] then {
81 -re ".*Kill the program being debugged.*y or n. $" {
83 send_gdb "file $binfile\n"
85 -re ".*Load new symbol table from.*y or n. $" {
88 -re "Reading symbols from.*$gdb_prompt $" {}
89 timeout { fail "loading symbols (timeout)"; return }
92 -re ".*gdb_prompt $" {}
93 timeout { fail "loading symbols (timeout)"; return }
96 -re ".*$gdb_prompt $" {}
97 timeout { fail "killing inferior (timeout)" ; return }
101 proc do_exec_tests {} {
109 # Start the program running, and stop at main.
111 if ![runto_main] then {
112 perror "Couldn't run ${testfile}"
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
123 -re "12.*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"}
128 send_gdb "print global_i\n"
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"}
135 send_gdb "print local_j\n"
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"}
142 send_gdb "print local_k\n"
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"}
150 # Try stepping through an execlp call, without catching it.
151 # We should stop in execd-program, at its first statement.
155 -re "Executing new program: .*${testfile2}.*${srcfile2}:17.*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"}
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.
166 -re "20.*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"}
171 send_gdb "print global_i\n"
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)"}
178 send_gdb "print local_j\n"
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)"}
185 send_gdb "print local_k\n"
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)"}
193 # Explicitly kill this program, or a subsequent rerun actually runs
194 # the exec'd program, not the original program...
197 # Start the program running, and stop at main.
199 if ![runto_main] then {
200 perror "Couldn't run ${testfile} (2nd try)"
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.)
209 send_gdb "catch exec\n"
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"}
217 # Verify that the catchpoint is mentioned in an "info breakpoints",
218 # and further that the catchpoint mentions no program name.
220 send_gdb "info breakpoints\n"
222 -re ".*catch exec.*keep y.*$gdb_prompt $"\
223 {pass "info shows catchpoint without exec pathname"}
224 -re ".*catch exec.*program \"\".*$gdb_prompt $"\
225 {fail "info shows catchpoint without exec pathname"}
226 -re "$gdb_prompt $" {fail "info shows catchpoint without exec pathname"}
227 timeout {fail "(timeout) info shows catchpoint without exec pathname"}
230 send_gdb "continue\n"
232 -re ".*Executing new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .START..*$gdb_prompt $"\
233 {pass "hit catch exec"}
234 -re "$gdb_prompt $" {fail "hit catch exec"}
235 timeout {fail "(timeout) hit catch exec"}
238 # Verify that the catchpoint is mentioned in an "info breakpoints",
239 # and further that the catchpoint managed to capture the exec'd
242 send_gdb "info breakpoints\n"
244 -re ".*catch exec .*program \".*${testfile2}\".*$gdb_prompt $"\
245 {pass "info shows catchpoint exec pathname"}
246 -re "$gdb_prompt $" {fail "info shows catchpoint exec pathname"}
247 timeout {fail "(timeout) info shows catchpoint exec pathname"}
250 # Verify that we can continue from the catchpoint, and land in the
251 # main of the newly-exec'd program.
253 send_gdb "continue\n"
255 -re ".*${srcfile2}:17.*$gdb_prompt $"\
256 {pass "continue after hit catch exec"}
257 -re "$gdb_prompt $" {fail "continue after hit catch exec"}
258 timeout {fail "(timeout) continue after hit catch exec"}
261 # Explicitly kill this program, or a subsequent rerun actually runs
262 # the exec'd program, not the original program...
265 # Start the program running, and stop at main.
267 if ![runto_main] then {
268 perror "Couldn't run ${testfile} (3rd try)"
272 # Verify that we can follow through follow an execl()
273 # call. (We must jump around earlier exec* calls.)
275 send_gdb "tbreak 19\n"
277 -re "Breakpoint .*file .*${srcfile}, line 19.*$gdb_prompt $"\
278 {pass "prepare to jump to execl call"}
279 -re "$gdb_prompt $" {fail "prepare to jump to execl call"}
280 timeout {fail "(timeout) prepare to jump to execl call"}
284 -re "main.* at .*${srcfile}:19.*$gdb_prompt $"\
285 {pass "jump to execl call"}
286 -re "$gdb_prompt $" {fail "jump to execl call"}
287 timeout {fail "(timeout) jump to execl call"}
289 # Note that stepping through an exec call causes the step-count
290 # to be reset to zero. I.e.: you may specify "next 2" at the
291 # call, but you'll actually stop at the first breakpoint set in
292 # the newly-exec'd program, not after the remaining step-count
297 -re "Executing new program: .*${testfile2}.*${srcfile2}:17.*int local_j = argc;.*$gdb_prompt $"\
298 {pass "step through execl call"}
299 -re "$gdb_prompt $" {fail "step through execl call"}
300 timeout {fail "(timeout) step through execl call"}
304 -re "20.*printf.*$gdb_prompt $"\
305 {pass "step after execl call"}
306 -re "$gdb_prompt $" {fail "step after execl call"}
307 timeout {fail "(timeout) step after execl call"}
310 # Verify that we can print a local variable (which happens to be
311 # assigned the value of main's argc).
313 send_gdb "print local_j\n"
315 -re ".* = 3.*$gdb_prompt $"\
316 {pass "print execd-program/local_j (after execl)"}
317 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execl)"}
318 timeout {fail "(timeout) print execd-program/local_j (after execl)"}
321 # Explicitly kill this program, or a subsequent rerun actually runs
322 # the exec'd program, not the original program...
325 # Start the program running, and stop at main.
327 if ![runto_main] then {
328 perror "Couldn't run ${testfile} (4th try)"
332 # Verify that we can follow through follow an execv()
333 # call. (We must jump around earlier exec* calls.)
335 send_gdb "tbreak 33\n"
337 -re "Breakpoint .*file .*${srcfile}, line 33.*$gdb_prompt $"\
338 {pass "prepare to jump to execv call"}
339 -re "$gdb_prompt $" {fail "prepare to jump to execv call"}
340 timeout {fail "(timeout) prepare to jump to execv call"}
344 -re "main.* at .*${srcfile}:33.*$gdb_prompt $"\
345 {pass "jump to execv call"}
346 -re "$gdb_prompt $" {fail "jump to execv call"}
347 timeout {fail "(timeout) jump to execv call"}
351 -re "Executing new program: .*${testfile2}.*${srcfile2}:17.*int local_j = argc;.*$gdb_prompt $"\
352 {pass "step through execv call"}
353 -re "$gdb_prompt $" {fail "step through execv call"}
354 timeout {fail "(timeout) step through execv call"}
358 -re "20.*printf.*$gdb_prompt $"\
359 {pass "step after execv call"}
360 -re "$gdb_prompt $" {fail "step after execv call"}
361 timeout {fail "(timeout) step after execv call"}
364 # Verify that we can print a local variable (which happens to be
365 # assigned the value of main's argc).
367 send_gdb "print local_j\n"
369 -re ".* = 2.*$gdb_prompt $"\
370 {pass "print execd-program/local_j (after execv)"}
371 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execv)"}
372 timeout {fail "(timeout) print execd-program/local_j (after execv)"}
375 # Explicitly kill this program, or a subsequent rerun actually runs
376 # the exec'd program, not the original program...
379 # Start the program running, and stop at main.
381 if ![runto_main] then {
382 perror "Couldn't run ${testfile} (4th try)"
386 # Verify that we can just continue and thereby follow through an
387 # exec call. (Since the breakpoint on "main" is reset, we should
388 # just stop in main of the newly-exec'd program.)
390 send_gdb "continue\n"
392 -re "Executing new program: .*${testfile2}.*${srcfile2}:17.*int local_j = argc;.*$gdb_prompt $"\
393 {pass "continue through exec"}
394 -re "$gdb_prompt $" {fail "continue through exec"}
395 timeout {fail "(timeout) continue through exec"}
399 # Start with a fresh gdb
403 gdb_reinitialize_dir $srcdir/$subdir
407 # This is a test of gdb's ability to follow a process through a
408 # Unix exec() system call.