From 3541979fff2861c9537f299e31ac17a436bf1228 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Tue, 10 Apr 2018 20:21:58 +0100 Subject: [PATCH] gdb/testsuite: Run test with software and hardware watchpoints Expand the gdb.base/watchpoint-reuse-slot.exp test to be run twice, once with hardware watchpoints disabled (this is new) and then with hardware watchpoints enabled (the old way). Running with hardware watchpoints enabled is skipped if the board file says that hardware watchpoints are not supported on this target. gdb/testsuite/ChangeLog: * gdb.base/watchpoint-reuse-slot.exp: Test with hardware watchpoints enabled and disabled. --- gdb/testsuite/ChangeLog | 5 + .../gdb.base/watchpoint-reuse-slot.exp | 176 +++++++++++------- 2 files changed, 115 insertions(+), 66 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 1ba373d62b..d073eda401 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-07-10 Andrew Burgess + + * gdb.base/watchpoint-reuse-slot.exp: Test with hardware + watchpoints enabled and disabled. + 2018-07-09 Andrew Burgess * gdb.base/examine-backward.exp: Still run tests around address diff --git a/gdb/testsuite/gdb.base/watchpoint-reuse-slot.exp b/gdb/testsuite/gdb.base/watchpoint-reuse-slot.exp index f196b89eab..e4ca94b053 100644 --- a/gdb/testsuite/gdb.base/watchpoint-reuse-slot.exp +++ b/gdb/testsuite/gdb.base/watchpoint-reuse-slot.exp @@ -22,11 +22,6 @@ # 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]} { @@ -85,54 +80,62 @@ proc stepi {} { gdb_breakpoint $srcline gdb_continue_to_breakpoint "stepi line" +set cur_addr [get_pc] # The test tries various sequences of different types of watchpoints. # Probe for support first. +proc build_cmds_list {} { + global gdb_prompt -# 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" + # 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" \ + "Set breakpoints always inserted while building cmds list" -# The list of supported commands. Below we'll probe for support and -# add elements to this list. -set cmds {} + # 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 { + 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 "Can't set read/access watchpoint when hardware watchpoints are disabled.*$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 "Target does not support.*$gdb_prompt $" { + -re "No hardware breakpoint support.*$gdb_prompt $" { unsupported $test } -re "$gdb_prompt $" { pass $test - lappend cmds $cmd + lappend cmds "hbreak" } } - delete_breakpoints + delete_breakpoints + + return $cmds } -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. @@ -184,8 +187,10 @@ proc valid_addr_p {cmd offset width} { # Watch WIDTH bytes at BASE + OFFSET. CMD specifices the specific # type of watchpoint to use. If CMD is "hbreak", WIDTH is ignored. +# The HW_WP_P flag tells us if hardware watchpoints are enabled or +# not. -proc watch_command {cmd base offset width} { +proc watch_command {cmd base offset width hw_wp_p} { global srcfile srcline hex if {$cmd == "hbreak"} { @@ -193,8 +198,15 @@ proc watch_command {cmd base offset width} { gdb_test "hbreak $expr" "Hardware assisted breakpoint \[0-9\]+ at $hex" } elseif {$cmd == "watch"} { set expr "*(buf.byte + $base + $offset)@$width" + + if { ! $hw_wp_p } { + set wp_prefix "Watchpoint" + } else { + set wp_prefix "Hardware watchpoint" + } + gdb_test "$cmd $expr" \ - "Hardware watchpoint \[0-9\]+: [string_to_regexp $expr]" + "${wp_prefix} \[0-9\]+: [string_to_regexp $expr]" } elseif {$cmd == "awatch"} { set expr "*(buf.byte + $base + $offset)@$width" gdb_test "$cmd $expr" \ @@ -206,42 +218,48 @@ proc watch_command {cmd base offset width} { } } -# Run test proper. See intro for description. +# Run the watchpoint tests (see the description at the top for details), the +# HW_WP_P flag tells us if hardware watchpoints are enabled or not. +proc run_watchpoints_tests {hw_wp_p} { -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} { + set cmds [build_cmds_list] - if {$cmd1 == "hbreak" && $cmd2 == "hbreak" && $width > 1} { - # hbreak ignores WIDTH, no use testing more than - # once. - continue - } + 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} { - 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. + if {$cmd1 == "hbreak" && $cmd2 == "hbreak" \ + && $width > 1} { + # hbreak ignores WIDTH, no use testing more than + # once. 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" + 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 } - with_test_prefix "base + 1" { - watch_command $cmd2 $x 1 $width - stepi - gdb_test_no_output "delete \$bpnum" + + 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 $hw_wp_p + stepi + gdb_test_no_output "delete \$bpnum" + } + with_test_prefix "base + 1" { + watch_command $cmd2 $x 1 $width $hw_wp_p + stepi + gdb_test_no_output "delete \$bpnum" + } } } } @@ -249,3 +267,29 @@ foreach always_inserted {"off" "on" } { } } } + +# Based on HW_WP_P set whether hardware watchpoints can be used or +# not, then call RUN_WATCHPOINTS_TESTS. +proc setup_and_run_watchpoints_tests { hw_wp_p } { + if {$hw_wp_p} { + set prefix "hw-watch" + } else { + set prefix "sw-watch" + } + + with_test_prefix $prefix { + gdb_test_no_output "set can-use-hw-watchpoints ${hw_wp_p}" + + run_watchpoints_tests $hw_wp_p + } +} + +# Run tests with hardware watchpoints disabled, then again with them +# enabled (if this target supports hardware watchpoints). +if { ![target_info exists gdb,no_hardware_watchpoints]} { + # Run test with H/W enabled. + setup_and_run_watchpoints_tests 1 +} + +# Run test with H/W disabled +setup_and_run_watchpoints_tests 0