1 # Copyright
1998-2019 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 programs in PIE
mode, to reproduce PR
21555.
19 foreach_with_prefix opts
{
21 { "-fPIE" "ldflags=-pie" } } {
23 # build the first test case
25 set testfile1
"reread1"
26 set srcfile1 $
{testfile1
}.c
27 # Cygwin needs $EXEEXT.
28 set binfile1
[standard_output_file $
{testfile1
}$EXEEXT
]
30 set testfile1_opt
[list debug nowarnings \
31 additional_flags
=[lindex $opts
0] \
33 if { [gdb_compile
"${srcdir}/${subdir}/${srcfile1}" "${binfile1}" \
34 executable $
{testfile1_opt
}] != "" } {
35 untested
"failed to compile first testcase"
39 # build the second test case
41 set testfile2
"reread2"
42 set srcfile2 $
{testfile2
}.c
43 set binfile2
[standard_output_file $
{testfile2
}$EXEEXT
]
45 set testfile2_opt1
[list debug nowarnings \
46 additional_flags
=[lindex $opts
0] \
48 set testfile2_op2
[list debug nowarnings \
49 "additional_flags=-DNO_SECTIONS [lindex $opts 0]" \
51 if { [gdb_compile
"${srcdir}/${subdir}/${srcfile2}" "${binfile2}" \
52 executable $
{testfile2_opt1
}] != ""
53 && [gdb_compile
"${srcdir}/${subdir}/${srcfile2}" "${binfile2}" \
54 executable $
{testfile2_opt2
}] != ""} {
55 untested
"failed to compile second testcase"
59 # Start with a fresh gdb.
62 set binfile
[standard_output_file $
{testfile
}$EXEEXT
]
65 gdb_reinitialize_dir $srcdir
/$subdir
67 #
Load the first executable.
69 gdb_rename_execfile $
{binfile1
} $
{binfile
}
72 #
Set a breakpoint at foo
74 gdb_test
"break foo" \
75 "Breakpoint.*at.* file .*$srcfile1, line 14.*" \
76 "breakpoint foo in first file"
79 # Run
, should see
"Breakpoint 1, foo () at hello1.c:14"
82 gdb_test
"" "Breakpoint.* foo .* at .*$srcfile1:14.*" "run to foo()"
84 # Restore first executable to its original
name, and
move
85 # second executable into its place. Ensure that the new
86 # executable is at least a second newer than the old.
88 gdb_rename_execfile $
{binfile
} $
{binfile1
}
89 gdb_rename_execfile $
{binfile2
} $
{binfile
}
90 gdb_test
"shell sleep 1" ".*" ""
91 gdb_touch_execfile $
{binfile
}
93 # Run a second time
; GDB should detect that the executable has changed
94 # and reset the breakpoints correctly.
95 # Should see
"Breakpoint 1, foo () at reread2.c:9"
97 set test
"run to foo() second time"
98 if [is_remote target
] {
102 gdb_test
"" "Breakpoint.* foo .* at .*:9.*" $test
106 ### Second pass
: verify that GDB checks the executable file
's
107 ### timestamp when the program is *restarted*, not just when it exits.
109 if [is_remote target] {
110 unsupported "second pass: GDB should check for changes before running"
113 # Put the older executable back in place.
114 gdb_rename_execfile ${binfile} ${binfile2}
115 gdb_rename_execfile ${binfile1} ${binfile}
117 # Restart GDB entirely.
118 clean_restart ${binfile}
120 # Set a breakpoint on foo and run to it.
121 gdb_test "break foo" \
122 "Breakpoint.*at.* file .*$srcfile1, line 14.*" \
123 "second pass: breakpoint foo in first file"
125 gdb_test "" "Breakpoint.* foo .* at .*$srcfile1:14.*" \
126 "second pass: run to foo()"
128 # This time, let the program run to completion. If GDB checks the
129 # executable file's timestamp now
, it won
't notice any change.
130 gdb_continue_to_end "second pass"
132 # Now move the newer executable into place, and re-run. GDB
133 # should still notice that the executable file has changed,
134 # and still re-set the breakpoint appropriately.
135 gdb_rename_execfile ${binfile} ${binfile1}
136 gdb_rename_execfile ${binfile2} ${binfile}
138 gdb_test "" "Breakpoint.* foo .* at .*:9.*" \
139 "second pass: run to foo() second time"