9#ifndef LLVM_OBJECT_MINIDUMP_H
10#define LLVM_OBJECT_MINIDUMP_H
46 std::optional<ArrayRef<uint8_t>>
53 return getDataSlice(getData(),
Desc.RVA,
Desc.DataSize);
65 return getStream<minidump::SystemInfo>(minidump::StreamType::SystemInfo);
74 return getListStream<minidump::Module>(minidump::StreamType::ModuleList);
83 return getListStream<minidump::Thread>(minidump::StreamType::ThreadList);
91 if (Directory.
Type != minidump::StreamType::Exception) {
92 return createError(
"Not an exception stream");
95 return getStreamFromDirectory<minidump::ExceptionStream>(Directory);
103 if (it.begin() == it.end())
104 return createError(
"No exception streams");
116 return getListStream<minidump::MemoryDescriptor>(
117 minidump::StreamType::MemoryList);
123 return getStream<minidump::Memory64ListHeader>(
124 minidump::StreamType::Memory64List);
129 std::forward_iterator_tag,
130 minidump::MemoryInfo> {
133 : Storage(Storage), Stride(Stride) {
138 return Storage.
size() == R.Storage.size();
169 return IsEnd == R.IsEnd;
174 const std::pair<minidump::MemoryDescriptor_64, ArrayRef<uint8_t>> &
179 const std::pair<minidump::MemoryDescriptor_64, ArrayRef<uint8_t>> *
185 if (Descriptors.empty()) {
194 return make_error<GenericBinaryError>(
195 "Memory64 Descriptor exceeds end of file.",
200 Current = std::make_pair(Descriptor,
Content);
203 Descriptors = Descriptors.drop_front();
212 : Storage(Storage), Descriptors(Descriptors), IsEnd(
false) {
214 Storage.
size() >= Descriptors.
front().DataSize);
217 Current = std::make_pair(Descriptor,
Content);
224 Descriptors(
ArrayRef<minidump::MemoryDescriptor_64>()), IsEnd(
true) {}
226 std::pair<minidump::MemoryDescriptor_64, ArrayRef<uint8_t>> Current;
236 : Streams(Streams), File(File) {}
239 return Streams.size() == R.Streams.size();
243 return !(*
this == R);
251 if (!Streams.empty())
252 Streams = Streams.drop_front();
290 static Error createEOFError() {
291 return make_error<GenericBinaryError>(
"Unexpected EOF",
302 template <
typename T>
309 std::vector<minidump::Directory> ExceptionStreams)
311 StreamMap(
std::
move(StreamMap)),
312 ExceptionStreams(
std::
move(ExceptionStreams)) {}
314 ArrayRef<uint8_t> getData()
const {
320 template <
typename T>
322 getStreamFromDirectory(minidump::Directory Directory)
const;
326 template <
typename T>
331 template <
typename T>
334 const minidump::Header &Header;
335 ArrayRef<minidump::Directory> Streams;
336 DenseMap<minidump::StreamType, std::size_t> StreamMap;
337 std::vector<minidump::Directory> ExceptionStreams;
342MinidumpFile::getStreamFromDirectory(minidump::Directory Directory)
const {
344 if (Stream.size() >=
sizeof(
T))
345 return *
reinterpret_cast<const T *
>(Stream.data());
346 return createEOFError();
351 if (std::optional<ArrayRef<uint8_t>> Stream =
getRawStream(Type)) {
352 if (Stream->size() >=
sizeof(
T))
353 return *
reinterpret_cast<const T *
>(Stream->data());
354 return createEOFError();
356 return createError(
"No such stream");
360Expected<ArrayRef<T>> MinidumpFile::getDataSliceAs(ArrayRef<uint8_t>
Data,
364 if (Count > std::numeric_limits<uint64_t>::max() /
sizeof(
T))
365 return createEOFError();
366 Expected<ArrayRef<uint8_t>> Slice =
369 return Slice.takeError();
371 return ArrayRef<T>(
reinterpret_cast<const T *
>(Slice->data()), Count);
377 std::optional<ArrayRef<uint8_t>> Stream =
getRawStream(Type);
379 return createError(
"No such stream");
380 auto ExpectedSize = getDataSliceAs<support::ulittle32_t>(*Stream, 0, 1);
382 return ExpectedSize.takeError();
384 size_t ListSize = ExpectedSize.get()[0];
386 size_t ListOffset = 4;
390 if (ListOffset +
sizeof(
T) * ListSize < Stream->
size())
393 return getDataSliceAs<T>(*Stream, ListOffset, ListSize);
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseMap class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
const T & front() const
front - Get the first element.
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
StringRef getBuffer() const
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
A wrapper class for fallible iterators.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
A range adaptor for a pair of iterators.
bool operator!=(const ExceptionStreamsIterator &R) const
Expected< const minidump::ExceptionStream & > operator*()
ExceptionStreamsIterator & operator++()
bool operator==(const ExceptionStreamsIterator &R) const
ExceptionStreamsIterator(ArrayRef< minidump::Directory > Streams, const MinidumpFile *File)
Class the provides an iterator over the memory64 memory ranges.
bool operator==(const Memory64Iterator &R) const
static Memory64Iterator begin(ArrayRef< uint8_t > Storage, ArrayRef< minidump::MemoryDescriptor_64 > Descriptors)
bool operator!=(const Memory64Iterator &R) const
const std::pair< minidump::MemoryDescriptor_64, ArrayRef< uint8_t > > & operator*()
const std::pair< minidump::MemoryDescriptor_64, ArrayRef< uint8_t > > * operator->()
static Memory64Iterator end()
bool operator==(const MemoryInfoIterator &R) const
MemoryInfoIterator & operator++()
MemoryInfoIterator(ArrayRef< uint8_t > Storage, size_t Stride)
const minidump::MemoryInfo & operator*() const
A class providing access to the contents of a minidump file.
Expected< iterator_range< MemoryInfoIterator > > getMemoryInfoList() const
Returns the list of descriptors embedded in the MemoryInfoList stream.
Expected< const minidump::ExceptionStream & > getExceptionStream(minidump::Directory Directory) const
Returns the contents of the Exception stream.
Expected< minidump::Memory64ListHeader > getMemoryList64Header() const
Returns the header to the memory 64 list stream.
ArrayRef< uint8_t > getRawStream(const minidump::Directory &Stream) const
Returns the raw contents of the stream given by the directory entry.
Expected< const minidump::ExceptionStream & > getExceptionStream() const
Returns the first exception stream in the file.
const minidump::Header & header() const
Returns the contents of the minidump header.
Expected< const minidump::SystemInfo & > getSystemInfo() const
Returns the contents of the SystemInfo stream, cast to the appropriate type.
Expected< ArrayRef< uint8_t > > getRawData(minidump::LocationDescriptor Desc) const
Returns the raw contents of an object given by the LocationDescriptor.
iterator_range< ExceptionStreamsIterator > getExceptionStreams() const
Returns an iterator that reads each exception stream independently.
static bool classof(const Binary *B)
Expected< std::string > getString(size_t Offset) const
Returns the minidump string at the given offset.
Expected< ArrayRef< minidump::MemoryDescriptor > > getMemoryList() const
Returns the list of descriptors embedded in the MemoryList stream.
Expected< ArrayRef< minidump::Module > > getModuleList() const
Returns the module list embedded in the ModuleList stream.
Expected< ArrayRef< minidump::Thread > > getThreadList() const
Returns the thread list embedded in the ThreadList stream.
ArrayRef< minidump::Directory > streams() const
Returns the list of streams (stream directory entries) in this file.
iterator_range< FallibleMemory64Iterator > getMemory64List(Error &Err) const
Returns an iterator that pairs each descriptor with it's respective content from the Memory64List str...
static Expected< std::unique_ptr< MinidumpFile > > create(MemoryBufferRef Source)
Construct a new MinidumpFile object from the given memory buffer.
StreamType
The type of a minidump stream identifies its contents.
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
Description of the encoding of one expression Op.
Specifies the location and type of a single stream in the minidump file.
LocationDescriptor Location
support::little_t< StreamType > Type
Specifies the location (and size) of various objects in the minidump file.
support::ulittle32_t DataSize
support::ulittle64_t DataSize