Skip to content

Commit

Permalink
[Debug-Info] add a wrapper addAttribute for addValue()
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzheng1030 committed Apr 23, 2021
1 parent 681d9ec commit b12067b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
16 changes: 7 additions & 9 deletions llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
Expand Up @@ -83,7 +83,7 @@ void DwarfCompileUnit::addLabelAddress(DIE &Die, dwarf::Attribute Attribute,

if (!Base || Base == Label) {
unsigned idx = DD->getAddressPool().getIndex(Label);
Die.addValue(DIEValueAllocator, Attribute,
addAttribute(Die, Attribute,
DD->getDwarfVersion() >= 5 ? dwarf::DW_FORM_addrx
: dwarf::DW_FORM_GNU_addr_index,
DIEInteger(idx));
Expand All @@ -100,7 +100,7 @@ void DwarfCompileUnit::addLabelAddress(DIE &Die, dwarf::Attribute Attribute,
addPoolOpAddress(*Loc, Label);
addBlock(Die, Attribute, dwarf::DW_FORM_exprloc, Loc);
} else
Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_LLVM_addrx_offset,
addAttribute(Die, Attribute, dwarf::DW_FORM_LLVM_addrx_offset,
new (DIEValueAllocator) DIEAddrOffset(
DD->getAddressPool().getIndex(Base), Label, Base));
}
Expand All @@ -112,11 +112,9 @@ void DwarfCompileUnit::addLocalLabelAddress(DIE &Die,
DD->addArangeLabel(SymbolCU(this, Label));

if (Label)
Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr,
DIELabel(Label));
addAttribute(Die, Attribute, dwarf::DW_FORM_addr, DIELabel(Label));
else
Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_addr,
DIEInteger(0));
addAttribute(Die, Attribute, dwarf::DW_FORM_addr, DIEInteger(0));
}

