]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/testsuite] Extend gdb.base/watchpoint-unaligned.exp
authorTom de Vries <tdevries@suse.de>
Tue, 12 Aug 2025 14:35:05 +0000 (16:35 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 12 Aug 2025 14:35:05 +0000 (16:35 +0200)
Extend the part of gdb.base/watchpoint-unaligned.exp handling
write_size8twice to also check read hardware watchpoints.

Tested on x86_64-linux.

Approved-By: Luis Machado <luis.machado.foss@gmail.com>
gdb/testsuite/gdb.base/watchpoint-unaligned.c
gdb/testsuite/gdb.base/watchpoint-unaligned.exp

index a3b6b74c3ff9df27cc5e0039cccd6adff2abf5fd..baa7ae021a1ed1c14d1a0f5f152e0f02123c8ea7 100644 (file)
@@ -65,6 +65,24 @@ write_size8twice (void)
   return; /* write_size8twice_return */
 }
 
+static void
+read_size8twice (void)
+{
+  static uint64_t volatile first;
+  static uint64_t volatile second;
+
+  first = data.u.size8twice[offset];
+  second = data.u.size8twice[offset + 1];
+
+  /* Setting a breakpoint on an instruction after an instruction triggering a
+     watchpoint makes it ambiguous which one will be reported.
+     Insert a dummy instruction inbetween to make sure the watchpoint gets
+     reported.  */
+  volatile_dummy = 1;
+
+  return; /* read_size8twice_return */
+}
+
 int
 main (void)
 {
@@ -73,6 +91,7 @@ main (void)
   assert (sizeof (data) == 8 + 3 * 8);
 
   write_size8twice ();
+  read_size8twice ();
 
   while (size)
     {
index ffa574b9dcf757b49c433bbe5b5b6323db986435..85b1eb7a9a2d455d88e7d1eeedea293817be8e50 100644 (file)
@@ -151,7 +151,7 @@ foreach_with_prefix wpcount {4 7} {
     gdb_assert $got_hit $test
 }
 
-proc size8twice { function offset index } {
+proc size8twice { function cmd offset index } {
     clean_restart $::testfile
 
     if { ![runto $function] } {
@@ -169,11 +169,11 @@ proc size8twice { function offset index } {
 
     # Set a hardware watchpoint.
     set watch_index [expr $offset + $index]
-    set test "watch data.u.size8twice\[$watch_index\]"
+    set test "$cmd data.u.size8twice\[$watch_index\]"
     set wpnum 0
     gdb_test_multiple $test "" {
-       -re -wrap "Hardware watchpoint ($::decimal): .*" {
-           set wpnum $expect_out(1,string)
+       -re -wrap "Hardware (read )?watchpoint ($::decimal): .*" {
+           set wpnum $expect_out(2,string)
            pass $gdb_test_name
        }
        -re -wrap "Watchpoint ($::decimal): .*" {
@@ -195,7 +195,7 @@ proc size8twice { function offset index } {
     gdb_test_multiple "continue" "" {
        -re -wrap "\r\nCould not insert hardware watchpoint .*" {
        }
-       -re -wrap "Hardware watchpoint $wpnum:.*New value = .*" {
+       -re -wrap "Hardware (read )?watchpoint $wpnum:.*(New value|Value) = .*" {
            set got_hit 1
            send_gdb "continue\n"
            exp_continue
@@ -203,7 +203,7 @@ proc size8twice { function offset index } {
        -re -wrap " $bp_src_string .*" {
        }
     }
-    gdb_assert $got_hit "size8twice write"
+    gdb_assert { $got_hit }
 
     return $got_hit
 }
@@ -215,10 +215,21 @@ proc size8twice { function offset index } {
 # For each case, check setting a watchpoint at:
 # - the first written element (index == 0), and
 # - the second element (index == 1).
-foreach_with_prefix offset { 0 1 } {
-    foreach_with_prefix index { 0 1 } {
-       if { [size8twice write_size8twice $offset $index] != 1 } {
-           return
+foreach_with_prefix fun { write_size8twice read_size8twice } {
+    if { $fun == "write_size8twice" } {
+       set cmd "watch"
+    } else {
+       set cmd "rwatch"
+    }
+    foreach_with_prefix offset { 0 1 } {
+       foreach_with_prefix index { 0 1 } {
+           set res [size8twice $fun $cmd $offset $index]
+           if { $res != 1 } {
+               break
+           }
+       }
+       if { $res != 1 } {
+           break
        }
     }
 }