[PATCH] D67276: [DWARF] Add a unit test for DWARFUnit::getLength().

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 10 02:04:07 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL371499: [DWARF] Add a unit test for DWARFUnit::getLength(). (authored by ikudrin, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D67276?vs=219093&id=219495#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67276/new/

https://reviews.llvm.org/D67276

Files:
  llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp


Index: llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
===================================================================
--- llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
+++ llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
@@ -3158,4 +3158,46 @@
   AssertRangesIntersect(Ranges, {{0x20, 0x21}, {0x2f, 0x31}});
 }
 
+TEST(DWARFDebugInfo, TestDWARF64UnitLength) {
+  static const char DebugInfoSecRaw[] =
+      "\xff\xff\xff\xff"                 // DWARF64 mark
+      "\x88\x77\x66\x55\x44\x33\x22\x11" // Length
+      "\x05\x00"                         // Version
+      "\x01"                             // DW_UT_compile
+      "\x04"                             // Address size
+      "\0\0\0\0\0\0\0\0";                // Offset Into Abbrev. Sec.
+  StringMap<std::unique_ptr<MemoryBuffer>> Sections;
+  Sections.insert(std::make_pair(
+      "debug_info", MemoryBuffer::getMemBuffer(
+                        StringRef(DebugInfoSecRaw, sizeof(DebugInfoSecRaw)))));
+  auto Context = DWARFContext::create(Sections, /* AddrSize = */ 4,
+                                      /* isLittleEndian = */ true);
+  const auto &Obj = Context->getDWARFObj();
+  Obj.forEachInfoSections([&](const DWARFSection &Sec) {
+    DWARFUnitHeader Header;
+    DWARFDataExtractor Data(Obj, Sec, /* IsLittleEndian = */ true,
+                            /* AddressSize = */ 4);
+    uint64_t Offset = 0;
+    EXPECT_FALSE(Header.extract(*Context, Data, &Offset));
+    // Header.extract() returns false because there is not enough space
+    // in the section for the declared length. Anyway, we can check that
+    // the properties are read correctly.
+    ASSERT_EQ(DwarfFormat::DWARF64, Header.getFormat());
+    ASSERT_EQ(0x1122334455667788ULL, Header.getLength());
+    ASSERT_EQ(5, Header.getVersion());
+    ASSERT_EQ(DW_UT_compile, Header.getUnitType());
+    ASSERT_EQ(4, Header.getAddressByteSize());
+
+    // Check that the length can be correctly read in the unit class.
+    DWARFUnitVector DummyUnitVector;
+    DWARFSection DummySec;
+    DWARFCompileUnit CU(*Context, Sec, Header, /* DA = */ 0, /* RS = */ 0,
+                        /* LocSection = */ 0, /* SS = */ StringRef(),
+                        /* SOS = */ DummySec, /* AOS = */ 0,
+                        /* LS = */ DummySec, /* LE = */ true,
+                        /* isDWO= */ false, DummyUnitVector);
+    ASSERT_EQ(0x1122334455667788ULL, CU.getLength());
+  });
+}
+
 } // end anonymous namespace


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67276.219495.patch
Type: text/x-patch
Size: 2508 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190910/3e0cd1d4/attachment.bin>


More information about the llvm-commits mailing list