1 # Copyright
1997, 1999 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 gdb_suppress_entire_file
"Testcase compile failed, so all tests in this file will automatically fail."
43 if { [gdb_compile
"${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
44 gdb_suppress_entire_file
"Testcase compile failed, so all tests in this file will automatically fail."
48 # Until
"catch exec" is implemented on other targets...
50 if ![istarget
"hppa*-hp-hpux*"] then {
60 -re
".*Kill the program being debugged.*y or n. $" {
62 send_gdb
"file $binfile\n"
64 -re
".*Load new symbol table from.*y or n. $" {
67 -re
"Reading symbols from.*$gdb_prompt $" {}
68 timeout
{ fail
"loading symbols (timeout)"; return }
71 -re
".*gdb_prompt $" {}
72 timeout
{ fail
"loading symbols (timeout)"; return }
75 -re
".*$gdb_prompt $" {}
76 timeout
{ fail
"killing inferior (timeout)" ; return }
80 proc do_exec_tests
{} {
88 # Start the
program running
, and stop at main.
90 if ![runto_main
] then {
91 perror
"Couldn't run ${testfile}"
95 # Verify that we can see various global and local variables
96 # in this
program, and that they have expected
values. Some
97 # of these variables are also declared in the
program we
'll
102 -re "20.*execlp.*$gdb_prompt $"\
103 {pass "step to exec call"}
104 -re "$gdb_prompt $" {fail "step to exec call"}
105 timeout {fail "(timeout) step to exec call"}
107 send_gdb "print global_i\n"
109 -re ".* = 100.*$gdb_prompt $"\
110 {pass "print follow-exec/global_i"}
111 -re "$gdb_prompt $" {fail "print follow-exec/global_i"}
112 timeout {fail "(timeout) print follow-exec/global_i"}
114 send_gdb "print local_j\n"
116 -re ".* = 101.*$gdb_prompt $"\
117 {pass "print follow-exec/local_j"}
118 -re "$gdb_prompt $" {fail "print follow-exec/local_j"}
119 timeout {fail "(timeout) print follow-exec/local_j"}
121 send_gdb "print local_k\n"
123 -re ".* = 102.*$gdb_prompt $"\
124 {pass "print follow-exec/local_k"}
125 -re "$gdb_prompt $" {fail "print follow-exec/local_k"}
126 timeout {fail "(timeout) print follow-exec/local_k"}
129 # Try stepping through an execlp call, without catching it.
130 # We should stop in execd-program, at its first statement.
134 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
135 {pass "step through execlp call"}
136 -re "$gdb_prompt $" {fail "step through execlp call"}
137 timeout {fail "(timeout) step through execlp call"}
140 # Verify that we can see the variables defined in the newly-exec'd
141 #
program, and CANNOT see those defined in the exec
'ing program.
145 -re "26.*printf.*$gdb_prompt $"\
146 {pass "step after execlp call"}
147 -re "$gdb_prompt $" {fail "step after execlp call"}
148 timeout {fail "(timeout) step after execlp call"}
150 send_gdb "print global_i\n"
152 -re ".* = 0.*$gdb_prompt $"\
153 {pass "print execd-program/global_i (after execlp)"}
154 -re "$gdb_prompt $" {fail "print execd-program/global_i (after execlp)"}
155 timeout {fail "(timeout) print execd-program/global_i (after execlp)"}
157 send_gdb "print local_j\n"
159 -re ".* = 2.*$gdb_prompt $"\
160 {pass "print execd-program/local_j (after execlp)"}
161 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execlp)"}
162 timeout {fail "(timeout) print execd-program/local_j (after execlp)"}
164 send_gdb "print local_k\n"
166 -re "No symbol \"local_k\" in current context.*$gdb_prompt $"\
167 {pass "print follow-exec/local_k (after execlp)"}
168 -re "$gdb_prompt $" {fail "print follow-exec/local_k (after execlp)"}
169 timeout {fail "(timeout) print follow-exec/local_k (after execlp)"}
172 # Explicitly kill this program, or a subsequent rerun actually runs
173 # the exec'd
program, not the original
program...
176 # Start the
program running
, and stop at main.
178 if ![runto_main
] then {
179 perror
"Couldn't run ${testfile} (2nd try)"
183 # Verify that we can catch an exec event
, and
then continue
184 # to follow through the exec.
(Since there
's a breakpoint on
185 # "main", it'll also be transferred to the exec
'd program,
186 # and we expect to stop there.)
188 send_gdb "catch exec\n"
190 -re "Catchpoint .*(exec).*$gdb_prompt $"\
191 {pass "set catch exec"}
192 -re "$gdb_prompt $" {fail "set catch exec"}
193 timeout {fail "(timeout) set catch exec"}
196 # Verify that the catchpoint is mentioned in an "info breakpoints",
197 # and further that the catchpoint mentions no program name.
199 send_gdb "info breakpoints\n"
201 -re ".*catch exec.*keep y.*$gdb_prompt $"\
202 {pass "info shows catchpoint without exec pathname"}
203 -re ".*catch exec.*program \"\".*$gdb_prompt $"\
204 {fail "info shows catchpoint without exec pathname"}
205 -re "$gdb_prompt $" {fail "info shows catchpoint without exec pathname"}
206 timeout {fail "(timeout) info shows catchpoint without exec pathname"}
210 # PA64 doesn't know about $START$ in dld.sl at this point. It should.
212 setup_xfail hppa2.0w
-hp
-hpux
* CLLbs16760
213 send_gdb
"continue\n"
215 -re
".*Executing new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .START..*$gdb_prompt $"\
216 {pass
"hit catch exec"}
217 -re
"$gdb_prompt $" {fail "hit catch exec"}
218 timeout
{fail
"(timeout) hit catch exec"}
222 # test gets out of sync
if previous test fails.
223 gdb_test
"bt" ".*" "sync up after possible failure 1"
224 gdb_test
"bt" "#0.*" "sync up after possible failure 2"
226 # Verify that the catchpoint is mentioned in an
"info breakpoints",
227 # and further that the catchpoint managed to capture the exec
'd
230 send_gdb
"info breakpoints\n"
232 -re
".*catch exec .*program \".*${testfile2}\".*$gdb_prompt $"\
233 {pass
"info shows catchpoint exec pathname"}
234 -re
"$gdb_prompt $" {fail "info shows catchpoint exec pathname"}
235 timeout
{fail
"(timeout) info shows catchpoint exec pathname"}
238 # Verify that we can
continue from the catchpoint
, and land in the
239 # main of the newly
-exec
'd program.
241 send_gdb "continue\n"
243 -re ".*${srcfile2}:23.*$gdb_prompt $"\
244 {pass "continue after hit catch exec"}
245 -re "$gdb_prompt $" {fail "continue after hit catch exec"}
246 timeout {fail "(timeout) continue after hit catch exec"}
249 # Explicitly kill this program, or a subsequent rerun actually runs
250 # the exec'd
program, not the original
program...
253 # Start the
program running
, and stop at main.
255 if ![runto_main
] then {
256 perror
"Couldn't run ${testfile} (3rd try)"
260 # Verify that we can follow through follow an execl
()
261 #
call.
(We must jump around earlier exec
* calls.
)
263 send_gdb
"tbreak 27\n"
265 -re
"Breakpoint .*file .*${srcfile}, line 27.*$gdb_prompt $"\
266 {pass
"prepare to jump to execl call"}
267 -re
"$gdb_prompt $" {fail "prepare to jump to execl call"}
268 timeout
{fail
"(timeout) prepare to jump to execl call"}
272 -re
"main.* at .*${srcfile}:27.*$gdb_prompt $"\
273 {pass
"jump to execl call"}
274 -re
"$gdb_prompt $" {fail "jump to execl call"}
275 timeout
{fail
"(timeout) jump to execl call"}
277 # Note that stepping through an exec
call causes the step
-count
278 # to be reset to zero. I.e.
: you may specify
"next 2" at the
279 #
call, but you
'll actually stop at the first breakpoint set in
280 # the newly-exec'd
program, not after the remaining step
-count
285 -re
"Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
286 {pass
"step through execl call"}
287 -re
"$gdb_prompt $" {fail "step through execl call"}
288 timeout
{fail
"(timeout) step through execl call"}
292 -re
"26.*printf.*$gdb_prompt $"\
293 {pass
"step after execl call"}
294 -re
"$gdb_prompt $" {fail "step after execl call"}
295 timeout
{fail
"(timeout) step after execl call"}
298 # Verify that we can print a local
variable (which happens to be
299 # assigned the value of main
's argc).
301 send_gdb "print local_j\n"
303 -re ".* = 3.*$gdb_prompt $"\
304 {pass "print execd-program/local_j (after execl)"}
305 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execl)"}
306 timeout {fail "(timeout) print execd-program/local_j (after execl)"}
309 # Explicitly kill this program, or a subsequent rerun actually runs
310 # the exec'd
program, not the original
program...
313 # Start the
program running
, and stop at main.
315 if ![runto_main
] then {
316 perror
"Couldn't run ${testfile} (4th try)"
320 # Verify that we can follow through follow an execv
()
321 #
call.
(We must jump around earlier exec
* calls.
)
323 send_gdb
"tbreak 41\n"
325 -re
"Breakpoint .*file .*${srcfile}, line 41.*$gdb_prompt $"\
326 {pass
"prepare to jump to execv call"}
327 -re
"$gdb_prompt $" {fail "prepare to jump to execv call"}
328 timeout
{fail
"(timeout) prepare to jump to execv call"}
332 -re
"main.* at .*${srcfile}:41.*$gdb_prompt $"\
333 {pass
"jump to execv call"}
334 -re
"$gdb_prompt $" {fail "jump to execv call"}
335 timeout
{fail
"(timeout) jump to execv call"}
339 -re
"Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
340 {pass
"step through execv call"}
341 -re
"$gdb_prompt $" {fail "step through execv call"}
342 timeout
{fail
"(timeout) step through execv call"}
346 -re
"26.*printf.*$gdb_prompt $"\
347 {pass
"step after execv call"}
348 -re
"$gdb_prompt $" {fail "step after execv call"}
349 timeout
{fail
"(timeout) step after execv call"}
352 # Verify that we can print a local
variable (which happens to be
353 # assigned the value of main
's argc).
355 send_gdb "print local_j\n"
357 -re ".* = 2.*$gdb_prompt $"\
358 {pass "print execd-program/local_j (after execv)"}
359 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execv)"}
360 timeout {fail "(timeout) print execd-program/local_j (after execv)"}
363 # Explicitly kill this program, or a subsequent rerun actually runs
364 # the exec'd
program, not the original
program...
367 # Start the
program running
, and stop at main.
369 if ![runto_main
] then {
370 perror
"Couldn't run ${testfile} (5th try)"
374 # Verify that we can just
continue and thereby follow through an
375 # exec
call.
(Since the breakpoint
on "main" is reset, we should
376 # just stop in main of the newly
-exec
'd program.)
378 send_gdb "continue\n"
380 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
381 {pass "continue through exec"}
382 -re "$gdb_prompt $" {fail "continue through exec"}
383 timeout {fail "(timeout) continue through exec"}
387 # Start with a fresh gdb
391 gdb_reinitialize_dir $srcdir/$subdir
395 # This is a test of gdb's ability to follow a process through a
396 # Unix exec
() system call.