diff --git a/llvm/include/llvm/Object/Minidump.h b/llvm/include/llvm/Object/Minidump.h index e6b21979ccaa1d..831be1c51d5748 100644 --- a/llvm/include/llvm/Object/Minidump.h +++ b/llvm/include/llvm/Object/Minidump.h @@ -371,6 +371,28 @@ Expected> MinidumpFile::getDataSliceAs(ArrayRef Data, return ArrayRef(reinterpret_cast(Slice->data()), Count); } +template +Expected> +MinidumpFile::getListStream(minidump::StreamType Type) const { + std::optional> Stream = getRawStream(Type); + if (!Stream) + return createError("No such stream"); + auto ExpectedSize = getDataSliceAs(*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(*Stream, ListOffset, ListSize); +} + } // end namespace object } // end namespace llvm diff --git a/llvm/lib/Object/Minidump.cpp b/llvm/lib/Object/Minidump.cpp index fe768c4c90711b..83c527e84365f8 100644 --- a/llvm/lib/Object/Minidump.cpp +++ b/llvm/lib/Object/Minidump.cpp @@ -78,33 +78,6 @@ MinidumpFile::getMemoryInfoList() const { MemoryInfoIterator({}, H.SizeOfEntry)); } -template -Expected> MinidumpFile::getListStream(StreamType Type) const { - std::optional> Stream = getRawStream(Type); - if (!Stream) - return createError("No such stream"); - auto ExpectedSize = getDataSliceAs(*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(*Stream, ListOffset, ListSize); -} -template Expected> - MinidumpFile::getListStream(StreamType) const; -template Expected> - MinidumpFile::getListStream(StreamType) const; -template Expected> - MinidumpFile::getListStream(StreamType) const; - Expected> MinidumpFile::getDataSlice(ArrayRef Data, uint64_t Offset, uint64_t Size) {