================ @@ -20,25 +20,104 @@ #include "lldb/Target/RegisterContext.h" #include "lldb/Target/StopInfo.h" #include "lldb/Target/ThreadList.h" +#include "lldb/Utility/DataBufferHeap.h" #include "lldb/Utility/DataExtractor.h" #include "lldb/Utility/LLDBLog.h" #include "lldb/Utility/Log.h" +#include "lldb/Utility/RangeMap.h" #include "lldb/Utility/RegisterValue.h" #include "llvm/ADT/StringRef.h" #include "llvm/BinaryFormat/Minidump.h" #include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/Endian.h" #include "llvm/Support/Error.h" +#include "llvm/TargetParser/Triple.h" #include "Plugins/Process/minidump/MinidumpTypes.h" +#include "lldb/lldb-enumerations.h" +#include "lldb/lldb-forward.h" +#include "lldb/lldb-types.h" +#include <algorithm> #include <cinttypes> +#include <climits> +#include <cstddef> +#include <cstdint> +#include <functional> +#include <iostream> +#include <set> +#include <utility> +#include <vector> using namespace lldb; using namespace lldb_private; using namespace llvm::minidump; -void MinidumpFileBuilder::AddDirectory(StreamType type, size_t stream_size) { +Status MinidumpFileBuilder::AddHeaderAndCalculateDirectories() { + // First set the offset on the file, and on the bytes saved + m_saved_data_size += header_size; + // We know we will have at least Misc, SystemInfo, Modules, and ThreadList + // (corresponding memory list for stacks) And an additional memory list for + // non-stacks. + lldb_private::Target &target = m_process_sp->GetTarget(); + m_expected_directories = 6; + // Check if OS is linux and reserve directory space for all linux specific breakpad extension directories. + if (target.GetArchitecture().GetTriple().getOS() == + llvm::Triple::OSType::Linux) + m_expected_directories += 9; + + // Go through all of the threads and check for exceptions. + lldb_private::ThreadList thread_list = m_process_sp->GetThreadList(); + const uint32_t num_threads = thread_list.GetSize(); + for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) { + ThreadSP thread_sp(thread_list.GetThreadAtIndex(thread_idx)); + StopInfoSP stop_info_sp = thread_sp->GetStopInfo(); + if (stop_info_sp && + stop_info_sp->GetStopReason() == StopReason::eStopReasonException) { + m_expected_directories++; + } + } + + // Now offset the file by the directores so we can write them in later. + offset_t directory_offset = m_expected_directories * directory_size; + m_saved_data_size += directory_offset; + Status error; + size_t zeroes = 0; // 8 0's + size_t remaining_bytes = m_saved_data_size; + while (remaining_bytes > 0) { + // Keep filling in zero's until we preallocate enough space for the header + // and directory sections. + size_t bytes_written = std::min(remaining_bytes, sizeof(size_t)); + error = m_core_file->Write(&zeroes, bytes_written); + if (error.Fail()) { + error.SetErrorStringWithFormat( + "Unable to write header and directory padding (written %zd/%zd)", + remaining_bytes - m_saved_data_size, m_saved_data_size); + break; + } + + remaining_bytes -= bytes_written; + } ---------------- clayborg wrote:
Just set the file position in the `m_core_file`: ``` m_core_file->SeekFromStart(m_saved_data_size); ``` And remove this entire while loop. https://github.com/llvm/llvm-project/pull/95312 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits