1 # Copyright 1997, 1999, 2007, 2008, 2009, 2010
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 if { [is_remote target] || ![isnative] } then {
24 set testfile "foll-exec"
25 set testfile2 "execd-prog"
26 set srcfile ${testfile}.c
27 set srcfile2 ${testfile2}.c
28 set binfile ${objdir}/${subdir}/${testfile}
29 set binfile2 ${objdir}/${subdir}/${testfile2}
31 # build the first test case
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
33 untested foll-exec.exp
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
38 untested foll-exec.exp
43 # Until "catch exec" is implemented on other targets...
45 if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
55 -re ".*Kill the program being debugged.*y or n. $" {
57 send_gdb "file $binfile\n"
59 -re ".*Load new symbol table from.*y or n. $" {
62 -re "Reading symbols from.*$gdb_prompt $" {}
63 timeout { fail "loading symbols (timeout)"; return }
66 -re ".*gdb_prompt $" {}
67 timeout { fail "loading symbols (timeout)"; return }
70 -re ".*$gdb_prompt $" {}
71 timeout { fail "killing inferior (timeout)" ; return }
75 proc do_exec_tests {} {
83 # Start the program running, and stop at main.
85 if ![runto_main] then {
86 perror "Couldn't run ${testfile}"
90 # Verify that the system supports "catch exec".
91 gdb_test "catch exec" "Catchpoint \[0-9\]* \\(exec\\)" "insert first exec catchpoint"
92 set has_exec_catchpoints 0
93 gdb_test_multiple "continue" "continue to first exec catchpoint" {
94 -re ".*Your system does not support exec catchpoints.*$gdb_prompt $" {
95 unsupported "continue to first exec catchpoint"
97 -re ".*Catchpoint.*$gdb_prompt $" {
98 set has_exec_catchpoints 1
99 pass "continue to first exec catchpoint"
103 if {$has_exec_catchpoints == 0} {
104 unsupported "exec catchpoints"
110 # Start the program running, and stop at main.
112 if ![runto_main] then {
113 perror "Couldn't run ${testfile}"
117 # Verify that we can see various global and local variables
118 # in this program, and that they have expected values. Some
119 # of these variables are also declared in the program we'll
124 -re "20.*execlp.*$gdb_prompt $"\
125 {pass "step to exec call"}
126 -re "$gdb_prompt $" {fail "step to exec call"}
127 timeout {fail "(timeout) step to exec call"}
129 send_gdb "print global_i\n"
131 -re ".* = 100.*$gdb_prompt $"\
132 {pass "print follow-exec/global_i"}
133 -re "$gdb_prompt $" {fail "print follow-exec/global_i"}
134 timeout {fail "(timeout) print follow-exec/global_i"}
136 send_gdb "print local_j\n"
138 -re ".* = 101.*$gdb_prompt $"\
139 {pass "print follow-exec/local_j"}
140 -re "$gdb_prompt $" {fail "print follow-exec/local_j"}
141 timeout {fail "(timeout) print follow-exec/local_j"}
143 send_gdb "print local_k\n"
145 -re ".* = 102.*$gdb_prompt $"\
146 {pass "print follow-exec/local_k"}
147 -re "$gdb_prompt $" {fail "print follow-exec/local_k"}
148 timeout {fail "(timeout) print follow-exec/local_k"}
151 # Try stepping through an execlp call, without catching it.
152 # We should stop in execd-program, at its first statement.
156 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
157 {pass "step through execlp call"}
158 -re "$gdb_prompt $" {fail "step through execlp call"}
159 timeout {fail "(timeout) step through execlp call"}
162 # Verify that we can see the variables defined in the newly-exec'd
163 # program, and CANNOT see those defined in the exec'ing program.
167 -re "26.*printf.*$gdb_prompt $"\
168 {pass "step after execlp call"}
169 -re "$gdb_prompt $" {fail "step after execlp call"}
170 timeout {fail "(timeout) step after execlp call"}
172 send_gdb "print global_i\n"
174 -re ".* = 0.*$gdb_prompt $"\
175 {pass "print execd-program/global_i (after execlp)"}
176 -re "$gdb_prompt $" {fail "print execd-program/global_i (after execlp)"}
177 timeout {fail "(timeout) print execd-program/global_i (after execlp)"}
179 send_gdb "print local_j\n"
181 -re ".* = 2.*$gdb_prompt $"\
182 {pass "print execd-program/local_j (after execlp)"}
183 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execlp)"}
184 timeout {fail "(timeout) print execd-program/local_j (after execlp)"}
186 send_gdb "print local_k\n"
188 -re "No symbol \"local_k\" in current context.*$gdb_prompt $"\
189 {pass "print follow-exec/local_k (after execlp)"}
190 -re "$gdb_prompt $" {fail "print follow-exec/local_k (after execlp)"}
191 timeout {fail "(timeout) print follow-exec/local_k (after execlp)"}
194 # Explicitly kill this program, or a subsequent rerun actually runs
195 # the exec'd program, not the original program...
198 # Start the program running, and stop at main.
200 if ![runto_main] then {
201 perror "Couldn't run ${testfile} (2nd try)"
205 # Verify that we can catch an exec event, and then continue
206 # to follow through the exec. (Since there's a breakpoint on
207 # "main", it'll also be transferred to the exec'd program,
208 # and we expect to stop there.)
210 send_gdb "catch exec\n"
212 -re "Catchpoint .*(exec).*$gdb_prompt $"\
213 {pass "set catch exec"}
214 -re "$gdb_prompt $" {fail "set catch exec"}
215 timeout {fail "(timeout) set catch exec"}
218 # Verify that the catchpoint is mentioned in an "info breakpoints",
219 # and further that the catchpoint mentions no program name.
221 set msg "info shows catchpoint without exec pathname"
222 gdb_test_multiple "info breakpoints" $msg {
223 -re ".*catchpoint.*keep y.*exec\[\n\r\]+$gdb_prompt $" {
229 # PA64 doesn't know about $START$ in dld.sl at this point. It should.
231 setup_xfail hppa2.0w-hp-hpux* CLLbs16760
232 send_gdb "continue\n"
234 -re ".*xecuting new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .*$gdb_prompt $"\
235 {pass "hit catch exec"}
236 -re "$gdb_prompt $" {fail "hit catch exec"}
237 timeout {fail "(timeout) hit catch exec"}
241 # test gets out of sync if previous test fails.
242 gdb_test "bt" ".*" "sync up after possible failure 1"
243 gdb_test "bt" "#0.*" "sync up after possible failure 2"
245 # Verify that the catchpoint is mentioned in an "info breakpoints",
246 # and further that the catchpoint managed to capture the exec'd
249 set msg "info shows catchpoint exec pathname"
250 gdb_test_multiple "info breakpoints" $msg {
251 -re ".*catchpoint.*keep y.*exec, program \".*${testfile2}\".*$gdb_prompt $" {
256 # Verify that we can continue from the catchpoint, and land in the
257 # main of the newly-exec'd program.
259 send_gdb "continue\n"
261 -re ".*${srcfile2}:23.*$gdb_prompt $"\
262 {pass "continue after hit catch exec"}
263 -re "$gdb_prompt $" {fail "continue after hit catch exec"}
264 timeout {fail "(timeout) continue after hit catch exec"}
267 # Explicitly kill this program, or a subsequent rerun actually runs
268 # the exec'd program, not the original program...
271 # Start the program running, and stop at main.
273 if ![runto_main] then {
274 perror "Couldn't run ${testfile} (3rd try)"
278 # Verify that we can follow through follow an execl()
279 # call. (We must jump around earlier exec* calls.)
281 send_gdb "tbreak 27\n"
283 -re "Temporary breakpoint .*file .*${srcfile}, line 27.*$gdb_prompt $"\
284 {pass "prepare to jump to execl call"}
285 -re "$gdb_prompt $" {fail "prepare to jump to execl call"}
286 timeout {fail "(timeout) prepare to jump to execl call"}
290 -re "main.* at .*${srcfile}:27.*$gdb_prompt $"\
291 {pass "jump to execl call"}
292 -re "$gdb_prompt $" {fail "jump to execl call"}
293 timeout {fail "(timeout) jump to execl call"}
295 # Note that stepping through an exec call causes the step-count
296 # to be reset to zero. I.e.: you may specify "next 2" at the
297 # call, but you'll actually stop at the first breakpoint set in
298 # the newly-exec'd program, not after the remaining step-count
303 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
304 {pass "step through execl call"}
305 -re "$gdb_prompt $" {fail "step through execl call"}
306 timeout {fail "(timeout) step through execl call"}
310 -re "26.*printf.*$gdb_prompt $"\
311 {pass "step after execl call"}
312 -re "$gdb_prompt $" {fail "step after execl call"}
313 timeout {fail "(timeout) step after execl call"}
316 # Verify that we can print a local variable (which happens to be
317 # assigned the value of main's argc).
319 send_gdb "print local_j\n"
321 -re ".* = 3.*$gdb_prompt $"\
322 {pass "print execd-program/local_j (after execl)"}
323 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execl)"}
324 timeout {fail "(timeout) print execd-program/local_j (after execl)"}
327 # Explicitly kill this program, or a subsequent rerun actually runs
328 # the exec'd program, not the original program...
331 # Start the program running, and stop at main.
333 if ![runto_main] then {
334 perror "Couldn't run ${testfile} (4th try)"
338 # Verify that we can follow through follow an execv()
339 # call. (We must jump around earlier exec* calls.)
341 send_gdb "tbreak 41\n"
343 -re "Temporary breakpoint .*file .*${srcfile}, line 41.*$gdb_prompt $"\
344 {pass "prepare to jump to execv call"}
345 -re "$gdb_prompt $" {fail "prepare to jump to execv call"}
346 timeout {fail "(timeout) prepare to jump to execv call"}
350 -re "main.* at .*${srcfile}:41.*$gdb_prompt $"\
351 {pass "jump to execv call"}
352 -re "$gdb_prompt $" {fail "jump to execv call"}
353 timeout {fail "(timeout) jump to execv call"}
357 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
358 {pass "step through execv call"}
359 -re "$gdb_prompt $" {fail "step through execv call"}
360 timeout {fail "(timeout) step through execv call"}
364 -re "26.*printf.*$gdb_prompt $"\
365 {pass "step after execv call"}
366 -re "$gdb_prompt $" {fail "step after execv call"}
367 timeout {fail "(timeout) step after execv call"}
370 # Verify that we can print a local variable (which happens to be
371 # assigned the value of main's argc).
373 send_gdb "print local_j\n"
375 -re ".* = 2.*$gdb_prompt $"\
376 {pass "print execd-program/local_j (after execv)"}
377 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execv)"}
378 timeout {fail "(timeout) print execd-program/local_j (after execv)"}
381 # Explicitly kill this program, or a subsequent rerun actually runs
382 # the exec'd program, not the original program...
385 # Start the program running, and stop at main.
387 if ![runto_main] then {
388 perror "Couldn't run ${testfile} (5th try)"
392 # Verify that we can just continue and thereby follow through an
393 # exec call. (Since the breakpoint on "main" is reset, we should
394 # just stop in main of the newly-exec'd program.)
396 send_gdb "continue\n"
398 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
399 {pass "continue through exec"}
400 -re "$gdb_prompt $" {fail "continue through exec"}
401 timeout {fail "(timeout) continue through exec"}
405 # Start with a fresh gdb
409 gdb_reinitialize_dir $srcdir/$subdir
413 # This is a test of gdb's ability to follow a process through a
414 # Unix exec() system call.