[gdb/testsuite] Extend gdb.base/watchpoint-unaligned.exp

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>
This commit is contained in:
Tom de Vries
2025-08-12 16:35:05 +02:00
parent d737aae03b
commit 3769fe5ed3
2 changed files with 40 additions and 10 deletions

View 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)
{

View 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
}
}
}