[PATCH] D101892: [DebugInfo] UnwindTable::create() should not add empty rows to CFI unwind table
Venkata Ramanaiah Nalamothu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 5 16:06:20 PDT 2021
RamNalamothu updated this revision to Diff 343225.
RamNalamothu added a comment.
Made the suggested code changes.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101892/new/
https://reviews.llvm.org/D101892
Files:
llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
llvm/unittests/DebugInfo/DWARF/DWARFDebugFrameTest.cpp
Index: llvm/unittests/DebugInfo/DWARF/DWARFDebugFrameTest.cpp
===================================================================
--- llvm/unittests/DebugInfo/DWARF/DWARFDebugFrameTest.cpp
+++ llvm/unittests/DebugInfo/DWARF/DWARFDebugFrameTest.cpp
@@ -447,6 +447,45 @@
expectDumpResult(Locs, "");
}
+// Here we test that empty rows are not added to UnwindTable when
+// dwarf::CIE::CFIs or dwarf::FDE::CFIs is empty.
+TEST(DWARFDebugFrame, UnwindTableEmptyRows) {
+ dwarf::CIE TestCIE = createCIE(/*IsDWARF64=*/false,
+ /*Offset=*/0x0,
+ /*Length=*/0xff);
+
+ // Having an empty instructions list is fine.
+ EXPECT_THAT_ERROR(parseCFI(TestCIE, {}), Succeeded());
+ EXPECT_TRUE(TestCIE.cfis().empty());
+
+ // Verify dwarf::UnwindTable::create() won't result in errors and
+ // and empty rows are not added to CIE UnwindTable.
+ Expected<dwarf::UnwindTable> RowsOrErr = dwarf::UnwindTable::create(&TestCIE);
+ EXPECT_THAT_ERROR(RowsOrErr.takeError(), Succeeded());
+ const size_t ExpectedNumOfRows = 0;
+ EXPECT_EQ(RowsOrErr->size(), ExpectedNumOfRows);
+
+ dwarf::FDE TestFDE(/*IsDWARF64=*/true,
+ /*Offset=*/0x3333abcdabcd,
+ /*Length=*/0x4444abcdabcd,
+ /*CIEPointer=*/0x1111abcdabcd,
+ /*InitialLocation=*/0x1000,
+ /*AddressRange=*/0x1000,
+ /*Cie=*/&TestCIE,
+ /*LSDAAddress=*/None,
+ /*Arch=*/Triple::x86_64);
+
+ // Having an empty instructions list is fine.
+ EXPECT_THAT_ERROR(parseCFI(TestFDE, {}), Succeeded());
+ EXPECT_TRUE(TestFDE.cfis().empty());
+
+ // Verify dwarf::UnwindTable::create() won't result in errors and
+ // and empty rows are not added to FDE UnwindTable.
+ RowsOrErr = dwarf::UnwindTable::create(&TestFDE);
+ EXPECT_THAT_ERROR(RowsOrErr.takeError(), Succeeded());
+ EXPECT_EQ(RowsOrErr->size(), ExpectedNumOfRows);
+}
+
TEST(DWARFDebugFrame, UnwindTableErrorNonAscendingFDERows) {
dwarf::CIE TestCIE = createCIE(/*IsDWARF64=*/false,
/*Offset=*/0x0,
Index: llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp
@@ -196,17 +196,20 @@
}
Expected<UnwindTable> UnwindTable::create(const FDE *Fde) {
- UnwindTable UT;
- UnwindRow Row;
- Row.setAddress(Fde->getInitialLocation());
- UT.EndAddress = Fde->getInitialLocation() + Fde->getAddressRange();
-
const CIE *Cie = Fde->getLinkedCIE();
if (Cie == nullptr)
return createStringError(errc::invalid_argument,
"unable to get CIE for FDE at offset 0x%" PRIx64,
Fde->getOffset());
+ // Rows will be empty if there are no CFI instructions.
+ if (Cie->cfis().empty() && Fde->cfis().empty())
+ return UnwindTable();
+
+ UnwindTable UT;
+ UnwindRow Row;
+ Row.setAddress(Fde->getInitialLocation());
+ UT.EndAddress = Fde->getInitialLocation() + Fde->getAddressRange();
if (Error CieError = UT.parseRows(Cie->cfis(), Row, nullptr))
return std::move(CieError);
// We need to save the initial locations of registers from the CIE parsing
@@ -219,6 +222,10 @@
}
Expected<UnwindTable> UnwindTable::create(const CIE *Cie) {
+ // Rows will be empty if there are no CFI instructions.
+ if (Cie->cfis().empty())
+ return UnwindTable();
+
UnwindTable UT;
UnwindRow Row;
if (Error CieError = UT.parseRows(Cie->cfis(), Row, nullptr))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101892.343225.patch
Type: text/x-patch
Size: 3652 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210505/3fc376d9/attachment.bin>
More information about the llvm-commits
mailing list