[llvm] 51a5053 - DebugInfo: Simplify line table parsing to take all the units together, rather than CUs and TUs separately

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 18 11:18:32 PDT 2020


Author: David Blaikie
Date: 2020-09-18T11:18:23-07:00
New Revision: 51a505340dfdfdfd9ab32c7267a74db3cdeefa56

URL: https://github.com/llvm/llvm-project/commit/51a505340dfdfdfd9ab32c7267a74db3cdeefa56
DIFF: https://github.com/llvm/llvm-project/commit/51a505340dfdfdfd9ab32c7267a74db3cdeefa56.diff

LOG: DebugInfo: Simplify line table parsing to take all the units together, rather than CUs and TUs separately

Added: 
    

Modified: 
    llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
    llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
    llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
    llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
index c229f1834410..31e2da10082b 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h
@@ -319,8 +319,7 @@ class DWARFDebugLine {
     using tu_range = DWARFUnitVector::iterator_range;
     using LineToUnitMap = std::map<uint64_t, DWARFUnit *>;
 
-    SectionParser(DWARFDataExtractor &Data, const DWARFContext &C, cu_range CUs,
-                  tu_range TUs);
+    SectionParser(DWARFDataExtractor &Data, const DWARFContext &C, DWARFUnitVector::iterator_range Units);
 
     /// Get the next line table from the section. Report any issues via the
     /// handlers.

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
index c2d906427033..bfdf222d78c9 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
@@ -548,8 +548,7 @@ void DWARFContext::dump(
                                    DObj->getLineSection().Data)) {
     DWARFDataExtractor LineData(*DObj, DObj->getLineSection(), isLittleEndian(),
                                 0);
-    DWARFDebugLine::SectionParser Parser(LineData, *this, compile_units(),
-                                         type_units());
+    DWARFDebugLine::SectionParser Parser(LineData, *this, normal_units());
     DumpLineSection(Parser, DumpOpts, *Off);
   }
 
@@ -558,8 +557,7 @@ void DWARFContext::dump(
                      DObj->getLineDWOSection().Data)) {
     DWARFDataExtractor LineData(*DObj, DObj->getLineDWOSection(),
                                 isLittleEndian(), 0);
-    DWARFDebugLine::SectionParser Parser(LineData, *this, dwo_compile_units(),
-                                         dwo_type_units());
+    DWARFDebugLine::SectionParser Parser(LineData, *this, dwo_units());
     DumpLineSection(Parser, DumpOpts, *Off);
   }
 

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
index 678f58694e0b..427d25f5011a 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp
@@ -1418,25 +1418,20 @@ bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
 // Therefore, collect up handles on all the Units that point into the
 // line-table section.
 static DWARFDebugLine::SectionParser::LineToUnitMap
