]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/reread.exp
65dab15ad92ce08270e547c8c5a608f4e6c1684d
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / reread.exp
1 # Copyright 1998-2023 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 # Build programs in PIE mode, to reproduce PR 21555.
17 foreach_with_prefix opts { "" "pie" } {
18
19 # build the first test case
20
21 set testfile1 "reread1"
22 set srcfile1 ${testfile1}.c
23 # Cygwin needs $EXEEXT.
24 set binfile1 [standard_output_file ${testfile1}$EXEEXT]
25
26 set testfile1_opt [list debug nowarnings $opts]
27 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile1}" \
28 executable ${testfile1_opt}] != "" } {
29 untested "failed to compile first testcase"
30 return -1
31 }
32
33 # build the second test case
34
35 set testfile2 "reread2"
36 set srcfile2 ${testfile2}.c
37 set binfile2 [standard_output_file ${testfile2}$EXEEXT]
38
39 set testfile2_opt1 [list debug nowarnings $opts]
40 set testfile2_op2 [list debug nowarnings $opts \
41 "additional_flags=-DNO_SECTIONS"]
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" \
43 executable ${testfile2_opt1}] != ""
44 && [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" \
45 executable ${testfile2_opt2}] != ""} {
46 untested "failed to compile second testcase"
47 return -1
48 }
49
50 # Start with a fresh gdb.
51
52 set testfile "reread"
53 set binfile [standard_output_file ${testfile}$EXEEXT]
54
55 gdb_start
56 gdb_reinitialize_dir $srcdir/$subdir
57
58 # Load the first executable.
59
60 gdb_rename_execfile ${binfile1} ${binfile}
61 gdb_load ${binfile}
62
63 # Set a breakpoint at foo
64
65 gdb_test "break foo" \
66 "Breakpoint.*at.* file .*$srcfile1, line 14.*" \
67 "breakpoint foo in first file"
68
69
70 # Run, should see "Breakpoint 1, foo () at hello1.c:14"
71
72 gdb_run_cmd
73 gdb_test "" "Breakpoint.* foo .* at .*$srcfile1:14.*" "run to foo()"
74
75 # Restore first executable to its original name, and move
76 # second executable into its place. Ensure that the new
77 # executable is at least a second newer than the old.
78
79 gdb_rename_execfile ${binfile} ${binfile1}
80 gdb_rename_execfile ${binfile2} ${binfile}
81 gdb_test "shell sleep 1" ".*" ""
82 gdb_touch_execfile ${binfile}
83
84 # Run a second time; GDB should detect that the executable has changed
85 # and reset the breakpoints correctly.
86 # Should see "Breakpoint 1, foo () at reread2.c:9"
87
88 set test "run to foo() second time"
89 if [is_remote target] {
90 unsupported $test
91 } else {
92 gdb_run_cmd
93 gdb_test "" "Breakpoint.* foo .* at .*:9.*" $test
94 }
95
96
97 ### Second pass: verify that GDB checks the executable file's
98 ### timestamp when the program is *restarted*, not just when it exits.
99
100 if [is_remote target] {
101 unsupported "second pass: GDB should check for changes before running"
102 } else {
103
104 # Put the older executable back in place.
105 gdb_rename_execfile ${binfile} ${binfile2}
106 gdb_rename_execfile ${binfile1} ${binfile}
107
108 # Restart GDB entirely.
109 clean_restart ${binfile}
110
111 # Set a breakpoint on foo and run to it.
112 gdb_test "break foo" \
113 "Breakpoint.*at.* file .*$srcfile1, line 14.*" \
114 "second pass: breakpoint foo in first file"
115 gdb_run_cmd
116 gdb_test "" "Breakpoint.* foo .* at .*$srcfile1:14.*" \
117 "second pass: run to foo()"
118
119 # This time, let the program run to completion. If GDB checks the
120 # executable file's timestamp now, it won't notice any change.
121 gdb_continue_to_end "second pass"
122
123 # Now move the newer executable into place, and re-run. GDB
124 # should still notice that the executable file has changed,
125 # and still re-set the breakpoint appropriately.
126 gdb_rename_execfile ${binfile} ${binfile1}
127 gdb_rename_execfile ${binfile2} ${binfile}
128 gdb_run_cmd
129 gdb_test "" "Breakpoint.* foo .* at .*:9.*" \
130 "second pass: run to foo() second time"
131 }
132
133 }
134 # End of tests.