DebugInfo: Simplify line table parsing to take all the units together, rather than...
authorDavid Blaikie <dblaikie@gmail.com>
Fri, 18 Sep 2020 18:17:56 +0000 (11:17 -0700)
committerDavid Blaikie <dblaikie@gmail.com>
Fri, 18 Sep 2020 18:18:23 +0000 (11:18 -0700)
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

index c229f1834410476c586ee2733d5d30919da1a7f2..31e2da10082b35c22e8a58d45e66f53b14589b97 100644 (file)
@@ -319,8 +319,7 @@ public:
     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.
index c2d9064270339d2424e2a11944fec09741f841f7..bfdf222d78c9145f8e06d5608c6b8e7e981ed549 100644 (file)
@@ -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);
   }
 
index 678f58694e0b5996159e7e89419765f8a30d7f1c..427d25f5011a20615eb7c154156d23cc9133655b 100644 (file)
@@ -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;
 }
index 26fb8e824923fc386a0fe6e79058385e03fa4838..987e0e46ed1957dfda4b6c97ff9e42460183f000 100644 (file)
@@ -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,