10SN/A# Copyright 1998, 2000, 2001, 2007, 2008, 2009, 2010, 2011
21472SN/A# Free Software Foundation, Inc.
30SN/A
40SN/A# This program is free software; you can redistribute it and/or modify
50SN/A# it under the terms of the GNU General Public License as published by
60SN/A# the Free Software Foundation; either version 3 of the License, or
70SN/A# (at your option) any later version.
80SN/A#
90SN/A# This program is distributed in the hope that it will be useful,
100SN/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
110SN/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
120SN/A# GNU General Public License for more details.
130SN/A#
140SN/A# You should have received a copy of the GNU General Public License
150SN/A# along with this program.  If not, see <http://www.gnu.org/licenses/>.
160SN/A
170SN/Aif $tracelevel then {
180SN/A	strace $tracelevel
191472SN/A}
201472SN/A
211472SN/Aset prototypes 1
220SN/A
230SN/A# build the first test case
240SN/A
250SN/Aset testfile1 "reread1"
260SN/Aset srcfile1 ${testfile1}.c
270SN/A# Cygwin needs $EXEEXT.
280SN/Aset binfile1 ${objdir}/${subdir}/${testfile1}$EXEEXT
290SN/A
300SN/Aif  { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile1}" executable {debug nowarnings}] != "" } {
310SN/A    untested reread.exp
320SN/A    return -1
330SN/A}
340SN/A
350SN/A# build the second test case
360SN/A
370SN/Aset testfile2 "reread2"
380SN/Aset srcfile2 ${testfile2}.c
390SN/Aset binfile2 ${objdir}/${subdir}/${testfile2}$EXEEXT
400SN/A
410SN/Aif  { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug nowarnings}] != "" } {
420SN/A    untested reread.exp
430SN/A    return -1
440SN/A}
450SN/A
460SN/A# Start with a fresh gdb.
470SN/A
480SN/Aset testfile "reread"
490SN/Aset binfile ${objdir}/${subdir}/${testfile}$EXEEXT
500SN/A
510SN/Agdb_start
520SN/Agdb_reinitialize_dir $srcdir/$subdir
530SN/A
540SN/A# Load the first executable.
550SN/A
560SN/Agdb_test "shell mv ${binfile1} ${binfile}" ".*" ""
570SN/Agdb_load ${binfile}
580SN/A
590SN/A# Set a breakpoint at foo
600SN/A
610SN/Agdb_test "break foo" \
620SN/A    "Breakpoint.*at.* file .*$srcfile1, line 14.*" \
630SN/A    "breakpoint foo in first file"
640SN/A
650SN/A
660SN/A# Run, should see "Breakpoint 1, foo () at hello1.c:14"
670SN/A
680SN/Agdb_run_cmd
690SN/A
700SN/Agdb_expect {
710SN/A    -re ".*Breakpoint.* foo .* at .*$srcfile1:14.*$gdb_prompt $"  {
720SN/A	pass "run to foo()";
730SN/A    }
740SN/A    -re ".*$gdb_prompt $" {
750SN/A	fail "run to foo()";
76	gdb_suppress_tests;
77    }
78    timeout { fail "run to foo() (timeout)" ; gdb_suppress_tests }
79}
80
81# Restore first executable to its original name, and move
82# second executable into its place.  Ensure that the new
83# executable is at least a second newer than the old.
84
85gdb_test "shell mv ${binfile} ${binfile1}" ".*" ""
86gdb_test "shell mv ${binfile2} ${binfile}" ".*" ""
87gdb_test "shell sleep 1" ".*" ""
88gdb_test "shell touch ${binfile}" ".*" ""
89
90# Run a second time; GDB should detect that the executable has changed
91# and reset the breakpoints correctly.
92# Should see "Breakpoint 1, foo () at reread2.c:9"
93
94if [is_remote target] {
95    unsupported "run to foo() second time ";
96} else {
97    gdb_run_cmd
98    gdb_expect {
99	#    -re ".*re-reading symbols.*Breakpoint.* foo .* at .*$srcfile2:9.*$gdb_prompt $" {}
100	-re ".*Breakpoint.* foo .* at .*:9.*$gdb_prompt $" {
101	    pass "run to foo() second time ";
102	}
103	-re ".*$gdb_prompt $" {
104	    fail "run to foo() second time";
105	    gdb_suppress_tests;
106	}
107	timeout {
108	    fail "run to foo() second time (timeout)" ;
109	    gdb_suppress_tests
110	}
111    }
112}
113
114
115### Second pass: verify that GDB checks the executable file's
116### timestamp when the program is *restarted*, not just when it exits.
117
118if [is_remote target] {
119    unsupported "second pass: GDB should check for changes before running"
120} else {
121
122    # Put the older executable back in place.
123    gdb_test "shell mv ${binfile} ${binfile2}" ".*" ""
124    gdb_test "shell mv ${binfile1} ${binfile}" ".*" ""
125
126    # Restart GDB entirely.
127    gdb_start
128    gdb_reinitialize_dir $srcdir/$subdir
129    gdb_load ${binfile}
130
131    # Set a breakpoint on foo and run to it.
132    gdb_test "break foo" \
133            "Breakpoint.*at.* file .*$srcfile1, line 14.*" \
134            "second pass: breakpoint foo in first file"
135    gdb_run_cmd
136    gdb_expect {
137        -re ".*Breakpoint.* foo .* at .*$srcfile1:14.*$gdb_prompt $"  {
138            pass "second pass: run to foo()";
139        }
140        -re ".*$gdb_prompt $" {
141            fail "second pass: run to foo()";
142            gdb_suppress_tests;
143        }
144        timeout {
145            fail "second pass: run to foo() (timeout)"
146            gdb_suppress_tests
147        }
148    }
149
150    # This time, let the program run to completion.  If GDB checks the
151    # executable file's timestamp now, it won't notice any change.
152    gdb_continue_to_end "second pass"
153
154    # Now move the newer executable into place, and re-run.  GDB
155    # should still notice that the executable file has changed,
156    # and still re-set the breakpoint appropriately.
157    gdb_test "shell mv ${binfile} ${binfile1}" ".*" ""
158    gdb_test "shell mv ${binfile2} ${binfile}" ".*" ""
159    gdb_run_cmd
160    gdb_expect {
161	-re ".*Breakpoint.* foo .* at .*:9.*$gdb_prompt $" {
162	    pass "second pass: run to foo() second time ";
163	}
164	-re ".*$gdb_prompt $" {
165	    fail "second pass: run to foo() second time";
166	    gdb_suppress_tests;
167	}
168	timeout {
169	    fail "second pass: run to foo() second time (timeout)" ;
170	    gdb_suppress_tests
171	}
172    }
173}
174
175# End of tests.
176
177gdb_stop_suppressing_tests
178
179return 0
180