diff --git a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp index 6cf555c69870..ff015aa54b76 100644 --- a/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp +++ b/lldb/source/Plugins/Process/minidump/MinidumpParser.cpp @@ -284,7 +284,7 @@ std::vector MinidumpParser::GetFilteredModuleList() { auto ExpectedName = m_file->getString(module.ModuleNameRVA); if (!ExpectedName) { LLDB_LOG_ERROR(log, ExpectedName.takeError(), - "Failed to module name: {0}"); + "Failed to get module name: {0}"); continue; } @@ -324,19 +324,15 @@ const MinidumpExceptionStream *MinidumpParser::GetExceptionStream() { llvm::Optional MinidumpParser::FindMemoryRange(lldb::addr_t addr) { - llvm::ArrayRef data = GetStream(StreamType::MemoryList); llvm::ArrayRef data64 = GetStream(StreamType::Memory64List); + Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_MODULES); - if (data.empty() && data64.empty()) - return llvm::None; - - if (!data.empty()) { - llvm::ArrayRef memory_list = ParseMemoryList(data); - - if (memory_list.empty()) - return llvm::None; - - for (const auto &memory_desc : memory_list) { + auto ExpectedMemory = GetMinidumpFile().getMemoryList(); + if (!ExpectedMemory) { + LLDB_LOG_ERROR(log, ExpectedMemory.takeError(), + "Failed to read memory list: {0}"); + } else { + for (const auto &memory_desc : *ExpectedMemory) { const LocationDescriptor &loc_desc = memory_desc.Memory; const lldb::addr_t range_start = memory_desc.StartOfMemoryRange; const size_t range_size = loc_desc.DataSize; @@ -345,8 +341,13 @@ MinidumpParser::FindMemoryRange(lldb::addr_t addr) { return llvm::None; if (range_start <= addr && addr < range_start + range_size) { - return minidump::Range(range_start, - GetData().slice(loc_desc.RVA, range_size)); + auto ExpectedSlice = GetMinidumpFile().getRawData(loc_desc); + if (!ExpectedSlice) { + LLDB_LOG_ERROR(log, ExpectedSlice.takeError(), + "Failed to get memory slice: {0}"); + return llvm::None; + } + return minidump::Range(range_start, *ExpectedSlice); } } } @@ -450,14 +451,15 @@ CreateRegionsCacheFromMemoryInfoList(MinidumpParser &parser, static bool CreateRegionsCacheFromMemoryList(MinidumpParser &parser, std::vector ®ions) { - auto data = parser.GetStream(StreamType::MemoryList); - if (data.empty()) + Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_MODULES); + auto ExpectedMemory = parser.GetMinidumpFile().getMemoryList(); + if (!ExpectedMemory) { + LLDB_LOG_ERROR(log, ExpectedMemory.takeError(), + "Failed to read memory list: {0}"); return false; - auto memory_list = ParseMemoryList(data); - if (memory_list.empty()) - return false; - regions.reserve(memory_list.size()); - for (const auto &memory_desc : memory_list) { + } + regions.reserve(ExpectedMemory->size()); + for (const MemoryDescriptor &memory_desc : *ExpectedMemory) { if (memory_desc.Memory.DataSize == 0) continue; MemoryRegionInfo region; diff --git a/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp b/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp index c3136ffe906a..d7fc6e43d090 100644 --- a/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp +++ b/lldb/source/Plugins/Process/minidump/MinidumpTypes.cpp @@ -68,25 +68,6 @@ MinidumpExceptionStream::Parse(llvm::ArrayRef &data) { return exception_stream; } -llvm::ArrayRef -minidump::ParseMemoryList(llvm::ArrayRef &data) { - const auto orig_size = data.size(); - const llvm::support::ulittle32_t *mem_ranges_count; - Status error = consumeObject(data, mem_ranges_count); - if (error.Fail() || - *mem_ranges_count * sizeof(MemoryDescriptor) > data.size()) - return {}; - - // Compilers might end up padding an extra 4 bytes depending on how the - // structure is padded by the compiler and the #pragma pack settings. - if (4 + *mem_ranges_count * sizeof(MemoryDescriptor) < orig_size) - data = data.drop_front(4); - - return llvm::makeArrayRef( - reinterpret_cast(data.data()), - *mem_ranges_count); -} - std::pair, uint64_t> MinidumpMemoryDescriptor64::ParseMemory64List(llvm::ArrayRef &data) { const llvm::support::ulittle64_t *mem_ranges_count; diff --git a/lldb/source/Plugins/Process/minidump/MinidumpTypes.h b/lldb/source/Plugins/Process/minidump/MinidumpTypes.h index 046832762730..b4878e82de5d 100644 --- a/lldb/source/Plugins/Process/minidump/MinidumpTypes.h +++ b/lldb/source/Plugins/Process/minidump/MinidumpTypes.h @@ -75,8 +75,6 @@ Status consumeObject(llvm::ArrayRef &Buffer, const T *&Object) { return error; } -llvm::ArrayRef ParseMemoryList(llvm::ArrayRef &data); - struct MinidumpMemoryDescriptor64 { llvm::support::ulittle64_t start_of_memory_range; llvm::support::ulittle64_t data_size;