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