aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2025-08-12 16:35:05 +0200
committerTom de Vries <tdevries@suse.de>2025-08-12 16:35:05 +0200
commitd737aae03b9e09e848260fc31c5b8b66de4a7a77 (patch)
treee072a4b6bb82d9b148f445736e37bb25f9039d52
parent89495c33260b3f637acb8f79181cc6db08771f90 (diff)
downloadbinutils-d737aae03b9e09e848260fc31c5b8b66de4a7a77.zip
binutils-d737aae03b9e09e848260fc31c5b8b66de4a7a77.tar.gz
binutils-d737aae03b9e09e848260fc31c5b8b66de4a7a77.tar.bz2
[gdb/testsuite] Improve gdb.base/watchpoint-unaligned.exp
Improve the part of gdb.base/watchpoint-unaligned.exp handling write_size8twice: - move the code into a proc - use -wrap - use $decimal more often - don't use gdb_test_multiple $test $test - add comments - start test when entering write_size8twice function, instead of main - finish test when leaving write_size8twice function, instead of main - add insn in between: - insn triggering watchpoint, and - insn triggering breakpoint to ensure that the watchpoint triggers before the breakpoint, and add a comment explaining this. Tested on x86_64-linux.
-rw-r--r--gdb/testsuite/gdb.base/watchpoint-unaligned.c10
-rw-r--r--gdb/testsuite/gdb.base/watchpoint-unaligned.exp100
2 files changed, 69 insertions, 41 deletions
diff --git a/gdb/testsuite/gdb.base/watchpoint-unaligned.c b/gdb/testsuite/gdb.base/watchpoint-unaligned.c
index d3c1349..a3b6b74 100644
--- a/gdb/testsuite/gdb.base/watchpoint-unaligned.c
+++ b/gdb/testsuite/gdb.base/watchpoint-unaligned.c
@@ -18,6 +18,8 @@
#include <stdint.h>
#include <assert.h>
+static volatile int volatile_dummy;
+
static int again;
static volatile struct
@@ -53,6 +55,14 @@ write_size8twice (void)
data.u.size8twice[offset] = first;
data.u.size8twice[offset + 1] = second;
#endif
+
+ /* Setting a breakpoint on an instruction after an instruction triggering a
+ watchpoint makes it ambiguous which one will be reported.
+ Insert a dummy instruction in between to make sure the watchpoint gets
+ reported. */
+ volatile_dummy = 1;
+
+ return; /* write_size8twice_return */
}
int
diff --git a/gdb/testsuite/gdb.base/watchpoint-unaligned.exp b/gdb/testsuite/gdb.base/watchpoint-unaligned.exp
index 9220402..ffa574b 100644
--- a/gdb/testsuite/gdb.base/watchpoint-unaligned.exp
+++ b/gdb/testsuite/gdb.base/watchpoint-unaligned.exp
@@ -151,6 +151,63 @@ foreach_with_prefix wpcount {4 7} {
gdb_assert $got_hit $test
}
+proc size8twice { function offset index } {
+ clean_restart $::testfile
+
+ if { ![runto $function] } {
+ return -1
+ }
+
+ # Set offset in the inferior.
+ gdb_test_no_output "set var offset = $offset"
+
+ # Set a breakpoint.
+ set bp_src_string "${function}_return"
+ set bp_loc [gdb_get_line_number $bp_src_string]
+ gdb_breakpoint $bp_loc \
+ "Breakpoint $::decimal at $::hex" "$bp_src_string"
+
+ # Set a hardware watchpoint.
+ set watch_index [expr $offset + $index]
+ set test "watch data.u.size8twice\[$watch_index\]"
+ set wpnum 0
+ gdb_test_multiple $test "" {
+ -re -wrap "Hardware watchpoint ($::decimal): .*" {
+ set wpnum $expect_out(1,string)
+ pass $gdb_test_name
+ }
+ -re -wrap "Watchpoint ($::decimal): .*" {
+ if {[istarget "arm*-*-*"]} {
+ untested $gdb_test_name
+ } else {
+ fail $gdb_test_name
+ }
+ }
+ }
+
+ if { ! $wpnum } {
+ # No hardware watchpoint, we're done.
+ return 0
+ }
+
+ # Try to trigger the hardware watchpoint.
+ set got_hit 0
+ gdb_test_multiple "continue" "" {
+ -re -wrap "\r\nCould not insert hardware watchpoint .*" {
+ }
+ -re -wrap "Hardware watchpoint $wpnum:.*New value = .*" {
+ set got_hit 1
+ send_gdb "continue\n"
+ exp_continue
+ }
+ -re -wrap " $bp_src_string .*" {
+ }
+ }
+ gdb_assert $got_hit "size8twice write"
+
+ return $got_hit
+}
+
# We've got an array with 3 8-byte elements. Do a store of 16 bytes,
# to:
# - elements 0 and 1 (offset == 0), and
@@ -160,47 +217,8 @@ foreach_with_prefix wpcount {4 7} {
# - the second element (index == 1).
foreach_with_prefix offset { 0 1 } {
foreach_with_prefix index { 0 1 } {
-
- clean_restart $binfile
-
- if ![runto_main] {
- return -1
- }
-
- gdb_test_no_output "set var offset = $offset"
- gdb_breakpoint [gdb_get_line_number "final_return"] \
- "Breakpoint $decimal at $hex" "final_return"
- set watch_index [expr $offset + $index]
- set test "watch data.u.size8twice\[$watch_index\]"
- set wpnum 0
- gdb_test_multiple $test $test {
- -re "Hardware watchpoint (\[0-9\]+): .*\r\n$gdb_prompt $" {
- set wpnum $expect_out(1,string)
- pass $gdb_test_name
- }
- -re "Watchpoint (\[0-9\]+): .*\r\n$gdb_prompt $" {
- if {[istarget "arm*-*-*"]} {
- untested $gdb_test_name
- } else {
- fail $gdb_test_name
- }
- }
- }
- if {$wpnum} {
- set test "continue"
- set got_hit 0
- gdb_test_multiple $test $test {
- -re "\r\nCould not insert hardware watchpoint .*\r\n$gdb_prompt $" {
- }
- -re "Hardware watchpoint $wpnum:.*New value = .*\r\n$gdb_prompt $" {
- set got_hit 1
- send_gdb "continue\n"
- exp_continue
- }
- -re " final_return .*\r\n$gdb_prompt $" {
- }
- }
- gdb_assert $got_hit "size8twice write"
+ if { [size8twice write_size8twice $offset $index] != 1 } {
+ return
}
}
}