1 # Copyright 2014-2017 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 "failed to compile"
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 } {
101 clean_restart ${exec1}
103 gdb_test_no_output "set breakpoint always-inserted $always_inserted"
105 if ![runto_main] then {
106 fail "couldn't run to main"
110 # Set a second breakpoint (whose original address also ends up
111 # unmmapped after the exec), for PR 19548.
112 gdb_test "break some_function" "Breakpoint .*"
114 # PR17431: with always-inserted on, we'd see:
118 # Cannot insert breakpoint 1.
119 # Cannot access memory at address 0x10000ff
121 # PR 19548: with more than one breakpoint, we'd see:
124 # process (...) is executing new program: (...)/execl-update-breakpoints2
125 # Error in re-setting breakpoint 1: Warning:
126 # Cannot insert breakpoint 2.
127 # Cannot access memory at address 0x1000764
128 set not_nl "\[^\r\n\]*"
132 "Continuing\\.\r\n" \
133 "${not_nl} is executing new program: ${not_nl}\r\n" \
134 "(Reading ${not_nl} from remote target\\.\\.\\.\r\n)*" \
136 "Breakpoint 1, main.*$gdb_prompt $"
137 set message "continue across exec"
138 gdb_test_multiple "continue" $message {
145 foreach always_inserted { "off" "on" } {
146 with_test_prefix "always-inserted $always_inserted" {
147 test $always_inserted