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