Remove HP-UX references fom testsuite
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / foll-exec.exp
CommitLineData
32d0add0 1# Copyright 1997-2015 Free Software Foundation, Inc.
74cf1395
JM
2
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
74cf1395 6# (at your option) any later version.
e22f8b7c 7#
74cf1395
JM
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.
e22f8b7c 12#
74cf1395 13# You should have received a copy of the GNU General Public License
e85a822c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
74cf1395 15
2fd33e94
DB
16# This is a test of gdb's ability to follow a process through a
17# Unix exec() system call.
18
2d4e0376
YQ
19# Until "catch exec" is implemented on other targets...
20#
3ca22649 21if { ![istarget "*-linux*"] } then {
2d4e0376
YQ
22 continue
23}
74cf1395 24
289f9037
TT
25standard_testfile foll-exec.c
26
74cf1395 27set testfile2 "execd-prog"
74cf1395 28set srcfile2 ${testfile2}.c
289f9037 29set binfile2 [standard_output_file ${testfile2}]
74cf1395 30
3fef966c
TT
31set compile_options debug
32set dirname [relative_filename [pwd] [file dirname $binfile]]
33lappend compile_options "additional_flags=-DBASEDIR=\"$dirname\""
34
74cf1395 35# build the first test case
3fef966c 36if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $compile_options] != "" } {
b60f0898
JB
37 untested foll-exec.exp
38 return -1
74cf1395
JM
39}
40
3fef966c 41if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $compile_options] != "" } {
b60f0898
JB
42 untested foll-exec.exp
43 return -1
74cf1395
JM
44}
45
74cf1395 46proc do_exec_tests {} {
2fd33e94 47 global binfile srcfile srcfile2 testfile testfile2
74cf1395 48 global gdb_prompt
74cf1395
JM
49
50 # Start the program running, and stop at main.
51 #
52 if ![runto_main] then {
2fd33e94 53 fail "Couldn't run ${testfile}"
74cf1395
JM
54 return
55 }
56
e85a822c
DJ
57 # Verify that the system supports "catch exec".
58 gdb_test "catch exec" "Catchpoint \[0-9\]* \\(exec\\)" "insert first exec catchpoint"
59 set has_exec_catchpoints 0
60 gdb_test_multiple "continue" "continue to first exec catchpoint" {
77b06cd7 61 -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
e85a822c
DJ
62 unsupported "continue to first exec catchpoint"
63 }
64 -re ".*Catchpoint.*$gdb_prompt $" {
65 set has_exec_catchpoints 1
66 pass "continue to first exec catchpoint"
67 }
68 }
69
70 if {$has_exec_catchpoints == 0} {
71 unsupported "exec catchpoints"
72 return
73 }
74
2fd33e94 75 clean_restart $binfile
e85a822c
DJ
76
77 # Start the program running, and stop at main.
78 #
79 if ![runto_main] then {
2fd33e94 80 fail "Couldn't run ${testfile}"
e85a822c
DJ
81 return
82 }
83
74cf1395
JM
84 # Verify that we can see various global and local variables
85 # in this program, and that they have expected values. Some
86 # of these variables are also declared in the program we'll
87 # exec in a moment.
88 #
89 send_gdb "next 3\n"
90 gdb_expect {
58fa2af0 91 -re "execlp \\(.*$gdb_prompt $"\
74cf1395
JM
92 {pass "step to exec call"}
93 -re "$gdb_prompt $" {fail "step to exec call"}
94 timeout {fail "(timeout) step to exec call"}
95 }
96 send_gdb "print global_i\n"
97 gdb_expect {
98 -re ".* = 100.*$gdb_prompt $"\
99 {pass "print follow-exec/global_i"}
100 -re "$gdb_prompt $" {fail "print follow-exec/global_i"}
101 timeout {fail "(timeout) print follow-exec/global_i"}
102 }
103 send_gdb "print local_j\n"
104 gdb_expect {
105 -re ".* = 101.*$gdb_prompt $"\
106 {pass "print follow-exec/local_j"}
107 -re "$gdb_prompt $" {fail "print follow-exec/local_j"}
108 timeout {fail "(timeout) print follow-exec/local_j"}
109 }
110 send_gdb "print local_k\n"
111 gdb_expect {
112 -re ".* = 102.*$gdb_prompt $"\
113 {pass "print follow-exec/local_k"}
114 -re "$gdb_prompt $" {fail "print follow-exec/local_k"}
115 timeout {fail "(timeout) print follow-exec/local_k"}
116 }
117
118 # Try stepping through an execlp call, without catching it.
119 # We should stop in execd-program, at its first statement.
120 #
58fa2af0 121 set execd_line [gdb_get_line_number "after-exec" $srcfile2]
74cf1395
JM
122 send_gdb "next\n"
123 gdb_expect {
58fa2af0 124 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
74cf1395
JM
125 {pass "step through execlp call"}
126 -re "$gdb_prompt $" {fail "step through execlp call"}
127 timeout {fail "(timeout) step through execlp call"}
128 }
129
130 # Verify that we can see the variables defined in the newly-exec'd
131 # program, and CANNOT see those defined in the exec'ing program.
132 #
133 send_gdb "next\n"
134 gdb_expect {
58fa2af0 135 -re "printf \\(.Hello .*$gdb_prompt $"\
74cf1395
JM
136 {pass "step after execlp call"}
137 -re "$gdb_prompt $" {fail "step after execlp call"}
138 timeout {fail "(timeout) step after execlp call"}
139 }
140 send_gdb "print global_i\n"
141 gdb_expect {
142 -re ".* = 0.*$gdb_prompt $"\
143 {pass "print execd-program/global_i (after execlp)"}
144 -re "$gdb_prompt $" {fail "print execd-program/global_i (after execlp)"}
145 timeout {fail "(timeout) print execd-program/global_i (after execlp)"}
146 }
147 send_gdb "print local_j\n"
148 gdb_expect {
149 -re ".* = 2.*$gdb_prompt $"\
150 {pass "print execd-program/local_j (after execlp)"}
151 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execlp)"}
152 timeout {fail "(timeout) print execd-program/local_j (after execlp)"}
153 }
154 send_gdb "print local_k\n"
155 gdb_expect {
156 -re "No symbol \"local_k\" in current context.*$gdb_prompt $"\
157 {pass "print follow-exec/local_k (after execlp)"}
158 -re "$gdb_prompt $" {fail "print follow-exec/local_k (after execlp)"}
159 timeout {fail "(timeout) print follow-exec/local_k (after execlp)"}
160 }
161
162 # Explicitly kill this program, or a subsequent rerun actually runs
163 # the exec'd program, not the original program...
2fd33e94 164 clean_restart $binfile
74cf1395
JM
165
166 # Start the program running, and stop at main.
167 #
168 if ![runto_main] then {
2fd33e94 169 fail "Couldn't run ${testfile} (2nd try)"
74cf1395
JM
170 return
171 }
172
173 # Verify that we can catch an exec event, and then continue
174 # to follow through the exec. (Since there's a breakpoint on
175 # "main", it'll also be transferred to the exec'd program,
176 # and we expect to stop there.)
177 #
178 send_gdb "catch exec\n"
179 gdb_expect {
180 -re "Catchpoint .*(exec).*$gdb_prompt $"\
181 {pass "set catch exec"}
182 -re "$gdb_prompt $" {fail "set catch exec"}
183 timeout {fail "(timeout) set catch exec"}
184 }
185
186 # Verify that the catchpoint is mentioned in an "info breakpoints",
187 # and further that the catchpoint mentions no program name.
188 #
462f405c
JB
189 set msg "info shows catchpoint without exec pathname"
190 gdb_test_multiple "info breakpoints" $msg {
191 -re ".*catchpoint.*keep y.*exec\[\n\r\]+$gdb_prompt $" {
192 pass $msg
193 }
74cf1395
JM
194 }
195
74cf1395
JM
196 send_gdb "continue\n"
197 gdb_expect {
6c95b8df 198 -re ".*xecuting new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .*$gdb_prompt $"\
74cf1395
JM
199 {pass "hit catch exec"}
200 -re "$gdb_prompt $" {fail "hit catch exec"}
201 timeout {fail "(timeout) hit catch exec"}
202 }
203
204 # DTS CLLbs16760
205 # test gets out of sync if previous test fails.
206 gdb_test "bt" ".*" "sync up after possible failure 1"
207 gdb_test "bt" "#0.*" "sync up after possible failure 2"
208
209 # Verify that the catchpoint is mentioned in an "info breakpoints",
210 # and further that the catchpoint managed to capture the exec'd
211 # program's name.
212 #
462f405c
JB
213 set msg "info shows catchpoint exec pathname"
214 gdb_test_multiple "info breakpoints" $msg {
215 -re ".*catchpoint.*keep y.*exec, program \".*${testfile2}\".*$gdb_prompt $" {
216 pass $msg
217 }
74cf1395
JM
218 }
219
220 # Verify that we can continue from the catchpoint, and land in the
221 # main of the newly-exec'd program.
222 #
223 send_gdb "continue\n"
224 gdb_expect {
58fa2af0 225 -re ".*${srcfile2}:${execd_line}.*$gdb_prompt $"\
74cf1395
JM
226 {pass "continue after hit catch exec"}
227 -re "$gdb_prompt $" {fail "continue after hit catch exec"}
228 timeout {fail "(timeout) continue after hit catch exec"}
229 }
230
231 # Explicitly kill this program, or a subsequent rerun actually runs
232 # the exec'd program, not the original program...
2fd33e94 233 clean_restart $binfile
74cf1395
JM
234
235 # Start the program running, and stop at main.
236 #
237 if ![runto_main] then {
2fd33e94 238 fail "Couldn't run ${testfile} (3rd try)"
74cf1395
JM
239 return
240 }
241
242 # Verify that we can follow through follow an execl()
243 # call. (We must jump around earlier exec* calls.)
244 #
58fa2af0
AA
245 set tbreak_line [gdb_get_line_number "tbreak-execl" $srcfile]
246 send_gdb "tbreak ${tbreak_line}\n"
74cf1395 247 gdb_expect {
58fa2af0 248 -re "Temporary breakpoint .*file .*${srcfile}, line ${tbreak_line}.*$gdb_prompt $"\
74cf1395
JM
249 {pass "prepare to jump to execl call"}
250 -re "$gdb_prompt $" {fail "prepare to jump to execl call"}
251 timeout {fail "(timeout) prepare to jump to execl call"}
252 }
58fa2af0 253 send_gdb "jump ${tbreak_line}\n"
74cf1395 254 gdb_expect {
58fa2af0 255 -re "main.* at .*${srcfile}:${tbreak_line}.*$gdb_prompt $"\
74cf1395
JM
256 {pass "jump to execl call"}
257 -re "$gdb_prompt $" {fail "jump to execl call"}
258 timeout {fail "(timeout) jump to execl call"}
259 }
260 # Note that stepping through an exec call causes the step-count
261 # to be reset to zero. I.e.: you may specify "next 2" at the
262 # call, but you'll actually stop at the first breakpoint set in
263 # the newly-exec'd program, not after the remaining step-count
264 # reaches zero.
265 #
266 send_gdb "next 2\n"
267 gdb_expect {
58fa2af0 268 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
74cf1395
JM
269 {pass "step through execl call"}
270 -re "$gdb_prompt $" {fail "step through execl call"}
271 timeout {fail "(timeout) step through execl call"}
272 }
273 send_gdb "next\n"
274 gdb_expect {
58fa2af0 275 -re "printf \\(.Hello .*$gdb_prompt $"\
74cf1395
JM
276 {pass "step after execl call"}
277 -re "$gdb_prompt $" {fail "step after execl call"}
278 timeout {fail "(timeout) step after execl call"}
279 }
280
281 # Verify that we can print a local variable (which happens to be
282 # assigned the value of main's argc).
283 #
284 send_gdb "print local_j\n"
285 gdb_expect {
286 -re ".* = 3.*$gdb_prompt $"\
287 {pass "print execd-program/local_j (after execl)"}
288 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execl)"}
289 timeout {fail "(timeout) print execd-program/local_j (after execl)"}
290 }
291
292 # Explicitly kill this program, or a subsequent rerun actually runs
293 # the exec'd program, not the original program...
2fd33e94 294 clean_restart $binfile
74cf1395
JM
295
296 # Start the program running, and stop at main.
297 #
298 if ![runto_main] then {
2fd33e94 299 fail "Couldn't run ${testfile} (4th try)"
74cf1395
JM
300 return
301 }
302
303 # Verify that we can follow through follow an execv()
304 # call. (We must jump around earlier exec* calls.)
305 #
58fa2af0
AA
306 set tbreak_line [gdb_get_line_number "tbreak-execv"]
307 send_gdb "tbreak ${tbreak_line}\n"
74cf1395 308 gdb_expect {
58fa2af0 309 -re "Temporary breakpoint .*file .*${srcfile}, line ${tbreak_line}.*$gdb_prompt $"\
74cf1395
JM
310 {pass "prepare to jump to execv call"}
311 -re "$gdb_prompt $" {fail "prepare to jump to execv call"}
312 timeout {fail "(timeout) prepare to jump to execv call"}
313 }
58fa2af0 314 send_gdb "jump ${tbreak_line}\n"
74cf1395 315 gdb_expect {
58fa2af0 316 -re "main.* at .*${srcfile}:${tbreak_line}.*$gdb_prompt $"\
74cf1395
JM
317 {pass "jump to execv call"}
318 -re "$gdb_prompt $" {fail "jump to execv call"}
319 timeout {fail "(timeout) jump to execv call"}
320 }
321 send_gdb "next\n"
322 gdb_expect {
58fa2af0 323 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
74cf1395
JM
324 {pass "step through execv call"}
325 -re "$gdb_prompt $" {fail "step through execv call"}
326 timeout {fail "(timeout) step through execv call"}
327 }
328 send_gdb "next\n"
329 gdb_expect {
58fa2af0 330 -re "printf \\(.Hello .*$gdb_prompt $"\
74cf1395
JM
331 {pass "step after execv call"}
332 -re "$gdb_prompt $" {fail "step after execv call"}
333 timeout {fail "(timeout) step after execv call"}
334 }
335
336 # Verify that we can print a local variable (which happens to be
337 # assigned the value of main's argc).
338 #
339 send_gdb "print local_j\n"
340 gdb_expect {
341 -re ".* = 2.*$gdb_prompt $"\
342 {pass "print execd-program/local_j (after execv)"}
343 -re "$gdb_prompt $" {fail "print execd-program/local_j (after execv)"}
344 timeout {fail "(timeout) print execd-program/local_j (after execv)"}
345 }
346
347 # Explicitly kill this program, or a subsequent rerun actually runs
348 # the exec'd program, not the original program...
2fd33e94 349 clean_restart $binfile
74cf1395
JM
350
351 # Start the program running, and stop at main.
352 #
353 if ![runto_main] then {
2fd33e94 354 fail "Couldn't run ${testfile} (5th try)"
74cf1395
JM
355 return
356 }
357
358 # Verify that we can just continue and thereby follow through an
359 # exec call. (Since the breakpoint on "main" is reset, we should
360 # just stop in main of the newly-exec'd program.)
361 #
362 send_gdb "continue\n"
363 gdb_expect {
58fa2af0 364 -re ".*xecuting new program: .*${testfile2}.*${srcfile2}:${execd_line}.*int local_j = argc;.*$gdb_prompt $"\
74cf1395
JM
365 {pass "continue through exec"}
366 -re "$gdb_prompt $" {fail "continue through exec"}
367 timeout {fail "(timeout) continue through exec"}
368 }
369}
370
371# Start with a fresh gdb
372
373gdb_exit
2fd33e94 374clean_restart $binfile
74cf1395 375
74cf1395
JM
376do_exec_tests
377
378return 0
This page took 1.632048 seconds and 4 git commands to generate.