1 # Copyright 1997-2014 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 standard_testfile foll-exec.c
28 set testfile2 "execd-prog"
29 set srcfile2 ${testfile2}.c
30 set binfile2 [standard_output_file ${testfile2}]
32 set compile_options debug
33 set dirname [relative_filename [pwd] [file dirname $binfile]]
34 lappend compile_options "additional_flags=-DBASEDIR=\"$dirname\""
36 # build the first test case
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $compile_options] != "" } {
38 untested foll-exec.exp
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $compile_options] != "" } {
43 untested foll-exec.exp
53 -re ".*Kill the program being debugged.*y or n. $" {
54 gdb_test_no_output "y" ""
55 send_gdb "file $binfile\n"
57 -re ".*Load new symbol table from.*y or n. $" {
60 -re "Reading symbols from.*$gdb_prompt $" {}
61 timeout { fail "loading symbols (timeout)"; return }
64 -re ".*gdb_prompt $" {}
65 timeout { fail "loading symbols (timeout)"; return }
68 -re ".*$gdb_prompt $" {}
69 timeout { fail "killing inferior (timeout)" ; return }
73 proc do_exec_tests {} {
81 # Start the program running, and stop at main.
83 if ![runto_main] then {
84 perror "Couldn't run ${testfile}"
88 # Verify that the system supports "catch exec".
89 gdb_test "catch exec" "Catchpoint \[0-9\]* \\(exec\\)" "insert first exec catchpoint"
90 set has_exec_catchpoints 0
91 gdb_test_multiple "continue" "continue to first exec catchpoint" {
92 -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
93 unsupported "continue to first exec catchpoint"
95 -re ".*Catchpoint.*$gdb_prompt $" {
96 set has_exec_catchpoints 1
97 pass "continue to first exec catchpoint"
101 if {$has_exec_catchpoints == 0} {
102 unsupported "exec catchpoints"
108 # Start the program running, and stop at main.
110 if ![runto_main] then {
111 perror "Couldn't run ${testfile}"
115 # Verify that we can see various global and local variables
116 # in this program, and that they have expected values. Some
117 # of these variables are also declared in the program we'll
122 -re "20.*execlp.*$gdb_prompt $"\
123 {pass "step to exec call"}
124 -re "$gdb_prompt $" {fail "step to exec call"}
125 timeout {fail "(timeout) step to exec call"}
127 send_gdb "print global_i\n"
129 -re ".* = 100.*$gdb_prompt $"\
130 {pass "print follow-exec/global_i"}
131 -re "$gdb_prompt $" {fail "print follow-exec/global_i"}
132 timeout {fail "(timeout) print follow-exec/global_i"}
134 send_gdb "print local_j\n"
136 -re ".* = 101.*$gdb_prompt $"\
137 {pass "print follow-exec/local_j"}
138 -re "$gdb_prompt $" {fail "print follow-exec/local_j"}
139 timeout {fail "(timeout) print follow-exec/local_j"}
141 send_gdb "print local_k\n"
143 -re ".* = 102.*$gdb_prompt $"\
144 {pass "print follow-exec/local_k"}
145 -re "$gdb_prompt $" {fail "print follow-exec/local_k"}
146 timeout {fail "(timeout) print follow-exec/local_k"}
149 # Try stepping through an execlp call, without catching it.
150 # We should stop in execd-program, at its first statement.
154 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
155 {pass "step through execlp call"}
156 -re "$gdb_prompt $" {fail "step through execlp call"}
157 timeout {fail "(timeout) step through execlp call"}
160 # Verify that we can see the variables defined in the newly-exec'd
161 # program, and CANNOT see those defined in the exec'ing program.
165 -re "26.*printf.*$gdb_prompt $"\
166 {pass "step after execlp call"}
167 -re "$gdb_prompt $" {fail "step after execlp call"}
168 timeout {fail "(timeout) step after execlp call"}
170 send_gdb "print global_i\n"
172 -re ".* = 0.*$gdb_prompt $"\
173 {pass "print execd-program/global_i (after execlp)"}
174 -re "$gdb_prompt $" {fail "print execd-program/global_i (after execlp)"}
175 timeout {fail "(timeout) print execd-program/global_i (after execlp)"}
177 send_gdb "print local_j\n"
179 -re ".* = 2.*$gdb_prompt $"\
180 {pass "print execd-program/local_j (after execlp)"}
181 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execlp)"}
182 timeout {fail "(timeout) print execd-program/local_j (after execlp)"}
184 send_gdb "print local_k\n"
186 -re "No symbol \"local_k\" in current context.*$gdb_prompt $"\
187 {pass "print follow-exec/local_k (after execlp)"}
188 -re "$gdb_prompt $" {fail "print follow-exec/local_k (after execlp)"}
189 timeout {fail "(timeout) print follow-exec/local_k (after execlp)"}
192 # Explicitly kill this program, or a subsequent rerun actually runs
193 # the exec'd program, not the original program...
196 # Start the program running, and stop at main.
198 if ![runto_main] then {
199 perror "Couldn't run ${testfile} (2nd try)"
203 # Verify that we can catch an exec event, and then continue
204 # to follow through the exec. (Since there's a breakpoint on
205 # "main", it'll also be transferred to the exec'd program,
206 # and we expect to stop there.)
208 send_gdb "catch exec\n"
210 -re "Catchpoint .*(exec).*$gdb_prompt $"\
211 {pass "set catch exec"}
212 -re "$gdb_prompt $" {fail "set catch exec"}
213 timeout {fail "(timeout) set catch exec"}
216 # Verify that the catchpoint is mentioned in an "info breakpoints",
217 # and further that the catchpoint mentions no program name.
219 set msg "info shows catchpoint without exec pathname"
220 gdb_test_multiple "info breakpoints" $msg {
221 -re ".*catchpoint.*keep y.*exec\[\n\r\]+$gdb_prompt $" {
227 # PA64 doesn't know about $START$ in dld.sl at this point. It should.
229 setup_xfail hppa2.0w-hp-hpux* CLLbs16760
230 send_gdb "continue\n"
232 -re ".*xecuting new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .*$gdb_prompt $"\
233 {pass "hit catch exec"}
234 -re "$gdb_prompt $" {fail "hit catch exec"}
235 timeout {fail "(timeout) hit catch exec"}
239 # test gets out of sync if previous test fails.
240 gdb_test "bt" ".*" "sync up after possible failure 1"
241 gdb_test "bt" "#0.*" "sync up after possible failure 2"
243 # Verify that the catchpoint is mentioned in an "info breakpoints",
244 # and further that the catchpoint managed to capture the exec'd
247 set msg "info shows catchpoint exec pathname"
248 gdb_test_multiple "info breakpoints" $msg {
249 -re ".*catchpoint.*keep y.*exec, program \".*${testfile2}\".*$gdb_prompt $" {
254 # Verify that we can continue from the catchpoint, and land in the
255 # main of the newly-exec'd program.
257 send_gdb "continue\n"
259 -re ".*${srcfile2}:23.*$gdb_prompt $"\
260 {pass "continue after hit catch exec"}
261 -re "$gdb_prompt $" {fail "continue after hit catch exec"}
262 timeout {fail "(timeout) continue after hit catch exec"}
265 # Explicitly kill this program, or a subsequent rerun actually runs
266 # the exec'd program, not the original program...
269 # Start the program running, and stop at main.
271 if ![runto_main] then {
272 perror "Couldn't run ${testfile} (3rd try)"
276 # Verify that we can follow through follow an execl()
277 # call. (We must jump around earlier exec* calls.)
279 send_gdb "tbreak 27\n"
281 -re "Temporary breakpoint .*file .*${srcfile}, line 27.*$gdb_prompt $"\
282 {pass "prepare to jump to execl call"}
283 -re "$gdb_prompt $" {fail "prepare to jump to execl call"}
284 timeout {fail "(timeout) prepare to jump to execl call"}
288 -re "main.* at .*${srcfile}:27.*$gdb_prompt $"\
289 {pass "jump to execl call"}
290 -re "$gdb_prompt $" {fail "jump to execl call"}
291 timeout {fail "(timeout) jump to execl call"}
293 # Note that stepping through an exec call causes the step-count
294 # to be reset to zero. I.e.: you may specify "next 2" at the
295 # call, but you'll actually stop at the first breakpoint set in
296 # the newly-exec'd program, not after the remaining step-count
301 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
302 {pass "step through execl call"}
303 -re "$gdb_prompt $" {fail "step through execl call"}
304 timeout {fail "(timeout) step through execl call"}
308 -re "26.*printf.*$gdb_prompt $"\
309 {pass "step after execl call"}
310 -re "$gdb_prompt $" {fail "step after execl call"}
311 timeout {fail "(timeout) step after execl call"}
314 # Verify that we can print a local variable (which happens to be
315 # assigned the value of main's argc).
317 send_gdb "print local_j\n"
319 -re ".* = 3.*$gdb_prompt $"\
320 {pass "print execd-program/local_j (after execl)"}
321 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execl)"}
322 timeout {fail "(timeout) print execd-program/local_j (after execl)"}
325 # Explicitly kill this program, or a subsequent rerun actually runs
326 # the exec'd program, not the original program...
329 # Start the program running, and stop at main.
331 if ![runto_main] then {
332 perror "Couldn't run ${testfile} (4th try)"
336 # Verify that we can follow through follow an execv()
337 # call. (We must jump around earlier exec* calls.)
339 send_gdb "tbreak 41\n"
341 -re "Temporary breakpoint .*file .*${srcfile}, line 41.*$gdb_prompt $"\
342 {pass "prepare to jump to execv call"}
343 -re "$gdb_prompt $" {fail "prepare to jump to execv call"}
344 timeout {fail "(timeout) prepare to jump to execv call"}
348 -re "main.* at .*${srcfile}:41.*$gdb_prompt $"\
349 {pass "jump to execv call"}
350 -re "$gdb_prompt $" {fail "jump to execv call"}
351 timeout {fail "(timeout) jump to execv call"}
355 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
356 {pass "step through execv call"}
357 -re "$gdb_prompt $" {fail "step through execv call"}
358 timeout {fail "(timeout) step through execv call"}
362 -re "26.*printf.*$gdb_prompt $"\
363 {pass "step after execv call"}
364 -re "$gdb_prompt $" {fail "step after execv call"}
365 timeout {fail "(timeout) step after execv call"}
368 # Verify that we can print a local variable (which happens to be
369 # assigned the value of main's argc).
371 send_gdb "print local_j\n"
373 -re ".* = 2.*$gdb_prompt $"\
374 {pass "print execd-program/local_j (after execv)"}
375 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execv)"}
376 timeout {fail "(timeout) print execd-program/local_j (after execv)"}
379 # Explicitly kill this program, or a subsequent rerun actually runs
380 # the exec'd program, not the original program...
383 # Start the program running, and stop at main.
385 if ![runto_main] then {
386 perror "Couldn't run ${testfile} (5th try)"
390 # Verify that we can just continue and thereby follow through an
391 # exec call. (Since the breakpoint on "main" is reset, we should
392 # just stop in main of the newly-exec'd program.)
394 send_gdb "continue\n"
396 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:23.*int local_j = argc;.*$gdb_prompt $"\
397 {pass "continue through exec"}
398 -re "$gdb_prompt $" {fail "continue through exec"}
399 timeout {fail "(timeout) continue through exec"}
403 # Start with a fresh gdb
407 gdb_reinitialize_dir $srcdir/$subdir
411 # This is a test of gdb's ability to follow a process through a
412 # Unix exec() system call.