Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright 2014-2016 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 |
19 | standard_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 |
25 | set objfile ${binfile}.o |
26 | set exec1 ${binfile}1 | |
27 | set exec2 ${binfile}2 | |
13fd3ff3 | 28 | |
fdb09caf AA |
29 | if { [gdb_compile [file join $srcdir $subdir $srcfile] $objfile \ |
30 | object [list debug]] != "" } { | |
31 | untested "compile failed" | |
13fd3ff3 PA |
32 | return -1 |
33 | } | |
fdb09caf AA |
34 | |
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] | |
39 | ||
40 | if { [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 | ||
56 | clean_restart ${exec1} | |
57 | if ![runto_main] then { | |
58 | fail "Couldn't run to main" | |
59 | return -1 | |
60 | } | |
61 | ||
62 | set addr "" | |
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) | |
67 | pass $test | |
68 | } | |
69 | } | |
70 | ||
71 | clean_restart ${exec2} | |
72 | if ![runto_main] then { | |
73 | fail "Couldn't run to main" | |
74 | return -1 | |
75 | } | |
76 | ||
77 | set cannot_access 0 | |
78 | set test "probe memory access" | |
79 | gdb_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 | ||
89 | if {!$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 | ||
97 | proc 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 { | |
106 | fail "Couldn't run to main" | |
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)*" \ | |
135 | "\r\n" \ | |
136 | "Breakpoint 1, main.*$gdb_prompt $" | |
137 | set message "continue across exec" | |
138 | gdb_test_multiple "continue" $message { | |
139 | -re $regex { | |
140 | pass $message | |
141 | } | |
142 | } | |
13fd3ff3 PA |
143 | } |
144 | ||
145 | foreach always_inserted { "off" "on" } { | |
146 | with_test_prefix "always-inserted $always_inserted" { | |
147 | test $always_inserted | |
148 | } | |
149 | } |