1 # Copyright 1998-2016 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # build the first test case
20 set testfile1 "reread1"
21 set srcfile1 ${testfile1}.c
22 # Cygwin needs $EXEEXT.
23 set binfile1 [standard_output_file ${testfile1}$EXEEXT]
25 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile1}" executable {debug nowarnings}] != "" } {
30 # build the second test case
32 set testfile2 "reread2"
33 set srcfile2 ${testfile2}.c
34 set binfile2 [standard_output_file ${testfile2}$EXEEXT]
36 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug nowarnings}] != ""
37 && [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable {debug nowarnings additional_flags=-DNO_SECTIONS}] != ""} {
42 # Start with a fresh gdb.
45 set binfile [standard_output_file ${testfile}$EXEEXT]
48 gdb_reinitialize_dir $srcdir/$subdir
50 # Load the first executable.
52 gdb_rename_execfile ${binfile1} ${binfile}
55 # Set a breakpoint at foo
57 gdb_test "break foo" \
58 "Breakpoint.*at.* file .*$srcfile1, line 14.*" \
59 "breakpoint foo in first file"
62 # Run, should see "Breakpoint 1, foo () at hello1.c:14"
65 gdb_test "" "Breakpoint.* foo .* at .*$srcfile1:14.*" "run to foo()"
67 # Restore first executable to its original name, and move
68 # second executable into its place. Ensure that the new
69 # executable is at least a second newer than the old.
71 gdb_rename_execfile ${binfile} ${binfile1}
72 gdb_rename_execfile ${binfile2} ${binfile}
73 gdb_test "shell sleep 1" ".*" ""
74 gdb_touch_execfile ${binfile}
76 # Run a second time; GDB should detect that the executable has changed
77 # and reset the breakpoints correctly.
78 # Should see "Breakpoint 1, foo () at reread2.c:9"
80 set test "run to foo() second time"
81 if [is_remote target] {
85 gdb_test "" "Breakpoint.* foo .* at .*:9.*" $test
89 ### Second pass: verify that GDB checks the executable file's
90 ### timestamp when the program is *restarted*, not just when it exits.
92 if [is_remote target] {
93 unsupported "second pass: GDB should check for changes before running"
96 # Put the older executable back in place.
97 gdb_rename_execfile ${binfile} ${binfile2}
98 gdb_rename_execfile ${binfile1} ${binfile}
100 # Restart GDB entirely.
101 clean_restart ${binfile}
103 # Set a breakpoint on foo and run to it.
104 gdb_test "break foo" \
105 "Breakpoint.*at.* file .*$srcfile1, line 14.*" \
106 "second pass: breakpoint foo in first file"
108 gdb_test "" "Breakpoint.* foo .* at .*$srcfile1:14.*" "second pass: run to foo()"
110 # This time, let the program run to completion. If GDB checks the
111 # executable file's timestamp now, it won't notice any change.
112 gdb_continue_to_end "second pass"
114 # Now move the newer executable into place, and re-run. GDB
115 # should still notice that the executable file has changed,
116 # and still re-set the breakpoint appropriately.
117 gdb_rename_execfile ${binfile} ${binfile1}
118 gdb_rename_execfile ${binfile2} ${binfile}
120 gdb_test "" "Breakpoint.* foo .* at .*:9.*" "second pass: run to foo() second time"