From 517aaf27d7802c919b82c6bd9f95eceda5f3d535 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Wed, 5 Mar 2014 22:41:20 +0000 Subject: [PATCH] Add a DIELocList class to handle pointers into the location list. 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 | 31 ++++++++++++++++++++++++ lib/CodeGen/AsmPrinter/DIE.h | 34 ++++++++++++++++++++++++++- lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 11 --------- lib/CodeGen/AsmPrinter/DwarfDebug.h | 3 +++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 13 ++++++++-- lib/CodeGen/AsmPrinter/DwarfUnit.h | 3 +++ 6 files changed, 81 insertions(+), 14 deletions(-) diff --git a/lib/CodeGen/AsmPrinter/DIE.cpp b/lib/CodeGen/AsmPrinter/DIE.cpp index e8be7ad626d..0c6e01504ef 100644 --- a/lib/CodeGen/AsmPrinter/DIE.cpp +++ b/lib/CodeGen/AsmPrinter/DIE.cpp @@ -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 diff --git a/lib/CodeGen/AsmPrinter/DIE.h b/lib/CodeGen/AsmPrinter/DIE.h index fa39806f1aa..43dd6b2d23b 100644 --- a/lib/CodeGen/AsmPrinter/DIE.h +++ b/lib/CodeGen/AsmPrinter/DIE.h @@ -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 diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index df686581b26..ba83b8b8d15 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2032,17 +2032,6 @@ void DwarfDebug::emitDIE(DIE *Die) { } break; } - case dwarf::DW_AT_location: { - if (DIELabel *L = dyn_cast(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(Values[i]); diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index 315544b5dfe..c74d76a06a1 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -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 T resolve(DIRef Ref) const { return Ref.resolve(TypeIdentifierMap); diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index b42869bbe0b..41c72a835d0 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -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; } diff --git a/lib/CodeGen/AsmPrinter/DwarfUnit.h b/lib/CodeGen/AsmPrinter/DwarfUnit.h index 82d3af2a84c..e338752b66a 100644 --- a/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -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,