ca5fd19bfb
We see some fails in watchpoint-reuse-slot.exp on aarch64-linux, because it sets some HW breakpoint on some address doesn't meet the alignment requirements by kernel, kernel will reject the ptrace (PTRACE_SETHBPREGS) call, and some fails are caused, for example: (gdb) PASS: gdb.base/watchpoint-reuse-slot.exp: always-inserted off: watch x hbreak: : width 1, iter 0: base + 0: delete $bpnum hbreak *(buf.byte + 0 + 1)^M Hardware assisted breakpoint 80 at 0x410a61^M (gdb) PASS: gdb.base/watchpoint-reuse-slot.exp: always-inserted off: watch x hbreak: : width 1, iter 0: base + 1: hbreak *(buf.byte + 0 + 1) stepi^M Warning:^M Cannot insert hardware breakpoint 80.^M Could not insert hardware breakpoints:^M You may have requested too many hardware breakpoints/watchpoints.^M ^M (gdb) FAIL: gdb.base/watchpoint-reuse-slot.exp: always-inserted off: watch x hbreak: : width 1, iter 0: base + 1: stepi advanced hbreak *(buf.byte + 0 + 1)^M Hardware assisted breakpoint 440 at 0x410a61^M Warning:^M Cannot insert hardware breakpoint 440.^M Could not insert hardware breakpoints:^M You may have requested too many hardware breakpoints/watchpoints.^M ^M (gdb) FAIL: gdb.base/watchpoint-reuse-slot.exp: always-inserted on: watch x hbreak: : width 1, iter 0: base + 1: hbreak *(buf.byte + 0 + 1) This patch is to skip some tests by checking proc valid_addr_p. We can handle other targets in valid_addr_p too. gdb/testsuite: 2015-03-16 Yao Qi <yao.qi@linaro.org> * gdb.base/watchpoint-reuse-slot.exp (valid_addr_p): New proc. (top level): Skip tests if valid_addr_p returns false for $cmd1 or $cmd2.
224 lines
6.1 KiB
Text
224 lines
6.1 KiB
Text
# Copyright 2014-2015 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/>.
|
|
|
|
# Test alternating between watchpoint types, watching a sliding window
|
|
# of addresses (thus alternating between aligned and unaligned
|
|
# addresses). Only a single watchpoint exists at any given time. On
|
|
# targets that only update the debug registers on resume, this
|
|
# stresses the debug register setup code, both in GDB and in the
|
|
# target/kernel as one watchpoint replaces the other in a single
|
|
# operation. (Note that we don't have any of these watchpoints
|
|
# trigger.)
|
|
|
|
if [target_info exists gdb,no_hardware_watchpoints] {
|
|
unsupported "no target support"
|
|
return
|
|
}
|
|
|
|
standard_testfile
|
|
|
|
if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
|
|
return -1
|
|
}
|
|
|
|
if ![runto_main] then {
|
|
fail "Can't run to main"
|
|
return 0
|
|
}
|
|
|
|
# The line we'll be stepping.
|
|
set srcline [gdb_get_line_number "stepi line"]
|
|
|
|
# The address the program is stopped at currently.
|
|
set cur_addr ""
|
|
|
|
# Get the current PC.
|
|
|
|
proc get_pc {} {
|
|
global hex gdb_prompt
|
|
|
|
set addr ""
|
|
set test "get PC"
|
|
gdb_test_multiple "p /x \$pc" "$test" {
|
|
-re " = ($hex).*$gdb_prompt $" {
|
|
set addr $expect_out(1,string)
|
|
pass "$test"
|
|
}
|
|
}
|
|
|
|
return $addr
|
|
}
|
|
|
|
|
|
# Issue a stepi, and make sure the program advanced past the current
|
|
# instruction (stored in the CUR_ADDR global).
|
|
|
|
proc stepi {} {
|
|
global hex gdb_prompt cur_addr
|
|
|
|
set srcline " for (i = 0; i < 100000; i++); /* stepi line */"
|
|
set test "stepi advanced"
|
|
gdb_test_multiple "stepi" $test {
|
|
-re "($hex).*[string_to_regexp $srcline]\r\n$gdb_prompt $" {
|
|
set addr $expect_out(1,string)
|
|
if {$addr != $cur_addr} {
|
|
pass $test
|
|
} else {
|
|
fail $test
|
|
}
|
|
set cur_addr addr
|
|
}
|
|
}
|
|
}
|
|
|
|
gdb_breakpoint $srcline
|
|
gdb_continue_to_breakpoint "stepi line"
|
|
|
|
# The test tries various sequences of different types of watchpoints.
|
|
# Probe for support first.
|
|
|
|
# So we get an immediate warning/error if the target doesn't support a
|
|
# given watchpoint type.
|
|
gdb_test_no_output "set breakpoint always-inserted on"
|
|
|
|
# The list of supported commands. Below we'll probe for support and
|
|
# add elements to this list.
|
|
set cmds {}
|
|
|
|
foreach cmd {"watch" "awatch" "rwatch"} {
|
|
set test $cmd
|
|
gdb_test_multiple "$cmd buf.byte\[0\]" $test {
|
|
-re "You may have requested too many.*$gdb_prompt $" {
|
|
unsupported $test
|
|
}
|
|
-re "Target does not support.*$gdb_prompt $" {
|
|
unsupported $test
|
|
}
|
|
-re "$gdb_prompt $" {
|
|
pass $test
|
|
lappend cmds $cmd
|
|
}
|
|
}
|
|
|
|
delete_breakpoints
|
|
}
|
|
|
|
set test "hbreak"
|
|
gdb_test_multiple "hbreak main" $test {
|
|
-re "You may have requested too many.*$gdb_prompt $" {
|
|
unsupported $test
|
|
}
|
|
-re "No hardware breakpoint support.*$gdb_prompt $" {
|
|
unsupported $test
|
|
}
|
|
-re "$gdb_prompt $" {
|
|
pass $test
|
|
lappend cmds "hbreak"
|
|
}
|
|
}
|
|
|
|
delete_breakpoints
|
|
|
|
set cur_addr [get_pc]
|
|
|
|
# Return true if the memory range [buf.byte + OFFSET, +WIDTH] can be
|
|
# monitored by CMD, otherwise return false.
|
|
|
|
proc valid_addr_p {cmd offset width} {
|
|
|
|
if { [istarget "aarch64*-*-linux*"] } {
|
|
# The aarch64 Linux kernel port only accepts 4-byte aligned addresses
|
|
# for hardware breakpoints and 8-byte aligned addresses for hardware
|
|
# watchpoints. However, both GDB and GDBserver support unaligned
|
|
# watchpoints by using more than one properly aligned watchpoint
|
|
# registers to represent the whole unaligned region. Breakpoint
|
|
# addresses must still be aligned though.
|
|
if {$cmd == "hbreak" } {
|
|
if { [expr ($offset) % 4] != 0 } {
|
|
return 0
|
|
}
|
|
}
|
|
}
|
|
|
|
return 1
|
|
}
|
|
|
|
# Watch WIDTH bytes at BASE + OFFSET. CMD specifices the specific
|
|
# type of watchpoint to use. If CMD is "hbreak", WIDTH is ignored.
|
|
|
|
proc watch_command {cmd base offset width} {
|
|
global srcfile srcline hex
|
|
|
|
if {$cmd == "hbreak"} {
|
|
set expr "*(buf.byte + $base + $offset)"
|
|
gdb_test "hbreak $expr" "Hardware assisted breakpoint \[0-9\]+ at $hex"
|
|
} elseif {$cmd == "watch"} {
|
|
set expr "*(buf.byte + $base + $offset)@$width"
|
|
gdb_test "$cmd $expr" \
|
|
"Hardware watchpoint \[0-9\]+: [string_to_regexp $expr]"
|
|
} elseif {$cmd == "awatch"} {
|
|
set expr "*(buf.byte + $base + $offset)@$width"
|
|
gdb_test "$cmd $expr" \
|
|
"Hardware access \\(read/write\\) watchpoint \[0-9\]+: [string_to_regexp $expr]"
|
|
} elseif {$cmd == "rwatch"} {
|
|
set expr "*(buf.byte + $base + $offset)@$width"
|
|
gdb_test "$cmd $expr" \
|
|
"Hardware read watchpoint \[0-9\]+: [string_to_regexp $expr]"
|
|
}
|
|
}
|
|
|
|
# Run test proper. See intro for description.
|
|
|
|
foreach always_inserted {"off" "on" } {
|
|
gdb_test_no_output "set breakpoint always-inserted $always_inserted"
|
|
foreach cmd1 $cmds {
|
|
foreach cmd2 $cmds {
|
|
for {set width 1} {$width < 4} {incr width} {
|
|
|
|
if {$cmd1 == "hbreak" && $cmd2 == "hbreak" && $width > 1} {
|
|
# hbreak ignores WIDTH, no use testing more than
|
|
# once.
|
|
continue
|
|
}
|
|
|
|
for {set x 0} {$x < 4} {incr x} {
|
|
|
|
if { ![valid_addr_p $cmd1 $x $width]
|
|
|| ![valid_addr_p $cmd2 $x+1 $width] } {
|
|
# Skip tests if requested address or length
|
|
# of breakpoint or watchpoint don't meet
|
|
# target or kernel requirements.
|
|
continue
|
|
}
|
|
|
|
set prefix "always-inserted $always_inserted: "
|
|
append prefix "$cmd1 x $cmd2: "
|
|
with_test_prefix "$prefix: width $width, iter $x" {
|
|
with_test_prefix "base + 0" {
|
|
watch_command $cmd1 $x 0 $width
|
|
stepi
|
|
gdb_test_no_output "delete \$bpnum"
|
|
}
|
|
with_test_prefix "base + 1" {
|
|
watch_command $cmd2 $x 1 $width
|
|
stepi
|
|
gdb_test_no_output "delete \$bpnum"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|