Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions llvm/include/llvm/Object/Minidump.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,28 @@ Expected<ArrayRef<T>> MinidumpFile::getDataSliceAs(ArrayRef<uint8_t> Data,
return ArrayRef<T>(reinterpret_cast<const T *>(Slice->data()), Count);
}

template <typename T>
Expected<ArrayRef<T>>
MinidumpFile::getListStream(minidump::StreamType Type) const {
std::optional<ArrayRef<uint8_t>> Stream = getRawStream(Type);
if (!Stream)
return createError("No such stream");
auto ExpectedSize = getDataSliceAs<support::ulittle32_t>(*Stream, 0, 1);
if (!ExpectedSize)
return ExpectedSize.takeError();

size_t ListSize = ExpectedSize.get()[0];

size_t ListOffset = 4;
// Some producers insert additional padding bytes to align the list to an
// 8-byte boundary. Check for that by comparing the list size with the overall
// stream size.
if (ListOffset + sizeof(T) * ListSize < Stream->size())
ListOffset = 8;

return getDataSliceAs<T>(*Stream, ListOffset, ListSize);
}

} // end namespace object
} // end namespace llvm

Expand Down
27 changes: 0 additions & 27 deletions llvm/lib/Object/Minidump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,6 @@ MinidumpFile::getMemoryInfoList() const {
MemoryInfoIterator({}, H.SizeOfEntry));
}

template <typename T>
Expected<ArrayRef<T>> MinidumpFile::getListStream(StreamType Type) const {
std::optional<ArrayRef<uint8_t>> Stream = getRawStream(Type);
if (!Stream)
return createError("No such stream");
auto ExpectedSize = getDataSliceAs<support::ulittle32_t>(*Stream, 0, 1);
if (!ExpectedSize)
return ExpectedSize.takeError();

size_t ListSize = ExpectedSize.get()[0];

size_t ListOffset = 4;
// Some producers insert additional padding bytes to align the list to an
// 8-byte boundary. Check for that by comparing the list size with the overall
// stream size.
if (ListOffset + sizeof(T) * ListSize < Stream->size())
ListOffset = 8;

return getDataSliceAs<T>(*Stream, ListOffset, ListSize);
}
template Expected<ArrayRef<Module>>
MinidumpFile::getListStream(StreamType) const;
template Expected<ArrayRef<Thread>>
MinidumpFile::getListStream(StreamType) const;
template Expected<ArrayRef<MemoryDescriptor>>
MinidumpFile::getListStream(StreamType) const;

Expected<ArrayRef<uint8_t>> MinidumpFile::getDataSlice(ArrayRef<uint8_t> Data,
uint64_t Offset,
uint64_t Size) {
Expand Down
Loading