LLVM: lib/Object/Minidump.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
11
12using namespace llvm;
15
16std::optional<ArrayRef<uint8_t>>
18 auto It = StreamMap.find(Type);
19 if (It != StreamMap.end())
21 return std::nullopt;
22}
23
25
26
27
28 auto ExpectedSize =
29 getDataSliceAssupport::ulittle32\_t(getData(), Offset, 1);
30 if (!ExpectedSize)
31 return ExpectedSize.takeError();
32 size_t Size = (*ExpectedSize)[0];
33 if (Size % 2 != 0)
34 return createError("String size not even");
36 if (Size == 0)
37 return "";
38
40 auto ExpectedData =
42 if (!ExpectedData)
43 return ExpectedData.takeError();
44
46 copy(*ExpectedData, WStr.begin());
47
48 std::string Result;
50 return createError("String decoding failed");
51
52 return Result;
53}
54
60
63 std::optional<ArrayRef<uint8_t>> Stream =
65 if (!Stream)
66 return createError("No such stream");
67 auto ExpectedHeader =
68 getDataSliceAsminidump::MemoryInfoListHeader(*Stream, 0, 1);
69 if (!ExpectedHeader)
70 return ExpectedHeader.takeError();
73 getDataSlice(*Stream, H.SizeOfHeader, H.SizeOfEntry * H.NumberOfEntries);
75 return Data.takeError();
78}
79
83
86 return createEOFError();
88}
89
93 auto ExpectedHeader = getDataSliceAsminidump::Header(Data, 0, 1);
94 if (!ExpectedHeader)
95 return ExpectedHeader.takeError();
96
99 return createError("Invalid signature");
101 return createError("Invalid version");
102
105 if (!ExpectedStreams)
106 return ExpectedStreams.takeError();
107
109 std::vector ExceptionStreams;
110 for (const auto &StreamDescriptor : llvm::enumerate(*ExpectedStreams)) {
113
115 getDataSlice(Data, Loc.RVA, Loc.DataSize);
116 if (!Stream)
118
120
121
122 continue;
123 }
124
125
126
127 if (Type == StreamType::Exception) {
128 ExceptionStreams.push_back(StreamDescriptor.value());
129 continue;
130 }
131
134 return createError("Cannot handle one of the minidump streams");
135
136
137 if (!StreamMap.try_emplace(Type, StreamDescriptor.index()).second)
138 return createError("Duplicate stream type");
139 }
140
141 return std::unique_ptr(
142 new MinidumpFile(Source, Hdr, *ExpectedStreams, std::move(StreamMap),
143 std::move(ExceptionStreams)));
144}
145
151 if (!ListHeader) {
154 }
155
156 std::optional<ArrayRef<uint8_t>> Stream =
158 if (!Stream) {
159 Err = createError("No such stream");
161 }
162
164 getDataSliceAsminidump::MemoryDescriptor\_64(
166 ListHeader->NumberOfMemoryRanges);
167
168 if (!Descriptors) {
171 }
172
173 if (!Descriptors->empty() &&
174 ListHeader->BaseRVA + Descriptors->front().DataSize > getData().size()) {
175 Err = createError("Memory64List header RVA out of range");
177 }
178
181 getData().slice(ListHeader->BaseRVA), *Descriptors),
182 Err),
184}
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Helper for Errors used as out-parameters.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
Type(LLVMContext &C, TypeID tid)
static fallible_iterator end(Memory64Iterator I)
static fallible_iterator itr(Memory64Iterator I, Error &Err)
A range adaptor for a pair of iterators.
StringRef getData() const
static Memory64Iterator begin(ArrayRef< uint8_t > Storage, ArrayRef< minidump::MemoryDescriptor_64 > Descriptors)
static Memory64Iterator end()
LLVM_ABI Expected< iterator_range< MemoryInfoIterator > > getMemoryInfoList() const
Returns the list of descriptors embedded in the MemoryInfoList stream.
Definition Minidump.cpp:62
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.
LLVM_ABI iterator_range< ExceptionStreamsIterator > getExceptionStreams() const
Returns an iterator that reads each exception stream independently.
Definition Minidump.cpp:56
LLVM_ABI Expected< std::string > getString(size_t Offset) const
Returns the minidump string at the given offset.
Definition Minidump.cpp:24
LLVM_ABI iterator_range< FallibleMemory64Iterator > getMemory64List(Error &Err) const
Returns an iterator that pairs each descriptor with it's respective content from the Memory64List str...
Definition Minidump.cpp:147
static LLVM_ABI Expected< std::unique_ptr< MinidumpFile > > create(MemoryBufferRef Source)
Construct a new MinidumpFile object from the given memory buffer.
Definition Minidump.cpp:91
StreamType
The type of a minidump stream identifies its contents.
detail::packed_endian_specific_integral< uint32_t, llvm::endianness::little, unaligned > ulittle32_t
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.
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
LLVM_ABI bool convertUTF16ToUTF8String(ArrayRef< char > SrcBytes, std::string &Out)
Converts a stream of raw bytes assumed to be UTF16 into a UTF8 std::string.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
OutputIt copy(R &&Range, OutputIt Out)
An information struct used to provide DenseMap with the various necessary components for a given valu...
Specifies the location (and size) of various objects in the minidump file.