@@ -83,15 +83,25 @@ class MinidumpFile : public Binary {
83
83
return getListStream<minidump::Thread>(minidump::StreamType::ThreadList);
84
84
}
85
85
86
- // / Returns the contents of the Exception stream. An error is returned if the
87
- // / file does not contain this stream, or the stream is smaller than the size
88
- // / of the ExceptionStream structure. The internal consistency of the stream
89
- // / is not checked in any way.
90
- Expected<const minidump::ExceptionStream &> getExceptionStream () const {
91
- return getStream<minidump::ExceptionStream>(
92
- minidump::StreamType::Exception);
86
+ // / Returns the contents of the Exception stream. An error is returned if the
87
+ // / associated stream is smaller than the size of the ExceptionStream
88
+ // / structure. Or the directory supplied is not of kind exception stream.
89
+ Expected<const minidump::ExceptionStream &>
90
+ getExceptionStream (minidump::Directory Directory) const {
91
+ if (Directory.Type != minidump::StreamType::Exception) {
92
+ return createError (" Not an exception stream" );
93
+ }
94
+
95
+ return getStreamFromDirectory<minidump::ExceptionStream>(Directory);
93
96
}
94
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
+
95
105
// / Returns the list of descriptors embedded in the MemoryList stream. The
96
106
// / descriptors provide the content of interesting regions of memory at the
97
107
// / time the minidump was taken. An error is returned if the file does not
@@ -264,6 +274,12 @@ class MinidumpFile : public Binary {
264
274
return arrayRefFromStringRef (Data.getBuffer ());
265
275
}
266
276
277
+ // / Return the stream of the given type, cast to the appropriate type. Checks
278
+ // / that the stream is large enough to hold an object of this type.
279
+ template <typename T>
280
+ Expected<const T &>
281
+ getStreamFromDirectory (minidump::Directory Directory) const ;
282
+
267
283
// / Return the stream of the given type, cast to the appropriate type. Checks
268
284
// / that the stream is large enough to hold an object of this type.
269
285
template <typename T>
@@ -279,6 +295,15 @@ class MinidumpFile : public Binary {
279
295
DenseMap<minidump::StreamType, std::size_t > StreamMap;
280
296
};
281
297
298
+ template <typename T>
299
+ Expected<const T &>
300
+ MinidumpFile::getStreamFromDirectory (minidump::Directory Directory) const {
301
+ ArrayRef<uint8_t > Stream = getRawStream (Directory);
302
+ if (Stream.size () >= sizeof (T))
303
+ return *reinterpret_cast <const T *>(Stream.data ());
304
+ return createEOFError ();
305
+ }
306
+
282
307
template <typename T>
283
308
Expected<const T &> MinidumpFile::getStream (minidump::StreamType Type) const {
284
309
if (std::optional<ArrayRef<uint8_t >> Stream = getRawStream (Type)) {
0 commit comments