Commit | Line | Data |
---|---|---|
13fd3ff3 PA |
1 | # Copyright 2014 Free Software Foundation, Inc. |
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 | ||
19 | # Remote protocol does not support follow-exec notifications. | |
20 | ||
21 | if [is_remote target] { | |
22 | continue | |
23 | } | |
24 | ||
25 | standard_testfile | |
26 | ||
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. | |
30 | ||
31 | set exec1 ${testfile}1 | |
32 | set exec2 ${testfile}2 | |
33 | set binfile1 ${binfile}1 | |
34 | set binfile2 ${binfile}2 | |
35 | ||
36 | if { [prepare_for_testing "failed to prepare" ${exec1} "${srcfile}" \ | |
37 | [list debug ldflags=-Wl,-Ttext=0x1000000]] } { | |
38 | return -1 | |
39 | } | |
40 | if { [prepare_for_testing "failed to prepare" ${exec2} "${srcfile}" \ | |
41 | [list debug ldflags=-Wl,-Ttext=0x2000000]] } { | |
42 | return -1 | |
43 | } | |
44 | ||
45 | # First check whether the address of "main" in exec1 is readable in | |
46 | # exec2. If it is, then skip the test as unsupported. | |
47 | ||
48 | clean_restart ${exec1} | |
49 | if ![runto_main] then { | |
50 | fail "Couldn't run to main" | |
51 | return -1 | |
52 | } | |
53 | ||
54 | set addr "" | |
55 | set test "main address first" | |
56 | gdb_test_multiple "p/x &main" $test { | |
57 | -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" { | |
58 | set addr $expect_out(1,string) | |
59 | pass $test | |
60 | } | |
61 | } | |
62 | ||
63 | clean_restart ${exec2} | |
64 | if ![runto_main] then { | |
65 | fail "Couldn't run to main" | |
66 | return -1 | |
67 | } | |
68 | ||
69 | set cannot_access 0 | |
70 | set test "probe memory access" | |
71 | gdb_test_multiple "x $addr" $test { | |
72 | -re "Cannot access memory at address .*$gdb_prompt $" { | |
73 | set cannot_access 1 | |
74 | pass $test | |
75 | } | |
76 | -re ".*$gdb_prompt $" { | |
77 | pass $test | |
78 | } | |
79 | } | |
80 | ||
81 | if {!$cannot_access} { | |
82 | unsupported "main address is readable in second binary" | |
83 | return | |
84 | } | |
85 | ||
86 | # The test proper. ALWAYS_INSERTED indicates whether testing in | |
87 | # "breakpoint always-inserted" mode. | |
88 | ||
89 | proc test { always_inserted } { | |
90 | global exec1 | |
91 | ||
92 | clean_restart ${exec1} | |
93 | ||
94 | gdb_test_no_output "set breakpoint always-inserted $always_inserted" | |
95 | ||
96 | if ![runto_main] then { | |
97 | fail "Couldn't run to main" | |
98 | return -1 | |
99 | } | |
100 | ||
101 | # On a buggy GDB, with always-inserted on, we'd see: | |
102 | # (gdb) continue | |
103 | # Continuing. | |
104 | # Warning: | |
105 | # Cannot insert breakpoint 1. | |
106 | # Cannot access memory at address 0x10000ff | |
107 | gdb_test "continue" "Breakpoint 1, main.*" "continue across exec" | |
108 | } | |
109 | ||
110 | foreach always_inserted { "off" "on" } { | |
111 | with_test_prefix "always-inserted $always_inserted" { | |
112 | test $always_inserted | |
113 | } | |
114 | } |