]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/execl-update-breakpoints.exp
GDB copyright headers update after running GDB's copyright.py script.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / execl-update-breakpoints.exp
1 # Copyright 2014-2016 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 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
25 set objfile ${binfile}.o
26 set exec1 ${binfile}1
27 set exec2 ${binfile}2
28
29 if { [gdb_compile [file join $srcdir $subdir $srcfile] $objfile \
30 object [list debug]] != "" } {
31 untested "compile failed"
32 return -1
33 }
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"
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
99
100 clean_restart ${exec1}
101
102 gdb_test_no_output "set breakpoint always-inserted $always_inserted"
103
104 if ![runto_main] then {
105 fail "Couldn't run to main"
106 return -1
107 }
108
109 # On a buggy GDB, with always-inserted on, we'd see:
110 # (gdb) continue
111 # Continuing.
112 # Warning:
113 # Cannot insert breakpoint 1.
114 # Cannot access memory at address 0x10000ff
115 gdb_test "continue" "Breakpoint 1, main.*" "continue across exec"
116 }
117
118 foreach always_inserted { "off" "on" } {
119 with_test_prefix "always-inserted $always_inserted" {
120 test $always_inserted
121 }
122 }