Skip to content

Commit c67ad40

Browse files
committed
Migrate the unit tests, and add a basic test to ensure we can read multiple exception streams
1 parent a33bb59 commit c67ad40

File tree

4 files changed

+67
-17
lines changed

4 files changed

+67
-17
lines changed

llvm/include/llvm/Object/Minidump.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ class ExceptionStreamsIterator {
236236

237237
bool operator!=(const ExceptionStreamsIterator &R) const { return !(*this == R); }
238238

239-
const Expected<const minidump::ExceptionStream &>
239+
Expected<const minidump::ExceptionStream &>
240240
operator*() {
241241
return ReadCurrent();
242242
}
243243

244-
const Expected<const minidump::ExceptionStream &>
244+
Expected<const minidump::ExceptionStream &>
245245
operator->() {
246246
return ReadCurrent();
247247
}

llvm/lib/Object/Minidump.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,11 @@ MinidumpFile::create(MemoryBufferRef Source) {
150150
continue;
151151
}
152152

153-
// We treat exceptions differently here because the LLDB minidump
154-
// makes some assumptions about uniqueness, all the streams other than
155-
// exceptions are lists. But exceptions are not a list, they are single
156-
// streams that point back to their thread So we will omit them here, and
157-
// will find them when needed in the MinidumpFile.
153+
// Exceptions can be treated as a special case of streams. Other streams
154+
// represent a list of entities, but exceptions are unique per stream.
158155
if (Type == StreamType::Exception) {
159156
ExceptionStreams.push_back(StreamDescriptor.value());
157+
continue;
160158
}
161159

162160
if (Type == DenseMapInfo<StreamType>::getEmptyKey() ||

llvm/unittests/Object/MinidumpTest.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,10 @@ TEST(MinidumpFile, getExceptionStream) {
751751
auto ExpectedFile = create(Data);
752752
ASSERT_THAT_EXPECTED(ExpectedFile, Succeeded());
753753
const MinidumpFile &File = **ExpectedFile;
754-
Expected<const minidump::ExceptionStream &> ExpectedStream =
755-
File.getExceptionStream();
754+
auto ExceptionIterator =
755+
File.getExceptionStreams().begin();
756+
757+
Expected<const ExceptionStream &> ExpectedStream = *ExceptionIterator;
756758
ASSERT_THAT_EXPECTED(ExpectedStream, Succeeded());
757759
EXPECT_EQ(0x04030201u, ExpectedStream->ThreadId);
758760
const minidump::Exception &Exception = ExpectedStream->ExceptionRecord;

llvm/unittests/ObjectYAML/MinidumpYAMLTest.cpp

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,10 @@ TEST(MinidumpYAML, ExceptionStream) {
162162

163163
ASSERT_EQ(1u, File.streams().size());
164164

165-
Expected<const minidump::ExceptionStream &> ExpectedStream =
166-
File.getExceptionStream();
165+
auto ExceptionIterator =
166+
File.getExceptionStreams().begin();
167+
168+
Expected<const ExceptionStream &> ExpectedStream = *ExceptionIterator;
167169

168170
ASSERT_THAT_EXPECTED(ExpectedStream, Succeeded());
169171

@@ -205,9 +207,10 @@ TEST(MinidumpYAML, ExceptionStream_NoParameters) {
205207

206208
ASSERT_EQ(1u, File.streams().size());
207209

208-
Expected<const minidump::ExceptionStream &> ExpectedStream =
209-
File.getExceptionStream();
210+
auto ExceptionIterator =
211+
File.getExceptionStreams().begin();
210212

213+
Expected<const ExceptionStream &> ExpectedStream = *ExceptionIterator;
211214
ASSERT_THAT_EXPECTED(ExpectedStream, Succeeded());
212215

213216
const minidump::ExceptionStream &Stream = *ExpectedStream;
@@ -261,8 +264,10 @@ TEST(MinidumpYAML, ExceptionStream_TooManyParameters) {
261264

262265
ASSERT_EQ(1u, File.streams().size());
263266

264-
Expected<const minidump::ExceptionStream &> ExpectedStream =
265-
File.getExceptionStream();
267+
auto ExceptionIterator =
268+
File.getExceptionStreams().begin();
269+
270+
Expected<const ExceptionStream &> ExpectedStream = *ExceptionIterator;
266271

267272
ASSERT_THAT_EXPECTED(ExpectedStream, Succeeded());
268273

@@ -312,8 +317,10 @@ TEST(MinidumpYAML, ExceptionStream_ExtraParameter) {
312317

313318
ASSERT_EQ(1u, File.streams().size());
314319

315-
Expected<const minidump::ExceptionStream &> ExpectedStream =
316-
File.getExceptionStream();
320+
auto ExceptionIterator =
321+
File.getExceptionStreams().begin();
322+
323+
Expected<const ExceptionStream &> ExpectedStream = *ExceptionIterator;
317324

318325
ASSERT_THAT_EXPECTED(ExpectedStream, Succeeded());
319326

@@ -398,4 +405,47 @@ TEST(MinidumpYAML, MemoryRegion_64bit) {
398405
ASSERT_THAT(*DescTwoExpectedContentSlice, arrayRefFromStringRef("world"));
399406

400407
ASSERT_EQ(Iterator, MemoryList.end());
408+
409+
}
410+
411+
// Test that we can parse multiple exception streams.
412+
TEST(MinidumpYAML, ExceptionStream_MultipleExceptions) {
413+
SmallString<0> Storage;
414+
auto ExpectedFile = toBinary(Storage, R"(
415+
--- !minidump
416+
Streams:
417+
- Type: Exception
418+
Thread ID: 0x7
419+
Exception Record:
420+
Exception Code: 0x23
421+
Exception Flags: 0x5
422+
Exception Record: 0x0102030405060708
423+
Exception Address: 0x0a0b0c0d0e0f1011
424+
Number of Parameters: 2
425+
Parameter 0: 0x99
426+
Parameter 1: 0x23
427+
Parameter 2: 0x42
428+
Thread Context: 3DeadBeefDefacedABadCafe
429+
- Type: Exception
430+
Thread ID: 0x5
431+
Exception Record:
432+
Exception Code: 0x23
433+
Exception Flags: 0x5
434+
Exception Record: 0x0102030405060708
435+
Exception Address: 0x0a0b0c0d0e0f1011
436+
Thread Context: 3DeadBeefDefacedABadCafe)");
437+
438+
ASSERT_THAT_EXPECTED(ExpectedFile, Succeeded());
439+
object::MinidumpFile &File = **ExpectedFile;
440+
441+
ASSERT_EQ(2u, File.streams().size());
442+
443+
size_t count = 0;
444+
for (auto exception_stream : File.getExceptionStreams()) {
445+
count++;
446+
ASSERT_THAT_EXPECTED(exception_stream, Succeeded());
447+
ASSERT_THAT(0x23u, exception_stream->ExceptionRecord.ExceptionCode);
448+
}
449+
450+
ASSERT_THAT(2u, count);
401451
}

0 commit comments

Comments
 (0)