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