Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] [gdb/testsuite] Fix gdb.mi/pr11022.exp on big endian
@ 2026-10-28 23:13 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2026-10-28 23:13 UTC (permalink / raw)
  To: gdb-patches

On s390x-linux, with test-case gdb.mi/pr11022.exp I run into:
...
FAIL: $exp: data-write-memory-bytes &x "01": \
  watchpoint hit 2 (unknown output after running)
...

The problem is that we're writing a byte to the start address of an int,
which gets different results on big and little endian.

Fix this by writing to an int8_t instead.

Likewise, make sure that the 4-byte write writes to a 4-byte int by using
int32_t instead of int.

While we're at it, reduce unnecessary escaping.

Tested on x86_64-linux and s390x-linux.
---
 gdb/testsuite/gdb.mi/pr11022.c   |  7 +++++--
 gdb/testsuite/gdb.mi/pr11022.exp | 31 ++++++++++++++++++++-----------
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/gdb/testsuite/gdb.mi/pr11022.c b/gdb/testsuite/gdb.mi/pr11022.c
index 676506c2849..240f50b8750 100644
--- a/gdb/testsuite/gdb.mi/pr11022.c
+++ b/gdb/testsuite/gdb.mi/pr11022.c
@@ -15,7 +15,10 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-int x;
+#include <stdint.h>
+
+int32_t x;
+int8_t b;
 
 int
 main ()
@@ -24,7 +27,7 @@ main ()
 
   for (i = 0; i < 500; ++i) {
     j = 0;  /* break here */
-    x = 42;
+    x = b = 42;
     j = i;  /* expect HW watchpoint stop */
   }
   return 0;
diff --git a/gdb/testsuite/gdb.mi/pr11022.exp b/gdb/testsuite/gdb.mi/pr11022.exp
index 35e31af95b1..b72db25a270 100644
--- a/gdb/testsuite/gdb.mi/pr11022.exp
+++ b/gdb/testsuite/gdb.mi/pr11022.exp
@@ -25,7 +25,7 @@ if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb
      return
 }
 
-proc test_memory_changed_observer { mi_command } {
+proc test_memory_changed_observer { var mi_command } {
     with_test_prefix "${mi_command}" {
 	global srcfile binfile
 
@@ -37,29 +37,38 @@ proc test_memory_changed_observer { mi_command } {
 	    {\^done,bkpt=.number="2",type="breakpoint".*\}} \
 	    "set breakpoint"
 
-	mi_gdb_test "watch x" ".*" "set watchpoint"
+	mi_gdb_test "watch $var" ".*" "set watchpoint"
 
 	mi_execute_to "exec-continue" "breakpoint-hit" "main" "" ".*" ".*" \
-	    { "" "disp=\"keep\"" } "breakpoint hit"
+	    { "" {disp="keep"} } "breakpoint hit"
+
+	set re_0 {0( '[^\r\n]*')?}
+	set re_1 {1( '[^\r\n]*')?}
+	set re_42 {42( '[^\r\n]*')?}
 
 	mi_execute_to "exec-continue" "watchpoint-trigger" "main" "" ".*" ".*" \
-	    { "" "wpt=\{number=\"3\",exp=\"x\"\},value=\{old=\"0\",new=\"42\"\}" } \
+	    [list \
+		 "" \
+		 [subst_vars \
+		      {wpt={number="3",exp="$var"},value={old="$re_0",new="$re_42"}}]] \
 	    "watchpoint hit"
 
 	mi_execute_to "exec-continue" "breakpoint-hit" "main" "" ".*" ".*" \
-	    { "" "disp=\"keep\"" } "breakpoint hit 2"
+	    { "" {disp="keep"} } "breakpoint hit 2"
 
-	mi_gdb_test "-${mi_command}" {\^done} "set x"
+	mi_gdb_test "-${mi_command}" {\^done} "set $var"
 
 	mi_execute_to "exec-continue" "watchpoint-trigger" "main" "" ".*" ".*" \
-	    { "" "wpt=\{number=\"3\",exp=\"x\"\},value=\{old=\"1\",new=\"42\"\}" } \
+	    [list \
+		 "" \
+		 [subst_vars \
+		      {wpt={number="3",exp="$var"},value={old="$re_1",new="$re_42"}}]] \
 	    "watchpoint hit 2"
 
 	mi_gdb_exit
     }
 }
 
-test_memory_changed_observer "data-write-memory-bytes &x \"01\""
-# We want to trigger a target memory write here, so the word size (4 or 8)
-# is not that important.
-test_memory_changed_observer "data-write-memory &x x 4 \"01\""
+test_memory_changed_observer b {data-write-memory-bytes &b "01"}
+
+test_memory_changed_observer x {data-write-memory &x x 4 "01"}

base-commit: aeed64b39aed57729f66ad51560d8964e8201e6e
-- 
2.51.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-28 23:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-28 23:13 [PATCH] [gdb/testsuite] Fix gdb.mi/pr11022.exp on big endian Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox