1 # Copyright 2014-2016 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 # Test that when following an exec, we don't try to insert breakpoints
17 # in the new image at the addresses the symbols had before the exec.
21 # Build two copies of the program, each linked at a different address.
22 # The address of "main" in the first binary should end up being an
23 # unmapped address in the second binary.
25 set objfile ${binfile}.o
29 if { [gdb_compile [file join $srcdir $subdir $srcfile] $objfile \
30 object [list debug]] != "" } {
31 untested "compile failed"
35 set opts1_ld [list debug ldflags=-Wl,-Ttext-segment=0x1000000]
36 set opts1_gold [list debug ldflags=-Wl,-Ttext=0x1000000]
37 set opts2_ld [list debug ldflags=-Wl,-Ttext-segment=0x2000000]
38 set opts2_gold [list debug ldflags=-Wl,-Ttext=0x2000000]
40 if { [gdb_compile $objfile $exec1 executable $opts1_ld] != "" } {
41 # Old gold linker versions don't support -Ttext-segment. Fall
43 if { [gdb_compile $objfile $exec1 executable $opts1_gold] != ""
44 || [gdb_compile $objfile $exec2 executable $opts2_gold] != ""} {
45 untested "link failed"
48 } elseif { [gdb_compile $objfile $exec2 executable $opts2_ld] != "" } {
49 untested "link failed"
53 # First check whether the address of "main" in exec1 is readable in
54 # exec2. If it is, then skip the test as unsupported.
56 clean_restart ${exec1}
57 if ![runto_main] then {
58 fail "Couldn't run to main"
63 set test "main address first"
64 gdb_test_multiple "p/x &main" $test {
65 -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
66 set addr $expect_out(1,string)
71 clean_restart ${exec2}
72 if ![runto_main] then {
73 fail "Couldn't run to main"
78 set test "probe memory access"
79 gdb_test_multiple "x $addr" $test {
80 -re "Cannot access memory at address .*$gdb_prompt $" {
84 -re ".*$gdb_prompt $" {
89 if {!$cannot_access} {
90 unsupported "main address is readable in second binary"
94 # The test proper. ALWAYS_INSERTED indicates whether testing in
95 # "breakpoint always-inserted" mode.
97 proc test { always_inserted } {
100 clean_restart ${exec1}
102 gdb_test_no_output "set breakpoint always-inserted $always_inserted"
104 if ![runto_main] then {
105 fail "Couldn't run to main"
109 # On a buggy GDB, with always-inserted on, we'd see:
113 # Cannot insert breakpoint 1.
114 # Cannot access memory at address 0x10000ff
115 gdb_test "continue" "Breakpoint 1, main.*" "continue across exec"
118 foreach always_inserted { "off" "on" } {
119 with_test_prefix "always-inserted $always_inserted" {
120 test $always_inserted