[Lldb-commits] [lldb] [lldb] Implement Process::ReadMemoryRanges (PR #163651)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Fri Oct 17 03:06:46 PDT 2025


================
@@ -1971,6 +1971,34 @@ size_t Process::ReadMemory(addr_t addr, void *buf, size_t size, Status &error) {
   }
 }
 
+llvm::SmallVector<llvm::MutableArrayRef<uint8_t>>
+Process::ReadMemoryRanges(llvm::ArrayRef<Range<lldb::addr_t, size_t>> ranges,
+                          llvm::MutableArrayRef<uint8_t> buffer) {
+  llvm::SmallVector<llvm::MutableArrayRef<uint8_t>> results;
+
+  for (auto [addr, len] : ranges) {
+    // This is either a programmer error, or a protocol violation.
+    // In production builds, gracefully fail.
+    assert(buffer.size() >= len);
----------------
DavidSpickett wrote:

I think your algorithm here is:
* For each range
* Take that much from the front of buffer, making buffer smaller
* So if at any point, there aren't "len" bytes left to take, the caller made a mistake and didn't provide enough buffer

I was confused at first because I read the assert backwards. We **expect** that the remaining buffer size will be >= len of the current range, if it's not then it fails.

But then I see below, `take_front(0)`. And now I'm confused again.

I think some comments would help like:
when the remaining buffer is > range we do this
when it's exactly the same we do this
when it's less than we decide that's an error so we do this



https://github.com/llvm/llvm-project/pull/163651


More information about the lldb-commits mailing list