]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/execl-update-breakpoints.exp
Update year range in copyright notice of all files owned by the GDB project.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / execl-update-breakpoints.exp
1 # Copyright 2014-2015 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 objfile ${binfile}.o
32 set exec1 ${binfile}1
33 set exec2 ${binfile}2
34
35 if { [gdb_compile [file join $srcdir $subdir $srcfile] $objfile \
36 object [list debug]] != "" } {
37 untested "compile failed"
38 return -1
39 }
40
41 set opts1_ld [list debug ldflags=-Wl,-Ttext-segment=0x1000000]
42 set opts1_gold [list debug ldflags=-Wl,-Ttext=0x1000000]
43 set opts2_ld [list debug ldflags=-Wl,-Ttext-segment=0x2000000]
44 set opts2_gold [list debug ldflags=-Wl,-Ttext=0x2000000]
45
46 if { [gdb_compile $objfile $exec1 executable $opts1_ld] != "" } {
47 # Old gold linker versions don't support -Ttext-segment. Fall
48 # back to -Ttext.
49 if { [gdb_compile $objfile $exec1 executable $opts1_gold] != ""
50 || [gdb_compile $objfile $exec2 executable $opts2_gold] != ""} {
51 untested "link failed"
52 return -1
53 }
54 } elseif { [gdb_compile $objfile $exec2 executable $opts2_ld] != "" } {
55 untested "link failed"
56 return -1
57 }
58
59 # First check whether the address of "main" in exec1 is readable in
60 # exec2. If it is, then skip the test as unsupported.
61
62 clean_restart ${exec1}
63 if ![runto_main] then {
64 fail "Couldn't run to main"
65 return -1
66 }
67
68 set addr ""
69 set test "main address first"
70 gdb_test_multiple "p/x &main" $test {
71 -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
72 set addr $expect_out(1,string)
73 pass $test
74 }
75 }
76
77 clean_restart ${exec2}
78 if ![runto_main] then {
79 fail "Couldn't run to main"
80 return -1
81 }
82
83 set cannot_access 0
84 set test "probe memory access"
85 gdb_test_multiple "x $addr" $test {
86 -re "Cannot access memory at address .*$gdb_prompt $" {
87 set cannot_access 1
88 pass $test
89 }
90 -re ".*$gdb_prompt $" {
91 pass $test
92 }
93 }
94
95 if {!$cannot_access} {
96 unsupported "main address is readable in second binary"
97 return
98 }
99
100 # The test proper. ALWAYS_INSERTED indicates whether testing in
101 # "breakpoint always-inserted" mode.
102
103 proc test { always_inserted } {
104 global exec1
105
106 clean_restart ${exec1}
107
108 gdb_test_no_output "set breakpoint always-inserted $always_inserted"
109
110 if ![runto_main] then {
111 fail "Couldn't run to main"
112 return -1
113 }
114
115 # On a buggy GDB, with always-inserted on, we'd see:
116 # (gdb) continue
117 # Continuing.
118 # Warning:
119 # Cannot insert breakpoint 1.
120 # Cannot access memory at address 0x10000ff
121 gdb_test "continue" "Breakpoint 1, main.*" "continue across exec"
122 }
123
124 foreach always_inserted { "off" "on" } {
125 with_test_prefix "always-inserted $always_inserted" {
126 test $always_inserted
127 }
128 }