[Lldb-commits] [lldb] [llvm] [Obj2Yaml] Add support for minidump generation with 64b memory ranges. (PR #101272)

Jacob Lalonde via lldb-commits lldb-commits at lists.llvm.org
Thu Aug 8 09:22:59 PDT 2024


================
@@ -336,3 +336,89 @@ TEST(MinidumpYAML, ExceptionStream_ExtraParameter) {
                                0xab, 0xad, 0xca, 0xfe}),
             *ExpectedContext);
 }
+
+TEST(MinidumpYAML, MemoryRegion_64bit) {
+  SmallString<0> Storage;
+  auto ExpectedFile = toBinary(Storage, R"(
+--- !minidump
+Streams:
+  - Type:            Memory64List
+    Memory Ranges:
+      - Start of Memory Range: 0x7FFFFFCF0818283
+        Content:               '68656c6c6f'
+      - Start of Memory Range: 0x7FFFFFFF0818283
+        Content:               '776f726c64'
+        )");
+
+  ASSERT_THAT_EXPECTED(ExpectedFile, Succeeded());
+  object::MinidumpFile &File = **ExpectedFile;
+
+  ASSERT_THAT(1u, File.streams().size());
+
+  Error Err = Error::success();
+  // Explicit Err check
+  ASSERT_FALSE(Err);
+  Expected<iterator_range<object::MinidumpFile::FallibleMemory64Iterator>>
+      ExpectedMemoryList = File.getMemory64List(Err);
+
+  ASSERT_THAT_EXPECTED(ExpectedMemoryList, Succeeded());
+
+  iterator_range<object::MinidumpFile::FallibleMemory64Iterator> MemoryList =
+      *ExpectedMemoryList;
+  auto Iterator = MemoryList.begin();
+
+  ++Iterator;
+  ASSERT_FALSE(Err);
+
+  auto DescOnePair = *Iterator;
+  const minidump::MemoryDescriptor_64 &DescOne = DescOnePair.first;
+  ASSERT_THAT(0x7FFFFFCF0818283u, DescOne.StartOfMemoryRange);
+  ASSERT_THAT(5u, DescOne.DataSize);
+
+  ++Iterator;
+  ASSERT_FALSE(Err);
+
+  auto DescTwoPair = *Iterator;
+  const minidump::MemoryDescriptor_64 &DescTwo = DescTwoPair.first;
+  ASSERT_THAT(0x7FFFFFFF0818283u, DescTwo.StartOfMemoryRange);
+  ASSERT_THAT(5u, DescTwo.DataSize);
+  const std::optional<ArrayRef<uint8_t>> ExpectedContent =
+      File.getRawStream(StreamType::Memory64List);
+  ASSERT_TRUE(ExpectedContent);
+  const size_t ExpectedStreamSize =
+      sizeof(Memory64ListHeader) + (sizeof(MemoryDescriptor_64) * 2);
+  ASSERT_THAT(ExpectedStreamSize, ExpectedContent->size());
+
+  Expected<minidump::Memory64ListHeader> ExpectedHeader =
+      File.getMemoryList64Header();
+  ASSERT_THAT_EXPECTED(ExpectedHeader, Succeeded());
+  ASSERT_THAT(ExpectedHeader->BaseRVA, 92u);
+
+  Expected<ArrayRef<uint8_t>> DescOneExpectedContentSlice = DescOnePair.second;
+  ASSERT_THAT_EXPECTED(DescOneExpectedContentSlice, Succeeded());
+  ASSERT_THAT(5u, DescOneExpectedContentSlice->size());
+  ASSERT_THAT(arrayRefFromStringRef("hello"), *DescOneExpectedContentSlice);
+
+  Expected<ArrayRef<uint8_t>> DescTwoExpectedContentSlice = DescTwoPair.second;
+  ASSERT_THAT_EXPECTED(DescTwoExpectedContentSlice, Succeeded());
+  ASSERT_THAT(arrayRefFromStringRef("world"), *DescTwoExpectedContentSlice);
+
+  ASSERT_TRUE(Iterator == MemoryList.end());
+}
+
+TEST(MinidumpYAML, MemoryRegion_DataSize_TooSmall) {
+  SmallString<0> Storage;
+  auto ExpectedFile = toBinary(Storage, R"(
+--- !minidump
+Streams:
+  - Type:            Memory64List
+    Memory Ranges:
+      - Start of Memory Range: 0x7FFFFFCF0818283
+        Data Size: 4           1
+        Content:               '68656c6c6f'
+      - Start of Memory Range: 0x7FFFFFFF0818283
+        Content:               '776f726c64'
+        )");
+
+  ASSERT_THAT_EXPECTED(ExpectedFile, Failed());
----------------
Jlalond wrote:

I'm going to drop this for now and extend basic.yaml in the positive case where datasize appends 0's

https://github.com/llvm/llvm-project/pull/101272


More information about the lldb-commits mailing list