1 # Copyright 2014-2024 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 if { [gdb_compile $objfile $exec1 executable {debug text_segment=0x1000000}] != ""
36 || [gdb_compile $objfile $exec2 executable {debug text_segment=0x2000000}] != ""} {
37 untested "link failed"
41 # First check whether the address of "main" in exec1 is readable in
42 # exec2. If it is, then skip the test as unsupported.
44 clean_restart ${exec1}
50 set test "main address first"
51 gdb_test_multiple "p/x &main" $test {
52 -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
53 set addr $expect_out(1,string)
58 clean_restart ${exec2}
64 set test "probe memory access"
65 gdb_test_multiple "x $addr" $test {
66 -re "Cannot access memory at address .*$gdb_prompt $" {
70 -re ".*$gdb_prompt $" {
75 if {!$cannot_access} {
76 unsupported "main address is readable in second binary"
80 # The test proper. ALWAYS_INSERTED indicates whether testing in
81 # "breakpoint always-inserted" mode.
83 proc test { always_inserted } {
87 clean_restart ${exec1}
89 gdb_test_no_output "set breakpoint always-inserted $always_inserted"
95 # Set a second breakpoint (whose original address also ends up
96 # unmmapped after the exec), for PR 19548.
97 gdb_test "break some_function" "Breakpoint .*"
99 # PR17431: with always-inserted on, we'd see:
103 # Cannot insert breakpoint 1.
104 # Cannot access memory at address 0x10000ff
106 # PR 19548: with more than one breakpoint, we'd see:
109 # process (...) is executing new program: (...)/execl-update-breakpoints2
110 # Error in re-setting breakpoint 1: Warning:
111 # Cannot insert breakpoint 2.
112 # Cannot access memory at address 0x1000764
113 set not_nl "\[^\r\n\]*"
117 "Continuing\\.\r\n" \
118 "${not_nl} is executing new program: ${not_nl}\r\n" \
119 "(Reading ${not_nl} from remote target\\.\\.\\.\r\n)*" \
120 "(?:.Thread debugging using .*? enabled.\r\nUsing .*? library .*?\\.\r\n)?" \
122 "Breakpoint 1, main.*$gdb_prompt $"
123 set message "continue across exec"
124 gdb_test_multiple "continue" $message {
131 foreach always_inserted { "off" "on" } {
132 with_test_prefix "always-inserted $always_inserted" {
133 test $always_inserted