]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/pie-execl.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / pie-execl.exp
1 # Copyright 2010-2024 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 # The problem was due to amd64_skip_prologue attempting to access inferior
17 # memory before the PIE (Position Independent Executable) gets relocated.
18
19 global inferior_spawn_id
20 global gdb_spawn_id
21
22 require {istarget *-linux*}
23
24 # In remote mode we cannot use the 'set args' command, and this
25 # test requires it.
26 if {[target_info exists gdb_protocol]} {
27 if {[target_info gdb_protocol] == "remote"} {
28 return
29 }
30 }
31
32 standard_testfile .c
33 set executable1 ${testfile}1
34 set executable2 ${testfile}2
35 set binfile1 ${binfile}1
36 set binfile2 ${binfile}2
37 set binfile2_test_msg OBJDIR/${subdir}/${executable2}
38
39 # Use conditional compilation according to `BIN' as GDB remembers the source
40 # file name of the breakpoint.
41
42 set opts [list debug pie]
43 if {[build_executable ${testfile}.exp $executable1 $srcfile [concat $opts {additional_flags=-DBIN=1}]] == -1
44 || [build_executable ${testfile}.exp $executable2 $srcfile [concat $opts {additional_flags=-DBIN=2}]] == -1} {
45 return -1
46 }
47
48 clean_restart ${executable1}
49
50 gdb_test_no_output "set args ${binfile2}" "set args ${binfile2_test_msg}"
51
52 if ![runto_main] {
53 return -1
54 }
55
56 # Do not stop on `main' after re-exec.
57 delete_breakpoints
58
59 gdb_breakpoint "pie_execl_marker"
60 gdb_test "info breakpoints" "" "info breakpoints first"
61
62 set addr1 ""
63 set test "pie_execl_marker address first"
64 gdb_test_multiple "p/x &pie_execl_marker" $test {
65 -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
66 set addr1 $expect_out(1,string)
67 pass $test
68 }
69 }
70 verbose -log "addr1 is $addr1"
71
72 set test "continue"
73 set matches_found 0
74 gdb_test_multiple $test $test {
75 -re "Error in re-setting breakpoint" {
76 fail $test
77 }
78 -re "Cannot access memory" {
79 fail $test
80 }
81 -i "$inferior_spawn_id" -re "pie-execl: re-exec" {
82 # output from inferior
83 incr matches_found
84 if { $matches_found == 2 } {
85 pass $test
86 } else {
87 exp_continue
88 }
89 }
90 -i "$gdb_spawn_id"
91 -re "executing new program.*\r\nBreakpoint \[0-9\]+,\[^\r\n\]* pie_execl_marker .*\r\n$gdb_prompt $" {
92 # output from gdb
93 incr matches_found
94 if { $matches_found == 2 } {
95 pass $test
96 } else {
97 exp_continue
98 }
99 }
100 }
101
102 gdb_test "info breakpoints" "" "info breakpoints second"
103
104 set addr2 ""
105 set test "pie_execl_marker address second"
106 gdb_test_multiple "p/x &pie_execl_marker" $test {
107 -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
108 set addr2 $expect_out(1,string)
109 pass $test
110 }
111 }
112 verbose -log "addr2 is $addr2"
113
114 # Ensure we cannot get a false PASS and the inferior has really changed.
115 set test "pie_execl_marker address has changed"
116 if [string equal $addr1 $addr2] {
117 fail $test
118 } else {
119 pass $test
120 }