Skip to content

Commit bc48588

Browse files
committed
Reland [DWARF] Add a unit test for DWARFUnit::getLength().
This is a follow-up of rL369529, where the return value of DWARFUnit::getLength() was changed from uint32_t to uint64_t. The test checks that a unit header with Length > 4G can be successfully parsed and the value of the Length field is not truncated. Differential Revision: https://reviews.llvm.org/D67276 llvm-svn: 371510
1 parent 89efb03 commit bc48588

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,4 +3158,46 @@ TEST(DWARFDebugInfo, TestDWARFDieRangeInfoIntersects) {
31583158
AssertRangesIntersect(Ranges, {{0x20, 0x21}, {0x2f, 0x31}});
31593159
}
31603160

3161+
TEST(DWARFDebugInfo, TestDWARF64UnitLength) {
3162+
static const char DebugInfoSecRaw[] =
3163+
"\xff\xff\xff\xff" // DWARF64 mark
3164+
"\x88\x77\x66\x55\x44\x33\x22\x11" // Length
3165+
"\x05\x00" // Version
3166+
"\x01" // DW_UT_compile
3167+
"\x04" // Address size
3168+
"\0\0\0\0\0\0\0\0"; // Offset Into Abbrev. Sec.
3169+
StringMap<std::unique_ptr<MemoryBuffer>> Sections;
3170+
Sections.insert(std::make_pair(
3171+
"debug_info", MemoryBuffer::getMemBuffer(StringRef(
3172+
DebugInfoSecRaw, sizeof(DebugInfoSecRaw) - 1))));
3173+
auto Context = DWARFContext::create(Sections, /* AddrSize = */ 4,
3174+
/* isLittleEndian = */ true);
3175+
const auto &Obj = Context->getDWARFObj();
3176+
Obj.forEachInfoSections([&](const DWARFSection &Sec) {
3177+
DWARFUnitHeader Header;
3178+
DWARFDataExtractor Data(Obj, Sec, /* IsLittleEndian = */ true,
3179+
/* AddressSize = */ 4);
3180+
uint64_t Offset = 0;
3181+
EXPECT_FALSE(Header.extract(*Context, Data, &Offset));
3182+
// Header.extract() returns false because there is not enough space
3183+
// in the section for the declared length. Anyway, we can check that
3184+
// the properties are read correctly.
3185+
ASSERT_EQ(DwarfFormat::DWARF64, Header.getFormat());
3186+
ASSERT_EQ(0x1122334455667788ULL, Header.getLength());
3187+
ASSERT_EQ(5, Header.getVersion());
3188+
ASSERT_EQ(DW_UT_compile, Header.getUnitType());
3189+
ASSERT_EQ(4, Header.getAddressByteSize());
3190+
3191+
// Check that the length can be correctly read in the unit class.
3192+
DWARFUnitVector DummyUnitVector;
3193+
DWARFSection DummySec;
3194+
DWARFCompileUnit CU(*Context, Sec, Header, /* DA = */ 0, /* RS = */ 0,
3195+
/* LocSection = */ 0, /* SS = */ StringRef(),
3196+
/* SOS = */ DummySec, /* AOS = */ 0,
3197+
/* LS = */ DummySec, /* LE = */ true,
3198+
/* isDWO= */ false, DummyUnitVector);
3199+
ASSERT_EQ(0x1122334455667788ULL, CU.getLength());
3200+
});
3201+
}
3202+
31613203
} // end anonymous namespace

0 commit comments

Comments
 (0)