================
@@ -2233,6 +2233,49 @@ size_t Process::ReadMemoryFromInferior(addr_t addr, void
*buf, size_t size,
return bytes_read;
}
+size_t Process::ReadMemoryInChunks(lldb::addr_t vm_addr, void *buf,
+ lldb::addr_t chunk_size, size_t size,
+ ReadMemoryChunkCallback callback) {
+ // Safety check to prevent an infinite loop.
+ if (chunk_size == 0)
+ return 0;
+
+ // Buffer for when a NULL buf is provided, initialized
+ // to 0 bytes, we set it to chunk_size and then replace buf
+ // with the new buffer.
+ DataBufferHeap data_buffer;
+ if (!buf) {
+ data_buffer.SetByteSize(chunk_size);
+ buf = data_buffer.GetBytes();
+ }
+
+ uint64_t bytes_remaining = size;
+ uint64_t bytes_read = 0;
+ Status error;
+ while (bytes_remaining > 0) {
+ // Get the next read chunk size as the minimum of the remaining bytes and
+ // the write chunk max size.
+ const size_t bytes_to_read = std::min(bytes_remaining, chunk_size);
+ const lldb::addr_t current_addr = vm_addr + bytes_read;
+ const size_t bytes_read_for_chunk =
+ ReadMemoryFromInferior(current_addr, buf, bytes_to_read, error);
+
+ if (callback(error, current_addr, buf, bytes_read_for_chunk) ==
+ IterationAction::Stop)
+ break;
+
+ bytes_read += bytes_read_for_chunk;
----------------
clayborg wrote:
Move this before the callback or our return value will be wrong
https://github.com/llvm/llvm-project/pull/129307
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits