LLVM: include/llvm/Object/Minidump.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_OBJECT_MINIDUMP_H
10#define LLVM_OBJECT_MINIDUMP_H
11
20
21namespace llvm {
23
24
25class MinidumpFile : public Binary {
26public:
27
28
29
32
34
35
37
38
40
41
45
46
47
48 LLVM_ABI std::optional<ArrayRef<uint8_t>>
50
51
52
57
58
59
61
62
63
64
65
67 return getStreamminidump::SystemInfo(minidump::StreamType::SystemInfo);
68 }
69
70
71
72
73
74
76 return getListStreamminidump::Module(minidump::StreamType::ModuleList);
77 }
78
79
80
81
82
83
85 return getListStreamminidump::Thread(minidump::StreamType::ThreadList);
86 }
87
88
89
90
93 if (Directory.Type != minidump::StreamType::Exception) {
94 return createError("Not an exception stream");
95 }
96
97 return getStreamFromDirectoryminidump::ExceptionStream(Directory);
98 }
99
100
101
102
105 if (it.begin() == it.end())
106 return createError("No exception streams");
107 return *it.begin();
108 }
109
110
111
112
113
114
115
116
118 return getListStreamminidump::MemoryDescriptor(
119 minidump::StreamType::MemoryList);
120 }
121
122
123
125 return getStreamminidump::Memory64ListHeader(
126 minidump::StreamType::Memory64List);
127 }
128
131 std::forward_iterator_tag,
132 minidump::MemoryInfo> {
133 public:
135 : Storage(Storage), Stride(Stride) {
136 assert(Storage.size() % Stride == 0);
137 }
138
140 return Storage.size() == R.Storage.size();
141 }
142
147
149 Storage = Storage.drop_front(Stride);
150 return *this;
151 }
152
153 private:
155 size_t Stride;
156 };
157
158
159
160 class Memory64Iterator {
161 public:
162 static Memory64Iterator
165 return Memory64Iterator(Storage, Descriptors);
166 }
167
168 static Memory64Iterator end() { return Memory64Iterator(); }
169
170 bool operator==(const Memory64Iterator &R) const {
171 return IsEnd == R.IsEnd;
172 }
173
174 bool operator!=(const Memory64Iterator &R) const { return !(*this == R); }
175
176 const std::pair<minidump::MemoryDescriptor_64, ArrayRef<uint8_t>> &
178 return Current;
179 }
180
181 const std::pair<minidump::MemoryDescriptor_64, ArrayRef<uint8_t>> *
183 return &Current;
184 }
185
187 if (Descriptors.empty()) {
188 IsEnd = true;
190 }
191
192
194 if (Descriptor.DataSize > Storage.size()) {
195 IsEnd = true;
197 "Memory64 Descriptor exceeds end of file.",
199 }
200
202 Current = std::make_pair(Descriptor, Content);
203
204 Storage = Storage.drop_front(Descriptor.DataSize);
205 Descriptors = Descriptors.drop_front();
206
208 }
209
210 private:
211
214 : Storage(Storage), Descriptors(Descriptors), IsEnd(false) {
216 Storage.size() >= Descriptors.front().DataSize);
219 Current = std::make_pair(Descriptor, Content);
220 this->Descriptors = Descriptors.drop_front();
222 }
223
224 Memory64Iterator()
227
228 std::pair<minidump::MemoryDescriptor_64, ArrayRef<uint8_t>> Current;
231 bool IsEnd;
232 };
233
235 public:
237 const MinidumpFile *File)
238 : Streams(Streams), File(File) {}
239
241 return Streams.size() == R.Streams.size();
242 }
243
245 return !(*this == R);
246 }
247
249 return File->getExceptionStream(Streams.front());
250 }
251
253 if (!Streams.empty())
254 Streams = Streams.drop_front();
255
256 return *this;
257 }
258
259 private:
261 const MinidumpFile *File;
262 };
263
265
266
267
268
269
271
272
273
274
275
278
279
280
281
282
283
284
285
288
289private:
292 }
293
294 static Error createEOFError() {
297 }
298
299
302
303
304
305
306 template
309
313 std::vectorminidump::Directory ExceptionStreams)
315 StreamMap(std::move(StreamMap)),
316 ExceptionStreams(std::move(ExceptionStreams)) {}
317
318 ArrayRef<uint8_t> getData() const {
320 }
321
322
323
324 template
325 Expected<const T &>
326 getStreamFromDirectory(minidump::Directory Directory) const;
327
328
329
330 template
332
333
334
335 template
337
338 const minidump::Header &Header;
340 DenseMap<minidump::StreamType, std::size_t> StreamMap;
341 std::vectorminidump::Directory ExceptionStreams;
342};
343
344template
345Expected<const T &>
346MinidumpFile::getStreamFromDirectory(minidump::Directory Directory) const {
347 ArrayRef<uint8_t> Stream = getRawStream(Directory);
348 if (Stream.size() >= sizeof(T))
349 return *reinterpret_cast<const T *>(Stream.data());
350 return createEOFError();
351}
352
353template
355 if (std::optional<ArrayRef<uint8_t>> Stream = getRawStream(Type)) {
356 if (Stream->size() >= sizeof(T))
357 return *reinterpret_cast<const T *>(Stream->data());
358 return createEOFError();
359 }
360 return createError("No such stream");
361}
362
363template
364Expected<ArrayRef> MinidumpFile::getDataSliceAs(ArrayRef<uint8_t> Data,
366 uint64_t Count) {
367
368 if (Count > std::numeric_limits<uint64_t>::max() / sizeof(T))
369 return createEOFError();
370 Expected<ArrayRef<uint8_t>> Slice =
372 if (!Slice)
373 return Slice.takeError();
374
375 return ArrayRef(reinterpret_cast<const T *>(Slice->data()), Count);
376}
377
378template
379Expected<ArrayRef>
381 std::optional<ArrayRef<uint8_t>> Stream = getRawStream(Type);
382 if (!Stream)
383 return createError("No such stream");
384 auto ExpectedSize = getDataSliceAssupport::ulittle32\_t(*Stream, 0, 1);
385 if (!ExpectedSize)
386 return ExpectedSize.takeError();
387
388 size_t ListSize = ExpectedSize.get()[0];
389
390 size_t ListOffset = 4;
391
392
393
394 if (ListOffset + sizeof(T) * ListSize < Stream->size())
395 ListOffset = 8;
396
397 return getDataSliceAs(*Stream, ListOffset, ListSize);
398}
399
400}
401}
402
403#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseMap class.
static Expected< const T & > getDataSliceAs(ArrayRef< uint8_t > Data, uint64_t Offset)
static Expected< ArrayRef< uint8_t > > getDataSlice(ArrayRef< uint8_t > Data, uint64_t Offset, uint64_t Size)
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.
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.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
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.
StringRef getData() const
Binary(unsigned int Type, MemoryBufferRef Source)
bool operator!=(const ExceptionStreamsIterator &R) const
Definition Minidump.h:244
Expected< const minidump::ExceptionStream & > operator*()
Definition Minidump.h:248
ExceptionStreamsIterator & operator++()
Definition Minidump.h:252
bool operator==(const ExceptionStreamsIterator &R) const
Definition Minidump.h:240
ExceptionStreamsIterator(ArrayRef< minidump::Directory > Streams, const MinidumpFile *File)
Definition Minidump.h:236
Class the provides an iterator over the memory64 memory ranges.
Definition Minidump.h:160
bool operator==(const Memory64Iterator &R) const
Definition Minidump.h:170
static Memory64Iterator begin(ArrayRef< uint8_t > Storage, ArrayRef< minidump::MemoryDescriptor_64 > Descriptors)
Definition Minidump.h:163
bool operator!=(const Memory64Iterator &R) const
Definition Minidump.h:174
const std::pair< minidump::MemoryDescriptor_64, ArrayRef< uint8_t > > & operator*()
Definition Minidump.h:177
const std::pair< minidump::MemoryDescriptor_64, ArrayRef< uint8_t > > * operator->()
Definition Minidump.h:182
Error inc()
Definition Minidump.h:186
static Memory64Iterator end()
Definition Minidump.h:168
bool operator==(const MemoryInfoIterator &R) const
Definition Minidump.h:139
MemoryInfoIterator & operator++()
Definition Minidump.h:148
MemoryInfoIterator(ArrayRef< uint8_t > Storage, size_t Stride)
Definition Minidump.h:134
const minidump::MemoryInfo & operator*() const
Definition Minidump.h:143
LLVM_ABI 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.
Definition Minidump.h:92
Expected< minidump::Memory64ListHeader > getMemoryList64Header() const
Returns the header to the memory 64 list stream.
Definition Minidump.h:124
ArrayRef< uint8_t > getRawStream(const minidump::Directory &Stream) const
Returns the raw contents of the stream given by the directory entry.
Definition Minidump.h:42
Expected< const minidump::ExceptionStream & > getExceptionStream() const
Returns the first exception stream in the file.
Definition Minidump.h:103
const minidump::Header & header() const
Returns the contents of the minidump header.
Definition Minidump.h:36
Expected< const minidump::SystemInfo & > getSystemInfo() const
Returns the contents of the SystemInfo stream, cast to the appropriate type.
Definition Minidump.h:66
Expected< ArrayRef< uint8_t > > getRawData(minidump::LocationDescriptor Desc) const
Returns the raw contents of an object given by the LocationDescriptor.
Definition Minidump.h:54
LLVM_ABI iterator_range< ExceptionStreamsIterator > getExceptionStreams() const
Returns an iterator that reads each exception stream independently.
static bool classof(const Binary *B)
Definition Minidump.h:33
LLVM_ABI 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.
Definition Minidump.h:117
llvm::fallible_iterator< Memory64Iterator > FallibleMemory64Iterator
Definition Minidump.h:264
Expected< ArrayRef< minidump::Module > > getModuleList() const
Returns the module list embedded in the ModuleList stream.
Definition Minidump.h:75
Expected< ArrayRef< minidump::Thread > > getThreadList() const
Returns the thread list embedded in the ThreadList stream.
Definition Minidump.h:84
ArrayRef< minidump::Directory > streams() const
Returns the list of streams (stream directory entries) in this file.
Definition Minidump.h:39
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...
static LLVM_ABI 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.
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
FunctionAddr VTableAddr Count
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
ArrayRef(const T &OneElt) -> ArrayRef< T >
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.
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