[PATCH] D98589: [llvm] [dwarf] Fix DWARFListTableHeader::getOffsetEntry off-by-one
Jan Kratochvil via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 13 13:56:46 PST 2021
jankratochvil created this revision.
jankratochvil added a reviewer: dblaikie.
jankratochvil added a project: LLVM.
jankratochvil requested review of this revision.
D98289 <https://reviews.llvm.org/D98289> was erroneously reporting `invalid range list offset 0x20110` instead of `invalid range list table index 0`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98589
Files:
llvm/include/llvm/DebugInfo/DWARF/DWARFListTable.h
llvm/unittests/DebugInfo/DWARF/DWARFListTableTest.cpp
Index: llvm/unittests/DebugInfo/DWARF/DWARFListTableTest.cpp
===================================================================
--- llvm/unittests/DebugInfo/DWARF/DWARFListTableTest.cpp
+++ llvm/unittests/DebugInfo/DWARF/DWARFListTableTest.cpp
@@ -73,4 +73,30 @@
EXPECT_EQ(Header.length(), 6u);
}
+TEST(DWARFListTableHeader, OffsetEntryCount) {
+ static const char SecData[] = "\x10\x00\x00\x00" // Length
+ "\x05\x00" // Version
+ "\x08" // Address size
+ "\x00" // Segment selector size
+ "\x01\x00\x00\x00" // Offset entry count
+ "\x04\x00\x00\x00" // offset[0]
+ "\x04" // DW_RLE_offset_pair
+ "\x01" // ULEB128 starting offset
+ "\x02" // ULEB128 ending offset
+ "\x00"; // DW_RLE_end_of_list
+ DWARFDataExtractor Extractor(StringRef(SecData, sizeof(SecData) - 1),
+ /*isLittleEndian=*/true,
+ /*AddrSize=*/4);
+ DWARFListTableHeader Header(/*SectionName=*/".debug_rnglists",
+ /*ListTypeString=*/"range");
+ uint64_t Offset = 0;
+ EXPECT_FALSE(!!Header.extract(Extractor, &Offset));
+ Optional<uint64_t> Offset0 = Header.getOffsetEntry(Extractor, 0);
+ EXPECT_TRUE(!!Offset0);
+ EXPECT_EQ(*Offset0, uint64_t(4));
+ Optional<uint64_t> Offset1 = Header.getOffsetEntry(Extractor, 1);
+ EXPECT_FALSE(!!Offset1);
+ EXPECT_EQ(Header.length(), sizeof(SecData) - 1);
+}
+
} // end anonymous namespace
Index: llvm/include/llvm/DebugInfo/DWARF/DWARFListTable.h
===================================================================
--- llvm/include/llvm/DebugInfo/DWARF/DWARFListTable.h
+++ llvm/include/llvm/DebugInfo/DWARF/DWARFListTable.h
@@ -113,7 +113,7 @@
void dump(DataExtractor Data, raw_ostream &OS,
DIDumpOptions DumpOpts = {}) const;
Optional<uint64_t> getOffsetEntry(DataExtractor Data, uint32_t Index) const {
- if (Index > HeaderData.OffsetEntryCount)
+ if (Index >= HeaderData.OffsetEntryCount)
return None;
return getOffsetEntry(Data, getHeaderOffset() + getHeaderSize(Format), Format, Index);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98589.330472.patch
Type: text/x-patch
Size: 2409 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210313/a5c74337/attachment.bin>
More information about the llvm-commits
mailing list