OSDN Git Service

Copyright updates for 2007.
[pf3gnuchains/pf3gnuchains3x.git] / gdb / testsuite / gdb.base / reread.exp
1 # Copyright 1998, 2000, 2001, 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 set prms_id 0
25 set bug_id 0
26
27 set prototypes 1
28
29 # build the first test case
30
31 set testfile1 "reread1"
32 set srcfile1 ${testfile1}.c
33 # Cygwin needs $EXEEXT.
34 set binfile1 ${objdir}/${subdir}/${testfile1}$EXEEXT
35
36 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile1}" executable {debug nowarnings}] != "" } {
37     untested reread.exp
38     return -1
39 }
40
41 # build the second test case
42
43 set testfile2 "reread2"
44 set srcfile2 ${testfile2}.c
45 set binfile2 ${objdir}/${subdir}/${testfile2}$EXEEXT
46
47 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug nowarnings}] != "" } {
48     untested reread.exp
49     return -1
50 }
51
52 # Start with a fresh gdb.
53
54 set testfile "reread"
55 set binfile ${objdir}/${subdir}/${testfile}$EXEEXT
56
57 gdb_start
58 gdb_reinitialize_dir $srcdir/$subdir
59
60 set prms_id 13484
61 set bug_id 0
62
63 # Load the first executable.
64
65 gdb_test "shell mv ${binfile1} ${binfile}" "" ""
66 gdb_load ${binfile}
67
68 # Set a breakpoint at foo
69
70 gdb_test "break foo" \
71     "Breakpoint.*at.* file .*$srcfile1, line 14.*" \
72     "breakpoint foo in first file"
73
74
75 # Run, should see "Breakpoint 1, foo () at hello1.c:14"
76
77 gdb_run_cmd
78
79 gdb_expect {
80     -re ".*Breakpoint.* foo .* at .*$srcfile1:14.*$gdb_prompt $"  {
81         pass "run to foo()";
82     }
83     -re ".*$gdb_prompt $" {
84         fail "run to foo()";
85         gdb_suppress_tests;
86     }
87     timeout { fail "run to foo() (timeout)" ; gdb_suppress_tests }
88 }
89
90 # Restore first executable to its original name, and move
91 # second executable into its place.  Ensure that the new
92 # executable is at least a second newer than the old.
93
94 gdb_test "shell mv ${binfile} ${binfile1}" "" ""
95 gdb_test "shell mv ${binfile2} ${binfile}" "" ""
96 gdb_test "shell sleep 1" "" ""
97 gdb_test "shell touch ${binfile}" "" ""
98
99 # Run a second time; GDB should detect that the executable has changed
100 # and reset the breakpoints correctly.
101 # Should see "Breakpoint 1, foo () at reread2.c:9"
102
103 set prms_id 0
104
105 if [is_remote target] {
106     unsupported "run to foo() second time ";
107 } else {
108     gdb_run_cmd
109     gdb_expect {
110         #    -re ".*re-reading symbols.*Breakpoint.* foo .* at .*$srcfile2:9.*$gdb_prompt $" {}
111         -re ".*Breakpoint.* foo .* at .*:9.*$gdb_prompt $" {
112             pass "run to foo() second time ";
113         }
114         -re ".*$gdb_prompt $" {
115             fail "run to foo() second time";
116             gdb_suppress_tests;
117         }
118         timeout { 
119             fail "run to foo() second time (timeout)" ; 
120             gdb_suppress_tests 
121         }
122     }
123 }
124
125
126 ### Second pass: verify that GDB checks the executable file's
127 ### timestamp when the program is *restarted*, not just when it exits.
128
129 if [is_remote target] {
130     unsupported "second pass: GDB should check for changes before running"
131 } else {
132
133     # Put the older executable back in place.
134     gdb_test "shell mv ${binfile} ${binfile2}" "" ""
135     gdb_test "shell mv ${binfile1} ${binfile}" "" ""
136
137     # Restart GDB entirely.
138     gdb_start
139     gdb_reinitialize_dir $srcdir/$subdir
140     gdb_load ${binfile}
141
142     # Set a breakpoint on foo and run to it.
143     gdb_test "break foo" \
144             "Breakpoint.*at.* file .*$srcfile1, line 14.*" \
145             "second pass: breakpoint foo in first file"
146     gdb_run_cmd
147     gdb_expect {
148         -re ".*Breakpoint.* foo .* at .*$srcfile1:14.*$gdb_prompt $"  {
149             pass "second pass: run to foo()";
150         }
151         -re ".*$gdb_prompt $" {
152             fail "second pass: run to foo()";
153             gdb_suppress_tests;
154         }
155         timeout {
156             fail "second pass: run to foo() (timeout)"
157             gdb_suppress_tests
158         }
159     }
160
161     # This time, let the program run to completion.  If GDB checks the
162     # executable file's timestamp now, it won't notice any change.
163     gdb_test "continue" ".*Program exited.*" \
164             "second pass: continue to completion"
165     
166     # Now move the newer executable into place, and re-run.  GDB
167     # should still notice that the executable file has changed,
168     # and still re-set the breakpoint appropriately.
169     gdb_test "shell mv ${binfile} ${binfile1}" "" ""
170     gdb_test "shell mv ${binfile2} ${binfile}" "" ""
171     gdb_run_cmd
172     gdb_expect {
173         -re ".*Breakpoint.* foo .* at .*:9.*$gdb_prompt $" {
174             pass "second pass: run to foo() second time ";
175         }
176         -re ".*$gdb_prompt $" {
177             fail "second pass: run to foo() second time";
178             gdb_suppress_tests;
179         }
180         timeout { 
181             fail "second pass: run to foo() second time (timeout)" ; 
182             gdb_suppress_tests 
183         }
184     }
185 }
186
187 # End of tests.
188
189 gdb_stop_suppressing_tests
190
191 return 0