unsigned DwarfCompileUnit::getOrCreateSourceID(const DIFile *File) {
Expand Down Expand Up @@ -1472,7 +1470,7 @@ void DwarfCompileUnit::addLocationList(DIE &Die, dwarf::Attribute Attribute,
dwarf::Form Form = (DD->getDwarfVersion() >= 5)
? dwarf::DW_FORM_loclistx
: DD->getDwarfSectionOffsetForm();
Die.addValue(DIEValueAllocator, Attribute, Form, DIELocList(Index));
addAttribute(Die, Attribute, Form, DIELocList(Index));
}

void DwarfCompileUnit::applyVariableAttributes(const DbgVariable &Var,
Expand Down Expand Up @@ -1504,7 +1502,7 @@ void DwarfCompileUnit::applyLabelAttributes(const DbgLabel &Label,
/// Add a Dwarf expression attribute data and value.
void DwarfCompileUnit::addExpr(DIELoc &Die, dwarf::Form Form,
const MCExpr *Expr) {
Die.addValue(DIEValueAllocator, (dwarf::Attribute)0, Form, DIEExpr(Expr));
addAttribute(Die, (dwarf::Attribute)0, Form, DIEExpr(Expr));
}

void DwarfCompileUnit::applySubprogramAttributesToDefinition(
Expand Down Expand Up @@ -1538,7 +1536,7 @@ void DwarfCompileUnit::addAddrTableBase() {
}

void DwarfCompileUnit::addBaseTypeRef(DIEValueList &Die, int64_t Idx) {
Die.addValue(DIEValueAllocator, (dwarf::Attribute)0, dwarf::DW_FORM_udata,
addAttribute(Die, (dwarf::Attribute)0, dwarf::DW_FORM_udata,
new (DIEValueAllocator) DIEBaseTypeRef(this, Idx));
}

Expand Down
36 changes: 16 additions & 20 deletions llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
Expand Up @@ -219,11 +219,9 @@ void DwarfUnit::insertDIE(DIE *D) {

void DwarfUnit::addFlag(DIE &Die, dwarf::Attribute Attribute) {
if (DD->getDwarfVersion() >= 4)
Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_flag_present,
DIEInteger(1));
addAttribute(Die, Attribute, dwarf::DW_FORM_flag_present, DIEInteger(1));
else
Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_flag,
DIEInteger(1));
addAttribute(Die, Attribute, dwarf::DW_FORM_flag, DIEInteger(1));
}

void DwarfUnit::addUInt(DIEValueList &Die, dwarf::Attribute Attribute,
Expand All @@ -232,7 +230,7 @@ void DwarfUnit::addUInt(DIEValueList &Die, dwarf::Attribute Attribute,
Form = DIEInteger::BestForm(false, Integer);
assert(Form != dwarf::DW_FORM_implicit_const &&
"DW_FORM_implicit_const is used only for signed integers");
Die.addValue(DIEValueAllocator, Attribute, *Form, DIEInteger(Integer));
addAttribute(Die, Attribute, *Form, DIEInteger(Integer));
}

void DwarfUnit::addUInt(DIEValueList &Block, dwarf::Form Form,
Expand All @@ -244,7 +242,7 @@ void DwarfUnit::addSInt(DIEValueList &Die, dwarf::Attribute Attribute,
Optional<dwarf::Form> Form, int64_t Integer) {
if (!Form)
Form = DIEInteger::BestForm(true, Integer);
Die.addValue(DIEValueAllocator, Attribute, *Form, DIEInteger(Integer));
addAttribute(Die, Attribute, *Form, DIEInteger(Integer));
}

void DwarfUnit::addSInt(DIELoc &Die, Optional<dwarf::Form> Form,
Expand All @@ -258,7 +256,7 @@ void DwarfUnit::addString(DIE &Die, dwarf::Attribute Attribute,
return;

if (DD->useInlineStrings()) {
Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_string,
addAttribute(Die, Attribute, dwarf::DW_FORM_string,
new (DIEValueAllocator)
DIEInlineString(String, DIEValueAllocator));
return;
Expand All @@ -282,13 +280,12 @@ void DwarfUnit::addString(DIE &Die, dwarf::Attribute Attribute,
else if (Index > 0xff)
IxForm = dwarf::DW_FORM_strx2;
}
Die.addValue(DIEValueAllocator, Attribute, IxForm,
DIEString(StringPoolEntry));
addAttribute(Die, Attribute, IxForm, DIEString(StringPoolEntry));
}

void DwarfUnit::addLabel(DIEValueList &Die, dwarf::Attribute Attribute,
dwarf::Form Form, const MCSymbol *Label) {
Die.addValue(DIEValueAllocator, Attribute, Form, DIELabel(Label));
addAttribute(Die, Attribute, Form, DIELabel(Label));
}

void DwarfUnit::addLabel(DIELoc &Die, dwarf::Form Form, const MCSymbol *Label) {
Expand Down Expand Up @@ -355,7 +352,7 @@ void DwarfUnit::addOpAddress(DIELoc &Die, const MCSymbol *Sym) {

void DwarfUnit::addLabelDelta(DIEValueList &Die, dwarf::Attribute Attribute,
const MCSymbol *Hi, const MCSymbol *Lo) {
Die.addValue(DIEValueAllocator, Attribute, dwarf::DW_FORM_data4,
addAttribute(Die, Attribute, dwarf::DW_FORM_data4,
new (DIEValueAllocator) DIEDelta(Hi, Lo));
}

Expand All @@ -370,8 +367,8 @@ void DwarfUnit::addDIETypeSignature(DIE &Die, uint64_t Signature) {
// and think this is a full definition.
addFlag(Die, dwarf::DW_AT_declaration);

Die.addValue(DIEValueAllocator, dwarf::DW_AT_signature,
dwarf::DW_FORM_ref_sig8, DIEInteger(Signature));
addAttribute(Die, dwarf::DW_AT_signature, dwarf::DW_FORM_ref_sig8,
DIEInteger(Signature));
}

void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute,
Expand All @@ -383,7 +380,7 @@ void DwarfUnit::addDIEEntry(DIE &Die, dwarf::Attribute Attribute,
CU = getUnitDie().getUnit();
if (!EntryCU)
EntryCU = getUnitDie().getUnit();
Die.addValue(DIEValueAllocator, Attribute,
addAttribute(Die, Attribute,
EntryCU == CU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
Entry);
}
Expand All @@ -398,15 +395,14 @@ DIE &DwarfUnit::createAndAddDIE(unsigned Tag, DIE &Parent, const DINode *N) {
void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc) {
Loc->ComputeSize(Asm);
DIELocs.push_back(Loc); // Memoize so we can call the destructor later on.
Die.addValue(DIEValueAllocator, Attribute,
Loc->BestForm(DD->getDwarfVersion()), Loc);
addAttribute(Die, Attribute, Loc->BestForm(DD->getDwarfVersion()), Loc);
}

void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute, dwarf::Form Form,
DIEBlock *Block) {
Block->ComputeSize(Asm);
DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
Die.addValue(DIEValueAllocator, Attribute, Form, Block);
addAttribute(Die, Attribute, Form, Block);
}

void DwarfUnit::addBlock(DIE &Die, dwarf::Attribute Attribute,
Expand Down Expand Up @@ -1639,8 +1635,8 @@ DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
// Objective-C properties.
if (DINode *PNode = DT->getObjCProperty())
if (DIE *PDie = getDIE(PNode))
MemberDie.addValue(DIEValueAllocator, dwarf::DW_AT_APPLE_property,
dwarf::DW_FORM_ref4, DIEEntry(*PDie));
addAttribute(MemberDie, dwarf::DW_AT_APPLE_property,
dwarf::DW_FORM_ref4, DIEEntry(*PDie));

if (DT->isArtificial())
addFlag(MemberDie, dwarf::DW_AT_artificial);
Expand Down Expand Up @@ -1746,7 +1742,7 @@ void DwarfTypeUnit::emitHeader(bool UseOffsets) {

void DwarfUnit::addSectionDelta(DIE &Die, dwarf::Attribute Attribute,
const MCSymbol *Hi, const MCSymbol *Lo) {
Die.addValue(DIEValueAllocator, Attribute, DD->getDwarfSectionOffsetForm(),
addAttribute(Die, Attribute, DD->getDwarfSectionOffsetForm(),
new (DIEValueAllocator) DIEDelta(Hi, Lo));
}

Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h
Expand Up @@ -76,6 +76,13 @@ class DwarfUnit : public DIEUnit {

bool isShareableAcrossCUs(const DINode *D) const;

template <typename T>
void addAttribute(DIEValueList &Die, dwarf::Attribute Attribute,
dwarf::Form Form, T &&Value) {
Die.addValue(DIEValueAllocator,
DIEValue(Attribute, Form, std::forward<T>(Value)));
}

public:
// Accessors.
AsmPrinter* getAsmPrinter() const { return Asm; }
Expand Down

0 comments on commit b12067b

Please sign in to comment.