@@ -95,13 +95,6 @@ class MinidumpFile : public Binary {
95
95
return getStreamFromDirectory<minidump::ExceptionStream>(Directory);
96
96
}
97
97
98
- // / Returns the contents of the Exception streams. An error is returned if
99
- // / any of the streams are smaller than the size of the ExceptionStream
100
- // / structure. The internal consistency of the stream is not checked in any
101
- // / way.
102
- Expected<std::vector<const minidump::ExceptionStream *>>
103
- getExceptionStreams () const ;
104
-
105
98
// / Returns the list of descriptors embedded in the MemoryList stream. The
106
99
// / descriptors provide the content of interesting regions of memory at the
107
100
// / time the minidump was taken. An error is returned if the file does not
@@ -226,8 +219,71 @@ class MinidumpFile : public Binary {
226
219
bool IsEnd;
227
220
};
228
221
222
+ class ExceptionStreamsIterator {
223
+ public:
224
+
225
+ static ExceptionStreamsIterator begin (ArrayRef<minidump::Directory> Streams, const MinidumpFile *File) {
226
+ return ExceptionStreamsIterator (Streams, File);
227
+ }
228
+
229
+ static ExceptionStreamsIterator end () {
230
+ return ExceptionStreamsIterator ();
231
+ }
232
+
233
+ bool operator ==(const ExceptionStreamsIterator &R) const {
234
+ return Streams.empty () && R.Streams .empty ();
235
+ }
236
+
237
+ bool operator !=(const ExceptionStreamsIterator &R) const { return !(*this == R); }
238
+
239
+ const Expected<const minidump::ExceptionStream &>
240
+ operator *() {
241
+ return ReadCurrent ();
242
+ }
243
+
244
+ const Expected<const minidump::ExceptionStream &>
245
+ operator ->() {
246
+ return ReadCurrent ();
247
+ }
248
+
249
+ ExceptionStreamsIterator &
250
+ operator ++ () {
251
+ if (!Streams.empty ())
252
+ Streams = Streams.drop_front ();
253
+
254
+
255
+ return *this ;
256
+ }
257
+
258
+ private:
259
+ ExceptionStreamsIterator (ArrayRef<minidump::Directory> Streams, const MinidumpFile *File)
260
+ : Streams(Streams), File(File) {}
261
+
262
+ ExceptionStreamsIterator () : Streams(ArrayRef<minidump::Directory>()), File(nullptr ) {}
263
+
264
+ ArrayRef<minidump::Directory> Streams;
265
+ const MinidumpFile *File;
266
+
267
+ Expected<const minidump::ExceptionStream&> ReadCurrent () {
268
+ assert (!Streams.empty ());
269
+ Expected<const minidump::ExceptionStream &> ExceptionStream =
270
+ File->getExceptionStream (Streams.front ());
271
+ if (!ExceptionStream)
272
+ return ExceptionStream.takeError ();
273
+
274
+ return ExceptionStream;
275
+ }
276
+ };
277
+
229
278
using FallibleMemory64Iterator = llvm::fallible_iterator<Memory64Iterator>;
230
279
280
+ // / Returns an iterator that reads each exception stream independently. The
281
+ // / contents of the exception strema are not validated before being read, an
282
+ // / error will be returned if the stream is not large enough to contain an
283
+ // / exception stream, or if the stream points beyond the end of the file.
284
+ iterator_range<ExceptionStreamsIterator>
285
+ getExceptionStreams () const ;
286
+
231
287
// / Returns an iterator that pairs each descriptor with it's respective
232
288
// / content from the Memory64List stream. An error is returned if the file
233
289
// / does not contain a Memory64List stream, or if the descriptor data is
@@ -266,9 +322,10 @@ class MinidumpFile : public Binary {
266
322
267
323
MinidumpFile (MemoryBufferRef Source, const minidump::Header &Header,
268
324
ArrayRef<minidump::Directory> Streams,
269
- DenseMap<minidump::StreamType, std::size_t > StreamMap)
325
+ DenseMap<minidump::StreamType, std::size_t > StreamMap,
326
+ std::vector<minidump::Directory> ExceptionStreams)
270
327
: Binary(ID_Minidump, Source), Header(Header), Streams(Streams),
271
- StreamMap(std::move(StreamMap)) {}
328
+ StreamMap(std::move(StreamMap)), ExceptionStreams(std::move(ExceptionStreams)) {}
272
329
273
330
ArrayRef<uint8_t > getData () const {
274
331
return arrayRefFromStringRef (Data.getBuffer ());
@@ -293,6 +350,7 @@ class MinidumpFile : public Binary {
293
350
const minidump::Header &Header;
294
351
ArrayRef<minidump::Directory> Streams;
295
352
DenseMap<minidump::StreamType, std::size_t > StreamMap;
353
+ std::vector<minidump::Directory> ExceptionStreams;
296
354
};
297
355
298
356
template <typename T>
0 commit comments