Add a DIELocList class to handle pointers into the location list.
authorEric Christopher <echristo@gmail.com>
Wed, 5 Mar 2014 22:41:20 +0000 (22:41 +0000)
committerEric Christopher <echristo@gmail.com>
Wed, 5 Mar 2014 22:41:20 +0000 (22:41 +0000)
This enables us to figure out where in the debug_loc section our
locations are so that we can eventually hash them. It also helps
remove some special case code in emission. No functional change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203018 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/DIE.cpp
lib/CodeGen/AsmPrinter/DIE.h
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/CodeGen/AsmPrinter/DwarfDebug.h
lib/CodeGen/AsmPrinter/DwarfUnit.cpp
lib/CodeGen/AsmPrinter/DwarfUnit.h

index e8be7ad626d6939f0b09b66eaf44d997c72cd97b..0c6e01504ef6ed8dfa7d2524b572f5941bdf4d40 100644 (file)
@@ -524,3 +524,34 @@ void DIEBlock::print(raw_ostream &O) const {
   DIE::print(O, 5);
 }
 #endif
+
+//===----------------------------------------------------------------------===//
+// DIELocList Implementation
+//===----------------------------------------------------------------------===//
+
+unsigned DIELocList::SizeOf(AsmPrinter *AP, dwarf::Form Form) const {
+  if (Form == dwarf::DW_FORM_data4)
+    return 4;
+  if (Form == dwarf::DW_FORM_sec_offset)
+    return 4;
+  return AP->getDataLayout().getPointerSize();
+}
+
+/// EmitValue - Emit label value.
+///
+void DIELocList::EmitValue(AsmPrinter *AP, dwarf::Form Form) const {
+  MCSymbol *Label = AP->GetTempSymbol("debug_loc", Index);
+  MCSymbol *DwarfDebugLocSectionSym = AP->getDwarfDebug()->getDebugLocSym();
+
+  if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
+    AP->EmitSectionOffset(Label, DwarfDebugLocSectionSym);
+  else
+    AP->EmitLabelDifference(Label, DwarfDebugLocSectionSym, 4);
+}
+
+#ifndef NDEBUG
+void DIELocList::print(raw_ostream &O) const {
+  O << "LocList: " << Index;
+
+}
+#endif
index fa39806f1aa27b833564bedc814c9b422a3ba6ea..43dd6b2d23b8526edef503e3f6f84dba63c2ccbb 100644 (file)
@@ -202,7 +202,8 @@ public:
     isEntry,
     isTypeSignature,
     isBlock,
-    isLoc
+    isLoc,
+    isLocList,
   };
 
 protected:
@@ -541,6 +542,37 @@ public:
   virtual void print(raw_ostream &O) const;
 #endif
 };
+
+//===--------------------------------------------------------------------===//
+/// DIELocList - Represents a pointer to a location list in the debug_loc
+/// section.
+//
+class DIELocList : public DIEValue {
+  // Index into the .debug_loc vector.
+  size_t Index;
+
+public:
+  DIELocList(size_t I) : DIEValue(isLocList), Index(I) {}
+
+  /// getValue - Grab the current index out.
+  size_t getValue() const { return Index; }
+
+  /// EmitValue - Emit location data.
+  ///
+  virtual void EmitValue(AsmPrinter *AP, dwarf::Form Form) const;
+
+  /// SizeOf - Determine size of location data in bytes.
+  ///
+  virtual unsigned SizeOf(AsmPrinter *AP, dwarf::Form Form) const;
+
+  // Implement isa/cast/dyncast.
+  static bool classof(const DIEValue *E) { return E->getType() == isLocList; }
+
+#ifndef NDEBUG
+  virtual void print(raw_ostream &O) const;
+#endif
+};
+
 } // end llvm namespace
 
 #endif
index df686581b26f104e63199038cd4bd6cfee5cd349..ba83b8b8d151f1b228fabeb2a9f16e6630a425e0 100644 (file)
@@ -2032,17 +2032,6 @@ void DwarfDebug::emitDIE(DIE *Die) {
       }
       break;
     }
-    case dwarf::DW_AT_location: {
-      if (DIELabel *L = dyn_cast<DIELabel>(Values[i])) {
-        if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
-          Asm->EmitSectionOffset(L->getValue(), DwarfDebugLocSectionSym);
-        else
-          Asm->EmitLabelDifference(L->getValue(), DwarfDebugLocSectionSym, 4);
-      } else {
-        Values[i]->EmitValue(Asm, Form);
-      }
-      break;
-    }
     case dwarf::DW_AT_accessibility: {
       if (Asm->isVerbose()) {
         DIEInteger *V = cast<DIEInteger>(Values[i]);
index 315544b5dfe816b77e1ff5d729cbaa07bc3ac7bb..c74d76a06a11332434f2ba5795d01a40790cbb9b 100644 (file)
@@ -751,6 +751,9 @@ public:
   /// Returns the Dwarf Version.
   unsigned getDwarfVersion() const { return DwarfVersion; }
 
+  /// Returns the section symbol for the .debug_loc section.
+  MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
+
   /// Find the MDNode for the given reference.
   template <typename T> T resolve(DIRef<T> Ref) const {
     return Ref.resolve(TypeIdentifierMap);
index b42869bbe0be335a28405d3514ab2c9d5523e52c..41c72a835d06efc2e3db6df9c6971f9996f4c929 100644 (file)
@@ -231,6 +231,16 @@ void DwarfUnit::addExpr(DIELoc *Die, dwarf::Form Form, const MCExpr *Expr) {
   Die->addValue((dwarf::Attribute)0, Form, Value);
 }
 
+/// addLocationList - Add a Dwarf loclistptr attribute data and value.
+///
+void DwarfUnit::addLocationList(DIE *Die, dwarf::Attribute Attribute,
+                                unsigned Index) {
+  DIEValue *Value = new (DIEValueAllocator) DIELocList(Index);
+  dwarf::Form Form = DD->getDwarfVersion() >= 4 ? dwarf::DW_FORM_sec_offset
+                                                : dwarf::DW_FORM_data4;
+  Die->addValue(Attribute, Form, Value);
+}
+
 /// addLabel - Add a Dwarf label attribute data and value.
 ///
 void DwarfUnit::addLabel(DIE *Die, dwarf::Attribute Attribute, dwarf::Form Form,
@@ -1796,8 +1806,7 @@ DIE *DwarfUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstract) {
 
   unsigned Offset = DV.getDotDebugLocOffset();
   if (Offset != ~0U) {
-    addSectionLabel(VariableDie, dwarf::DW_AT_location,
-                    Asm->GetTempSymbol("debug_loc", Offset));
+    addLocationList(VariableDie, dwarf::DW_AT_location, Offset);
     DV.setDIE(VariableDie);
     return VariableDie;
   }
index 82d3af2a84cfc9a0fc6686d07e3eac71f102aab5..e338752b66a00c2bf84331d18f449aec5393e0b7 100644 (file)
@@ -340,6 +340,9 @@ public:
 
   void addLabel(DIELoc *Die, dwarf::Form Form, const MCSymbol *Label);
 
+  /// addLocationList - Add a Dwarf loclistptr attribute data and value.
+  void addLocationList(DIE *Die, dwarf::Attribute Attribute, unsigned Index);
+
   /// addSectionLabel - Add a Dwarf section label attribute data and value.
   ///
   void addSectionLabel(DIE *Die, dwarf::Attribute Attribute,