Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH] [gdb/testsuite] Fix gdb.mi/pr11022.exp on big endian
Date: Thu, 29 Oct 2026 00:13:13 +0100	[thread overview]
Message-ID: <20261028231313.1835272-1-tdevries@suse.de> (raw)

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


                 reply	other threads:[~2026-10-28 23:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261028231313.1835272-1-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox