1 //===--- DebugInfo.cpp - Debug Information Helper Classes -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the helper classes used to build and interpret debug
11 // information in LLVM IR form.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Analysis/DebugInfo.h"
16 #include "llvm/Constants.h"
17 #include "llvm/DerivedTypes.h"
18 #include "llvm/Intrinsics.h"
19 #include "llvm/IntrinsicInst.h"
20 #include "llvm/Instructions.h"
21 #include "llvm/Module.h"
22 #include "llvm/Analysis/ValueTracking.h"
23 #include "llvm/ADT/SmallPtrSet.h"
24 #include "llvm/ADT/SmallString.h"
25 #include "llvm/ADT/STLExtras.h"
26 #include "llvm/Support/Debug.h"
27 #include "llvm/Support/Dwarf.h"
28 #include "llvm/Support/raw_ostream.h"
30 using namespace llvm::dwarf;
32 //===----------------------------------------------------------------------===//
34 //===----------------------------------------------------------------------===//
36 DIDescriptor::DIDescriptor(const DIFile F) : DbgNode(F.DbgNode) {
39 DIDescriptor::DIDescriptor(const DISubprogram F) : DbgNode(F.DbgNode) {
42 DIDescriptor::DIDescriptor(const DILexicalBlock F) : DbgNode(F.DbgNode) {
45 DIDescriptor::DIDescriptor(const DIVariable F) : DbgNode(F.DbgNode) {
48 DIDescriptor::DIDescriptor(const DIType F) : DbgNode(F.DbgNode) {
52 DIDescriptor::getStringField(unsigned Elt) const {
56 if (Elt < DbgNode->getNumOperands())
57 if (MDString *MDS = dyn_cast_or_null<MDString>(DbgNode->getOperand(Elt)))
58 return MDS->getString();
63 uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
67 if (Elt < DbgNode->getNumOperands())
68 if (ConstantInt *CI = dyn_cast<ConstantInt>(DbgNode->getOperand(Elt)))
69 return CI->getZExtValue();
74 DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
76 return DIDescriptor();
78 if (Elt < DbgNode->getNumOperands())
80 DIDescriptor(dyn_cast_or_null<const MDNode>(DbgNode->getOperand(Elt)));
81 return DIDescriptor();
84 GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
88 if (Elt < DbgNode->getNumOperands())
89 return dyn_cast_or_null<GlobalVariable>(DbgNode->getOperand(Elt));
93 Constant *DIDescriptor::getConstantField(unsigned Elt) const {
97 if (Elt < DbgNode->getNumOperands())
98 return dyn_cast_or_null<Constant>(DbgNode->getOperand(Elt));
102 Function *DIDescriptor::getFunctionField(unsigned Elt) const {
106 if (Elt < DbgNode->getNumOperands())
107 return dyn_cast_or_null<Function>(DbgNode->getOperand(Elt));
111 unsigned DIVariable::getNumAddrElements() const {
112 if (getVersion() <= llvm::LLVMDebugVersion8)
113 return DbgNode->getNumOperands()-6;
114 if (getVersion() == llvm::LLVMDebugVersion9)
115 return DbgNode->getNumOperands()-7;
116 return DbgNode->getNumOperands()-8;
120 //===----------------------------------------------------------------------===//
122 //===----------------------------------------------------------------------===//
124 /// isBasicType - Return true if the specified tag is legal for
126 bool DIDescriptor::isBasicType() const {
127 return DbgNode && getTag() == dwarf::DW_TAG_base_type;
130 /// isDerivedType - Return true if the specified tag is legal for DIDerivedType.
131 bool DIDescriptor::isDerivedType() const {
132 if (!DbgNode) return false;
134 case dwarf::DW_TAG_typedef:
135 case dwarf::DW_TAG_pointer_type:
136 case dwarf::DW_TAG_reference_type:
137 case dwarf::DW_TAG_const_type:
138 case dwarf::DW_TAG_volatile_type:
139 case dwarf::DW_TAG_restrict_type:
140 case dwarf::DW_TAG_member:
141 case dwarf::DW_TAG_inheritance:
142 case dwarf::DW_TAG_friend:
145 // CompositeTypes are currently modelled as DerivedTypes.
146 return isCompositeType();
150 /// isCompositeType - Return true if the specified tag is legal for
152 bool DIDescriptor::isCompositeType() const {
153 if (!DbgNode) return false;
155 case dwarf::DW_TAG_array_type:
156 case dwarf::DW_TAG_structure_type:
157 case dwarf::DW_TAG_union_type:
158 case dwarf::DW_TAG_enumeration_type:
159 case dwarf::DW_TAG_vector_type:
160 case dwarf::DW_TAG_subroutine_type:
161 case dwarf::DW_TAG_class_type:
168 /// isVariable - Return true if the specified tag is legal for DIVariable.
169 bool DIDescriptor::isVariable() const {
170 if (!DbgNode) return false;
172 case dwarf::DW_TAG_auto_variable:
173 case dwarf::DW_TAG_arg_variable:
174 case dwarf::DW_TAG_return_variable:
181 /// isType - Return true if the specified tag is legal for DIType.
182 bool DIDescriptor::isType() const {
183 return isBasicType() || isCompositeType() || isDerivedType();
186 /// isSubprogram - Return true if the specified tag is legal for
188 bool DIDescriptor::isSubprogram() const {
189 return DbgNode && getTag() == dwarf::DW_TAG_subprogram;
192 /// isGlobalVariable - Return true if the specified tag is legal for
193 /// DIGlobalVariable.
194 bool DIDescriptor::isGlobalVariable() const {
195 return DbgNode && (getTag() == dwarf::DW_TAG_variable ||
196 getTag() == dwarf::DW_TAG_constant);
199 /// isGlobal - Return true if the specified tag is legal for DIGlobal.
200 bool DIDescriptor::isGlobal() const {
201 return isGlobalVariable();
204 /// isUnspecifiedParmeter - Return true if the specified tag is
205 /// DW_TAG_unspecified_parameters.
206 bool DIDescriptor::isUnspecifiedParameter() const {
207 return DbgNode && getTag() == dwarf::DW_TAG_unspecified_parameters;
210 /// isScope - Return true if the specified tag is one of the scope
212 bool DIDescriptor::isScope() const {
213 if (!DbgNode) return false;
215 case dwarf::DW_TAG_compile_unit:
216 case dwarf::DW_TAG_lexical_block:
217 case dwarf::DW_TAG_subprogram:
218 case dwarf::DW_TAG_namespace:
226 /// isTemplateTypeParameter - Return true if the specified tag is
227 /// DW_TAG_template_type_parameter.
228 bool DIDescriptor::isTemplateTypeParameter() const {
229 return DbgNode && getTag() == dwarf::DW_TAG_template_type_parameter;
232 /// isTemplateValueParameter - Return true if the specified tag is
233 /// DW_TAG_template_value_parameter.
234 bool DIDescriptor::isTemplateValueParameter() const {
235 return DbgNode && getTag() == dwarf::DW_TAG_template_value_parameter;
238 /// isCompileUnit - Return true if the specified tag is DW_TAG_compile_unit.
239 bool DIDescriptor::isCompileUnit() const {
240 return DbgNode && getTag() == dwarf::DW_TAG_compile_unit;
243 /// isFile - Return true if the specified tag is DW_TAG_file_type.
244 bool DIDescriptor::isFile() const {
245 return DbgNode && getTag() == dwarf::DW_TAG_file_type;
248 /// isNameSpace - Return true if the specified tag is DW_TAG_namespace.
249 bool DIDescriptor::isNameSpace() const {
250 return DbgNode && getTag() == dwarf::DW_TAG_namespace;
253 /// isLexicalBlock - Return true if the specified tag is DW_TAG_lexical_block.
254 bool DIDescriptor::isLexicalBlock() const {
255 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block;
258 /// isSubrange - Return true if the specified tag is DW_TAG_subrange_type.
259 bool DIDescriptor::isSubrange() const {
260 return DbgNode && getTag() == dwarf::DW_TAG_subrange_type;
263 /// isEnumerator - Return true if the specified tag is DW_TAG_enumerator.
264 bool DIDescriptor::isEnumerator() const {
265 return DbgNode && getTag() == dwarf::DW_TAG_enumerator;
268 //===----------------------------------------------------------------------===//
269 // Simple Descriptor Constructors and other Methods
270 //===----------------------------------------------------------------------===//
272 DIType::DIType(const MDNode *N) : DIScope(N) {
274 if (!isBasicType() && !isDerivedType() && !isCompositeType()) {
279 unsigned DIArray::getNumElements() const {
282 return DbgNode->getNumOperands();
285 /// replaceAllUsesWith - Replace all uses of debug info referenced by
287 void DIType::replaceAllUsesWith(DIDescriptor &D) {
291 // Since we use a TrackingVH for the node, its easy for clients to manufacture
292 // legitimate situations where they want to replaceAllUsesWith() on something
293 // which, due to uniquing, has merged with the source. We shield clients from
294 // this detail by allowing a value to be replaced with replaceAllUsesWith()
297 MDNode *Node = const_cast<MDNode*>(DbgNode);
298 const MDNode *DN = D;
299 const Value *V = cast_or_null<Value>(DN);
300 Node->replaceAllUsesWith(const_cast<Value*>(V));
301 MDNode::deleteTemporary(Node);
305 /// replaceAllUsesWith - Replace all uses of debug info referenced by
307 void DIType::replaceAllUsesWith(MDNode *D) {
311 // Since we use a TrackingVH for the node, its easy for clients to manufacture
312 // legitimate situations where they want to replaceAllUsesWith() on something
313 // which, due to uniquing, has merged with the source. We shield clients from
314 // this detail by allowing a value to be replaced with replaceAllUsesWith()
317 MDNode *Node = const_cast<MDNode*>(DbgNode);
318 const MDNode *DN = D;
319 const Value *V = cast_or_null<Value>(DN);
320 Node->replaceAllUsesWith(const_cast<Value*>(V));
321 MDNode::deleteTemporary(Node);
325 /// Verify - Verify that a compile unit is well formed.
326 bool DICompileUnit::Verify() const {
329 StringRef N = getFilename();
332 // It is possible that directory and produce string is empty.
336 /// Verify - Verify that a type descriptor is well formed.
337 bool DIType::Verify() const {
340 if (!getContext().Verify())
342 unsigned Tag = getTag();
343 if (!isBasicType() && Tag != dwarf::DW_TAG_const_type &&
344 Tag != dwarf::DW_TAG_volatile_type && Tag != dwarf::DW_TAG_pointer_type &&
345 Tag != dwarf::DW_TAG_reference_type && Tag != dwarf::DW_TAG_restrict_type
346 && Tag != dwarf::DW_TAG_vector_type && Tag != dwarf::DW_TAG_array_type
347 && Tag != dwarf::DW_TAG_enumeration_type
348 && getFilename().empty())
353 /// Verify - Verify that a basic type descriptor is well formed.
354 bool DIBasicType::Verify() const {
355 return isBasicType();
358 /// Verify - Verify that a derived type descriptor is well formed.
359 bool DIDerivedType::Verify() const {
360 return isDerivedType();
363 /// Verify - Verify that a composite type descriptor is well formed.
364 bool DICompositeType::Verify() const {
367 if (!getContext().Verify())
370 DICompileUnit CU = getCompileUnit();
376 /// Verify - Verify that a subprogram descriptor is well formed.
377 bool DISubprogram::Verify() const {
381 if (!getContext().Verify())
384 DICompileUnit CU = getCompileUnit();
388 DICompositeType Ty = getType();
394 /// Verify - Verify that a global variable descriptor is well formed.
395 bool DIGlobalVariable::Verify() const {
399 if (getDisplayName().empty())
402 if (!getContext().Verify())
405 DICompileUnit CU = getCompileUnit();
409 DIType Ty = getType();
413 if (!getGlobal() && !getConstant())
419 /// Verify - Verify that a variable descriptor is well formed.
420 bool DIVariable::Verify() const {
424 if (!getContext().Verify())
427 if (!getCompileUnit().Verify())
430 DIType Ty = getType();
437 /// Verify - Verify that a location descriptor is well formed.
438 bool DILocation::Verify() const {
442 return DbgNode->getNumOperands() == 4;
445 /// Verify - Verify that a namespace descriptor is well formed.
446 bool DINameSpace::Verify() const {
449 if (getName().empty())
451 if (!getCompileUnit().Verify())
456 /// getOriginalTypeSize - If this type is derived from a base type then
457 /// return base type size.
458 uint64_t DIDerivedType::getOriginalTypeSize() const {
459 unsigned Tag = getTag();
460 if (Tag == dwarf::DW_TAG_member || Tag == dwarf::DW_TAG_typedef ||
461 Tag == dwarf::DW_TAG_const_type || Tag == dwarf::DW_TAG_volatile_type ||
462 Tag == dwarf::DW_TAG_restrict_type) {
463 DIType BaseType = getTypeDerivedFrom();
464 // If this type is not derived from any type then take conservative
466 if (!BaseType.isValid())
467 return getSizeInBits();
468 if (BaseType.isDerivedType())
469 return DIDerivedType(BaseType).getOriginalTypeSize();
471 return BaseType.getSizeInBits();
474 return getSizeInBits();
477 /// isInlinedFnArgument - Return true if this variable provides debugging
478 /// information for an inlined function arguments.
479 bool DIVariable::isInlinedFnArgument(const Function *CurFn) {
480 assert(CurFn && "Invalid function");
481 if (!getContext().isSubprogram())
483 // This variable is not inlined function argument if its scope
484 // does not describe current function.
485 return !(DISubprogram(getContext()).describes(CurFn));
488 /// describes - Return true if this subprogram provides debugging
489 /// information for the function F.
490 bool DISubprogram::describes(const Function *F) {
491 assert(F && "Invalid function");
492 if (F == getFunction())
494 StringRef Name = getLinkageName();
497 if (F->getName() == Name)
502 unsigned DISubprogram::isOptimized() const {
503 assert (DbgNode && "Invalid subprogram descriptor!");
504 if (DbgNode->getNumOperands() == 16)
505 return getUnsignedField(15);
509 StringRef DIScope::getFilename() const {
512 if (isLexicalBlock())
513 return DILexicalBlock(DbgNode).getFilename();
515 return DISubprogram(DbgNode).getFilename();
517 return DICompileUnit(DbgNode).getFilename();
519 return DINameSpace(DbgNode).getFilename();
521 return DIType(DbgNode).getFilename();
523 return DIFile(DbgNode).getFilename();
524 assert(0 && "Invalid DIScope!");
528 StringRef DIScope::getDirectory() const {
531 if (isLexicalBlock())
532 return DILexicalBlock(DbgNode).getDirectory();
534 return DISubprogram(DbgNode).getDirectory();
536 return DICompileUnit(DbgNode).getDirectory();
538 return DINameSpace(DbgNode).getDirectory();
540 return DIType(DbgNode).getDirectory();
542 return DIFile(DbgNode).getDirectory();
543 assert(0 && "Invalid DIScope!");
547 //===----------------------------------------------------------------------===//
548 // DIDescriptor: dump routines for all descriptors.
549 //===----------------------------------------------------------------------===//
552 /// print - Print descriptor.
553 void DIDescriptor::print(raw_ostream &OS) const {
554 OS << "[" << dwarf::TagString(getTag()) << "] ";
555 OS.write_hex((intptr_t) &*DbgNode) << ']';
558 /// print - Print compile unit.
559 void DICompileUnit::print(raw_ostream &OS) const {
561 OS << " [" << dwarf::LanguageString(getLanguage()) << "] ";
563 OS << " [" << getDirectory() << "/" << getFilename() << "]";
566 /// print - Print type.
567 void DIType::print(raw_ostream &OS) const {
568 if (!DbgNode) return;
570 StringRef Res = getName();
572 OS << " [" << Res << "] ";
574 unsigned Tag = getTag();
575 OS << " [" << dwarf::TagString(Tag) << "] ";
577 // TODO : Print context
578 getCompileUnit().print(OS);
580 << "line " << getLineNumber() << ", "
581 << getSizeInBits() << " bits, "
582 << getAlignInBits() << " bit alignment, "
583 << getOffsetInBits() << " bit offset"
588 else if (isProtected())
589 OS << " [protected] ";
595 DIBasicType(DbgNode).print(OS);
596 else if (isDerivedType())
597 DIDerivedType(DbgNode).print(OS);
598 else if (isCompositeType())
599 DICompositeType(DbgNode).print(OS);
601 OS << "Invalid DIType\n";
608 /// print - Print basic type.
609 void DIBasicType::print(raw_ostream &OS) const {
610 OS << " [" << dwarf::AttributeEncodingString(getEncoding()) << "] ";
613 /// print - Print derived type.
614 void DIDerivedType::print(raw_ostream &OS) const {
615 OS << "\n\t Derived From: "; getTypeDerivedFrom().print(OS);
618 /// print - Print composite type.
619 void DICompositeType::print(raw_ostream &OS) const {
620 DIArray A = getTypeArray();
621 OS << " [" << A.getNumElements() << " elements]";
624 /// print - Print subprogram.
625 void DISubprogram::print(raw_ostream &OS) const {
626 StringRef Res = getName();
628 OS << " [" << Res << "] ";
630 unsigned Tag = getTag();
631 OS << " [" << dwarf::TagString(Tag) << "] ";
633 // TODO : Print context
634 getCompileUnit().print(OS);
635 OS << " [" << getLineNumber() << "] ";
646 /// print - Print global variable.
647 void DIGlobalVariable::print(raw_ostream &OS) const {
649 StringRef Res = getName();
651 OS << " [" << Res << "] ";
653 unsigned Tag = getTag();
654 OS << " [" << dwarf::TagString(Tag) << "] ";
656 // TODO : Print context
657 getCompileUnit().print(OS);
658 OS << " [" << getLineNumber() << "] ";
666 if (isGlobalVariable())
667 DIGlobalVariable(DbgNode).print(OS);
671 /// print - Print variable.
672 void DIVariable::print(raw_ostream &OS) const {
673 StringRef Res = getName();
675 OS << " [" << Res << "] ";
677 getCompileUnit().print(OS);
678 OS << " [" << getLineNumber() << "] ";
682 // FIXME: Dump complex addresses
685 /// dump - Print descriptor to dbgs() with a newline.
686 void DIDescriptor::dump() const {
687 print(dbgs()); dbgs() << '\n';
690 /// dump - Print compile unit to dbgs() with a newline.
691 void DICompileUnit::dump() const {
692 print(dbgs()); dbgs() << '\n';
695 /// dump - Print type to dbgs() with a newline.
696 void DIType::dump() const {
697 print(dbgs()); dbgs() << '\n';
700 /// dump - Print basic type to dbgs() with a newline.
701 void DIBasicType::dump() const {
702 print(dbgs()); dbgs() << '\n';
705 /// dump - Print derived type to dbgs() with a newline.
706 void DIDerivedType::dump() const {
707 print(dbgs()); dbgs() << '\n';
710 /// dump - Print composite type to dbgs() with a newline.
711 void DICompositeType::dump() const {
712 print(dbgs()); dbgs() << '\n';
715 /// dump - Print subprogram to dbgs() with a newline.
716 void DISubprogram::dump() const {
717 print(dbgs()); dbgs() << '\n';
720 /// dump - Print global variable.
721 void DIGlobalVariable::dump() const {
722 print(dbgs()); dbgs() << '\n';
725 /// dump - Print variable.
726 void DIVariable::dump() const {
727 print(dbgs()); dbgs() << '\n';
730 /// fixupObjcLikeName - Replace contains special characters used
731 /// in a typical Objective-C names with '.' in a given string.
732 static void fixupObjcLikeName(StringRef Str, SmallVectorImpl<char> &Out) {
733 bool isObjCLike = false;
734 for (size_t i = 0, e = Str.size(); i < e; ++i) {
739 if (isObjCLike && (C == '[' || C == ']' || C == ' ' || C == ':' ||
740 C == '+' || C == '(' || C == ')'))
747 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
748 /// suitable to hold function specific information.
749 NamedMDNode *llvm::getFnSpecificMDNode(const Module &M, StringRef FuncName) {
750 SmallString<32> Name = StringRef("llvm.dbg.lv.");
751 fixupObjcLikeName(FuncName, Name);
753 return M.getNamedMetadata(Name.str());
756 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
757 /// to hold function specific information.
758 NamedMDNode *llvm::getOrInsertFnSpecificMDNode(Module &M, StringRef FuncName) {
759 SmallString<32> Name = StringRef("llvm.dbg.lv.");
760 fixupObjcLikeName(FuncName, Name);
762 return M.getOrInsertNamedMetadata(Name.str());
765 /// createInlinedVariable - Create a new inlined variable based on current
767 /// @param DV Current Variable.
768 /// @param InlinedScope Location at current variable is inlined.
769 DIVariable llvm::createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
770 LLVMContext &VMContext) {
771 SmallVector<Value *, 16> Elts;
772 // Insert inlined scope as 7th element.
773 for (unsigned i = 0, e = DV->getNumOperands(); i != e; ++i)
774 i == 7 ? Elts.push_back(InlinedScope) :
775 Elts.push_back(DV->getOperand(i));
776 return DIVariable(MDNode::get(VMContext, Elts));
779 //===----------------------------------------------------------------------===//
780 // DebugInfoFinder implementations.
781 //===----------------------------------------------------------------------===//
783 /// processModule - Process entire module and collect debug info.
784 void DebugInfoFinder::processModule(Module &M) {
785 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
786 for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
787 for (BasicBlock::iterator BI = (*FI).begin(), BE = (*FI).end(); BI != BE;
789 if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI))
792 DebugLoc Loc = BI->getDebugLoc();
796 LLVMContext &Ctx = BI->getContext();
797 DIDescriptor Scope(Loc.getScope(Ctx));
799 if (Scope.isCompileUnit())
800 addCompileUnit(DICompileUnit(Scope));
801 else if (Scope.isSubprogram())
802 processSubprogram(DISubprogram(Scope));
803 else if (Scope.isLexicalBlock())
804 processLexicalBlock(DILexicalBlock(Scope));
806 if (MDNode *IA = Loc.getInlinedAt(Ctx))
807 processLocation(DILocation(IA));
810 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv")) {
811 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
812 DIGlobalVariable DIG(cast<MDNode>(NMD->getOperand(i)));
813 if (addGlobalVariable(DIG)) {
814 addCompileUnit(DIG.getCompileUnit());
815 processType(DIG.getType());
820 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
821 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
822 processSubprogram(DISubprogram(NMD->getOperand(i)));
825 /// processLocation - Process DILocation.
826 void DebugInfoFinder::processLocation(DILocation Loc) {
827 if (!Loc.Verify()) return;
828 DIDescriptor S(Loc.getScope());
829 if (S.isCompileUnit())
830 addCompileUnit(DICompileUnit(S));
831 else if (S.isSubprogram())
832 processSubprogram(DISubprogram(S));
833 else if (S.isLexicalBlock())
834 processLexicalBlock(DILexicalBlock(S));
835 processLocation(Loc.getOrigLocation());
838 /// processType - Process DIType.
839 void DebugInfoFinder::processType(DIType DT) {
843 addCompileUnit(DT.getCompileUnit());
844 if (DT.isCompositeType()) {
845 DICompositeType DCT(DT);
846 processType(DCT.getTypeDerivedFrom());
847 DIArray DA = DCT.getTypeArray();
848 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
849 DIDescriptor D = DA.getElement(i);
851 processType(DIType(D));
852 else if (D.isSubprogram())
853 processSubprogram(DISubprogram(D));
855 } else if (DT.isDerivedType()) {
856 DIDerivedType DDT(DT);
857 processType(DDT.getTypeDerivedFrom());
861 /// processLexicalBlock
862 void DebugInfoFinder::processLexicalBlock(DILexicalBlock LB) {
863 DIScope Context = LB.getContext();
864 if (Context.isLexicalBlock())
865 return processLexicalBlock(DILexicalBlock(Context));
867 return processSubprogram(DISubprogram(Context));
870 /// processSubprogram - Process DISubprogram.
871 void DebugInfoFinder::processSubprogram(DISubprogram SP) {
872 if (!addSubprogram(SP))
874 addCompileUnit(SP.getCompileUnit());
875 processType(SP.getType());
878 /// processDeclare - Process DbgDeclareInst.
879 void DebugInfoFinder::processDeclare(DbgDeclareInst *DDI) {
880 MDNode *N = dyn_cast<MDNode>(DDI->getVariable());
884 if (!DV.isVariable())
887 if (!NodesSeen.insert(DV))
890 addCompileUnit(DIVariable(N).getCompileUnit());
891 processType(DIVariable(N).getType());
894 /// addType - Add type into Tys.
895 bool DebugInfoFinder::addType(DIType DT) {
899 if (!NodesSeen.insert(DT))
906 /// addCompileUnit - Add compile unit into CUs.
907 bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) {
911 if (!NodesSeen.insert(CU))
918 /// addGlobalVariable - Add global variable into GVs.
919 bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) {
920 if (!DIDescriptor(DIG).isGlobalVariable())
923 if (!NodesSeen.insert(DIG))
930 // addSubprogram - Add subprgoram into SPs.
931 bool DebugInfoFinder::addSubprogram(DISubprogram SP) {
932 if (!DIDescriptor(SP).isSubprogram())
935 if (!NodesSeen.insert(SP))
942 /// getDISubprogram - Find subprogram that is enclosing this scope.
943 DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
944 DIDescriptor D(Scope);
945 if (D.isSubprogram())
946 return DISubprogram(Scope);
948 if (D.isLexicalBlock())
949 return getDISubprogram(DILexicalBlock(Scope).getContext());
951 return DISubprogram();
954 /// getDICompositeType - Find underlying composite type.
955 DICompositeType llvm::getDICompositeType(DIType T) {
956 if (T.isCompositeType())
957 return DICompositeType(T);
959 if (T.isDerivedType())
960 return getDICompositeType(DIDerivedType(T).getTypeDerivedFrom());
962 return DICompositeType();