1 # Copyright 1997, 1999, 2007, 2008, 2009 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 if { [is_remote target] || ![isnative] } then {
23 set testfile "foll-exec"
24 set testfile2 "execd-prog"
25 set srcfile ${testfile}.c
26 set srcfile2 ${testfile2}.c
27 set binfile ${objdir}/${subdir}/${testfile}
28 set binfile2 ${objdir}/${subdir}/${testfile2}
30 # build the first test case
31 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
32 untested foll-exec.exp
36 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
37 untested foll-exec.exp
42 # Until "catch exec" is implemented on other targets...
44 if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
54 -re ".*Kill the program being debugged.*y or n. $" {
56 send_gdb "file $binfile\n"
58 -re ".*Load new symbol table from.*y or n. $" {
61 -re "Reading symbols from.*$gdb_prompt $" {}
62 timeout { fail "loading symbols (timeout)"; return }
65 -re ".*gdb_prompt $" {}
66 timeout { fail "loading symbols (timeout)"; return }
69 -re ".*$gdb_prompt $" {}
70 timeout { fail "killing inferior (timeout)" ; return }
74 proc do_exec_tests {} {
82 # Start the program running, and stop at main.
84 if ![runto_main] then {
85 perror "Couldn't run ${testfile}"
89 # Verify that the system supports "catch exec".
90 gdb_test "catch exec" "Catchpoint \[0-9\]* \\(exec\\)" "insert first exec catchpoint"
91 set has_exec_catchpoints 0
92 gdb_test_multiple "continue" "continue to first exec catchpoint" {
93 -re ".*Your system does not support exec catchpoints.*$gdb_prompt $" {
94 unsupported "continue to first exec catchpoint"
96 -re ".*Catchpoint.*$gdb_prompt $" {
97 set has_exec_catchpoints 1
98 pass "continue to first exec catchpoint"
102 if {$has_exec_catchpoints == 0} {
103 unsupported "exec catchpoints"
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 "20.*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}:23.*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 "26.*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 set msg "info shows catchpoint without exec pathname"
221 gdb_test_multiple "info breakpoints" $msg {
222 -re ".*catchpoint.*keep y.*exec\[\n\r\]+$gdb_prompt $" {
228 # PA64 doesn't know about $START$ in dld.sl at this point. It should.
230 setup_xfail hppa2.0w-hp-hpux* CLLbs16760
231 send_gdb "continue\n"
233 -re ".*Executing new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .*$gdb_prompt $"\
234 {pass "hit catch exec"}
235 -re "$gdb_prompt $" {fail "hit catch exec"}
236 timeout {fail "(timeout) hit catch exec"}
240 # test gets out of sync if previous test fails.
241 gdb_test "bt" ".*" "sync up after possible failure 1"
242 gdb_test "bt" "#0.*" "sync up after possible failure 2"
244 # Verify that the catchpoint is mentioned in an "info breakpoints",
245 # and further that the catchpoint managed to capture the exec'd
248 set msg "info shows catchpoint exec pathname"
249 gdb_test_multiple "info breakpoints" $msg {
250 -re ".*catchpoint.*keep y.*exec, program \".*${testfile2}\".*$gdb_prompt $" {
255 # Verify that we can continue from the catchpoint, and land in the
256 # main of the newly-exec'd program.
258 send_gdb "continue\n"
260 -re ".*${srcfile2}:23.*$gdb_prompt $"\
261 {pass "continue after hit catch exec"}
262 -re "$gdb_prompt $" {fail "continue after hit catch exec"}
263 timeout {fail "(timeout) continue after hit catch exec"}
266 # Explicitly kill this program, or a subsequent rerun actually runs
267 # the exec'd program, not the original program...
270 # Start the program running, and stop at main.
272 if ![runto_main] then {
273 perror "Couldn't run ${testfile} (3rd try)"
277 # Verify that we can follow through follow an execl()
278 # call. (We must jump around earlier exec* calls.)
280 send_gdb "tbreak 27\n"
282 -re "Temporary breakpoint .*file .*${srcfile}, line 27.*$gdb_prompt $"\
283 {pass "prepare to jump to execl call"}
284 -re "$gdb_prompt $" {fail "prepare to jump to execl call"}
285 timeout {fail "(timeout) prepare to jump to execl call"}
289 -re "main.* at .*${srcfile}:27.*$gdb_prompt $"\
290 {pass "jump to execl call"}
291 -re "$gdb_prompt $" {fail "jump to execl call"}
292 timeout {fail "(timeout) jump to execl call"}
294 # Note that stepping through an exec call causes the step-count
295 # to be reset to zero. I.e.: you may specify "next 2" at the
296 # call, but you'll actually stop at the first breakpoint set in
297 # the newly-exec'd program, not after the remaining step-count
302 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
303 {pass "step through execl call"}
304 -re "$gdb_prompt $" {fail "step through execl call"}
305 timeout {fail "(timeout) step through execl call"}
309 -re "26.*printf.*$gdb_prompt $"\
310 {pass "step after execl call"}
311 -re "$gdb_prompt $" {fail "step after execl call"}
312 timeout {fail "(timeout) step after execl call"}
315 # Verify that we can print a local variable (which happens to be
316 # assigned the value of main's argc).
318 send_gdb "print local_j\n"
320 -re ".* = 3.*$gdb_prompt $"\
321 {pass "print execd-program/local_j (after execl)"}
322 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execl)"}
323 timeout {fail "(timeout) print execd-program/local_j (after execl)"}
326 # Explicitly kill this program, or a subsequent rerun actually runs
327 # the exec'd program, not the original program...
330 # Start the program running, and stop at main.
332 if ![runto_main] then {
333 perror "Couldn't run ${testfile} (4th try)"
337 # Verify that we can follow through follow an execv()
338 # call. (We must jump around earlier exec* calls.)
340 send_gdb "tbreak 41\n"
342 -re "Temporary breakpoint .*file .*${srcfile}, line 41.*$gdb_prompt $"\
343 {pass "prepare to jump to execv call"}
344 -re "$gdb_prompt $" {fail "prepare to jump to execv call"}
345 timeout {fail "(timeout) prepare to jump to execv call"}
349 -re "main.* at .*${srcfile}:41.*$gdb_prompt $"\
350 {pass "jump to execv call"}
351 -re "$gdb_prompt $" {fail "jump to execv call"}
352 timeout {fail "(timeout) jump to execv call"}
356 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
357 {pass "step through execv call"}
358 -re "$gdb_prompt $" {fail "step through execv call"}
359 timeout {fail "(timeout) step through execv call"}
363 -re "26.*printf.*$gdb_prompt $"\
364 {pass "step after execv call"}
365 -re "$gdb_prompt $" {fail "step after execv call"}
366 timeout {fail "(timeout) step after execv call"}
369 # Verify that we can print a local variable (which happens to be
370 # assigned the value of main's argc).
372 send_gdb "print local_j\n"
374 -re ".* = 2.*$gdb_prompt $"\
375 {pass "print execd-program/local_j (after execv)"}
376 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execv)"}
377 timeout {fail "(timeout) print execd-program/local_j (after execv)"}
380 # Explicitly kill this program, or a subsequent rerun actually runs
381 # the exec'd program, not the original program...
384 # Start the program running, and stop at main.
386 if ![runto_main] then {
387 perror "Couldn't run ${testfile} (5th try)"
391 # Verify that we can just continue and thereby follow through an
392 # exec call. (Since the breakpoint on "main" is reset, we should
393 # just stop in main of the newly-exec'd program.)
395 send_gdb "continue\n"
397 -re "Executing new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
398 {pass "continue through exec"}
399 -re "$gdb_prompt $" {fail "continue through exec"}
400 timeout {fail "(timeout) continue through exec"}
404 # Start with a fresh gdb
408 gdb_reinitialize_dir $srcdir/$subdir
412 # This is a test of gdb's ability to follow a process through a
413 # Unix exec() system call.