1 # Copyright 2014-2015 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.
19 # Remote protocol does not support follow-exec notifications.
21 if [is_remote target] {
27 # Build two copies of the program, each linked at a different address.
28 # The address of "main" in the first binary should end up being an
29 # unmapped address in the second binary.
31 set objfile ${binfile}.o
35 if { [gdb_compile [file join $srcdir $subdir $srcfile] $objfile \
36 object [list debug]] != "" } {
37 untested "compile failed"
41 set opts1_ld [list debug ldflags=-Wl,-Ttext-segment=0x1000000]
42 set opts1_gold [list debug ldflags=-Wl,-Ttext=0x1000000]
43 set opts2_ld [list debug ldflags=-Wl,-Ttext-segment=0x2000000]
44 set opts2_gold [list debug ldflags=-Wl,-Ttext=0x2000000]
46 if { [gdb_compile $objfile $exec1 executable $opts1_ld] != "" } {
47 # Old gold linker versions don't support -Ttext-segment. Fall
49 if { [gdb_compile $objfile $exec1 executable $opts1_gold] != ""
50 || [gdb_compile $objfile $exec2 executable $opts2_gold] != ""} {
51 untested "link failed"
54 } elseif { [gdb_compile $objfile $exec2 executable $opts2_ld] != "" } {
55 untested "link failed"
59 # First check whether the address of "main" in exec1 is readable in
60 # exec2. If it is, then skip the test as unsupported.
62 clean_restart ${exec1}
63 if ![runto_main] then {
64 fail "Couldn't run to main"
69 set test "main address first"
70 gdb_test_multiple "p/x &main" $test {
71 -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
72 set addr $expect_out(1,string)
77 clean_restart ${exec2}
78 if ![runto_main] then {
79 fail "Couldn't run to main"
84 set test "probe memory access"
85 gdb_test_multiple "x $addr" $test {
86 -re "Cannot access memory at address .*$gdb_prompt $" {
90 -re ".*$gdb_prompt $" {
95 if {!$cannot_access} {
96 unsupported "main address is readable in second binary"
100 # The test proper. ALWAYS_INSERTED indicates whether testing in
101 # "breakpoint always-inserted" mode.
103 proc test { always_inserted } {
106 clean_restart ${exec1}
108 gdb_test_no_output "set breakpoint always-inserted $always_inserted"
110 if ![runto_main] then {
111 fail "Couldn't run to main"
115 # On a buggy GDB, with always-inserted on, we'd see:
119 # Cannot insert breakpoint 1.
120 # Cannot access memory at address 0x10000ff
121 gdb_test "continue" "Breakpoint 1, main.*" "continue across exec"
124 foreach always_inserted { "off" "on" } {
125 with_test_prefix "always-inserted $always_inserted" {
126 test $always_inserted