Skip to content

Commit

Permalink
Just declare MinidumpFile::getListStream in the header instead of ext…
Browse files Browse the repository at this point in the history
…ern template
  • Loading branch information
fsfod committed Nov 1, 2024
1 parent 12e26d1 commit 1f54810
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 40 deletions.
34 changes: 21 additions & 13 deletions llvm/include/llvm/Object/Minidump.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@
#include "llvm/ADT/iterator.h"
#include "llvm/BinaryFormat/Minidump.h"
#include "llvm/Object/Binary.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"

namespace llvm {
namespace minidump {
struct Module;
struct Thread;
struct MemoryDescriptor;
} // namespace minidump
namespace object {

/// A class providing access to the contents of a minidump file.
Expand Down Expand Up @@ -377,13 +371,27 @@ Expected<ArrayRef<T>> MinidumpFile::getDataSliceAs(ArrayRef<uint8_t> Data,
return ArrayRef<T>(reinterpret_cast<const T *>(Slice->data()), Count);
}

// Needed by MinidumpTest.cpp
extern template LLVM_TEMPLATE_ABI Expected<ArrayRef<minidump::Module>>
MinidumpFile::getListStream(minidump::StreamType) const;
extern template LLVM_TEMPLATE_ABI Expected<ArrayRef<minidump::Thread>>
MinidumpFile::getListStream(minidump::StreamType) const;
extern template LLVM_TEMPLATE_ABI Expected<ArrayRef<minidump::MemoryDescriptor>>
MinidumpFile::getListStream(minidump::StreamType) const;
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 LLVM_EXPORT_TEMPLATE Expected<ArrayRef<Module>>
MinidumpFile::getListStream(StreamType) const;
template LLVM_EXPORT_TEMPLATE Expected<ArrayRef<Thread>>
MinidumpFile::getListStream(StreamType) const;
template LLVM_EXPORT_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 1f54810

Please sign in to comment.