================ @@ -969,6 +969,66 @@ Status MinidumpFileBuilder::DumpDirectories() const { return error; } +Status MinidumpFileBuilder::ReadWriteMemoryInChunks( + lldb_private::DataBufferHeap &data_buffer, + const lldb_private::CoreFileMemoryRange &range, uint64_t &bytes_read) { + + const lldb::addr_t addr = range.range.start(); + const lldb::addr_t size = range.range.size(); + Log *log = GetLog(LLDBLog::Object); + Status addDataError; + Process::ReadMemoryChunkCallback callback = + [&](Status &error, lldb::addr_t current_addr, const void *buf, + 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(buf, bytes_read_for_chunk); + if (addDataError.Fail()) + return lldb_private::IterationAction::Stop; + + // If we have a partial read, report it, but only if the partial read + // didn't finish reading the entire region. + if (bytes_read_for_chunk != data_buffer.GetByteSize() && + current_addr + bytes_read_for_chunk != size) { + LLDB_LOGF(log, + "Memory region at: %" PRIx64 " partiall read %" PRIx64 ---------------- clayborg wrote:
s/partiall/partial/ You also want all addresses to be prefixed with 0x here, so the format string should be: ``` "Memory region at: 0x%" PRIx64 " partiall read 0x%" PRIx64 ``` Same for format string below. https://github.com/llvm/llvm-project/pull/129307 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits