Skip to content

Commit

Permalink
[Minidump] Declare MinidumpFile::getListStream in the header instead …
Browse files Browse the repository at this point in the history
…of extern template (llvm#112568)

This is part of the work to enable LLVM_BUILD_LLVM_DYLIB and LLVM
plugins on window.
  • Loading branch information
fsfod authored and NoumanAmir657 committed Nov 4, 2024
1 parent dfb63df commit 11bf398
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
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

0 comments on commit 11bf398

Please sign in to comment.