1 # Copyright 1997-2015 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 "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.
152 set execd_line [gdb_get_line_number "after-exec" $srcfile2]
155 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*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 "printf \\(.Hello .*$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 ".*xecuting 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}:${execd_line}.*$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 set tbreak_line [gdb_get_line_number "tbreak-execl" $srcfile]
281 send_gdb "tbreak ${tbreak_line}\n"
283 -re "Temporary breakpoint .*file .*${srcfile}, line ${tbreak_line}.*$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"}
288 send_gdb "jump ${tbreak_line}\n"
290 -re "main.* at .*${srcfile}:${tbreak_line}.*$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}:${execd_line}.*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 "printf \\(.Hello .*$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 set tbreak_line [gdb_get_line_number "tbreak-execv"]
342 send_gdb "tbreak ${tbreak_line}\n"
344 -re "Temporary breakpoint .*file .*${srcfile}, line ${tbreak_line}.*$gdb_prompt $"\
345 {pass "prepare to jump to execv call"}
346 -re "$gdb_prompt $" {fail "prepare to jump to execv call"}
347 timeout {fail "(timeout) prepare to jump to execv call"}
349 send_gdb "jump ${tbreak_line}\n"
351 -re "main.* at .*${srcfile}:${tbreak_line}.*$gdb_prompt $"\
352 {pass "jump to execv call"}
353 -re "$gdb_prompt $" {fail "jump to execv call"}
354 timeout {fail "(timeout) jump to execv call"}
358 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
359 {pass "step through execv call"}
360 -re "$gdb_prompt $" {fail "step through execv call"}
361 timeout {fail "(timeout) step through execv call"}
365 -re "printf \\(.Hello .*$gdb_prompt $"\
366 {pass "step after execv call"}
367 -re "$gdb_prompt $" {fail "step after execv call"}
368 timeout {fail "(timeout) step after execv call"}
371 # Verify that we can print a local variable (which happens to be
372 # assigned the value of main's argc).
374 send_gdb "print local_j\n"
376 -re ".* = 2.*$gdb_prompt $"\
377 {pass "print execd-program/local_j (after execv)"}
378 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execv)"}
379 timeout {fail "(timeout) print execd-program/local_j (after execv)"}
382 # Explicitly kill this program, or a subsequent rerun actually runs
383 # the exec'd program, not the original program...
386 # Start the program running, and stop at main.
388 if ![runto_main] then {
389 perror "Couldn't run ${testfile} (5th try)"
393 # Verify that we can just continue and thereby follow through an
394 # exec call. (Since the breakpoint on "main" is reset, we should
395 # just stop in main of the newly-exec'd program.)
397 send_gdb "continue\n"
399 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
400 {pass "continue through exec"}
401 -re "$gdb_prompt $" {fail "continue through exec"}
402 timeout {fail "(timeout) continue through exec"}
406 # Start with a fresh gdb
410 gdb_reinitialize_dir $srcdir/$subdir
414 # This is a test of gdb's ability to follow a process through a
415 # Unix exec() system call.