Skip to content

Commit d6a970d

Browse files
[lldb][test] Add tests for repeating "memory read" command (#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.
1 parent 169148a commit d6a970d

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

lldb/test/API/commands/memory/read/TestMemoryRead.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,45 @@ def check_file_content(expected):
181181
)
182182
)
183183
check_file_content([golden_output, golden_output])
184+
185+
def test_memory_read_repeat(self):
186+
self.build_run_stop()
187+
188+
def expected_bytes(start, end):
189+
# Generates ": <2 digit hex> <2 digit hex> <repeats><double space>".
190+
return ": " + " ".join([f"{n:02x}" for n in range(start, end)]) + " "
191+
192+
# First read gives us the first half of the array.
193+
self.expect(
194+
"memory read &incrementing_bytes",
195+
substrs=[expected_bytes(0x0, 0x10), expected_bytes(0x10, 0x20)],
196+
)
197+
198+
# Repeating the command sets the start address to the end address of the
199+
# previous use.
200+
self.expect(
201+
"memory read",
202+
substrs=[expected_bytes(0x20, 0x30), expected_bytes(0x30, 0x40)],
203+
)
204+
205+
# Read first half of array as characters.
206+
self.expect(
207+
'memory read --format "character" --count 32 &incrementing_bytes',
208+
substrs=[
209+
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",
210+
],
211+
)
212+
213+
# Repeated command should read the second half and retain the character
214+
# format.
215+
# FIXME: Options are not repeated, see https://github.com/llvm/llvm-project/issues/192057.
216+
# self.expect("memory read", substrs=[
217+
# # Note that the second space is actually in the array.
218+
# ": !\"#$%&'()*+,-./0123456789:;<=>?"
219+
# ])
220+
# Due to that bug, only the address is incremented, and the style is
221+
# reset to the default.
222+
self.expect(
223+
"memory read",
224+
substrs=[expected_bytes(0x20, 0x30), expected_bytes(0x30, 0x40)],
225+
)

lldb/test/API/commands/memory/read/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@ int main(int argc, const char *argv[]) {
88
// assume that 0xffffff is invalid instruction in RISC-V and AArch64,
99
// so decoding it will fail
1010
char my_insns[] = {0xff, 0xff, 0xff};
11+
// 2 x the default read size of 32 bytes.
12+
uint8_t incrementing_bytes[64];
13+
for (unsigned i = 0; i < 64; ++i)
14+
incrementing_bytes[i] = i;
1115
return 0; // break here
1216
}

0 commit comments

Comments
 (0)