[Lldb-commits] [lldb] [lldb] Implement Process::ReadMemoryRanges (PR #163651)
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Tue Oct 21 07:25:30 PDT 2025
================
@@ -225,3 +226,62 @@ TEST_F(MemoryTest, TesetMemoryCacheRead) {
// instead of using an
// old cache
}
+
+/// A process class that, when asked to read memory from some address X, returns
+/// the least significant byte of X.
+class DummyReaderProcess : public Process {
+public:
+ size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
+ Status &error) override {
+ uint8_t *buffer = static_cast<uint8_t *>(buf);
+ for (size_t addr = vm_addr; addr < vm_addr + size; addr++)
+ buffer[addr - vm_addr] = static_cast<uint8_t>(addr); // LSB of addr.
+ return size;
+ }
+ // Boilerplate, nothing interesting below.
+ DummyReaderProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp)
+ : Process(target_sp, listener_sp) {}
+ bool CanDebug(lldb::TargetSP, bool) override { return true; }
+ Status DoDestroy() override { return {}; }
+ void RefreshStateAfterStop() override {}
+ bool DoUpdateThreadList(ThreadList &, ThreadList &) override { return false; }
+ llvm::StringRef GetPluginName() override { return "Dummy"; }
+};
+
+TEST_F(MemoryTest, TestReadMemoryRanges) {
+ ArchSpec arch("x86_64-apple-macosx-");
+
+ Platform::SetHostPlatform(PlatformRemoteMacOSX::CreateInstance(true, &arch));
+
+ DebuggerSP debugger_sp = Debugger::CreateInstance();
+ ASSERT_TRUE(debugger_sp);
+
+ TargetSP target_sp = CreateTarget(debugger_sp, arch);
+ ASSERT_TRUE(target_sp);
+
+ ListenerSP listener_sp(Listener::MakeListener("dummy"));
+ ProcessSP process_sp =
+ std::make_shared<DummyReaderProcess>(target_sp, listener_sp);
+ ASSERT_TRUE(process_sp);
+
+ DummyProcess *process = static_cast<DummyProcess *>(process_sp.get());
+ process->SetMaxReadSize(1024);
+
+ llvm::SmallVector<uint8_t, 0> buffer(1024, 0);
+
+ // Read 8 ranges of 128 bytes with arbitrary base addresses.
+ llvm::SmallVector<Range<addr_t, size_t>> ranges = {
+ {0x12345, 128}, {0x11112222, 128}, {0x77777777, 128},
+ {0xffaabbccdd, 128}, {0x0, 128}, {0x4242424242, 128},
+ {0x17171717, 128}, {0x99999, 128}};
+
+ llvm::SmallVector<llvm::MutableArrayRef<uint8_t>> read_results =
+ process->ReadMemoryRanges(ranges, buffer);
+
+ for (auto [range, memory] : llvm::zip(ranges, read_results)) {
+ ASSERT_EQ(memory.size(), 128u);
+ addr_t range_base = range.GetRangeBase();
+ for (auto [idx, byte] : llvm::enumerate(memory))
+ ASSERT_EQ(byte, static_cast<uint8_t>(range_base + idx));
+ }
+}
----------------
DavidSpickett wrote:
I didn't consider the assert. I don't disagree with it existing for development builds.
I think you could use https://google.github.io/googletest/advanced.html#death-tests in the case where asserts are on. If not, then it's unfortunate but I am ok not having coverage.
https://github.com/llvm/llvm-project/pull/163651
More information about the lldb-commits
mailing list