1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# Copyright 2014 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file is part of the gdb testsuite
standard_testfile
if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
return -1
}
if ![runto main] {
return -1
}
delete_breakpoints
# Get the bounds of a function, and write them to FUNC_LO (inclusive),
# FUNC_HI (exclusive). Return true on success and false on failure.
proc get_function_bounds {function func_lo func_hi} {
global gdb_prompt
global hex decimal
upvar $func_lo lo
upvar $func_hi hi
set lo ""
set size ""
set test "get lo address of $function"
gdb_test_multiple "disassemble $function" $test {
-re "($hex) .*$hex <\\+($decimal)>:\[^\r\n\]+\r\nEnd of assembler dump\.\r\n$gdb_prompt $" {
set lo $expect_out(1,string)
set size $expect_out(2,string)
pass $test
}
}
if { $lo == "" || $size == "" } {
return false
}
# Account for the size of the last instruction.
set test "get hi address of $function"
gdb_test_multiple "x/2i $function+$size" $test {
-re ".*$hex <$function\\+$size>:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
set hi $expect_out(1,string)
pass $test
}
}
if { $hi == "" } {
return false
}
# Remove unnecessary leading 0's (0x00000ADDR => 0xADDR) so we can
# easily do matches. Disassemble includes leading zeros, while
# x/i doesn't.
regsub -all "0x0\+" $lo "0x" lo
regsub -all "0x0\+" $hi "0x" hi
return true
}
# Get the address where the thread is currently stopped.
proc get_curr_insn {} {
global gdb_prompt
global hex
set pc ""
set test "get current insn"
gdb_test_multiple "p /x \$pc" $test {
-re " = ($hex)\r\n$gdb_prompt $" {
set pc $expect_out(1,string)
pass $test
}
}
return $pc
}
# Get the address of where a single-step should land.
proc get_next_insn {} {
global gdb_prompt
global hex
set next ""
set test "get next insn"
gdb_test_multiple "x/2i \$pc" $test {
-re "$hex .*:\[^\r\n\]+\r\n\[ \]+($hex).*\.\r\n$gdb_prompt $" {
set next $expect_out(1,string)
pass $test
}
}
return $next
}
if ![get_function_bounds "main" main_lo main_hi] {
# Can't do the following tests if main's bounds are unknown.
return -1
}
# Manually create a read-only memory region that covers 'main'.
gdb_test_no_output "mem $main_lo $main_hi ro" \
"create read-only mem region covering main"
# So that we don't fail inserting breakpoints on addresses outside
# main, like the internal event breakpoints.
gdb_test_no_output "set mem inaccessible-by-default off"
# So we get an immediate warning/error without needing to resume the
# target.
gdb_test_no_output "set breakpoint always-inserted on"
# Disable the automatic fallback to HW breakpoints. We want a
# software breakpoint to be attempted, and to fail.
gdb_test_no_output "set breakpoint auto-hw off"
# Confirm manual writes to the read-only memory region fail.
gdb_test "p /x *(char *) $main_lo = 1" \
"Cannot access memory at address $main_lo" \
"writing to read-only memory fails"
# Ensure that inserting a software breakpoint in a known-read-only
# region fails.
gdb_test "break *$main_lo" \
"Cannot insert breakpoint .*Cannot set software breakpoint at read-only address $main_lo.*" \
"inserting software breakpoint in read-only memory fails"
|