]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.hp/foll-exec.exp
* config/sh/tm-sh.h (BELIEVE_PCC_PROMOTION): Define, so that
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.hp / 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 # are we on a target board
28 if ![isnative] then {
29 return
30 }
31
32 if {![istarget "hppa*-*-hpux10.30"] && ![istarget "hppa*-*-hpux11.*"]} {
33 #setup_xfail "*-*.*"
34 return 0
35 }
36
37 set testfile "foll-exec"
38 set testfile2 "execd-program"
39 set srcfile ${testfile}.c
40 set srcfile2 ${testfile2}.c
41 set binfile ${objdir}/${subdir}/${testfile}
42 set binfile2 ${objdir}/${subdir}/${testfile2}
43
44 # build the first test case
45 #if { [compile "-g -DNO_PROTOTYPES ${srcdir}/${subdir}/${srcfile2} -o ${binfile2} "] != "" } {
46 # perror "Couldn't compile ${srcfile2}"
47 # return -1
48 #}
49 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug}] != "" } {
50 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
51 }
52
53 #if { [compile "-g ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } {
54 # execute_anywhere "rm -f ${objdir}/${subdir}/${testfile}.tmp"
55 # built the second test case since we can't use prototypes
56 # warning "Prototypes not supported, rebuilding with -DNO_PROTOTYPES"
57 # execute_anywhere "echo set prototypes 0 > ${objdir}/${subdir}/${testfile}.tmp"
58 # if { [compile "-g -DNO_PROTOTYPES ${srcdir}/${subdir}/${srcfile} -o ${binfile} "] != "" } {
59 # perror "Couldn't compile ${testfile}.c"
60 # return -1
61 # }
62 #}
63
64 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
65 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
66 }
67
68
69 # Until "catch exec" is implemented on other targets...
70 #
71 if ![istarget "hppa*-hp-hpux*"] then {
72 setup_xfail "*-*-*"
73 }
74
75 proc zap_session {} {
76 global gdb_prompt
77 global binfile
78
79 send_gdb "kill\n"
80 gdb_expect {
81 -re ".*Kill the program being debugged.*y or n. $" {
82 send_gdb "y\n"
83 send_gdb "file $binfile\n"
84 gdb_expect {
85 -re ".*Load new symbol table from.*y or n. $" {
86 send_gdb "y\n"
87 gdb_expect {
88 -re "Reading symbols from.*$gdb_prompt $" {}
89 timeout { fail "loading symbols (timeout)"; return }
90 }
91 }
92 -re ".*gdb_prompt $" {}
93 timeout { fail "loading symbols (timeout)"; return }
94 }
95 }
96 -re ".*$gdb_prompt $" {}
97 timeout { fail "killing inferior (timeout)" ; return }
98 }
99 }
100
101 proc do_exec_tests {} {
102 global gdb_prompt
103 global binfile
104 global srcfile
105 global srcfile2
106 global testfile
107 global testfile2
108
109 # Start the program running, and stop at main.
110 #
111 if ![runto_main] then {
112 perror "Couldn't run ${testfile}"
113 return
114 }
115
116 # Verify that we can see various global and local variables
117 # in this program, and that they have expected values. Some
118 # of these variables are also declared in the program we'll
119 # exec in a moment.
120 #
121 send_gdb "next 3\n"
122 gdb_expect {
123 -re "12.*execlp.*$gdb_prompt $"\
124 {pass "step to exec call"}
125 -re "$gdb_prompt $" {fail "step to exec call"}
126 timeout {fail "(timeout) step to exec call"}
127 }
128 send_gdb "print global_i\n"
129 gdb_expect {
130 -re ".* = 100.*$gdb_prompt $"\
131 {pass "print follow-exec/global_i"}
132 -re "$gdb_prompt $" {fail "print follow-exec/global_i"}
133 timeout {fail "(timeout) print follow-exec/global_i"}
134 }
135 send_gdb "print local_j\n"
136 gdb_expect {
137 -re ".* = 101.*$gdb_prompt $"\
138 {pass "print follow-exec/local_j"}
139 -re "$gdb_prompt $" {fail "print follow-exec/local_j"}
140 timeout {fail "(timeout) print follow-exec/local_j"}
141 }
142 send_gdb "print local_k\n"
143 gdb_expect {
144 -re ".* = 102.*$gdb_prompt $"\
145 {pass "print follow-exec/local_k"}
146 -re "$gdb_prompt $" {fail "print follow-exec/local_k"}
147 timeout {fail "(timeout) print follow-exec/local_k"}
148 }
149
150 # Try stepping through an execlp call, without catching it.
151 # We should stop in execd-program, at its first statement.
152 #
153 send_gdb "next\n"
154 gdb_expect {
155 -re "Executing new program: .*${testfile2}.*${srcfile2}:17.*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"}
159 }
160
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.
163 #
164 send_gdb "next\n"
165 gdb_expect {
166 -re "20.*printf.*$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"}
170 }
171 send_gdb "print global_i\n"
172 gdb_expect {
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)"}
177 }
178 send_gdb "print local_j\n"
179 gdb_expect {
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)"}
184 }
185 send_gdb "print local_k\n"
186 gdb_expect {
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)"}
191 }
192
193 # Explicitly kill this program, or a subsequent rerun actually runs
194 # the exec'd program, not the original program...
195 zap_session
196
197 # Start the program running, and stop at main.
198 #
199 if ![runto_main] then {
200 perror "Couldn't run ${testfile} (2nd try)"
201 return
202 }
203
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.)
208 #
209 send_gdb "catch exec\n"
210 gdb_expect {
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"}
215 }
216
217 # Verify that the catchpoint is mentioned in an "info breakpoints",
218 # and further that the catchpoint mentions no program name.
219 #
220 send_gdb "info breakpoints\n"
221 gdb_expect {
222 -re ".*catch exec.*keep y.*$gdb_prompt $"\
223 {pass "info shows catchpoint without exec pathname"}
224 -re ".*catch exec.*program \"\".*$gdb_prompt $"\
225 {fail "info shows catchpoint without exec pathname"}
226 -re "$gdb_prompt $" {fail "info shows catchpoint without exec pathname"}
227 timeout {fail "(timeout) info shows catchpoint without exec pathname"}
228 }
229
230 send_gdb "continue\n"
231 gdb_expect {
232 -re ".*Executing new program:.*${testfile2}.*Catchpoint .*(exec\'d .*${testfile2}).*in .START..*$gdb_prompt $"\
233 {pass "hit catch exec"}
234 -re "$gdb_prompt $" {fail "hit catch exec"}
235 timeout {fail "(timeout) hit catch exec"}
236 }
237
238 # Verify that the catchpoint is mentioned in an "info breakpoints",
239 # and further that the catchpoint managed to capture the exec'd
240 # program's name.
241 #
242 send_gdb "info breakpoints\n"
243 gdb_expect {
244 -re ".*catch exec .*program \".*${testfile2}\".*$gdb_prompt $"\
245 {pass "info shows catchpoint exec pathname"}
246 -re "$gdb_prompt $" {fail "info shows catchpoint exec pathname"}
247 timeout {fail "(timeout) info shows catchpoint exec pathname"}
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}:17.*$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 19\n"
276 gdb_expect {
277 -re "Breakpoint .*file .*${srcfile}, line 19.*$gdb_prompt $"\
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 19\n"
283 gdb_expect {
284 -re "main.* at .*${srcfile}:19.*$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 {
297 -re "Executing new program: .*${testfile2}.*${srcfile2}:17.*int local_j = argc;.*$gdb_prompt $"\
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 "20.*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 33\n"
336 gdb_expect {
337 -re "Breakpoint .*file .*${srcfile}, line 33.*$gdb_prompt $"\
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 33\n"
343 gdb_expect {
344 -re "main.* at .*${srcfile}:33.*$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 {
351 -re "Executing new program: .*${testfile2}.*${srcfile2}:17.*int local_j = argc;.*$gdb_prompt $"\
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 "20.*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} (4th 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 {
392 -re "Executing new program: .*${testfile2}.*${srcfile2}:17.*int local_j = argc;.*$gdb_prompt $"\
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
401 gdb_exit
402 gdb_start
403 gdb_reinitialize_dir $srcdir/$subdir
404 gdb_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 #
410 do_exec_tests
411
412 return 0