]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/pie-execl.exp
* gdb.base/break-interp.exp: Remove ${objdir} from test messages.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / pie-execl.exp
1 # Copyright 2010, 2011 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 if ![istarget *-linux*] {
20 continue
21 }
22
23 # Remote protocol does not support follow-exec notifications.
24
25 if [is_remote target] {
26 continue
27 }
28
29 set testfile "pie-execl"
30 set srcfile ${testfile}.c
31 set executable1 ${testfile}1
32 set executable2 ${testfile}2
33 set binfile1 ${objdir}/${subdir}/${executable1}
34 set binfile2 ${objdir}/${subdir}/${executable2}
35 set binfile2_test_msg OBJDIR/${subdir}/${executable2}
36
37 # Use conditional compilation according to `BIN' as GDB remembers the source
38 # file name of the breakpoint.
39
40 set opts [list debug {additional_flags=-fPIE -pie}]
41 if {[build_executable ${testfile}.exp $executable1 $srcfile [concat $opts {additional_flags=-DBIN=1}]] == ""
42 || [build_executable ${testfile}.exp $executable2 $srcfile [concat $opts {additional_flags=-DBIN=2}]] == ""} {
43 return -1
44 }
45
46 clean_restart ${executable1}
47
48 gdb_test_no_output "set args ${binfile2}" "set args ${binfile2_test_msg}"
49
50 if ![runto_main] {
51 return -1
52 }
53
54 # Do not stop on `main' after re-exec.
55 delete_breakpoints
56
57 gdb_breakpoint "pie_execl_marker"
58 gdb_test "info breakpoints" ".*" ""
59
60 set addr1 ""
61 set test "pie_execl_marker address first"
62 gdb_test_multiple "p/x &pie_execl_marker" $test {
63 -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
64 set addr1 $expect_out(1,string)
65 pass $test
66 }
67 }
68 verbose -log "addr1 is $addr1"
69
70 set test "continue"
71 gdb_test_multiple $test $test {
72 -re "Error in re-setting breakpoint" {
73 fail $test
74 }
75 -re "Cannot access memory" {
76 fail $test
77 }
78 -re "pie-execl: re-exec.*executing new program.*\r\nBreakpoint \[0-9\]+,\[^\r\n\]* pie_execl_marker .*\r\n$gdb_prompt $" {
79 pass $test
80 }
81 }
82
83 gdb_test "info breakpoints" ".*" ""
84
85 set addr2 ""
86 set test "pie_execl_marker address second"
87 gdb_test_multiple "p/x &pie_execl_marker" $test {
88 -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
89 set addr2 $expect_out(1,string)
90 pass $test
91 }
92 }
93 verbose -log "addr2 is $addr2"
94
95 # Ensure we cannot get a false PASS and the inferior has really changed.
96 set test "pie_execl_marker address has changed"
97 if [string equal $addr1 $addr2] {
98 fail $test
99 } else {
100 pass $test
101 }