[Lldb-commits] [lldb] [lldb][test] Add tests for repeating "memory read" command (PR #192063)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 14 07:06:28 PDT 2026


https://github.com/DavidSpickett created https://github.com/llvm/llvm-project/pull/192063

Tests that show the effect of #192057.

Until now repeating the command options was only tested in memory tagging tests, which I don't run often. Here I am adding tests that'll run anywhere.

>From ca48f487a7209182ed8f81bdd283b58ade642ed8 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at arm.com>
Date: Tue, 14 Apr 2026 13:40:08 +0000
Subject: [PATCH] [lldb][test] Add tests for repeating "memory read" command

Tests that show the result of https://github.com/llvm/llvm-project/issues/192057.

Until now repeating the command options was only tested in
memory tagging tests, which I don't run often. Here I am adding
tests that'll run anywhere.
---
 .../commands/memory/read/TestMemoryRead.py    | 42 +++++++++++++++++++
 lldb/test/API/commands/memory/read/main.c     |  4 ++
 2 files changed, 46 insertions(+)

diff --git a/lldb/test/API/commands/memory/read/TestMemoryRead.py b/lldb/test/API/commands/memory/read/TestMemoryRead.py
index 8247efed9bd9b..bc8c45a402423 100644
--- a/lldb/test/API/commands/memory/read/TestMemoryRead.py
+++ b/lldb/test/API/commands/memory/read/TestMemoryRead.py
@@ -181,3 +181,45 @@ def check_file_content(expected):
             )
         )
         check_file_content([golden_output, golden_output])
+
+    def test_memory_read_repeat(self):
+        self.build_run_stop()
+
+        def expected_bytes(start, end):
+            # Generates ": <2 digit hex> <2 digit hex> <repeats><double space>".
+            return ": " + " ".join([f"{n:02x}" for n in range(start, end)]) + "  "
+
+        # First read gives us the first half of the array.
+        self.expect(
+            "memory read &incrementing_bytes",
+            substrs=[expected_bytes(0x0, 0x10), expected_bytes(0x10, 0x20)],
+        )
+
+        # Repeating the command sets the start address to the end address of the
+        # previous use.
+        self.expect(
+            "memory read",
+            substrs=[expected_bytes(0x20, 0x30), expected_bytes(0x30, 0x40)],
+        )
+
+        # Read first half of array as characters.
+        self.expect(
+            'memory read --format "character" --count 32 &incrementing_bytes',
+            substrs=[
+                r": \0\x01\x02\x03\x04\x05\x06\a\b\t\n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\e\x1c\x1d\x1e\x1f",
+            ],
+        )
+
+        # Repeated command should read the second half and retain the character
+        # format.
+        # FIXME: Options are not repeated, see https://github.com/llvm/llvm-project/issues/192057.
+        # self.expect("memory read", substrs=[
+        #    # Note that the second space is actually in the array.
+        #    ":  !\"#$%&'()*+,-./0123456789:;<=>?"
+        #    ])
+        # Due to that bug, only the address is incremented, and the style is
+        # reset to the default.
+        self.expect(
+            "memory read",
+            substrs=[expected_bytes(0x20, 0x30), expected_bytes(0x30, 0x40)],
+        )
diff --git a/lldb/test/API/commands/memory/read/main.c b/lldb/test/API/commands/memory/read/main.c
index 360f85af919cc..a44b687af9f5a 100644
--- a/lldb/test/API/commands/memory/read/main.c
+++ b/lldb/test/API/commands/memory/read/main.c
@@ -8,5 +8,9 @@ int main(int argc, const char *argv[]) {
   // assume that 0xffffff is invalid instruction in RISC-V and AArch64,
   // so decoding it will fail
   char my_insns[] = {0xff, 0xff, 0xff};
+  // 2 x the default read size of 32 bytes.
+  uint8_t incrementing_bytes[64];
+  for (unsigned i = 0; i < 64; ++i)
+    incrementing_bytes[i] = i;
   return 0; // break here
 }



More information about the lldb-commits mailing list