Fix: Null pointer dereference in ldlex.l
[binutils-gdb.git] / gdb / testsuite / gdb.base / gcore-relro-pie.exp
blobb64f9fa00b957115b2db439ce4a6d3d483680f40
1 # Copyright 2013-2023 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/>.
16 # PR 11786 (Gold and strip differ on flags,align fields of PT_GNU_RELRO).
17 # Generate a core file from the stripped version of the program,
18 # and then try to debug the core with the unstripped version.
20 standard_testfile
22 if {[build_executable "failed to prepare" $testfile $srcfile \
23 {debug pie "ldflags=-Wl,-z,relro"}]} {
24 return -1
27 set stripped_binfile ${binfile}.stripped
28 set gcorefile ${binfile}.gcore
30 set strip_program [transform strip]
31 remote_file host delete ${stripped_binfile}
32 if [run_on_host "strip" "$strip_program" "-g -o ${stripped_binfile} $binfile"] {
33 return -1
36 # Workaround PR binutils/10802:
37 # Preserve the 'x' bit also for PIEs (Position Independent Executables).
38 set perm [file attributes ${binfile} -permissions]
39 file attributes ${stripped_binfile} -permissions $perm
41 clean_restart ${stripped_binfile}
43 # The binary is stripped of debug info, but not minsyms.
44 if ![runto break_here] {
45 return -1
48 if {![gdb_gcore_cmd $gcorefile "save a corefile"]} {
49 return -1
52 # Now restart gdb with the unstripped binary and load the corefile.
54 clean_restart ${binfile}
56 gdb_test "core ${gcorefile}" \
57 "Core was generated by .*" "re-load generated corefile"
59 # Put $pc in gdb.log for debug purposes for comparison with stripped case.
60 gdb_test "x/i \$pc" "break_here.*"
62 gdb_test "frame" "#0 \[^\r\n\]* break_here .*" "unstripped + core ok"