1 # Copyright 1997-2013 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 {
20 # Until "catch exec" is implemented on other targets...
22 if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
26 set testfile "foll-exec"
27 set testfile2 "execd-prog"
28 set srcfile ${testfile}.c
29 set srcfile2 ${testfile2}.c
30 set binfile ${objdir}/${subdir}/${testfile}
31 set binfile2 ${objdir}/${subdir}/${testfile2}
33 # build the first test case
34 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
35 untested foll-exec.exp
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40 untested foll-exec.exp
50 -re ".*Kill the program being debugged.*y or n. $" {
51 gdb_test_no_output "y" ""
52 send_gdb "file $binfile\n"
54 -re ".*Load new symbol table from.*y or n. $" {
57 -re "Reading symbols from.*$gdb_prompt $" {}
58 timeout { fail "loading symbols (timeout)"; return }
61 -re ".*gdb_prompt $" {}
62 timeout { fail "loading symbols (timeout)"; return }
65 -re ".*$gdb_prompt $" {}
66 timeout { fail "killing inferior (timeout)" ; return }
70 proc do_exec_tests {} {
78 # Start the program running, and stop at main.
80 if ![runto_main] then {
81 perror "Couldn't run ${testfile}"
85 # Verify that the system supports "catch exec".
86 gdb_test "catch exec" "Catchpoint \[0-9\]* \\(exec\\)" "insert first exec catchpoint"
87 set has_exec_catchpoints 0
88 gdb_test_multiple "continue" "continue to first exec catchpoint" {
89 -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
90 unsupported "continue to first exec catchpoint"
92 -re ".*Catchpoint.*$gdb_prompt $" {
93 set has_exec_catchpoints 1
94 pass "continue to first exec catchpoint"
98 if {$has_exec_catchpoints == 0} {
99 unsupported "exec catchpoints"
105 # Start the program running, and stop at main.
107 if ![runto_main] then {
108 perror "Couldn't run ${testfile}"
112 # Verify that we can see various global and local variables
113 # in this program, and that they have expected values. Some
114 # of these variables are also declared in the program we'll
119 -re "20.*execlp.*$gdb_prompt $"\
120 {pass "step to exec call"}
121 -re "$gdb_prompt $" {fail "step to exec call"}
122 timeout {fail "(timeout) step to exec call"}
124 send_gdb "print global_i\n"
126 -re ".* = 100.*$gdb_prompt $"\
127 {pass "print follow-exec/global_i"}
128 -re "$gdb_prompt $" {fail "print follow-exec/global_i"}
129 timeout {fail "(timeout) print follow-exec/global_i"}
131 send_gdb "print local_j\n"
133 -re ".* = 101.*$gdb_prompt $"\
134 {pass "print follow-exec/local_j"}
135 -re "$gdb_prompt $" {fail "print follow-exec/local_j"}
136 timeout {fail "(timeout) print follow-exec/local_j"}
138 send_gdb "print local_k\n"
140 -re ".* = 102.*$gdb_prompt $"\
141 {pass "print follow-exec/local_k"}
142 -re "$gdb_prompt $" {fail "print follow-exec/local_k"}
143 timeout {fail "(timeout) print follow-exec/local_k"}
146 # Try stepping through an execlp call, without catching it.
147 # We should stop in execd-program, at its first statement.
151 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
152 {pass "step through execlp call"}
153 -re "$gdb_prompt $" {fail "step through execlp call"}
154 timeout {fail "(timeout) step through execlp call"}
157 # Verify that we can see the variables defined in the newly-exec'd
158 # program, and CANNOT see those defined in the exec'ing program.
162 -re "26.*printf.*$gdb_prompt $"\
163 {pass "step after execlp call"}
164 -re "$gdb_prompt $" {fail "step after execlp call"}
165 timeout {fail "(timeout) step after execlp call"}
167 send_gdb "print global_i\n"
169 -re ".* = 0.*$gdb_prompt $"\
170 {pass "print execd-program/global_i (after execlp)"}
171 -re "$gdb_prompt $" {fail "print execd-program/global_i (after execlp)"}
172 timeout {fail "(timeout) print execd-program/global_i (after execlp)"}
174 send_gdb "print local_j\n"
176 -re ".* = 2.*$gdb_prompt $"\
177 {pass "print execd-program/local_j (after execlp)"}
178 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execlp)"}
179 timeout {fail "(timeout) print execd-program/local_j (after execlp)"}
181 send_gdb "print local_k\n"
183 -re "No symbol \"local_k\" in current context.*$gdb_prompt $"\
184 {pass "print follow-exec/local_k (after execlp)"}
185 -re "$gdb_prompt $" {fail "print follow-exec/local_k (after execlp)"}
186 timeout {fail "(timeout) print follow-exec/local_k (after execlp)"}
189 # Explicitly kill this program, or a subsequent rerun actually runs
190 # the exec'd program, not the original program...
193 # Start the program running, and stop at main.
195 if ![runto_main] then {
196 perror "Couldn't run ${testfile} (2nd try)"
200 # Verify that we can catch an exec event, and then continue
201 # to follow through the exec. (Since there's a breakpoint on
202 # "main", it'll also be transferred to the exec'd program,
203 # and we expect to stop there.)
205 send_gdb "catch exec\n"
207 -re "Catchpoint .*(exec).*$gdb_prompt $"\
208 {pass "set catch exec"}
209 -re "$gdb_prompt $" {fail "set catch exec"}
210 timeout {fail "(timeout) set catch exec"}
213 # Verify that the catchpoint is mentioned in an "info breakpoints",
214 # and further that the catchpoint mentions no program name.
216 set msg "info shows catchpoint without exec pathname"
217 gdb_test_multiple "info breakpoints" $msg {
218 -re ".*catchpoint.*keep y.*exec\[\n\r\]+$gdb_prompt $" {
224 # PA64 doesn't know about $START$ in dld.sl at this point. It should.
226 setup_xfail hppa2.0w-hp-hpux* CLLbs16760
227 send_gdb "continue\n"
229 -re ".*xecuting new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .*$gdb_prompt $"\
230 {pass "hit catch exec"}
231 -re "$gdb_prompt $" {fail "hit catch exec"}
232 timeout {fail "(timeout) hit catch exec"}
236 # test gets out of sync if previous test fails.
237 gdb_test "bt" ".*" "sync up after possible failure 1"
238 gdb_test "bt" "#0.*" "sync up after possible failure 2"
240 # Verify that the catchpoint is mentioned in an "info breakpoints",
241 # and further that the catchpoint managed to capture the exec'd
244 set msg "info shows catchpoint exec pathname"
245 gdb_test_multiple "info breakpoints" $msg {
246 -re ".*catchpoint.*keep y.*exec, program \".*${testfile2}\".*$gdb_prompt $" {
251 # Verify that we can continue from the catchpoint, and land in the
252 # main of the newly-exec'd program.
254 send_gdb "continue\n"
256 -re ".*${srcfile2}:23.*$gdb_prompt $"\
257 {pass "continue after hit catch exec"}
258 -re "$gdb_prompt $" {fail "continue after hit catch exec"}
259 timeout {fail "(timeout) continue after hit catch exec"}
262 # Explicitly kill this program, or a subsequent rerun actually runs
263 # the exec'd program, not the original program...
266 # Start the program running, and stop at main.
268 if ![runto_main] then {
269 perror "Couldn't run ${testfile} (3rd try)"
273 # Verify that we can follow through follow an execl()
274 # call. (We must jump around earlier exec* calls.)
276 send_gdb "tbreak 27\n"
278 -re "Temporary breakpoint .*file .*${srcfile}, line 27.*$gdb_prompt $"\
279 {pass "prepare to jump to execl call"}
280 -re "$gdb_prompt $" {fail "prepare to jump to execl call"}
281 timeout {fail "(timeout) prepare to jump to execl call"}
285 -re "main.* at .*${srcfile}:27.*$gdb_prompt $"\
286 {pass "jump to execl call"}
287 -re "$gdb_prompt $" {fail "jump to execl call"}
288 timeout {fail "(timeout) jump to execl call"}
290 # Note that stepping through an exec call causes the step-count
291 # to be reset to zero. I.e.: you may specify "next 2" at the
292 # call, but you'll actually stop at the first breakpoint set in
293 # the newly-exec'd program, not after the remaining step-count
298 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
299 {pass "step through execl call"}
300 -re "$gdb_prompt $" {fail "step through execl call"}
301 timeout {fail "(timeout) step through execl call"}
305 -re "26.*printf.*$gdb_prompt $"\
306 {pass "step after execl call"}
307 -re "$gdb_prompt $" {fail "step after execl call"}
308 timeout {fail "(timeout) step after execl call"}
311 # Verify that we can print a local variable (which happens to be
312 # assigned the value of main's argc).
314 send_gdb "print local_j\n"
316 -re ".* = 3.*$gdb_prompt $"\
317 {pass "print execd-program/local_j (after execl)"}
318 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execl)"}
319 timeout {fail "(timeout) print execd-program/local_j (after execl)"}
322 # Explicitly kill this program, or a subsequent rerun actually runs
323 # the exec'd program, not the original program...
326 # Start the program running, and stop at main.
328 if ![runto_main] then {
329 perror "Couldn't run ${testfile} (4th try)"
333 # Verify that we can follow through follow an execv()
334 # call. (We must jump around earlier exec* calls.)
336 send_gdb "tbreak 41\n"
338 -re "Temporary breakpoint .*file .*${srcfile}, line 41.*$gdb_prompt $"\
339 {pass "prepare to jump to execv call"}
340 -re "$gdb_prompt $" {fail "prepare to jump to execv call"}
341 timeout {fail "(timeout) prepare to jump to execv call"}
345 -re "main.* at .*${srcfile}:41.*$gdb_prompt $"\
346 {pass "jump to execv call"}
347 -re "$gdb_prompt $" {fail "jump to execv call"}
348 timeout {fail "(timeout) jump to execv call"}
352 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
353 {pass "step through execv call"}
354 -re "$gdb_prompt $" {fail "step through execv call"}
355 timeout {fail "(timeout) step through execv call"}
359 -re "26.*printf.*$gdb_prompt $"\
360 {pass "step after execv call"}
361 -re "$gdb_prompt $" {fail "step after execv call"}
362 timeout {fail "(timeout) step after execv call"}
365 # Verify that we can print a local variable (which happens to be
366 # assigned the value of main's argc).
368 send_gdb "print local_j\n"
370 -re ".* = 2.*$gdb_prompt $"\
371 {pass "print execd-program/local_j (after execv)"}
372 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execv)"}
373 timeout {fail "(timeout) print execd-program/local_j (after execv)"}
376 # Explicitly kill this program, or a subsequent rerun actually runs
377 # the exec'd program, not the original program...
380 # Start the program running, and stop at main.
382 if ![runto_main] then {
383 perror "Couldn't run ${testfile} (5th try)"
387 # Verify that we can just continue and thereby follow through an
388 # exec call. (Since the breakpoint on "main" is reset, we should
389 # just stop in main of the newly-exec'd program.)
391 send_gdb "continue\n"
393 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
394 {pass "continue through exec"}
395 -re "$gdb_prompt $" {fail "continue through exec"}
396 timeout {fail "(timeout) continue through exec"}
400 # Start with a fresh gdb
404 gdb_reinitialize_dir $srcdir/$subdir
408 # This is a test of gdb's ability to follow a process through a
409 # Unix exec() system call.