minidump: Use MemoryList parsing code from llvm

llvm-svn: 361010
This commit is contained in:
Pavel Labath 2019-05-17 09:47:34 +00:00
parent 632dfdda16
commit 62370dd0e0
3 changed files with 23 additions and 42 deletions

View File

@ -284,7 +284,7 @@ std::vector<const minidump::Module *> 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<minidump::Range>
MinidumpParser::FindMemoryRange(lldb::addr_t addr) {
llvm::ArrayRef<uint8_t> data = GetStream(StreamType::MemoryList);
llvm::ArrayRef<uint8_t> data64 = GetStream(StreamType::Memory64List);
Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_MODULES);
if (data.empty() && data64.empty())
return llvm::None;
if (!data.empty()) {
llvm::ArrayRef<MemoryDescriptor> 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<MemoryRegionInfo> &regions) {
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;

View File

@ -68,25 +68,6 @@ MinidumpExceptionStream::Parse(llvm::ArrayRef<uint8_t> &data) {
return exception_stream;
}
llvm::ArrayRef<MemoryDescriptor>
minidump::ParseMemoryList(llvm::ArrayRef<uint8_t> &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<const MemoryDescriptor *>(data.data()),
*mem_ranges_count);
}
std::pair<llvm::ArrayRef<MinidumpMemoryDescriptor64>, uint64_t>
MinidumpMemoryDescriptor64::ParseMemory64List(llvm::ArrayRef<uint8_t> &data) {
const llvm::support::ulittle64_t *mem_ranges_count;

View File

@ -75,8 +75,6 @@ Status consumeObject(llvm::ArrayRef<uint8_t> &Buffer, const T *&Object) {
return error;
}
llvm::ArrayRef<MemoryDescriptor> ParseMemoryList(llvm::ArrayRef<uint8_t> &data);
struct MinidumpMemoryDescriptor64 {
llvm::support::ulittle64_t start_of_memory_range;
llvm::support::ulittle64_t data_size;