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
This commit is contained in:
Eric Christopher 2014-03-05 22:41:20 +00:00
parent f698d7775a
commit 517aaf27d7
6 changed files with 81 additions and 14 deletions

View 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

View 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

View 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]);

View 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);

View 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;
}

View 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,