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