Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / execl-update-breakpoints.exp
CommitLineData
88b9d363 1# Copyright 2014-2022 Free Software Foundation, Inc.
13fd3ff3
PA
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# 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.
18
13fd3ff3
PA
19standard_testfile
20
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.
24
fdb09caf
AA
25set objfile ${binfile}.o
26set exec1 ${binfile}1
27set exec2 ${binfile}2
13fd3ff3 28
fdb09caf
AA
29if { [gdb_compile [file join $srcdir $subdir $srcfile] $objfile \
30 object [list debug]] != "" } {
84c93cd5 31 untested "failed to compile"
13fd3ff3
PA
32 return -1
33}
fdb09caf
AA
34
35set opts1_ld [list debug ldflags=-Wl,-Ttext-segment=0x1000000]
36set opts1_gold [list debug ldflags=-Wl,-Ttext=0x1000000]
37set opts2_ld [list debug ldflags=-Wl,-Ttext-segment=0x2000000]
38set opts2_gold [list debug ldflags=-Wl,-Ttext=0x2000000]
39
40if { [gdb_compile $objfile $exec1 executable $opts1_ld] != "" } {
41 # Old gold linker versions don't support -Ttext-segment. Fall
42 # back to -Ttext.
43 if { [gdb_compile $objfile $exec1 executable $opts1_gold] != ""
44 || [gdb_compile $objfile $exec2 executable $opts2_gold] != ""} {
45 untested "link failed"
46 return -1
47 }
48} elseif { [gdb_compile $objfile $exec2 executable $opts2_ld] != "" } {
49 untested "link failed"
13fd3ff3
PA
50 return -1
51}
52
53# First check whether the address of "main" in exec1 is readable in
54# exec2. If it is, then skip the test as unsupported.
55
56clean_restart ${exec1}
57if ![runto_main] then {
bc6c7af4 58 fail "couldn't run to main"
13fd3ff3
PA
59 return -1
60}
61
62set addr ""
63set test "main address first"
64gdb_test_multiple "p/x &main" $test {
65 -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
66 set addr $expect_out(1,string)
67 pass $test
68 }
69}
70
71clean_restart ${exec2}
72if ![runto_main] then {
bc6c7af4 73 fail "couldn't run to main"
13fd3ff3
PA
74 return -1
75}
76
77set cannot_access 0
78set test "probe memory access"
79gdb_test_multiple "x $addr" $test {
80 -re "Cannot access memory at address .*$gdb_prompt $" {
81 set cannot_access 1
82 pass $test
83 }
84 -re ".*$gdb_prompt $" {
85 pass $test
86 }
87}
88
89if {!$cannot_access} {
90 unsupported "main address is readable in second binary"
91 return
92}
93
94# The test proper. ALWAYS_INSERTED indicates whether testing in
95# "breakpoint always-inserted" mode.
96
97proc test { always_inserted } {
98 global exec1
2a7f3dff 99 global gdb_prompt
13fd3ff3
PA
100
101 clean_restart ${exec1}
102
103 gdb_test_no_output "set breakpoint always-inserted $always_inserted"
104
105 if ![runto_main] then {
bc6c7af4 106 fail "couldn't run to main"
13fd3ff3
PA
107 return -1
108 }
109
2a7f3dff
PA
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 .*"
113
114 # PR17431: with always-inserted on, we'd see:
13fd3ff3
PA
115 # (gdb) continue
116 # Continuing.
117 # Warning:
118 # Cannot insert breakpoint 1.
119 # Cannot access memory at address 0x10000ff
2a7f3dff
PA
120
121 # PR 19548: with more than one breakpoint, we'd see:
122 # (gdb) continue
123 # Continuing.
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\]*"
129 set regex ""
130 append regex \
131 "^continue\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)*" \
4cc2e606 135 "(?:.Thread debugging using .*? enabled.\r\nUsing .*? library .*?\\.\r\n)?" \
2a7f3dff
PA
136 "\r\n" \
137 "Breakpoint 1, main.*$gdb_prompt $"
138 set message "continue across exec"
139 gdb_test_multiple "continue" $message {
140 -re $regex {
141 pass $message
142 }
143 }
13fd3ff3
PA
144}
145
146foreach always_inserted { "off" "on" } {
147 with_test_prefix "always-inserted $always_inserted" {
148 test $always_inserted
149 }
150}
This page took 1.047814 seconds and 4 git commands to generate.