David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 1 | #include "DwarfCompileUnit.h" |
Adrian Prantl | 7813d9c | 2015-01-14 01:01:30 +0000 | [diff] [blame] | 2 | #include "DwarfExpression.h" |
David Blaikie | cda2aa8 | 2014-10-04 16:24:00 +0000 | [diff] [blame] | 3 | #include "llvm/CodeGen/MachineFunction.h" |
Duncan P. N. Exon Smith | 364a300 | 2015-04-17 21:34:47 +0000 | [diff] [blame] | 4 | #include "llvm/IR/Constants.h" |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 5 | #include "llvm/IR/DataLayout.h" |
| 6 | #include "llvm/IR/GlobalValue.h" |
| 7 | #include "llvm/IR/GlobalVariable.h" |
| 8 | #include "llvm/IR/Instruction.h" |
| 9 | #include "llvm/MC/MCAsmInfo.h" |
| 10 | #include "llvm/MC/MCStreamer.h" |
David Blaikie | ee7df55 | 2014-10-09 17:56:36 +0000 | [diff] [blame] | 11 | #include "llvm/Target/TargetFrameLowering.h" |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 12 | #include "llvm/Target/TargetLoweringObjectFile.h" |
David Blaikie | cda2aa8 | 2014-10-04 16:24:00 +0000 | [diff] [blame] | 13 | #include "llvm/Target/TargetMachine.h" |
David Blaikie | cda2aa8 | 2014-10-04 16:24:00 +0000 | [diff] [blame] | 14 | #include "llvm/Target/TargetRegisterInfo.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 15 | #include "llvm/Target/TargetSubtargetInfo.h" |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 16 | |
| 17 | namespace llvm { |
| 18 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 19 | DwarfCompileUnit::DwarfCompileUnit(unsigned UID, const DICompileUnit *Node, |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 20 | AsmPrinter *A, DwarfDebug *DW, |
| 21 | DwarfFile *DWU) |
David Blaikie | 7cbf58a | 2014-11-01 18:18:07 +0000 | [diff] [blame] | 22 | : DwarfUnit(UID, dwarf::DW_TAG_compile_unit, Node, A, DW, DWU), |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 23 | Skeleton(nullptr), BaseAddress(nullptr) { |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 24 | insertDIE(Node, &getUnitDie()); |
| 25 | } |
| 26 | |
| 27 | /// addLabelAddress - Add a dwarf label attribute data and value using |
| 28 | /// DW_FORM_addr or DW_FORM_GNU_addr_index. |
| 29 | /// |
| 30 | void DwarfCompileUnit::addLabelAddress(DIE &Die, dwarf::Attribute Attribute, |
| 31 | const MCSymbol *Label) { |
| 32 | |
| 33 | // Don't use the address pool in non-fission or in the skeleton unit itself. |
| 34 | // FIXME: Once GDB supports this, it's probably worthwhile using the address |
| 35 | // pool from the skeleton - maybe even in non-fission (possibly fewer |
| 36 | // relocations by sharing them in the pool, but we have other ideas about how |
| 37 | // to reduce the number of relocations as well/instead). |
| 38 | if (!DD->useSplitDwarf() || !Skeleton) |
| 39 | return addLocalLabelAddress(Die, Attribute, Label); |
| 40 | |
| 41 | if (Label) |
| 42 | DD->addArangeLabel(SymbolCU(this, Label)); |
| 43 | |
| 44 | unsigned idx = DD->getAddressPool().getIndex(Label); |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame^] | 45 | Die.addValue(Attribute, dwarf::DW_FORM_GNU_addr_index, DIEInteger(idx)); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | void DwarfCompileUnit::addLocalLabelAddress(DIE &Die, |
| 49 | dwarf::Attribute Attribute, |
| 50 | const MCSymbol *Label) { |
| 51 | if (Label) |
| 52 | DD->addArangeLabel(SymbolCU(this, Label)); |
| 53 | |
| 54 | Die.addValue(Attribute, dwarf::DW_FORM_addr, |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame^] | 55 | Label ? DIEValue(DIELabel(Label)) : DIEValue(DIEInteger(0))); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 56 | } |
| 57 | |
David Blaikie | 8945219 | 2014-10-04 16:00:26 +0000 | [diff] [blame] | 58 | unsigned DwarfCompileUnit::getOrCreateSourceID(StringRef FileName, |
| 59 | StringRef DirName) { |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 60 | // If we print assembly, we can't separate .file entries according to |
| 61 | // compile units. Thus all files will belong to the default compile unit. |
| 62 | |
| 63 | // FIXME: add a better feature test than hasRawTextSupport. Even better, |
| 64 | // extend .file to support this. |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 65 | return Asm->OutStreamer->EmitDwarfFileDirective( |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 66 | 0, DirName, FileName, |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 67 | Asm->OutStreamer->hasRawTextSupport() ? 0 : getUniqueID()); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | // Return const expression if value is a GEP to access merged global |
| 71 | // constant. e.g. |
| 72 | // i8* getelementptr ({ i8, i8, i8, i8 }* @_MergedGlobals, i32 0, i32 0) |
| 73 | static const ConstantExpr *getMergedGlobalExpr(const Value *V) { |
| 74 | const ConstantExpr *CE = dyn_cast_or_null<ConstantExpr>(V); |
| 75 | if (!CE || CE->getNumOperands() != 3 || |
| 76 | CE->getOpcode() != Instruction::GetElementPtr) |
| 77 | return nullptr; |
| 78 | |
| 79 | // First operand points to a global struct. |
| 80 | Value *Ptr = CE->getOperand(0); |
| 81 | if (!isa<GlobalValue>(Ptr) || |
| 82 | !isa<StructType>(cast<PointerType>(Ptr->getType())->getElementType())) |
| 83 | return nullptr; |
| 84 | |
| 85 | // Second operand is zero. |
| 86 | const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(CE->getOperand(1)); |
| 87 | if (!CI || !CI->isZero()) |
| 88 | return nullptr; |
| 89 | |
| 90 | // Third operand is offset. |
| 91 | if (!isa<ConstantInt>(CE->getOperand(2))) |
| 92 | return nullptr; |
| 93 | |
| 94 | return CE; |
| 95 | } |
| 96 | |
| 97 | /// getOrCreateGlobalVariableDIE - get or create global variable DIE. |
Duncan P. N. Exon Smith | 60635e3 | 2015-04-21 18:44:06 +0000 | [diff] [blame] | 98 | DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE( |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 99 | const DIGlobalVariable *GV) { |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 100 | // Check for pre-existence. |
| 101 | if (DIE *Die = getDIE(GV)) |
| 102 | return Die; |
| 103 | |
Duncan P. N. Exon Smith | e686f15 | 2015-04-06 23:27:40 +0000 | [diff] [blame] | 104 | assert(GV); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 105 | |
Duncan P. N. Exon Smith | be9e4fe | 2015-04-20 18:32:29 +0000 | [diff] [blame] | 106 | auto *GVContext = GV->getScope(); |
| 107 | auto *GTy = DD->resolve(GV->getType()); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 108 | |
David Blaikie | 49cfc8c | 2014-10-23 19:12:43 +0000 | [diff] [blame] | 109 | // Construct the context before querying for the existence of the DIE in |
| 110 | // case such construction creates the DIE. |
| 111 | DIE *ContextDIE = getOrCreateContextDIE(GVContext); |
| 112 | |
| 113 | // Add to map. |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 114 | DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 115 | DIScope *DeclContext; |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 116 | if (auto *SDMDecl = GV->getStaticDataMemberDeclaration()) { |
| 117 | DeclContext = resolve(SDMDecl->getScope()); |
| 118 | assert(SDMDecl->isStaticMember() && "Expected static member decl"); |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 119 | assert(GV->isDefinition()); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 120 | // We need the declaration DIE that is in the static member's class. |
David Blaikie | 49cfc8c | 2014-10-23 19:12:43 +0000 | [diff] [blame] | 121 | DIE *VariableSpecDIE = getOrCreateStaticMemberDIE(SDMDecl); |
| 122 | addDIEEntry(*VariableDIE, dwarf::DW_AT_specification, *VariableSpecDIE); |
| 123 | } else { |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 124 | DeclContext = GV->getScope(); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 125 | // Add name and type. |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 126 | addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName()); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 127 | addType(*VariableDIE, GTy); |
| 128 | |
| 129 | // Add scoping info. |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 130 | if (!GV->isLocalToUnit()) |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 131 | addFlag(*VariableDIE, dwarf::DW_AT_external); |
| 132 | |
| 133 | // Add line number info. |
| 134 | addSourceLine(*VariableDIE, GV); |
| 135 | } |
| 136 | |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 137 | if (!GV->isDefinition()) |
David Blaikie | 49cfc8c | 2014-10-23 19:12:43 +0000 | [diff] [blame] | 138 | addFlag(*VariableDIE, dwarf::DW_AT_declaration); |
David Blaikie | 877354a | 2015-04-14 18:08:25 +0000 | [diff] [blame] | 139 | else |
| 140 | addGlobalName(GV->getName(), *VariableDIE, DeclContext); |
David Blaikie | 49cfc8c | 2014-10-23 19:12:43 +0000 | [diff] [blame] | 141 | |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 142 | // Add location. |
| 143 | bool addToAccelTable = false; |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 144 | if (auto *Global = dyn_cast_or_null<GlobalVariable>(GV->getVariable())) { |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 145 | addToAccelTable = true; |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame^] | 146 | DIELoc *Loc = new (DIEValueAllocator) DIELoc; |
Duncan P. N. Exon Smith | cca5f68 | 2015-04-13 20:39:25 +0000 | [diff] [blame] | 147 | const MCSymbol *Sym = Asm->getSymbol(Global); |
| 148 | if (Global->isThreadLocal()) { |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 149 | // FIXME: Make this work with -gsplit-dwarf. |
| 150 | unsigned PointerSize = Asm->getDataLayout().getPointerSize(); |
| 151 | assert((PointerSize == 4 || PointerSize == 8) && |
| 152 | "Add support for other sizes if necessary"); |
| 153 | // Based on GCC's support for TLS: |
| 154 | if (!DD->useSplitDwarf()) { |
| 155 | // 1) Start with a constNu of the appropriate pointer size |
| 156 | addUInt(*Loc, dwarf::DW_FORM_data1, |
| 157 | PointerSize == 4 ? dwarf::DW_OP_const4u : dwarf::DW_OP_const8u); |
| 158 | // 2) containing the (relocated) offset of the TLS variable |
| 159 | // within the module's TLS block. |
| 160 | addExpr(*Loc, dwarf::DW_FORM_udata, |
| 161 | Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym)); |
| 162 | } else { |
| 163 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_const_index); |
| 164 | addUInt(*Loc, dwarf::DW_FORM_udata, |
| 165 | DD->getAddressPool().getIndex(Sym, /* TLS */ true)); |
| 166 | } |
Paul Robinson | 78cc082 | 2015-03-04 20:55:11 +0000 | [diff] [blame] | 167 | // 3) followed by an OP to make the debugger do a TLS lookup. |
| 168 | addUInt(*Loc, dwarf::DW_FORM_data1, |
| 169 | DD->useGNUTLSOpcode() ? dwarf::DW_OP_GNU_push_tls_address |
| 170 | : dwarf::DW_OP_form_tls_address); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 171 | } else { |
| 172 | DD->addArangeLabel(SymbolCU(this, Sym)); |
| 173 | addOpAddress(*Loc, Sym); |
| 174 | } |
David Blaikie | 49cfc8c | 2014-10-23 19:12:43 +0000 | [diff] [blame] | 175 | |
| 176 | addBlock(*VariableDIE, dwarf::DW_AT_location, Loc); |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 177 | addLinkageName(*VariableDIE, GV->getLinkageName()); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 178 | } else if (const ConstantInt *CI = |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 179 | dyn_cast_or_null<ConstantInt>(GV->getVariable())) { |
David Blaikie | 49cfc8c | 2014-10-23 19:12:43 +0000 | [diff] [blame] | 180 | addConstantValue(*VariableDIE, CI, GTy); |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 181 | } else if (const ConstantExpr *CE = getMergedGlobalExpr(GV->getVariable())) { |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 182 | addToAccelTable = true; |
| 183 | // GV is a merged global. |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame^] | 184 | DIELoc *Loc = new (DIEValueAllocator) DIELoc; |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 185 | Value *Ptr = CE->getOperand(0); |
| 186 | MCSymbol *Sym = Asm->getSymbol(cast<GlobalValue>(Ptr)); |
| 187 | DD->addArangeLabel(SymbolCU(this, Sym)); |
| 188 | addOpAddress(*Loc, Sym); |
| 189 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_constu); |
| 190 | SmallVector<Value *, 3> Idx(CE->op_begin() + 1, CE->op_end()); |
| 191 | addUInt(*Loc, dwarf::DW_FORM_udata, |
| 192 | Asm->getDataLayout().getIndexedOffset(Ptr->getType(), Idx)); |
| 193 | addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus); |
| 194 | addBlock(*VariableDIE, dwarf::DW_AT_location, Loc); |
| 195 | } |
| 196 | |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 197 | if (addToAccelTable) { |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 198 | DD->addAccelName(GV->getName(), *VariableDIE); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 199 | |
| 200 | // If the linkage name is different than the name, go ahead and output |
| 201 | // that as well into the name table. |
Duncan P. N. Exon Smith | 7348dda | 2015-04-14 02:22:36 +0000 | [diff] [blame] | 202 | if (GV->getLinkageName() != "" && GV->getName() != GV->getLinkageName()) |
| 203 | DD->addAccelName(GV->getLinkageName(), *VariableDIE); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 204 | } |
| 205 | |
David Blaikie | 49cfc8c | 2014-10-23 19:12:43 +0000 | [diff] [blame] | 206 | return VariableDIE; |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | void DwarfCompileUnit::addRange(RangeSpan Range) { |
| 210 | bool SameAsPrevCU = this == DD->getPrevCU(); |
| 211 | DD->setPrevCU(this); |
| 212 | // If we have no current ranges just add the range and return, otherwise, |
| 213 | // check the current section and CU against the previous section and CU we |
| 214 | // emitted into and the subprogram was contained within. If these are the |
| 215 | // same then extend our current range, otherwise add this as a new range. |
| 216 | if (CURanges.empty() || !SameAsPrevCU || |
| 217 | (&CURanges.back().getEnd()->getSection() != |
| 218 | &Range.getEnd()->getSection())) { |
| 219 | CURanges.push_back(Range); |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | CURanges.back().setEnd(Range.getEnd()); |
| 224 | } |
| 225 | |
David Blaikie | 6c0ee4e | 2014-10-08 22:46:27 +0000 | [diff] [blame] | 226 | void DwarfCompileUnit::addSectionLabel(DIE &Die, dwarf::Attribute Attribute, |
| 227 | const MCSymbol *Label, |
| 228 | const MCSymbol *Sec) { |
| 229 | if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) |
| 230 | addLabel(Die, Attribute, |
| 231 | DD->getDwarfVersion() >= 4 ? dwarf::DW_FORM_sec_offset |
| 232 | : dwarf::DW_FORM_data4, |
| 233 | Label); |
| 234 | else |
| 235 | addSectionDelta(Die, Attribute, Label, Sec); |
| 236 | } |
| 237 | |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 238 | void DwarfCompileUnit::initStmtList() { |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 239 | // Define start line table label for each Compile Unit. |
| 240 | MCSymbol *LineTableStartSym = |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 241 | Asm->OutStreamer->getDwarfLineTableSymbol(getUniqueID()); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 242 | |
| 243 | stmtListIndex = UnitDie.getValues().size(); |
| 244 | |
| 245 | // DW_AT_stmt_list is a offset of line number information for this |
| 246 | // compile unit in debug_line section. For split dwarf this is |
| 247 | // left in the skeleton CU and so not included. |
| 248 | // The line table entries are not always emitted in assembly, so it |
| 249 | // is not okay to use line_table_start here. |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 250 | const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); |
David Blaikie | 6c0ee4e | 2014-10-08 22:46:27 +0000 | [diff] [blame] | 251 | addSectionLabel(UnitDie, dwarf::DW_AT_stmt_list, LineTableStartSym, |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 252 | TLOF.getDwarfLineSection()->getBeginSymbol()); |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | void DwarfCompileUnit::applyStmtList(DIE &D) { |
| 256 | D.addValue(dwarf::DW_AT_stmt_list, |
| 257 | UnitDie.getAbbrev().getData()[stmtListIndex].getForm(), |
| 258 | UnitDie.getValues()[stmtListIndex]); |
| 259 | } |
| 260 | |
David Blaikie | 14499a7 | 2014-10-04 15:58:47 +0000 | [diff] [blame] | 261 | void DwarfCompileUnit::attachLowHighPC(DIE &D, const MCSymbol *Begin, |
| 262 | const MCSymbol *End) { |
| 263 | assert(Begin && "Begin label should not be null!"); |
| 264 | assert(End && "End label should not be null!"); |
| 265 | assert(Begin->isDefined() && "Invalid starting label"); |
| 266 | assert(End->isDefined() && "Invalid end label"); |
| 267 | |
| 268 | addLabelAddress(D, dwarf::DW_AT_low_pc, Begin); |
| 269 | if (DD->getDwarfVersion() < 4) |
| 270 | addLabelAddress(D, dwarf::DW_AT_high_pc, End); |
| 271 | else |
| 272 | addLabelDelta(D, dwarf::DW_AT_high_pc, End, Begin); |
| 273 | } |
| 274 | |
David Blaikie | cda2aa8 | 2014-10-04 16:24:00 +0000 | [diff] [blame] | 275 | // Find DIE for the given subprogram and attach appropriate DW_AT_low_pc |
| 276 | // and DW_AT_high_pc attributes. If there are global variables in this |
| 277 | // scope then create and insert DIEs for these variables. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 278 | DIE &DwarfCompileUnit::updateSubprogramScopeDIE(const DISubprogram *SP) { |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 279 | DIE *SPDie = getOrCreateSubprogramDIE(SP, includeMinimalInlineScopes()); |
David Blaikie | cda2aa8 | 2014-10-04 16:24:00 +0000 | [diff] [blame] | 280 | |
Rafael Espindola | 07c03d3 | 2015-03-05 02:05:42 +0000 | [diff] [blame] | 281 | attachLowHighPC(*SPDie, Asm->getFunctionBegin(), Asm->getFunctionEnd()); |
David Blaikie | cda2aa8 | 2014-10-04 16:24:00 +0000 | [diff] [blame] | 282 | if (!DD->getCurrentFunction()->getTarget().Options.DisableFramePointerElim( |
| 283 | *DD->getCurrentFunction())) |
| 284 | addFlag(*SPDie, dwarf::DW_AT_APPLE_omit_frame_ptr); |
| 285 | |
| 286 | // Only include DW_AT_frame_base in full debug info |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 287 | if (!includeMinimalInlineScopes()) { |
Eric Christopher | d4e723f | 2015-02-20 22:36:11 +0000 | [diff] [blame] | 288 | const TargetRegisterInfo *RI = Asm->MF->getSubtarget().getRegisterInfo(); |
David Blaikie | cda2aa8 | 2014-10-04 16:24:00 +0000 | [diff] [blame] | 289 | MachineLocation Location(RI->getFrameRegister(*Asm->MF)); |
Adrian Prantl | 8efadbf | 2015-01-14 00:15:16 +0000 | [diff] [blame] | 290 | if (RI->isPhysicalRegister(Location.getReg())) |
| 291 | addAddress(*SPDie, dwarf::DW_AT_frame_base, Location); |
David Blaikie | cda2aa8 | 2014-10-04 16:24:00 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | // Add name to the name table, we do this here because we're guaranteed |
| 295 | // to have concrete versions of our DW_TAG_subprogram nodes. |
| 296 | DD->addSubprogramNames(SP, *SPDie); |
| 297 | |
| 298 | return *SPDie; |
| 299 | } |
| 300 | |
David Blaikie | 9c65b13 | 2014-10-08 22:20:02 +0000 | [diff] [blame] | 301 | // Construct a DIE for this scope. |
| 302 | void DwarfCompileUnit::constructScopeDIE( |
| 303 | LexicalScope *Scope, SmallVectorImpl<std::unique_ptr<DIE>> &FinalChildren) { |
| 304 | if (!Scope || !Scope->getScopeNode()) |
| 305 | return; |
| 306 | |
Duncan P. N. Exon Smith | be9e4fe | 2015-04-20 18:32:29 +0000 | [diff] [blame] | 307 | auto *DS = Scope->getScopeNode(); |
David Blaikie | 9c65b13 | 2014-10-08 22:20:02 +0000 | [diff] [blame] | 308 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 309 | assert((Scope->getInlinedAt() || !isa<DISubprogram>(DS)) && |
David Blaikie | 9c65b13 | 2014-10-08 22:20:02 +0000 | [diff] [blame] | 310 | "Only handle inlined subprograms here, use " |
| 311 | "constructSubprogramScopeDIE for non-inlined " |
| 312 | "subprograms"); |
| 313 | |
| 314 | SmallVector<std::unique_ptr<DIE>, 8> Children; |
| 315 | |
| 316 | // We try to create the scope DIE first, then the children DIEs. This will |
| 317 | // avoid creating un-used children then removing them later when we find out |
| 318 | // the scope DIE is null. |
| 319 | std::unique_ptr<DIE> ScopeDIE; |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 320 | if (Scope->getParent() && isa<DISubprogram>(DS)) { |
David Blaikie | 01b48a8 | 2014-10-09 16:50:53 +0000 | [diff] [blame] | 321 | ScopeDIE = constructInlinedScopeDIE(Scope); |
David Blaikie | 9c65b13 | 2014-10-08 22:20:02 +0000 | [diff] [blame] | 322 | if (!ScopeDIE) |
| 323 | return; |
| 324 | // We create children when the scope DIE is not null. |
David Blaikie | 8b2fdb8 | 2014-10-09 18:24:28 +0000 | [diff] [blame] | 325 | createScopeChildrenDIE(Scope, Children); |
David Blaikie | 9c65b13 | 2014-10-08 22:20:02 +0000 | [diff] [blame] | 326 | } else { |
| 327 | // Early exit when we know the scope DIE is going to be null. |
| 328 | if (DD->isLexicalScopeDIENull(Scope)) |
| 329 | return; |
| 330 | |
| 331 | unsigned ChildScopeCount; |
| 332 | |
| 333 | // We create children here when we know the scope DIE is not going to be |
| 334 | // null and the children will be added to the scope DIE. |
David Blaikie | 8b2fdb8 | 2014-10-09 18:24:28 +0000 | [diff] [blame] | 335 | createScopeChildrenDIE(Scope, Children, &ChildScopeCount); |
David Blaikie | 9c65b13 | 2014-10-08 22:20:02 +0000 | [diff] [blame] | 336 | |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 337 | // Skip imported directives in gmlt-like data. |
| 338 | if (!includeMinimalInlineScopes()) { |
| 339 | // There is no need to emit empty lexical block DIE. |
| 340 | for (const auto &E : DD->findImportedEntitiesForScope(DS)) |
| 341 | Children.push_back( |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 342 | constructImportedEntityDIE(cast<DIImportedEntity>(E.second))); |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 343 | } |
| 344 | |
David Blaikie | 9c65b13 | 2014-10-08 22:20:02 +0000 | [diff] [blame] | 345 | // If there are only other scopes as children, put them directly in the |
| 346 | // parent instead, as this scope would serve no purpose. |
| 347 | if (Children.size() == ChildScopeCount) { |
| 348 | FinalChildren.insert(FinalChildren.end(), |
| 349 | std::make_move_iterator(Children.begin()), |
| 350 | std::make_move_iterator(Children.end())); |
| 351 | return; |
| 352 | } |
David Blaikie | 0fbf8bd | 2014-10-09 17:08:42 +0000 | [diff] [blame] | 353 | ScopeDIE = constructLexicalScopeDIE(Scope); |
David Blaikie | 9c65b13 | 2014-10-08 22:20:02 +0000 | [diff] [blame] | 354 | assert(ScopeDIE && "Scope DIE should not be null."); |
| 355 | } |
| 356 | |
| 357 | // Add children |
| 358 | for (auto &I : Children) |
| 359 | ScopeDIE->addChild(std::move(I)); |
| 360 | |
| 361 | FinalChildren.push_back(std::move(ScopeDIE)); |
| 362 | } |
| 363 | |
David Blaikie | e5feec5 | 2014-10-08 23:30:05 +0000 | [diff] [blame] | 364 | void DwarfCompileUnit::addSectionDelta(DIE &Die, dwarf::Attribute Attribute, |
| 365 | const MCSymbol *Hi, const MCSymbol *Lo) { |
David Blaikie | e5feec5 | 2014-10-08 23:30:05 +0000 | [diff] [blame] | 366 | Die.addValue(Attribute, DD->getDwarfVersion() >= 4 ? dwarf::DW_FORM_sec_offset |
| 367 | : dwarf::DW_FORM_data4, |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame^] | 368 | new (DIEValueAllocator) DIEDelta(Hi, Lo)); |
David Blaikie | e5feec5 | 2014-10-08 23:30:05 +0000 | [diff] [blame] | 369 | } |
| 370 | |
David Blaikie | 5b02a19 | 2014-11-03 23:10:59 +0000 | [diff] [blame] | 371 | void DwarfCompileUnit::addScopeRangeList(DIE &ScopeDIE, |
| 372 | SmallVector<RangeSpan, 2> Range) { |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 373 | const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); |
| 374 | |
David Blaikie | 5240020 | 2014-10-09 00:11:39 +0000 | [diff] [blame] | 375 | // Emit offset in .debug_range as a relocatable label. emitDIE will handle |
| 376 | // emitting it appropriately. |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 377 | const MCSymbol *RangeSectionSym = |
| 378 | TLOF.getDwarfRangesSection()->getBeginSymbol(); |
David Blaikie | 5240020 | 2014-10-09 00:11:39 +0000 | [diff] [blame] | 379 | |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 380 | RangeSpanList List(Asm->createTempSymbol("debug_ranges"), std::move(Range)); |
David Blaikie | 5b02a19 | 2014-11-03 23:10:59 +0000 | [diff] [blame] | 381 | |
David Blaikie | 5240020 | 2014-10-09 00:11:39 +0000 | [diff] [blame] | 382 | // Under fission, ranges are specified by constant offsets relative to the |
| 383 | // CU's DW_AT_GNU_ranges_base. |
David Blaikie | 5b02a19 | 2014-11-03 23:10:59 +0000 | [diff] [blame] | 384 | if (isDwoUnit()) |
| 385 | addSectionDelta(ScopeDIE, dwarf::DW_AT_ranges, List.getSym(), |
| 386 | RangeSectionSym); |
David Blaikie | 5240020 | 2014-10-09 00:11:39 +0000 | [diff] [blame] | 387 | else |
David Blaikie | 5b02a19 | 2014-11-03 23:10:59 +0000 | [diff] [blame] | 388 | addSectionLabel(ScopeDIE, dwarf::DW_AT_ranges, List.getSym(), |
| 389 | RangeSectionSym); |
David Blaikie | 5240020 | 2014-10-09 00:11:39 +0000 | [diff] [blame] | 390 | |
| 391 | // Add the range list to the set of ranges to be emitted. |
David Blaikie | 542616d | 2014-11-03 21:52:56 +0000 | [diff] [blame] | 392 | (Skeleton ? Skeleton : this)->CURangeLists.push_back(std::move(List)); |
David Blaikie | 5240020 | 2014-10-09 00:11:39 +0000 | [diff] [blame] | 393 | } |
| 394 | |
David Blaikie | de12375 | 2014-10-09 00:21:42 +0000 | [diff] [blame] | 395 | void DwarfCompileUnit::attachRangesOrLowHighPC( |
David Blaikie | 5b02a19 | 2014-11-03 23:10:59 +0000 | [diff] [blame] | 396 | DIE &Die, SmallVector<RangeSpan, 2> Ranges) { |
| 397 | if (Ranges.size() == 1) { |
| 398 | const auto &single = Ranges.front(); |
| 399 | attachLowHighPC(Die, single.getStart(), single.getEnd()); |
| 400 | } else |
| 401 | addScopeRangeList(Die, std::move(Ranges)); |
| 402 | } |
| 403 | |
| 404 | void DwarfCompileUnit::attachRangesOrLowHighPC( |
David Blaikie | de12375 | 2014-10-09 00:21:42 +0000 | [diff] [blame] | 405 | DIE &Die, const SmallVectorImpl<InsnRange> &Ranges) { |
David Blaikie | 5b02a19 | 2014-11-03 23:10:59 +0000 | [diff] [blame] | 406 | SmallVector<RangeSpan, 2> List; |
| 407 | List.reserve(Ranges.size()); |
| 408 | for (const InsnRange &R : Ranges) |
| 409 | List.push_back(RangeSpan(DD->getLabelBeforeInsn(R.first), |
| 410 | DD->getLabelAfterInsn(R.second))); |
| 411 | attachRangesOrLowHighPC(Die, std::move(List)); |
David Blaikie | de12375 | 2014-10-09 00:21:42 +0000 | [diff] [blame] | 412 | } |
| 413 | |
David Blaikie | 01b48a8 | 2014-10-09 16:50:53 +0000 | [diff] [blame] | 414 | // This scope represents inlined body of a function. Construct DIE to |
| 415 | // represent this concrete inlined copy of the function. |
| 416 | std::unique_ptr<DIE> |
| 417 | DwarfCompileUnit::constructInlinedScopeDIE(LexicalScope *Scope) { |
| 418 | assert(Scope->getScopeNode()); |
Duncan P. N. Exon Smith | be9e4fe | 2015-04-20 18:32:29 +0000 | [diff] [blame] | 419 | auto *DS = Scope->getScopeNode(); |
| 420 | auto *InlinedSP = getDISubprogram(DS); |
David Blaikie | 01b48a8 | 2014-10-09 16:50:53 +0000 | [diff] [blame] | 421 | // Find the subprogram's DwarfCompileUnit in the SPMap in case the subprogram |
| 422 | // was inlined from another compile unit. |
David Blaikie | f6dac29 | 2014-11-01 17:21:26 +0000 | [diff] [blame] | 423 | DIE *OriginDIE = DU->getAbstractSPDies()[InlinedSP]; |
David Blaikie | 01b48a8 | 2014-10-09 16:50:53 +0000 | [diff] [blame] | 424 | assert(OriginDIE && "Unable to find original DIE for an inlined subprogram."); |
| 425 | |
| 426 | auto ScopeDIE = make_unique<DIE>(dwarf::DW_TAG_inlined_subroutine); |
| 427 | addDIEEntry(*ScopeDIE, dwarf::DW_AT_abstract_origin, *OriginDIE); |
| 428 | |
| 429 | attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges()); |
| 430 | |
| 431 | // Add the call site information to the DIE. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 432 | const DILocation *IA = Scope->getInlinedAt(); |
David Blaikie | 01b48a8 | 2014-10-09 16:50:53 +0000 | [diff] [blame] | 433 | addUInt(*ScopeDIE, dwarf::DW_AT_call_file, None, |
Duncan P. N. Exon Smith | b7e221b | 2015-04-14 01:35:55 +0000 | [diff] [blame] | 434 | getOrCreateSourceID(IA->getFilename(), IA->getDirectory())); |
| 435 | addUInt(*ScopeDIE, dwarf::DW_AT_call_line, None, IA->getLine()); |
David Blaikie | 01b48a8 | 2014-10-09 16:50:53 +0000 | [diff] [blame] | 436 | |
| 437 | // Add name to the name table, we do this here because we're guaranteed |
| 438 | // to have concrete versions of our DW_TAG_inlined_subprogram nodes. |
| 439 | DD->addSubprogramNames(InlinedSP, *ScopeDIE); |
| 440 | |
| 441 | return ScopeDIE; |
| 442 | } |
| 443 | |
David Blaikie | 0fbf8bd | 2014-10-09 17:08:42 +0000 | [diff] [blame] | 444 | // Construct new DW_TAG_lexical_block for this scope and attach |
| 445 | // DW_AT_low_pc/DW_AT_high_pc labels. |
| 446 | std::unique_ptr<DIE> |
| 447 | DwarfCompileUnit::constructLexicalScopeDIE(LexicalScope *Scope) { |
| 448 | if (DD->isLexicalScopeDIENull(Scope)) |
| 449 | return nullptr; |
| 450 | |
| 451 | auto ScopeDIE = make_unique<DIE>(dwarf::DW_TAG_lexical_block); |
| 452 | if (Scope->isAbstractScope()) |
| 453 | return ScopeDIE; |
| 454 | |
| 455 | attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges()); |
| 456 | |
| 457 | return ScopeDIE; |
| 458 | } |
| 459 | |
David Blaikie | ee7df55 | 2014-10-09 17:56:36 +0000 | [diff] [blame] | 460 | /// constructVariableDIE - Construct a DIE for the given DbgVariable. |
| 461 | std::unique_ptr<DIE> DwarfCompileUnit::constructVariableDIE(DbgVariable &DV, |
| 462 | bool Abstract) { |
| 463 | auto D = constructVariableDIEImpl(DV, Abstract); |
| 464 | DV.setDIE(*D); |
| 465 | return D; |
| 466 | } |
| 467 | |
| 468 | std::unique_ptr<DIE> |
| 469 | DwarfCompileUnit::constructVariableDIEImpl(const DbgVariable &DV, |
| 470 | bool Abstract) { |
| 471 | // Define variable debug information entry. |
| 472 | auto VariableDie = make_unique<DIE>(DV.getTag()); |
| 473 | |
| 474 | if (Abstract) { |
| 475 | applyVariableAttributes(DV, *VariableDie); |
| 476 | return VariableDie; |
| 477 | } |
| 478 | |
| 479 | // Add variable address. |
| 480 | |
Duncan P. N. Exon Smith | 364a300 | 2015-04-17 21:34:47 +0000 | [diff] [blame] | 481 | unsigned Offset = DV.getDebugLocListIndex(); |
David Blaikie | ee7df55 | 2014-10-09 17:56:36 +0000 | [diff] [blame] | 482 | if (Offset != ~0U) { |
| 483 | addLocationList(*VariableDie, dwarf::DW_AT_location, Offset); |
| 484 | return VariableDie; |
| 485 | } |
| 486 | |
| 487 | // Check if variable is described by a DBG_VALUE instruction. |
| 488 | if (const MachineInstr *DVInsn = DV.getMInsn()) { |
| 489 | assert(DVInsn->getNumOperands() == 4); |
| 490 | if (DVInsn->getOperand(0).isReg()) { |
| 491 | const MachineOperand RegOp = DVInsn->getOperand(0); |
| 492 | // If the second operand is an immediate, this is an indirect value. |
| 493 | if (DVInsn->getOperand(1).isImm()) { |
| 494 | MachineLocation Location(RegOp.getReg(), |
| 495 | DVInsn->getOperand(1).getImm()); |
| 496 | addVariableAddress(DV, *VariableDie, Location); |
| 497 | } else if (RegOp.getReg()) |
| 498 | addVariableAddress(DV, *VariableDie, MachineLocation(RegOp.getReg())); |
| 499 | } else if (DVInsn->getOperand(0).isImm()) |
| 500 | addConstantValue(*VariableDie, DVInsn->getOperand(0), DV.getType()); |
| 501 | else if (DVInsn->getOperand(0).isFPImm()) |
| 502 | addConstantFPValue(*VariableDie, DVInsn->getOperand(0)); |
| 503 | else if (DVInsn->getOperand(0).isCImm()) |
| 504 | addConstantValue(*VariableDie, DVInsn->getOperand(0).getCImm(), |
| 505 | DV.getType()); |
| 506 | |
| 507 | return VariableDie; |
| 508 | } |
| 509 | |
| 510 | // .. else use frame index. |
Adrian Prantl | ca7e470 | 2015-02-10 23:18:28 +0000 | [diff] [blame] | 511 | if (DV.getFrameIndex().back() == ~0) |
| 512 | return VariableDie; |
| 513 | |
| 514 | auto Expr = DV.getExpression().begin(); |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame^] | 515 | DIELoc *Loc = new (DIEValueAllocator) DIELoc; |
Adrian Prantl | ca7e470 | 2015-02-10 23:18:28 +0000 | [diff] [blame] | 516 | DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc); |
| 517 | for (auto FI : DV.getFrameIndex()) { |
David Blaikie | ee7df55 | 2014-10-09 17:56:36 +0000 | [diff] [blame] | 518 | unsigned FrameReg = 0; |
Eric Christopher | d4e723f | 2015-02-20 22:36:11 +0000 | [diff] [blame] | 519 | const TargetFrameLowering *TFI = Asm->MF->getSubtarget().getFrameLowering(); |
David Blaikie | ee7df55 | 2014-10-09 17:56:36 +0000 | [diff] [blame] | 520 | int Offset = TFI->getFrameIndexReference(*Asm->MF, FI, FrameReg); |
Duncan P. N. Exon Smith | 57bab0b | 2015-02-17 22:30:56 +0000 | [diff] [blame] | 521 | assert(Expr != DV.getExpression().end() && |
| 522 | "Wrong number of expressions"); |
Adrian Prantl | ca7e470 | 2015-02-10 23:18:28 +0000 | [diff] [blame] | 523 | DwarfExpr.AddMachineRegIndirect(FrameReg, Offset); |
Duncan P. N. Exon Smith | 76c9184 | 2015-04-07 03:45:57 +0000 | [diff] [blame] | 524 | DwarfExpr.AddExpression((*Expr)->expr_op_begin(), (*Expr)->expr_op_end()); |
Duncan P. N. Exon Smith | 57bab0b | 2015-02-17 22:30:56 +0000 | [diff] [blame] | 525 | ++Expr; |
David Blaikie | ee7df55 | 2014-10-09 17:56:36 +0000 | [diff] [blame] | 526 | } |
Adrian Prantl | ca7e470 | 2015-02-10 23:18:28 +0000 | [diff] [blame] | 527 | addBlock(*VariableDie, dwarf::DW_AT_location, Loc); |
David Blaikie | ee7df55 | 2014-10-09 17:56:36 +0000 | [diff] [blame] | 528 | |
| 529 | return VariableDie; |
| 530 | } |
| 531 | |
David Blaikie | 4a1a44e | 2014-10-09 17:56:39 +0000 | [diff] [blame] | 532 | std::unique_ptr<DIE> DwarfCompileUnit::constructVariableDIE( |
| 533 | DbgVariable &DV, const LexicalScope &Scope, DIE *&ObjectPointer) { |
| 534 | auto Var = constructVariableDIE(DV, Scope.isAbstractScope()); |
| 535 | if (DV.isObjectPointer()) |
| 536 | ObjectPointer = Var.get(); |
| 537 | return Var; |
| 538 | } |
| 539 | |
David Blaikie | 8b2fdb8 | 2014-10-09 18:24:28 +0000 | [diff] [blame] | 540 | DIE *DwarfCompileUnit::createScopeChildrenDIE( |
| 541 | LexicalScope *Scope, SmallVectorImpl<std::unique_ptr<DIE>> &Children, |
| 542 | unsigned *ChildScopeCount) { |
| 543 | DIE *ObjectPointer = nullptr; |
| 544 | |
David Blaikie | 80e5b1e | 2014-10-24 17:57:34 +0000 | [diff] [blame] | 545 | for (DbgVariable *DV : DU->getScopeVariables().lookup(Scope)) |
David Blaikie | 8b2fdb8 | 2014-10-09 18:24:28 +0000 | [diff] [blame] | 546 | Children.push_back(constructVariableDIE(*DV, *Scope, ObjectPointer)); |
| 547 | |
| 548 | unsigned ChildCountWithoutScopes = Children.size(); |
| 549 | |
| 550 | for (LexicalScope *LS : Scope->getChildren()) |
| 551 | constructScopeDIE(LS, Children); |
| 552 | |
| 553 | if (ChildScopeCount) |
| 554 | *ChildScopeCount = Children.size() - ChildCountWithoutScopes; |
| 555 | |
| 556 | return ObjectPointer; |
| 557 | } |
| 558 | |
David Blaikie | 1d07234 | 2014-10-09 20:21:36 +0000 | [diff] [blame] | 559 | void DwarfCompileUnit::constructSubprogramScopeDIE(LexicalScope *Scope) { |
| 560 | assert(Scope && Scope->getScopeNode()); |
| 561 | assert(!Scope->getInlinedAt()); |
| 562 | assert(!Scope->isAbstractScope()); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 563 | auto *Sub = cast<DISubprogram>(Scope->getScopeNode()); |
David Blaikie | 1d07234 | 2014-10-09 20:21:36 +0000 | [diff] [blame] | 564 | |
| 565 | DD->getProcessedSPNodes().insert(Sub); |
| 566 | |
| 567 | DIE &ScopeDIE = updateSubprogramScopeDIE(Sub); |
| 568 | |
David Blaikie | 1d07234 | 2014-10-09 20:21:36 +0000 | [diff] [blame] | 569 | // If this is a variadic function, add an unspecified parameter. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 570 | DITypeRefArray FnArgs = Sub->getType()->getTypeArray(); |
David Blaikie | 1dd573d | 2014-10-23 22:27:50 +0000 | [diff] [blame] | 571 | |
| 572 | // Collect lexical scope children first. |
| 573 | // ObjectPointer might be a local (non-argument) local variable if it's a |
| 574 | // block's synthetic this pointer. |
| 575 | if (DIE *ObjectPointer = createAndAddScopeChildren(Scope, ScopeDIE)) |
| 576 | addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, *ObjectPointer); |
| 577 | |
David Blaikie | 1d07234 | 2014-10-09 20:21:36 +0000 | [diff] [blame] | 578 | // If we have a single element of null, it is a function that returns void. |
| 579 | // If we have more than one elements and the last one is null, it is a |
| 580 | // variadic function. |
Duncan P. N. Exon Smith | 000fa2c | 2015-04-07 04:14:33 +0000 | [diff] [blame] | 581 | if (FnArgs.size() > 1 && !FnArgs[FnArgs.size() - 1] && |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 582 | !includeMinimalInlineScopes()) |
David Blaikie | 1d07234 | 2014-10-09 20:21:36 +0000 | [diff] [blame] | 583 | ScopeDIE.addChild(make_unique<DIE>(dwarf::DW_TAG_unspecified_parameters)); |
David Blaikie | 1d07234 | 2014-10-09 20:21:36 +0000 | [diff] [blame] | 584 | } |
| 585 | |
David Blaikie | 78b65b6 | 2014-10-09 20:26:15 +0000 | [diff] [blame] | 586 | DIE *DwarfCompileUnit::createAndAddScopeChildren(LexicalScope *Scope, |
| 587 | DIE &ScopeDIE) { |
| 588 | // We create children when the scope DIE is not null. |
| 589 | SmallVector<std::unique_ptr<DIE>, 8> Children; |
| 590 | DIE *ObjectPointer = createScopeChildrenDIE(Scope, Children); |
| 591 | |
| 592 | // Add children |
| 593 | for (auto &I : Children) |
| 594 | ScopeDIE.addChild(std::move(I)); |
| 595 | |
| 596 | return ObjectPointer; |
| 597 | } |
| 598 | |
David Blaikie | 49be5b3 | 2014-10-31 21:57:02 +0000 | [diff] [blame] | 599 | void |
David Blaikie | 58410f2 | 2014-10-10 06:39:26 +0000 | [diff] [blame] | 600 | DwarfCompileUnit::constructAbstractSubprogramScopeDIE(LexicalScope *Scope) { |
David Blaikie | f6dac29 | 2014-11-01 17:21:26 +0000 | [diff] [blame] | 601 | DIE *&AbsDef = DU->getAbstractSPDies()[Scope->getScopeNode()]; |
David Blaikie | 49be5b3 | 2014-10-31 21:57:02 +0000 | [diff] [blame] | 602 | if (AbsDef) |
| 603 | return; |
| 604 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 605 | auto *SP = cast<DISubprogram>(Scope->getScopeNode()); |
David Blaikie | 58410f2 | 2014-10-10 06:39:26 +0000 | [diff] [blame] | 606 | |
| 607 | DIE *ContextDIE; |
| 608 | |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 609 | if (includeMinimalInlineScopes()) |
| 610 | ContextDIE = &getUnitDie(); |
David Blaikie | 58410f2 | 2014-10-10 06:39:26 +0000 | [diff] [blame] | 611 | // Some of this is duplicated from DwarfUnit::getOrCreateSubprogramDIE, with |
Duncan P. N. Exon Smith | 7c60f20 | 2015-04-18 00:35:36 +0000 | [diff] [blame] | 612 | // the important distinction that the debug node is not associated with the |
| 613 | // DIE (since the debug node will be associated with the concrete DIE, if |
David Blaikie | 58410f2 | 2014-10-10 06:39:26 +0000 | [diff] [blame] | 614 | // any). It could be refactored to some common utility function. |
Duncan P. N. Exon Smith | 537b4a8 | 2015-04-14 03:40:37 +0000 | [diff] [blame] | 615 | else if (auto *SPDecl = SP->getDeclaration()) { |
David Blaikie | 58410f2 | 2014-10-10 06:39:26 +0000 | [diff] [blame] | 616 | ContextDIE = &getUnitDie(); |
| 617 | getOrCreateSubprogramDIE(SPDecl); |
| 618 | } else |
Duncan P. N. Exon Smith | 537b4a8 | 2015-04-14 03:40:37 +0000 | [diff] [blame] | 619 | ContextDIE = getOrCreateContextDIE(resolve(SP->getScope())); |
David Blaikie | 58410f2 | 2014-10-10 06:39:26 +0000 | [diff] [blame] | 620 | |
Duncan P. N. Exon Smith | 7c60f20 | 2015-04-18 00:35:36 +0000 | [diff] [blame] | 621 | // Passing null as the associated node because the abstract definition |
David Blaikie | 58410f2 | 2014-10-10 06:39:26 +0000 | [diff] [blame] | 622 | // shouldn't be found by lookup. |
Duncan P. N. Exon Smith | 7c60f20 | 2015-04-18 00:35:36 +0000 | [diff] [blame] | 623 | AbsDef = &createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, nullptr); |
David Blaikie | 49be5b3 | 2014-10-31 21:57:02 +0000 | [diff] [blame] | 624 | applySubprogramAttributesToDefinition(SP, *AbsDef); |
David Blaikie | 58410f2 | 2014-10-10 06:39:26 +0000 | [diff] [blame] | 625 | |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 626 | if (!includeMinimalInlineScopes()) |
David Blaikie | 49be5b3 | 2014-10-31 21:57:02 +0000 | [diff] [blame] | 627 | addUInt(*AbsDef, dwarf::DW_AT_inline, None, dwarf::DW_INL_inlined); |
| 628 | if (DIE *ObjectPointer = createAndAddScopeChildren(Scope, *AbsDef)) |
| 629 | addDIEEntry(*AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer); |
David Blaikie | 58410f2 | 2014-10-10 06:39:26 +0000 | [diff] [blame] | 630 | } |
| 631 | |
Frederic Riss | 987fe22 | 2014-10-24 21:31:09 +0000 | [diff] [blame] | 632 | std::unique_ptr<DIE> |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 633 | DwarfCompileUnit::constructImportedEntityDIE(const DIImportedEntity *Module) { |
Duncan P. N. Exon Smith | de8e427 | 2015-04-14 01:46:44 +0000 | [diff] [blame] | 634 | std::unique_ptr<DIE> IMDie = make_unique<DIE>((dwarf::Tag)Module->getTag()); |
Frederic Riss | 987fe22 | 2014-10-24 21:31:09 +0000 | [diff] [blame] | 635 | insertDIE(Module, IMDie.get()); |
| 636 | DIE *EntityDie; |
Duncan P. N. Exon Smith | de8e427 | 2015-04-14 01:46:44 +0000 | [diff] [blame] | 637 | auto *Entity = resolve(Module->getEntity()); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 638 | if (auto *NS = dyn_cast<DINamespace>(Entity)) |
Duncan P. N. Exon Smith | e686f15 | 2015-04-06 23:27:40 +0000 | [diff] [blame] | 639 | EntityDie = getOrCreateNameSpace(NS); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 640 | else if (auto *SP = dyn_cast<DISubprogram>(Entity)) |
Duncan P. N. Exon Smith | e686f15 | 2015-04-06 23:27:40 +0000 | [diff] [blame] | 641 | EntityDie = getOrCreateSubprogramDIE(SP); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 642 | else if (auto *T = dyn_cast<DIType>(Entity)) |
Duncan P. N. Exon Smith | e686f15 | 2015-04-06 23:27:40 +0000 | [diff] [blame] | 643 | EntityDie = getOrCreateTypeDIE(T); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 644 | else if (auto *GV = dyn_cast<DIGlobalVariable>(Entity)) |
Duncan P. N. Exon Smith | e686f15 | 2015-04-06 23:27:40 +0000 | [diff] [blame] | 645 | EntityDie = getOrCreateGlobalVariableDIE(GV); |
Frederic Riss | 987fe22 | 2014-10-24 21:31:09 +0000 | [diff] [blame] | 646 | else |
| 647 | EntityDie = getDIE(Entity); |
| 648 | assert(EntityDie); |
Duncan P. N. Exon Smith | de8e427 | 2015-04-14 01:46:44 +0000 | [diff] [blame] | 649 | addSourceLine(*IMDie, Module->getLine(), Module->getScope()->getFilename(), |
| 650 | Module->getScope()->getDirectory()); |
Frederic Riss | 987fe22 | 2014-10-24 21:31:09 +0000 | [diff] [blame] | 651 | addDIEEntry(*IMDie, dwarf::DW_AT_import, *EntityDie); |
Duncan P. N. Exon Smith | de8e427 | 2015-04-14 01:46:44 +0000 | [diff] [blame] | 652 | StringRef Name = Module->getName(); |
Frederic Riss | 987fe22 | 2014-10-24 21:31:09 +0000 | [diff] [blame] | 653 | if (!Name.empty()) |
| 654 | addString(*IMDie, dwarf::DW_AT_name, Name); |
| 655 | |
| 656 | return IMDie; |
| 657 | } |
| 658 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 659 | void DwarfCompileUnit::finishSubprogramDefinition(const DISubprogram *SP) { |
David Blaikie | 4191cbc | 2014-10-10 06:39:29 +0000 | [diff] [blame] | 660 | DIE *D = getDIE(SP); |
David Blaikie | f6dac29 | 2014-11-01 17:21:26 +0000 | [diff] [blame] | 661 | if (DIE *AbsSPDIE = DU->getAbstractSPDies().lookup(SP)) { |
David Blaikie | 4191cbc | 2014-10-10 06:39:29 +0000 | [diff] [blame] | 662 | if (D) |
| 663 | // If this subprogram has an abstract definition, reference that |
| 664 | addDIEEntry(*D, dwarf::DW_AT_abstract_origin, *AbsSPDIE); |
| 665 | } else { |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 666 | if (!D && !includeMinimalInlineScopes()) |
David Blaikie | 4191cbc | 2014-10-10 06:39:29 +0000 | [diff] [blame] | 667 | // Lazily construct the subprogram if we didn't see either concrete or |
| 668 | // inlined versions during codegen. (except in -gmlt ^ where we want |
| 669 | // to omit these entirely) |
| 670 | D = getOrCreateSubprogramDIE(SP); |
| 671 | if (D) |
| 672 | // And attach the attributes |
| 673 | applySubprogramAttributesToDefinition(SP, *D); |
| 674 | } |
| 675 | } |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 676 | void DwarfCompileUnit::collectDeadVariables(const DISubprogram *SP) { |
Duncan P. N. Exon Smith | e686f15 | 2015-04-06 23:27:40 +0000 | [diff] [blame] | 677 | assert(SP && "CU's subprogram list contains a non-subprogram"); |
Duncan P. N. Exon Smith | 537b4a8 | 2015-04-14 03:40:37 +0000 | [diff] [blame] | 678 | assert(SP->isDefinition() && |
David Blaikie | 1d96cc2 | 2014-10-31 22:30:30 +0000 | [diff] [blame] | 679 | "CU's subprogram list contains a subprogram declaration"); |
Duncan P. N. Exon Smith | 000fa2c | 2015-04-07 04:14:33 +0000 | [diff] [blame] | 680 | auto Variables = SP->getVariables(); |
| 681 | if (Variables.size() == 0) |
David Blaikie | 1d96cc2 | 2014-10-31 22:30:30 +0000 | [diff] [blame] | 682 | return; |
| 683 | |
David Blaikie | f6dac29 | 2014-11-01 17:21:26 +0000 | [diff] [blame] | 684 | DIE *SPDIE = DU->getAbstractSPDies().lookup(SP); |
David Blaikie | 1d96cc2 | 2014-10-31 22:30:30 +0000 | [diff] [blame] | 685 | if (!SPDIE) |
| 686 | SPDIE = getDIE(SP); |
| 687 | assert(SPDIE); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 688 | for (const DILocalVariable *DV : Variables) { |
Duncan P. N. Exon Smith | 60635e3 | 2015-04-21 18:44:06 +0000 | [diff] [blame] | 689 | DbgVariable NewVar(DV, /* IA */ nullptr, /* Expr */ nullptr, DD); |
David Blaikie | 1d96cc2 | 2014-10-31 22:30:30 +0000 | [diff] [blame] | 690 | auto VariableDie = constructVariableDIE(NewVar); |
| 691 | applyVariableAttributes(NewVar, *VariableDie); |
| 692 | SPDIE->addChild(std::move(VariableDie)); |
| 693 | } |
| 694 | } |
David Blaikie | 4191cbc | 2014-10-10 06:39:29 +0000 | [diff] [blame] | 695 | |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 696 | void DwarfCompileUnit::emitHeader(bool UseOffsets) { |
David Blaikie | b6726a9 | 2014-11-02 02:26:24 +0000 | [diff] [blame] | 697 | // Don't bother labeling the .dwo unit, as its offset isn't used. |
Rafael Espindola | 3c31114 | 2015-03-10 03:11:11 +0000 | [diff] [blame] | 698 | if (!Skeleton) { |
Rafael Espindola | 9ab0923 | 2015-03-17 20:07:06 +0000 | [diff] [blame] | 699 | LabelBegin = Asm->createTempSymbol("cu_begin"); |
Lang Hames | 9ff69c8 | 2015-04-24 19:11:51 +0000 | [diff] [blame] | 700 | Asm->OutStreamer->EmitLabel(LabelBegin); |
Rafael Espindola | 3c31114 | 2015-03-10 03:11:11 +0000 | [diff] [blame] | 701 | } |
David Blaikie | ae57e66 | 2014-11-01 23:59:23 +0000 | [diff] [blame] | 702 | |
Rafael Espindola | 063d725 | 2015-03-10 16:58:10 +0000 | [diff] [blame] | 703 | DwarfUnit::emitHeader(UseOffsets); |
David Blaikie | ae57e66 | 2014-11-01 23:59:23 +0000 | [diff] [blame] | 704 | } |
| 705 | |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 706 | /// addGlobalName - Add a new global name to the compile unit. |
| 707 | void DwarfCompileUnit::addGlobalName(StringRef Name, DIE &Die, |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 708 | const DIScope *Context) { |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 709 | if (includeMinimalInlineScopes()) |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 710 | return; |
| 711 | std::string FullName = getParentContextString(Context) + Name.str(); |
| 712 | GlobalNames[FullName] = &Die; |
| 713 | } |
| 714 | |
| 715 | /// Add a new global type to the unit. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 716 | void DwarfCompileUnit::addGlobalType(const DIType *Ty, const DIE &Die, |
| 717 | const DIScope *Context) { |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 718 | if (includeMinimalInlineScopes()) |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 719 | return; |
Duncan P. N. Exon Smith | b105564 | 2015-04-16 01:01:28 +0000 | [diff] [blame] | 720 | std::string FullName = getParentContextString(Context) + Ty->getName().str(); |
David Blaikie | 192b45c | 2014-11-02 06:16:39 +0000 | [diff] [blame] | 721 | GlobalTypes[FullName] = &Die; |
| 722 | } |
David Blaikie | ae57e66 | 2014-11-01 23:59:23 +0000 | [diff] [blame] | 723 | |
David Blaikie | 7d48be2 | 2014-11-02 06:37:23 +0000 | [diff] [blame] | 724 | /// addVariableAddress - Add DW_AT_location attribute for a |
| 725 | /// DbgVariable based on provided MachineLocation. |
| 726 | void DwarfCompileUnit::addVariableAddress(const DbgVariable &DV, DIE &Die, |
| 727 | MachineLocation Location) { |
| 728 | if (DV.variableHasComplexAddress()) |
| 729 | addComplexAddress(DV, Die, dwarf::DW_AT_location, Location); |
| 730 | else if (DV.isBlockByrefVariable()) |
| 731 | addBlockByrefAddress(DV, Die, dwarf::DW_AT_location, Location); |
| 732 | else |
Adrian Prantl | 5883af3 | 2015-01-19 17:57:29 +0000 | [diff] [blame] | 733 | addAddress(Die, dwarf::DW_AT_location, Location); |
David Blaikie | 7d48be2 | 2014-11-02 06:37:23 +0000 | [diff] [blame] | 734 | } |
David Blaikie | f7435ee | 2014-11-02 06:46:40 +0000 | [diff] [blame] | 735 | |
| 736 | /// Add an address attribute to a die based on the location provided. |
| 737 | void DwarfCompileUnit::addAddress(DIE &Die, dwarf::Attribute Attribute, |
Adrian Prantl | 5883af3 | 2015-01-19 17:57:29 +0000 | [diff] [blame] | 738 | const MachineLocation &Location) { |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame^] | 739 | DIELoc *Loc = new (DIEValueAllocator) DIELoc; |
David Blaikie | f7435ee | 2014-11-02 06:46:40 +0000 | [diff] [blame] | 740 | |
Adrian Prantl | ab255fc | 2014-12-05 01:02:46 +0000 | [diff] [blame] | 741 | bool validReg; |
Adrian Prantl | 5883af3 | 2015-01-19 17:57:29 +0000 | [diff] [blame] | 742 | if (Location.isReg()) |
Adrian Prantl | ab255fc | 2014-12-05 01:02:46 +0000 | [diff] [blame] | 743 | validReg = addRegisterOpPiece(*Loc, Location.getReg()); |
| 744 | else |
| 745 | validReg = addRegisterOffset(*Loc, Location.getReg(), Location.getOffset()); |
| 746 | |
| 747 | if (!validReg) |
| 748 | return; |
| 749 | |
David Blaikie | f7435ee | 2014-11-02 06:46:40 +0000 | [diff] [blame] | 750 | // Now attach the location information to the DIE. |
| 751 | addBlock(Die, Attribute, Loc); |
| 752 | } |
David Blaikie | 77895fb | 2014-11-02 06:58:44 +0000 | [diff] [blame] | 753 | |
| 754 | /// Start with the address based on the location provided, and generate the |
| 755 | /// DWARF information necessary to find the actual variable given the extra |
| 756 | /// address information encoded in the DbgVariable, starting from the starting |
| 757 | /// location. Add the DWARF information to the die. |
| 758 | void DwarfCompileUnit::addComplexAddress(const DbgVariable &DV, DIE &Die, |
| 759 | dwarf::Attribute Attribute, |
| 760 | const MachineLocation &Location) { |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame^] | 761 | DIELoc *Loc = new (DIEValueAllocator) DIELoc; |
Adrian Prantl | 7813d9c | 2015-01-14 01:01:30 +0000 | [diff] [blame] | 762 | DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc); |
Adrian Prantl | ca7e470 | 2015-02-10 23:18:28 +0000 | [diff] [blame] | 763 | assert(DV.getExpression().size() == 1); |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 764 | const DIExpression *Expr = DV.getExpression().back(); |
Adrian Prantl | 40cb819 | 2015-01-25 19:04:08 +0000 | [diff] [blame] | 765 | bool ValidReg; |
Adrian Prantl | 7813d9c | 2015-01-14 01:01:30 +0000 | [diff] [blame] | 766 | if (Location.getOffset()) { |
Adrian Prantl | 40cb819 | 2015-01-25 19:04:08 +0000 | [diff] [blame] | 767 | ValidReg = DwarfExpr.AddMachineRegIndirect(Location.getReg(), |
| 768 | Location.getOffset()); |
| 769 | if (ValidReg) |
Duncan P. N. Exon Smith | 76c9184 | 2015-04-07 03:45:57 +0000 | [diff] [blame] | 770 | DwarfExpr.AddExpression(Expr->expr_op_begin(), Expr->expr_op_end()); |
Adrian Prantl | 5883af3 | 2015-01-19 17:57:29 +0000 | [diff] [blame] | 771 | } else |
Adrian Prantl | 40cb819 | 2015-01-25 19:04:08 +0000 | [diff] [blame] | 772 | ValidReg = DwarfExpr.AddMachineRegExpression(Expr, Location.getReg()); |
David Blaikie | 77895fb | 2014-11-02 06:58:44 +0000 | [diff] [blame] | 773 | |
| 774 | // Now attach the location information to the DIE. |
Adrian Prantl | 40cb819 | 2015-01-25 19:04:08 +0000 | [diff] [blame] | 775 | if (ValidReg) |
| 776 | addBlock(Die, Attribute, Loc); |
David Blaikie | 77895fb | 2014-11-02 06:58:44 +0000 | [diff] [blame] | 777 | } |
David Blaikie | 4bc0881 | 2014-11-02 07:03:19 +0000 | [diff] [blame] | 778 | |
| 779 | /// Add a Dwarf loclistptr attribute data and value. |
| 780 | void DwarfCompileUnit::addLocationList(DIE &Die, dwarf::Attribute Attribute, |
| 781 | unsigned Index) { |
David Blaikie | 4bc0881 | 2014-11-02 07:03:19 +0000 | [diff] [blame] | 782 | dwarf::Form Form = DD->getDwarfVersion() >= 4 ? dwarf::DW_FORM_sec_offset |
| 783 | : dwarf::DW_FORM_data4; |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame^] | 784 | Die.addValue(Attribute, Form, DIELocList(Index)); |
David Blaikie | 4bc0881 | 2014-11-02 07:03:19 +0000 | [diff] [blame] | 785 | } |
David Blaikie | 02a6333 | 2014-11-02 07:06:51 +0000 | [diff] [blame] | 786 | |
David Blaikie | 8c485b5 | 2014-11-02 07:08:12 +0000 | [diff] [blame] | 787 | void DwarfCompileUnit::applyVariableAttributes(const DbgVariable &Var, |
| 788 | DIE &VariableDie) { |
David Blaikie | 02a6333 | 2014-11-02 07:06:51 +0000 | [diff] [blame] | 789 | StringRef Name = Var.getName(); |
| 790 | if (!Name.empty()) |
| 791 | addString(VariableDie, dwarf::DW_AT_name, Name); |
| 792 | addSourceLine(VariableDie, Var.getVariable()); |
| 793 | addType(VariableDie, Var.getType()); |
| 794 | if (Var.isArtificial()) |
| 795 | addFlag(VariableDie, dwarf::DW_AT_artificial); |
| 796 | } |
David Blaikie | 9780208 | 2014-11-02 07:11:55 +0000 | [diff] [blame] | 797 | |
| 798 | /// Add a Dwarf expression attribute data and value. |
| 799 | void DwarfCompileUnit::addExpr(DIELoc &Die, dwarf::Form Form, |
| 800 | const MCExpr *Expr) { |
Duncan P. N. Exon Smith | e7e1d0c | 2015-05-27 22:14:58 +0000 | [diff] [blame^] | 801 | Die.addValue((dwarf::Attribute)0, Form, DIEExpr(Expr)); |
David Blaikie | 9780208 | 2014-11-02 07:11:55 +0000 | [diff] [blame] | 802 | } |
David Blaikie | 3363a57 | 2014-11-02 08:09:09 +0000 | [diff] [blame] | 803 | |
Duncan P. N. Exon Smith | 2fbe135 | 2015-04-20 22:10:08 +0000 | [diff] [blame] | 804 | void DwarfCompileUnit::applySubprogramAttributesToDefinition( |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 805 | const DISubprogram *SP, DIE &SPDie) { |
Duncan P. N. Exon Smith | 537b4a8 | 2015-04-14 03:40:37 +0000 | [diff] [blame] | 806 | auto *SPDecl = SP->getDeclaration(); |
Duncan P. N. Exon Smith | be9e4fe | 2015-04-20 18:32:29 +0000 | [diff] [blame] | 807 | auto *Context = resolve(SPDecl ? SPDecl->getScope() : SP->getScope()); |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 808 | applySubprogramAttributes(SP, SPDie, includeMinimalInlineScopes()); |
Duncan P. N. Exon Smith | 537b4a8 | 2015-04-14 03:40:37 +0000 | [diff] [blame] | 809 | addGlobalName(SP->getName(), SPDie, Context); |
David Blaikie | 3363a57 | 2014-11-02 08:09:09 +0000 | [diff] [blame] | 810 | } |
David Blaikie | cafd962 | 2014-11-02 08:51:37 +0000 | [diff] [blame] | 811 | |
| 812 | bool DwarfCompileUnit::isDwoUnit() const { |
| 813 | return DD->useSplitDwarf() && Skeleton; |
| 814 | } |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 815 | |
| 816 | bool DwarfCompileUnit::includeMinimalInlineScopes() const { |
Duncan P. N. Exon Smith | 35ef22c | 2015-04-15 23:19:27 +0000 | [diff] [blame] | 817 | return getCUNode()->getEmissionKind() == DIBuilder::LineTablesOnly || |
David Blaikie | 3a443c2 | 2014-11-04 22:12:25 +0000 | [diff] [blame] | 818 | (DD->useSplitDwarf() && !Skeleton); |
| 819 | } |
David Blaikie | 37c5231 | 2014-10-04 15:49:50 +0000 | [diff] [blame] | 820 | } // end llvm namespace |