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