[llvm] r310923 - [llvm-dwarfdump] - Refactor section name/uniqueness gathering.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 15 08:54:43 PDT 2017


Author: grimar
Date: Tue Aug 15 08:54:43 2017
New Revision: 310923

URL: http://llvm.org/viewvc/llvm-project?rev=310923&view=rev
Log:
[llvm-dwarfdump] - Refactor section name/uniqueness gathering.

As was requested in D36313 thread,

with this patch section names and uniqueness calculated once,
and not every time when a range is dumped.

Differential revision: https://reviews.llvm.org/D36740

Modified:
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFObject.h
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFSection.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFObject.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFObject.h?rev=310923&r1=310922&r2=310923&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFObject.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFObject.h Tue Aug 15 08:54:43 2017
@@ -29,6 +29,7 @@ public:
   virtual ~DWARFObject() = default;
   virtual StringRef getFileName() const { llvm_unreachable("unimplemented"); }
   virtual const object::ObjectFile *getFile() const { return nullptr; }
+  virtual ArrayRef<SectionName> getSectionNames() const { return {}; }
   virtual bool isLittleEndian() const = 0;
   virtual uint8_t getAddressSize() const { llvm_unreachable("unimplemented"); }
   virtual const DWARFSection &getInfoSection() const { return Dummy; }

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFSection.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFSection.h?rev=310923&r1=310922&r2=310923&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFSection.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFSection.h Tue Aug 15 08:54:43 2017
@@ -19,6 +19,11 @@ struct DWARFSection {
   StringRef Data;
 };
 
+struct SectionName {
+  StringRef Name;
+  bool IsNameUnique;
+};
+
 } // end namespace llvm
 
 #endif // LLVM_DEBUGINFO_DWARF_DWARFSECTION_H

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=310923&r1=310922&r2=310923&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Tue Aug 15 08:54:43 2017
@@ -934,6 +934,7 @@ class DWARFObjInMemory final : public DW
   uint8_t AddressSize;
   StringRef FileName;
   const object::ObjectFile *Obj = nullptr;
+  std::vector<SectionName> SectionNames;
 
   using TypeSectionMap = MapVector<object::SectionRef, DWARFSectionMap,
                                    std::map<object::SectionRef, unsigned>>;
@@ -1055,9 +1056,13 @@ public:
         AddressSize(Obj.getBytesInAddress()), FileName(Obj.getFileName()),
         Obj(&Obj) {
 
+    StringMap<unsigned> SectionAmountMap;
     for (const SectionRef &Section : Obj.sections()) {
       StringRef Name;
       Section.getName(Name);
+      ++SectionAmountMap[Name];
+      SectionNames.push_back({ Name, true });
+
       // Skip BSS and Virtual sections, they aren't interesting.
       if (Section.isBSS() || Section.isVirtual())
         continue;
@@ -1179,6 +1184,10 @@ public:
         Map->insert({Reloc.getOffset(), Rel});
       }
     }
+
+    for (SectionName &S : SectionNames)
+      if (SectionAmountMap[S.Name] > 1)
+        S.IsNameUnique = false;
   }
 
   Optional<RelocAddrEntry> find(const DWARFSection &S,
@@ -1192,6 +1201,10 @@ public:
 
   const object::ObjectFile *getFile() const override { return Obj; }
 
+  ArrayRef<SectionName> getSectionNames() const override {
+    return SectionNames;
+  }
+
   bool isLittleEndian() const override { return IsLittleEndian; }
   StringRef getAbbrevDWOSection() const override { return AbbrevDWOSection; }
   const DWARFSection &getLineDWOSection() const override {

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp?rev=310923&r1=310922&r2=310923&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDie.cpp Tue Aug 15 08:54:43 2017
@@ -57,18 +57,9 @@ static void dumpRanges(const DWARFObject
                        const DWARFAddressRangesVector &Ranges,
                        unsigned AddressSize, unsigned Indent,
                        const DIDumpOptions &DumpOpts) {
-  StringMap<unsigned> SectionAmountMap;
-  std::vector<StringRef> SectionNames;
-  if (Obj.getFile() && !DumpOpts.Brief) {
-    for (const SectionRef &Section : Obj.getFile()->sections()) {
-      StringRef Name;
-      if (Section.getName(Name))
-        Name = "<error>";
-
-      ++SectionAmountMap[Name];
-      SectionNames.push_back(Name);
-    }
-  }
+  ArrayRef<SectionName> SectionNames;
+  if (!DumpOpts.Brief)
+    SectionNames = Obj.getSectionNames();
 
   for (size_t I = 0; I < Ranges.size(); ++I) {
     const DWARFAddressRange &R = Ranges[I];
@@ -81,13 +72,11 @@ static void dumpRanges(const DWARFObject
     if (SectionNames.empty() || R.SectionIndex == -1ULL)
       continue;
 
-    StringRef Name = R.SectionIndex < SectionNames.size()
-                         ? SectionNames[R.SectionIndex]
-                         : "<error>";
-    OS << format(" \"%s\"", Name.str().c_str());
+    StringRef Name = SectionNames[R.SectionIndex].Name;
+    OS << " \"" << Name << '\"';
 
-    // Print section index if there is more than one section with this name.
-    if (SectionAmountMap[Name] > 1)
+    // Print section index if name is not unique.
+    if (!SectionNames[R.SectionIndex].IsNameUnique)
       OS << format(" [%u]", R.SectionIndex);
   }
 }




More information about the llvm-commits mailing list