[llvm] 1eea3fa - DWARFDebugLoclists: Add an api to get the location lists of a DWARF unit

Pavel Labath via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 13 07:35:13 PST 2019


Author: Pavel Labath
Date: 2019-11-13T16:26:16+01:00
New Revision: 1eea3fa063884e36165d122db32228f307793485

URL: https://github.com/llvm/llvm-project/commit/1eea3fa063884e36165d122db32228f307793485
DIFF: https://github.com/llvm/llvm-project/commit/1eea3fa063884e36165d122db32228f307793485.diff

LOG: DWARFDebugLoclists: Add an api to get the location lists of a DWARF unit

Summary:
This avoid the need to duplicate the location lists searching logic in
various users. The "inline location list dumping" code (which is the
only user actually updated to handle DWARF v5 location lists)  is
switched to this method. After adding v4 location list support, I'll
switch other users too.

Reviewers: dblaikie, probinson, JDevlieghere, aprantl, SouraVX

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D70084

Added: 
    

Modified: 
    llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
    llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
    llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
index 51de114a3506..9efad189cb61 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h
@@ -16,6 +16,7 @@
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/BinaryFormat/Dwarf.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
+#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugRnglists.h"
 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
@@ -199,12 +200,14 @@ class DWARFUnit {
   const DWARFDebugAbbrev *Abbrev;
   const DWARFSection *RangeSection;
   uint64_t RangeSectionBase;
-  /// We either keep track of the location list section or its data, depending
-  /// on whether we are handling a split DWARF section or not.
-  union {
-    const DWARFSection *LocSection;
-    StringRef LocSectionData;
-  };
+
+  /// Section containing the location lists of this unit used for non-split
+  /// DWARF<=v4 units.
+  const DWARFSection *LocSection;
+
+  /// Location table of this unit. Used for DWARF v5 and DWO units.
+  std::unique_ptr<DWARFLocationTable> LocTable;
+
   const DWARFSection &LineSection;
   StringRef StringSection;
   const DWARFSection &StringOffsetSection;
@@ -275,7 +278,6 @@ class DWARFUnit {
   DWARFContext& getContext() const { return Context; }
   const DWARFSection &getInfoSection() const { return InfoSection; }
   const DWARFSection *getLocSection() const { return LocSection; }
-  StringRef getLocSectionData() const { return LocSectionData; }
   uint64_t getOffset() const { return Header.getOffset(); }
   const dwarf::FormParams &getFormParams() const {
     return Header.getFormParams();
@@ -319,6 +321,8 @@ class DWARFUnit {
     return DataExtractor(StringSection, false, 0);
   }
 
+  const DWARFLocationTable *getLocationTable() { return LocTable.get(); }
+
   /// Extract the range list referenced by this compile unit from the
   /// .debug_ranges section. If the extraction is unsuccessful, an error
   /// is returned. Successful extraction requires that the compile unit

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index 22ae8ebb6494..308f731570cd 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -92,49 +92,35 @@ static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue,
   }
 
   if (FormValue.isFormClass(DWARFFormValue::FC_SectionOffset)) {
+    auto LLDumpOpts = DumpOpts;
+    LLDumpOpts.Verbose = false;
+
     uint64_t Offset = *FormValue.getAsSectionOffset();
     uint64_t BaseAddr = 0;
     if (Optional<object::SectionedAddress> BA = U->getBaseAddress())
       BaseAddr = BA->Address;
-    auto LLDumpOpts = DumpOpts;
-    LLDumpOpts.Verbose = false;
-
-    if (!U->isDWOUnit() && !U->getLocSection()->Data.empty()) {
-      DWARFDebugLoc DebugLoc;
-      DWARFDataExtractor Data(Obj, *U->getLocSection(), Ctx.isLittleEndian(),
-                              Obj.getAddressSize());
-
-      FormValue.dump(OS, DumpOpts);
-      OS << ": ";
 
-      if (Expected<DWARFDebugLoc::LocationList> LL =
-              DebugLoc.parseOneLocationList(Data, &Offset)) {
-        LL->dump(OS, BaseAddr, Ctx.isLittleEndian(), Obj.getAddressSize(), MRI,
-                 U, LLDumpOpts, Indent);
-      } else {
-        OS << '\n';
-        OS.indent(Indent);
-        OS << formatv("error extracting location list: {0}",
-                      fmt_consume(LL.takeError()));
-      }
+    if (const DWARFLocationTable *LT = U->getLocationTable()) {
+      LT->dumpLocationList(&Offset, OS, BaseAddr, MRI, U, LLDumpOpts, Indent);
       return;
     }
 
-    bool UseLocLists = !U->isDWOUnit();
-    auto Data =
-        UseLocLists
-            ? DWARFDataExtractor(Obj, Obj.getLoclistsSection(),
-                                 Ctx.isLittleEndian(), Obj.getAddressSize())
-            : DWARFDataExtractor(U->getLocSectionData(), Ctx.isLittleEndian(),
-                                 Obj.getAddressSize());
-
-    if (!Data.getData().empty()) {
-      // Old-style location list were used in DWARF v4 (.debug_loc.dwo section).
-      // Modern locations list (.debug_loclists) are used starting from v5.
-      // Ideally we should take the version from the .debug_loclists section
-      // header, but using CU's version for simplicity.
-      DWARFDebugLoclists(Data, UseLocLists ? U->getVersion() : 4)
-          .dumpLocationList(&Offset, OS, BaseAddr, MRI, U, LLDumpOpts, Indent);
+    DWARFDebugLoc DebugLoc;
+    DWARFDataExtractor Data(Obj, *U->getLocSection(), Ctx.isLittleEndian(),
+                            Obj.getAddressSize());
+
+    FormValue.dump(OS, DumpOpts);
+    OS << ": ";
+
+    if (Expected<DWARFDebugLoc::LocationList> LL =
+            DebugLoc.parseOneLocationList(Data, &Offset)) {
+      LL->dump(OS, BaseAddr, Ctx.isLittleEndian(), Obj.getAddressSize(), MRI, U,
+               LLDumpOpts, Indent);
+    } else {
+      OS << '\n';
+      OS.indent(Indent);
+      OS << formatv("error extracting location list: {0}",
+                    fmt_consume(LL.takeError()));
     }
     return;
   }

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
index a56402a707ad..81c7959f6460 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp
@@ -179,14 +179,22 @@ DWARFUnit::DWARFUnit(DWARFContext &DC, const DWARFSection &Section,
       StringSection(SS), StringOffsetSection(SOS), AddrOffsetSection(AOS),
       isLittleEndian(LE), IsDWO(IsDWO), UnitVector(UnitVector) {
   clear();
-  // For split DWARF we only need to keep track of the location list section's
-  // data (no relocations), and if we are reading a package file, we need to
-  // adjust the location list data based on the index entries.
   if (IsDWO) {
-    LocSectionData = LocSection->Data;
+    // If we are reading a package file, we need to adjust the location list
+    // data based on the index entries.
+    StringRef Data = LocSection->Data;
     if (auto *IndexEntry = Header.getIndexEntry())
       if (const auto *C = IndexEntry->getOffset(DW_SECT_LOC))
-        LocSectionData = LocSectionData.substr(C->Offset, C->Length);
+        Data = Data.substr(C->Offset, C->Length);
+    LocTable = std::make_unique<DWARFDebugLoclists>(
+        DWARFDataExtractor(Data, isLittleEndian, getAddressByteSize()),
+        Header.getVersion());
+  } else if (Header.getVersion() >= 5) {
+    LocTable = std::make_unique<DWARFDebugLoclists>(
+        DWARFDataExtractor(Context.getDWARFObj(),
+                           Context.getDWARFObj().getLoclistsSection(),
+                           isLittleEndian, getAddressByteSize()),
+        Header.getVersion());
   }
 }
 


        


More information about the llvm-commits mailing list