llvm.org GIT mirror llvm / 355ec00
DebugInfo: Gut DIVariable and DIGlobalVariable Gut all the non-pointer API from the variable wrappers, except an implicit conversion from `DIGlobalVariable` to `DIDescriptor`. Note that if you're updating out-of-tree code, `DIVariable` wraps `MDLocalVariable` (`MDVariable` is a common base class shared with `MDGlobalVariable`). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234840 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
14 changed file(s) with 85 addition(s) and 122 deletion(s). Raw diff Collapse all Expand all
580580 Metadata *getValue() const { return get()->getValue(); }
581581 };
582582
583 /// \brief This is a wrapper for a global variable.
584 class DIGlobalVariable : public DIDescriptor {
585 DIFile getFile() const { return DIFile(get()->getFile()); }
586
587 public:
588 DIGlobalVariable() = default;
589 DIGlobalVariable(const MDGlobalVariable *N) : DIDescriptor(N) {}
590
591 MDGlobalVariable *get() const {
592 return cast_or_null(DIDescriptor::get());
593 }
594 operator MDGlobalVariable *() const { return get(); }
595 MDGlobalVariable *operator->() const { return get(); }
596 MDGlobalVariable &operator*() const { return *get(); }
597
598 StringRef getName() const { return get()->getName(); }
599 StringRef getDisplayName() const { return get()->getDisplayName(); }
600 StringRef getLinkageName() const { return get()->getLinkageName(); }
601 unsigned getLineNumber() const { return get()->getLine(); }
602 unsigned isLocalToUnit() const { return get()->isLocalToUnit(); }
603 unsigned isDefinition() const { return get()->isDefinition(); }
604
605 DIScope getContext() const { return get()->getScope(); }
606 StringRef getFilename() const { return get()->getFilename(); }
607 StringRef getDirectory() const { return get()->getDirectory(); }
608 DITypeRef getType() const { return get()->getType(); }
609
610 Constant *getConstant() const { return get()->getVariable(); }
611 DIDerivedType getStaticDataMemberDeclaration() const {
612 return get()->getStaticDataMemberDeclaration();
613 }
614 };
615
616 /// \brief This is a wrapper for a variable (e.g. parameter, local, global etc).
617 class DIVariable : public DIDescriptor {
618 unsigned getFlags() const { return get()->getFlags(); }
619
620 public:
621 DIVariable() = default;
622 DIVariable(const MDLocalVariable *N) : DIDescriptor(N) {}
623
624 MDLocalVariable *get() const {
625 return cast_or_null(DIDescriptor::get());
626 }
627 operator MDLocalVariable *() const { return get(); }
628 MDLocalVariable *operator->() const { return get(); }
629 MDLocalVariable &operator*() const { return *get(); }
630
631 StringRef getName() const { return get()->getName(); }
632 unsigned getLineNumber() const { return get()->getLine(); }
633 unsigned getArgNumber() const { return get()->getArg(); }
634
635 DIScope getContext() const { return get()->getScope(); }
636 DIFile getFile() const { return get()->getFile(); }
637 DITypeRef getType() const { return get()->getType(); }
638
639 bool isArtificial() const { return get()->isArtificial(); }
640 bool isObjectPointer() const { return get()->isObjectPointer(); }
641
642 /// \brief If this variable is inlined then return inline location.
643 MDNode *getInlinedAt() const { return get()->getInlinedAt(); }
644 };
583 class DIGlobalVariable {
584 MDGlobalVariable *N;
585
586 public:
587 DIGlobalVariable(const MDGlobalVariable *N = nullptr)
588 : N(const_cast(N)) {}
589
590 operator DIDescriptor() const { return N; }
591 operator MDGlobalVariable *() const { return N; }
592 MDGlobalVariable *operator->() const { return N; }
593 MDGlobalVariable &operator*() const { return *N; }
594 };
595
596 class DIVariable {
597 MDLocalVariable *N;
598
599 public:
600 DIVariable(const MDLocalVariable *N = nullptr)
601 : N(const_cast(N)) {}
602
603 operator MDLocalVariable *() const { return N; }
604 MDLocalVariable *operator->() const { return N; }
605 MDLocalVariable &operator*() const { return *N; }
606 };
607
645608
646609 class DIExpression {
647610 MDExpression *N;
9090 }
9191
9292 for (DIGlobalVariable GV : Finder.global_variables()) {
93 O << "Global variable: " << GV.getName();
94 printFile(O, GV.getFilename(), GV.getDirectory(), GV.getLineNumber());
95 if (!GV.getLinkageName().empty())
96 O << " ('" << GV.getLinkageName() << "')";
93 O << "Global variable: " << GV->getName();
94 printFile(O, GV->getFilename(), GV->getDirectory(), GV->getLine());
95 if (!GV->getLinkageName().empty())
96 O << " ('" << GV->getLinkageName() << "')";
9797 O << '\n';
9898 }
9999
670670 OS << "DEBUG_VALUE: ";
671671
672672 DIVariable V = MI->getDebugVariable();
673 if (DISubprogram SP = dyn_cast(V.getContext())) {
673 if (DISubprogram SP = dyn_cast(V->getScope())) {
674674 StringRef Name = SP.getDisplayName();
675675 if (!Name.empty())
676676 OS << Name << ":";
677677 }
678 OS << V.getName();
678 OS << V->getName();
679679
680680 DIExpression Expr = MI->getDebugExpression();
681681 if (Expr->isBitPiece())
102102
103103 assert(GV);
104104
105 DIScope GVContext = GV.getContext();
106 DIType GTy = DD->resolve(GV.getType());
105 DIScope GVContext = GV->getScope();
106 DIType GTy = DD->resolve(GV->getType());
107107
108108 // Construct the context before querying for the existence of the DIE in
109109 // case such construction creates the DIE.
110110 DIE *ContextDIE = getOrCreateContextDIE(GVContext);
111111
112112 // Add to map.
113 DIE *VariableDIE = &createAndAddDIE(GV.getTag(), *ContextDIE, GV);
113 DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV);
114114 DIScope DeclContext;
115115
116 if (DIDerivedType SDMDecl = GV.getStaticDataMemberDeclaration()) {
116 if (DIDerivedType SDMDecl = GV->getStaticDataMemberDeclaration()) {
117117 DeclContext = resolve(SDMDecl.getContext());
118118 assert(SDMDecl.isStaticMember() && "Expected static member decl");
119 assert(GV.isDefinition());
119 assert(GV->isDefinition());
120120 // We need the declaration DIE that is in the static member's class.
121121 DIE *VariableSpecDIE = getOrCreateStaticMemberDIE(SDMDecl);
122122 addDIEEntry(*VariableDIE, dwarf::DW_AT_specification, *VariableSpecDIE);
123123 } else {
124 DeclContext = GV.getContext();
124 DeclContext = GV->getScope();
125125 // Add name and type.
126 addString(*VariableDIE, dwarf::DW_AT_name, GV.getDisplayName());
126 addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName());
127127 addType(*VariableDIE, GTy);
128128
129129 // Add scoping info.
130 if (!GV.isLocalToUnit())
130 if (!GV->isLocalToUnit())
131131 addFlag(*VariableDIE, dwarf::DW_AT_external);
132132
133133 // Add line number info.
134134 addSourceLine(*VariableDIE, GV);
135135 }
136136
137 if (!GV.isDefinition())
137 if (!GV->isDefinition())
138138 addFlag(*VariableDIE, dwarf::DW_AT_declaration);
139139
140140 // Add location.
141141 bool addToAccelTable = false;
142 if (auto *Global = dyn_cast_or_null(GV.getConstant())) {
142 if (auto *Global = dyn_cast_or_null(GV->getVariable())) {
143143 addToAccelTable = true;
144144 DIELoc *Loc = new (DIEValueAllocator) DIELoc();
145145 const MCSymbol *Sym = Asm->getSymbol(Global);
172172 }
173173
174174 addBlock(*VariableDIE, dwarf::DW_AT_location, Loc);
175 addLinkageName(*VariableDIE, GV.getLinkageName());
175 addLinkageName(*VariableDIE, GV->getLinkageName());
176176 } else if (const ConstantInt *CI =
177 dyn_cast_or_null(GV.getConstant())) {
177 dyn_cast_or_null(GV->getVariable())) {
178178 addConstantValue(*VariableDIE, CI, GTy);
179 } else if (const ConstantExpr *CE = getMergedGlobalExpr(GV.getConstant())) {
179 } else if (const ConstantExpr *CE = getMergedGlobalExpr(GV->getVariable())) {
180180 addToAccelTable = true;
181181 // GV is a merged global.
182182 DIELoc *Loc = new (DIEValueAllocator) DIELoc();
193193 }
194194
195195 if (addToAccelTable) {
196 DD->addAccelName(GV.getName(), *VariableDIE);
196 DD->addAccelName(GV->getName(), *VariableDIE);
197197
198198 // If the linkage name is different than the name, go ahead and output
199199 // that as well into the name table.
200 if (GV.getLinkageName() != "" && GV.getName() != GV.getLinkageName())
201 DD->addAccelName(GV.getLinkageName(), *VariableDIE);
202 }
203
204 addGlobalName(GV.getName(), *VariableDIE, DeclContext);
200 if (GV->getLinkageName() != "" && GV->getName() != GV->getLinkageName())
201 DD->addAccelName(GV->getLinkageName(), *VariableDIE);
202 }
203
204 addGlobalName(GV->getName(), *VariableDIE, DeclContext);
205205 return VariableDIE;
206206 }
207207
140140 }
141141
142142 DIType DbgVariable::getType() const {
143 DIType Ty = Var.getType().resolve(DD->getTypeIdentifierMap());
143 DIType Ty = Var->getType().resolve(DD->getTypeIdentifierMap());
144144 // FIXME: isBlockByrefVariable should be reformulated in terms of complex
145145 // addresses instead.
146146 if (Ty->isBlockByrefStruct()) {
893893 continue;
894894
895895 LexicalScope *Scope = nullptr;
896 if (MDLocation *IA = DV.get()->getInlinedAt())
897 Scope = LScopes.findInlinedScope(DV.get()->getScope(), IA);
896 if (MDLocation *IA = DV->getInlinedAt())
897 Scope = LScopes.findInlinedScope(DV->getScope(), IA);
898898 else
899 Scope = LScopes.findLexicalScope(DV.get()->getScope());
899 Scope = LScopes.findLexicalScope(DV->getScope());
900900 // If variable scope is not found then skip this variable.
901901 if (!Scope)
902902 continue;
932932 for (DIVariable DV : SP->getVariables()) {
933933 if (!Processed.insert(DV).second)
934934 continue;
935 if (LexicalScope *Scope = LScopes.findLexicalScope(DV.get()->getScope())) {
935 if (LexicalScope *Scope = LScopes.findLexicalScope(DV->getScope())) {
936936 ensureAbstractVariableIsCreatedIfScoped(DV, Scope->getScopeNode());
937937 DIExpression NoExpr;
938938 ConcreteVariables.push_back(make_unique(DV, NoExpr, this));
11271127 // The first mention of a function argument gets the CurrentFnBegin
11281128 // label, so arguments are visible when breaking at function entry.
11291129 DIVariable DIVar = Ranges.front().first->getDebugVariable();
1130 if (DIVar.getTag() == dwarf::DW_TAG_arg_variable &&
1131 getDISubprogram(DIVar.getContext()).describes(MF->getFunction())) {
1130 if (DIVar->getTag() == dwarf::DW_TAG_arg_variable &&
1131 getDISubprogram(DIVar->getScope()).describes(MF->getFunction())) {
11321132 LabelsBeforeInsn[Ranges.front().first] = Asm->getFunctionBegin();
11331133 if (Ranges.front().first->getDebugExpression()->isBitPiece()) {
11341134 // Mark all non-overlapping initial pieces.
12191219 for (DIVariable DV : SP->getVariables()) {
12201220 if (!ProcessedVars.insert(DV).second)
12211221 continue;
1222 ensureAbstractVariableIsCreated(DV, DV.getContext());
1222 ensureAbstractVariableIsCreated(DV, DV->getScope());
12231223 assert(LScopes.getAbstractScopesList().size() == NumAbstractScopes
12241224 && "ensureAbstractVariableIsCreated inserted abstract scopes");
12251225 }
14791479 Streamer);
14801480 // Regular entry.
14811481 if (Value.isInt()) {
1482 MDType *T = DV.getType().resolve(TypeIdentifierMap);
1482 MDType *T = DV->getType().resolve(TypeIdentifierMap);
14831483 auto *B = dyn_cast(T);
14841484 if (B && (B->getEncoding() == dwarf::DW_ATE_signed ||
14851485 B->getEncoding() == dwarf::DW_ATE_signed_char))
106106 DIE *getDIE() const { return TheDIE; }
107107 void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
108108 unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
109 StringRef getName() const { return Var.getName(); }
109 StringRef getName() const { return Var->getName(); }
110110 const MachineInstr *getMInsn() const { return MInsn; }
111111 const ArrayRef getFrameIndex() const { return FrameIndex; }
112112
129129
130130 // Translate tag to proper Dwarf tag.
131131 dwarf::Tag getTag() const {
132 if (Var.getTag() == dwarf::DW_TAG_arg_variable)
132 if (Var->getTag() == dwarf::DW_TAG_arg_variable)
133133 return dwarf::DW_TAG_formal_parameter;
134134
135135 return dwarf::DW_TAG_variable;
136136 }
137137 /// \brief Return true if DbgVariable is artificial.
138138 bool isArtificial() const {
139 if (Var.isArtificial())
139 if (Var->isArtificial())
140140 return true;
141141 if (getType().isArtificial())
142142 return true;
144144 }
145145
146146 bool isObjectPointer() const {
147 if (Var.isObjectPointer())
147 if (Var->isObjectPointer())
148148 return true;
149149 if (getType().isObjectPointer())
150150 return true;
138138 SmallVectorImpl &Vars = ScopeVariables[LS];
139139 DIVariable DV = Var->getVariable();
140140 // Variables with positive arg numbers are parameters.
141 if (unsigned ArgNum = DV.getArgNumber()) {
141 if (unsigned ArgNum = DV->getArg()) {
142142 // Keep all parameters in order at the start of the variable list to ensure
143143 // function types are correct (no out-of-order parameters)
144144 //
148148 // rather than linear search.
149149 auto I = Vars.begin();
150150 while (I != Vars.end()) {
151 unsigned CurNum = (*I)->getVariable().getArgNumber();
151 unsigned CurNum = (*I)->getVariable()->getArg();
152152 // A local (non-parameter) variable has been found, insert immediately
153153 // before it.
154154 if (CurNum == 0)
398398 void DwarfUnit::addSourceLine(DIE &Die, DIVariable V) {
399399 assert(V);
400400
401 addSourceLine(Die, V.getLineNumber(), V.getContext().getFilename(),
402 V.getContext().getDirectory());
401 addSourceLine(Die, V->getLine(), V->getScope()->getFilename(),
402 V->getScope()->getDirectory());
403403 }
404404
405405 /// addSourceLine - Add location information to specified debug information
407407 void DwarfUnit::addSourceLine(DIE &Die, DIGlobalVariable G) {
408408 assert(G);
409409
410 addSourceLine(Die, G.getLineNumber(), G.getFilename(), G.getDirectory());
410 addSourceLine(Die, G->getLine(), G->getFilename(), G->getDirectory());
411411 }
412412
413413 /// addSourceLine - Add location information to specified debug information
16191619 if (isDebugValue() && MO.isMetadata()) {
16201620 // Pretty print DBG_VALUE instructions.
16211621 DIVariable DIV = dyn_cast(MO.getMetadata());
1622 if (DIV && !DIV.getName().empty())
1623 OS << "!\"" << DIV.getName() << '\"';
1622 if (DIV && !DIV->getName().empty())
1623 OS << "!\"" << DIV->getName() << '\"';
16241624 else
16251625 MO.print(OS, TRI);
16261626 } else if (TRI && (isInsertSubreg() || isRegSequence()) && MO.isImm()) {
17101710 if (isDebugValue() && getOperand(e - 2).isMetadata()) {
17111711 if (!HaveSemi) OS << ";";
17121712 DIVariable DV = cast(getOperand(e - 2).getMetadata());
1713 OS << " line no:" << DV.getLineNumber();
1714 if (auto *InlinedAt = DV.getInlinedAt()) {
1713 OS << " line no:" << DV->getLine();
1714 if (auto *InlinedAt = DV->getInlinedAt()) {
17151715 DebugLoc InlinedAtDL(InlinedAt);
17161716 if (InlinedAtDL && MF) {
17171717 OS << " inlined @[ ";
46724672 Address = BCI->getOperand(0);
46734673 // Parameters are handled specially.
46744674 bool isParameter =
4675 (DIVariable(Variable).getTag() == dwarf::DW_TAG_arg_variable ||
4675 (DIVariable(Variable)->getTag() == dwarf::DW_TAG_arg_variable ||
46764676 isa(Address));
46774677
46784678 const AllocaInst *AI = dyn_cast(Address);
151151 addCompileUnit(CU);
152152 for (DIGlobalVariable DIG : CU->getGlobalVariables()) {
153153 if (addGlobalVariable(DIG)) {
154 processScope(DIG.getContext());
155 processType(DIG.getType().resolve(TypeIdentifierMap));
154 processScope(DIG->getScope());
155 processType(DIG->getType().resolve(TypeIdentifierMap));
156156 }
157157 }
158158 for (auto *SP : CU->getSubprograms())
257257
258258 if (!NodesSeen.insert(DV).second)
259259 return;
260 processScope(DV.getContext());
261 processType(DV.getType().resolve(TypeIdentifierMap));
260 processScope(DV->getScope());
261 processType(DV->getType().resolve(TypeIdentifierMap));
262262 }
263263
264264 void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) {
273273
274274 if (!NodesSeen.insert(DV).second)
275275 return;
276 processScope(DV.getContext());
277 processType(DV.getType().resolve(TypeIdentifierMap));
276 processScope(DV->getScope());
277 processType(DV->getType().resolve(TypeIdentifierMap));
278278 }
279279
280280 bool DebugInfoFinder::addType(DIType DT) {
347347 assert(NOps == 4);
348348 OS << '\t' << MAI->getCommentString() << "DEBUG_VALUE: ";
349349 // cast away const; DIetc do not take const operands for some reason.
350 DIVariable V = cast(MI->getOperand(NOps - 2).getMetadata());
351 OS << V.getName();
350 OS << cast(MI->getOperand(NOps - 2).getMetadata())
351 ->getName();
352352 OS << " <- ";
353353 // Frame address. Currently handles register +- offset only.
354354 assert(MI->getOperand(0).isReg() && MI->getOperand(1).isImm());
334334
335335 // If the global variable referenced by DIG is not null, the global
336336 // variable is live.
337 if (DIG.getConstant())
337 if (DIG->getVariable())
338338 LiveGlobalVariables.push_back(DIG);
339339 else
340340 GlobalVariableChange = true;
349349 }
350350
351351 if (GlobalVariableChange) {
352 DIC.replaceGlobalVariables(DIArray(MDNode::get(C, LiveGlobalVariables)));
352 DIC.replaceGlobalVariables(MDTuple::get(C, LiveGlobalVariables));
353353 Changed = true;
354354 }
355355
9393 OS.PadToColumn(50);
9494 OS << ";";
9595 }
96 OS << " [debug variable = " << Var.getName() << "]";
96 OS << " [debug variable = " << Var->getName() << "]";
9797 }
9898 else if (const DbgValueInst *DVI = dyn_cast(I)) {
9999 DIVariable Var(DVI->getVariable());
101101 OS.PadToColumn(50);
102102 OS << ";";
103103 }
104 OS << " [debug variable = " << Var.getName() << "]";
104 OS << " [debug variable = " << Var->getName() << "]";
105105 }
106106 }
107107 }