[Lldb-commits] [lldb] [LLDB][Minidump]Update MinidumpFileBuilder to read and write in chunks (PR #129307)

Jacob Lalonde via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 7 15:48:10 PDT 2025


================
@@ -969,6 +969,64 @@ Status MinidumpFileBuilder::DumpDirectories() const {
   return error;
 }
 
+Status MinidumpFileBuilder::ReadWriteMemoryInChunks(
+    lldb_private::DataBufferHeap &data_buffer,
+    const lldb_private::CoreFileMemoryRange &range, uint64_t &bytes_read) {
+
+  Log *log = GetLog(LLDBLog::Object);
+  Status addDataError;
+  Process::ReadMemoryChunkCallback callback =
+      [&](Status &error, DataBufferHeap &data, lldb::addr_t current_addr,
+          uint64_t bytes_to_read,
+          uint64_t bytes_read_for_chunk) -> lldb_private::IterationAction {
+    if (error.Fail() || bytes_read_for_chunk == 0) {
+      LLDB_LOGF(log,
+                "Failed to read memory region at: %" PRIx64
+                ". Bytes read: %zu, error: %s",
+                current_addr, bytes_read_for_chunk, error.AsCString());
+
+      // If we failed in a memory read, we would normally want to skip
+      // this entire region, if we had already written to the minidump
+      // file, we can't easily rewind that state.
+      //
+      // So if we do encounter an error while reading, we just return
+      // immediately, any prior bytes read will still be included but
+      // any bytes partially read before the error are ignored.
+      return lldb_private::IterationAction::Stop;
+    }
+
+    // Write to the minidump file with the chunk potentially flushing to
+    // disk.
+    // This error will be captured by the outer scope and is considered fatal.
+    // If we get an error writing to disk we can't easily guarauntee that we
+    // won't corrupt the minidump.
+    addDataError = AddData(data_buffer.GetBytes(), bytes_read_for_chunk);
+    if (addDataError.Fail())
+      return lldb_private::IterationAction::Stop;
+
+    if (bytes_read_for_chunk != bytes_to_read) {
----------------
Jlalond wrote:

We're already passing `bytes_read_for_chunk` and `bytes_to_read` which is the expected size, so I didn't need to change the lambda here

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


More information about the lldb-commits mailing list