-buildLineToUnitMap(DWARFDebugLine::SectionParser::cu_range CUs,
-                   DWARFDebugLine::SectionParser::tu_range TUs) {
+buildLineToUnitMap(DWARFUnitVector::iterator_range Units) {
   DWARFDebugLine::SectionParser::LineToUnitMap LineToUnit;
-  for (const auto &CU : CUs)
-    if (auto CUDIE = CU->getUnitDIE())
+  for (const auto &U : Units)
+    if (auto CUDIE = U->getUnitDIE())
       if (auto StmtOffset = toSectionOffset(CUDIE.find(DW_AT_stmt_list)))
-        LineToUnit.insert(std::make_pair(*StmtOffset, &*CU));
-  for (const auto &TU : TUs)
-    if (auto TUDIE = TU->getUnitDIE())
-      if (auto StmtOffset = toSectionOffset(TUDIE.find(DW_AT_stmt_list)))
-        LineToUnit.insert(std::make_pair(*StmtOffset, &*TU));
+        LineToUnit.insert(std::make_pair(*StmtOffset, &*U));
   return LineToUnit;
 }
 
-DWARFDebugLine::SectionParser::SectionParser(DWARFDataExtractor &Data,
-                                             const DWARFContext &C,
-                                             cu_range CUs, tu_range TUs)
+DWARFDebugLine::SectionParser::SectionParser(
+    DWARFDataExtractor &Data, const DWARFContext &C,
+    DWARFUnitVector::iterator_range Units)
     : DebugLineData(Data), Context(C) {
-  LineToUnit = buildLineToUnitMap(CUs, TUs);
+  LineToUnit = buildLineToUnitMap(Units);
   if (!DebugLineData.isValidOffset(Offset))
     Done = true;
 }

diff  --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
index 26fb8e824923..987e0e46ed19 100644
--- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
+++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
@@ -86,7 +86,7 @@ struct CommonFixture {
 
     generate();
 
-    return DWARFDebugLine::SectionParser(LineData, *Context, CUs, TUs);
+    return DWARFDebugLine::SectionParser(LineData, *Context, Units);
   }
 
   void recordRecoverable(Error Err) {
@@ -114,8 +114,7 @@ struct CommonFixture {
   Error Unrecoverable;
   std::function<void(Error)> RecordUnrecoverable;
 
-  SmallVector<std::unique_ptr<DWARFUnit>, 2> CUs;
-  SmallVector<std::unique_ptr<DWARFUnit>, 2> TUs;
+  SmallVector<std::unique_ptr<DWARFUnit>, 2> Units;
 };
 
 // Fixtures must derive from "Test", but parameterised fixtures from
@@ -1087,7 +1086,7 @@ TEST_F(DebugLineBasicFixture, ParserAlwaysDoneForEmptySection) {
     return;
 
   generate();
-  DWARFDebugLine::SectionParser Parser(LineData, *Context, CUs, TUs);
+  DWARFDebugLine::SectionParser Parser(LineData, *Context, Units);
 
   EXPECT_TRUE(Parser.done());
 }
@@ -1101,7 +1100,7 @@ TEST_F(DebugLineBasicFixture, ParserMarkedAsDoneForBadLengthWhenParsing) {
   Gen->addLineTable();
   generate();
 
-  DWARFDebugLine::SectionParser Parser(LineData, *Context, CUs, TUs);
+  DWARFDebugLine::SectionParser Parser(LineData, *Context, Units);
   Parser.parseNext(RecordRecoverable, RecordUnrecoverable);
 
   EXPECT_EQ(Parser.getOffset(), 0u);
@@ -1124,7 +1123,7 @@ TEST_F(DebugLineBasicFixture, ParserMarkedAsDoneForBadLengthWhenSkipping) {
   Gen->addLineTable();
   generate();
 
-  DWARFDebugLine::SectionParser Parser(LineData, *Context, CUs, TUs);
+  DWARFDebugLine::SectionParser Parser(LineData, *Context, Units);
   Parser.skip(RecordRecoverable, RecordUnrecoverable);
 
   EXPECT_EQ(Parser.getOffset(), 0u);
@@ -1148,7 +1147,7 @@ TEST_F(DebugLineBasicFixture, ParserReportsFirstErrorInEachTableWhenParsing) {
   LT2.setCustomPrologue({{2, LineTable::Long}, {1, LineTable::Half}});
   generate();
 
-  DWARFDebugLine::SectionParser Parser(LineData, *Context, CUs, TUs);
+  DWARFDebugLine::SectionParser Parser(LineData, *Context, Units);
   Parser.parseNext(RecordRecoverable, RecordUnrecoverable);
   ASSERT_FALSE(Parser.done());
   Parser.parseNext(RecordRecoverable, RecordUnrecoverable);
@@ -1177,7 +1176,7 @@ TEST_F(DebugLineBasicFixture, ParserReportsNonPrologueProblemsWhenParsing) {
   LT2.addByte(0xbb);
   generate();
 
-  DWARFDebugLine::SectionParser Parser(LineData, *Context, CUs, TUs);
+  DWARFDebugLine::SectionParser Parser(LineData, *Context, Units);
   Parser.parseNext(RecordRecoverable, RecordUnrecoverable);
   EXPECT_FALSE(Unrecoverable);
   ASSERT_FALSE(Parser.done());
@@ -1207,7 +1206,7 @@ TEST_F(DebugLineBasicFixture,
   LT2.setCustomPrologue({{2, LineTable::Long}, {1, LineTable::Half}});
   generate();
 
-  DWARFDebugLine::SectionParser Parser(LineData, *Context, CUs, TUs);
+  DWARFDebugLine::SectionParser Parser(LineData, *Context, Units);
   Parser.skip(RecordRecoverable, RecordUnrecoverable);
   ASSERT_FALSE(Parser.done());
   Parser.skip(RecordRecoverable, RecordUnrecoverable);
@@ -1231,7 +1230,7 @@ TEST_F(DebugLineBasicFixture, ParserIgnoresNonPrologueErrorsWhenSkipping) {
   LT.addExtendedOpcode(42, DW_LNE_end_sequence, {});
   generate();
 
-  DWARFDebugLine::SectionParser Parser(LineData, *Context, CUs, TUs);
+  DWARFDebugLine::SectionParser Parser(LineData, *Context, Units);
   Parser.skip(RecordRecoverable, RecordUnrecoverable);
 
   EXPECT_TRUE(Parser.done());
@@ -1290,7 +1289,7 @@ TEST_F(DebugLineBasicFixture, VerboseOutput) {
 
   generate();
 
-  DWARFDebugLine::SectionParser Parser(LineData, *Context, CUs, TUs);
+  DWARFDebugLine::SectionParser Parser(LineData, *Context, Units);
   std::string Output;
   raw_string_ostream OS(Output);
   Parser.parseNext(RecordRecoverable, RecordUnrecoverable, &OS,
@@ -1527,7 +1526,7 @@ struct TruncatedOpcodeFixtureBase : public CommonFixture {
 
   void runTest(uint8_t OpcodeValue) {
     generate();
-    DWARFDebugLine::SectionParser Parser(LineData, *Context, CUs, TUs);
+    DWARFDebugLine::SectionParser Parser(LineData, *Context, Units);
     std::string Output;
     raw_string_ostream OS(Output);
     Parser.parseNext(RecordRecoverable, RecordUnrecoverable, &OS,


        


More information about the llvm-commits mailing list