OSDN Git Service

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