[Lldb-commits] [lldb] [LLDB][Minidump]Update MinidumpFileBuilder to read and write in chunks (PR #129307)
Greg Clayton via lldb-commits
lldb-commits at lists.llvm.org
Mon Apr 7 10:57:45 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) {
----------------
clayborg wrote:
You will pass in a chunk_size which can be captured in the lambda and you compare the "bytes_size" to your "chunk_size".
https://github.com/llvm/llvm-project/pull/129307
More information about the lldb-commits
mailing list