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 return DbgNode
->getNumOperands()-7;
118 //===----------------------------------------------------------------------===//
120 //===----------------------------------------------------------------------===//
122 /// isBasicType - Return true if the specified tag is legal for
124 bool DIDescriptor::isBasicType() const {
125 return DbgNode
&& getTag() == dwarf::DW_TAG_base_type
;
128 /// isDerivedType - Return true if the specified tag is legal for DIDerivedType.
129 bool DIDescriptor::isDerivedType() const {
130 if (!DbgNode
) return false;
132 case dwarf::DW_TAG_typedef
:
133 case dwarf::DW_TAG_pointer_type
:
134 case dwarf::DW_TAG_reference_type
:
135 case dwarf::DW_TAG_const_type
:
136 case dwarf::DW_TAG_volatile_type
:
137 case dwarf::DW_TAG_restrict_type
:
138 case dwarf::DW_TAG_member
:
139 case dwarf::DW_TAG_inheritance
:
140 case dwarf::DW_TAG_friend
:
143 // CompositeTypes are currently modelled as DerivedTypes.
144 return isCompositeType();
148 /// isCompositeType - Return true if the specified tag is legal for
150 bool DIDescriptor::isCompositeType() const {
151 if (!DbgNode
) return false;
153 case dwarf::DW_TAG_array_type
:
154 case dwarf::DW_TAG_structure_type
:
155 case dwarf::DW_TAG_union_type
:
156 case dwarf::DW_TAG_enumeration_type
:
157 case dwarf::DW_TAG_vector_type
:
158 case dwarf::DW_TAG_subroutine_type
:
159 case dwarf::DW_TAG_class_type
:
166 /// isVariable - Return true if the specified tag is legal for DIVariable.
167 bool DIDescriptor::isVariable() const {
168 if (!DbgNode
) return false;
170 case dwarf::DW_TAG_auto_variable
:
171 case dwarf::DW_TAG_arg_variable
:
172 case dwarf::DW_TAG_return_variable
:
179 /// isType - Return true if the specified tag is legal for DIType.
180 bool DIDescriptor::isType() const {
181 return isBasicType() || isCompositeType() || isDerivedType();
184 /// isSubprogram - Return true if the specified tag is legal for
186 bool DIDescriptor::isSubprogram() const {
187 return DbgNode
&& getTag() == dwarf::DW_TAG_subprogram
;
190 /// isGlobalVariable - Return true if the specified tag is legal for
191 /// DIGlobalVariable.
192 bool DIDescriptor::isGlobalVariable() const {
193 return DbgNode
&& (getTag() == dwarf::DW_TAG_variable
||
194 getTag() == dwarf::DW_TAG_constant
);
197 /// isGlobal - Return true if the specified tag is legal for DIGlobal.
198 bool DIDescriptor::isGlobal() const {
199 return isGlobalVariable();
202 /// isUnspecifiedParmeter - Return true if the specified tag is
203 /// DW_TAG_unspecified_parameters.
204 bool DIDescriptor::isUnspecifiedParameter() const {
205 return DbgNode
&& getTag() == dwarf::DW_TAG_unspecified_parameters
;
208 /// isScope - Return true if the specified tag is one of the scope
210 bool DIDescriptor::isScope() const {
211 if (!DbgNode
) return false;
213 case dwarf::DW_TAG_compile_unit
:
214 case dwarf::DW_TAG_lexical_block
:
215 case dwarf::DW_TAG_subprogram
:
216 case dwarf::DW_TAG_namespace
:
224 /// isTemplateTypeParameter - Return true if the specified tag is
225 /// DW_TAG_template_type_parameter.
226 bool DIDescriptor::isTemplateTypeParameter() const {
227 return DbgNode
&& getTag() == dwarf::DW_TAG_template_type_parameter
;
230 /// isTemplateValueParameter - Return true if the specified tag is
231 /// DW_TAG_template_value_parameter.
232 bool DIDescriptor::isTemplateValueParameter() const {
233 return DbgNode
&& getTag() == dwarf::DW_TAG_template_value_parameter
;
236 /// isCompileUnit - Return true if the specified tag is DW_TAG_compile_unit.
237 bool DIDescriptor::isCompileUnit() const {
238 return DbgNode
&& getTag() == dwarf::DW_TAG_compile_unit
;
241 /// isFile - Return true if the specified tag is DW_TAG_file_type.
242 bool DIDescriptor::isFile() const {
243 return DbgNode
&& getTag() == dwarf::DW_TAG_file_type
;
246 /// isNameSpace - Return true if the specified tag is DW_TAG_namespace.
247 bool DIDescriptor::isNameSpace() const {
248 return DbgNode
&& getTag() == dwarf::DW_TAG_namespace
;
251 /// isLexicalBlock - Return true if the specified tag is DW_TAG_lexical_block.
252 bool DIDescriptor::isLexicalBlock() const {
253 return DbgNode
&& getTag() == dwarf::DW_TAG_lexical_block
;
256 /// isSubrange - Return true if the specified tag is DW_TAG_subrange_type.
257 bool DIDescriptor::isSubrange() const {
258 return DbgNode
&& getTag() == dwarf::DW_TAG_subrange_type
;
261 /// isEnumerator - Return true if the specified tag is DW_TAG_enumerator.
262 bool DIDescriptor::isEnumerator() const {
263 return DbgNode
&& getTag() == dwarf::DW_TAG_enumerator
;
266 //===----------------------------------------------------------------------===//
267 // Simple Descriptor Constructors and other Methods
268 //===----------------------------------------------------------------------===//
270 DIType::DIType(const MDNode
*N
) : DIScope(N
) {
272 if (!isBasicType() && !isDerivedType() && !isCompositeType()) {
277 unsigned DIArray::getNumElements() const {
280 return DbgNode
->getNumOperands();
283 /// replaceAllUsesWith - Replace all uses of debug info referenced by
285 void DIType::replaceAllUsesWith(DIDescriptor
&D
) {
289 // Since we use a TrackingVH for the node, its easy for clients to manufacture
290 // legitimate situations where they want to replaceAllUsesWith() on something
291 // which, due to uniquing, has merged with the source. We shield clients from
292 // this detail by allowing a value to be replaced with replaceAllUsesWith()
295 MDNode
*Node
= const_cast<MDNode
*>(DbgNode
);
296 const MDNode
*DN
= D
;
297 const Value
*V
= cast_or_null
<Value
>(DN
);
298 Node
->replaceAllUsesWith(const_cast<Value
*>(V
));
299 MDNode::deleteTemporary(Node
);
303 /// replaceAllUsesWith - Replace all uses of debug info referenced by
305 void DIType::replaceAllUsesWith(MDNode
*D
) {
309 // Since we use a TrackingVH for the node, its easy for clients to manufacture
310 // legitimate situations where they want to replaceAllUsesWith() on something
311 // which, due to uniquing, has merged with the source. We shield clients from
312 // this detail by allowing a value to be replaced with replaceAllUsesWith()
315 MDNode
*Node
= const_cast<MDNode
*>(DbgNode
);
316 const MDNode
*DN
= D
;
317 const Value
*V
= cast_or_null
<Value
>(DN
);
318 Node
->replaceAllUsesWith(const_cast<Value
*>(V
));
319 MDNode::deleteTemporary(Node
);
323 /// Verify - Verify that a compile unit is well formed.
324 bool DICompileUnit::Verify() const {
327 StringRef N
= getFilename();
330 // It is possible that directory and produce string is empty.
334 /// Verify - Verify that a type descriptor is well formed.
335 bool DIType::Verify() const {
338 if (!getContext().Verify())
340 unsigned Tag
= getTag();
341 if (!isBasicType() && Tag
!= dwarf::DW_TAG_const_type
&&
342 Tag
!= dwarf::DW_TAG_volatile_type
&& Tag
!= dwarf::DW_TAG_pointer_type
&&
343 Tag
!= dwarf::DW_TAG_reference_type
&& Tag
!= dwarf::DW_TAG_restrict_type
344 && Tag
!= dwarf::DW_TAG_vector_type
&& Tag
!= dwarf::DW_TAG_array_type
345 && Tag
!= dwarf::DW_TAG_enumeration_type
346 && getFilename().empty())
351 /// Verify - Verify that a basic type descriptor is well formed.
352 bool DIBasicType::Verify() const {
353 return isBasicType();
356 /// Verify - Verify that a derived type descriptor is well formed.
357 bool DIDerivedType::Verify() const {
358 return isDerivedType();
361 /// Verify - Verify that a composite type descriptor is well formed.
362 bool DICompositeType::Verify() const {
365 if (!getContext().Verify())
368 DICompileUnit CU
= getCompileUnit();
374 /// Verify - Verify that a subprogram descriptor is well formed.
375 bool DISubprogram::Verify() const {
379 if (!getContext().Verify())
382 DICompileUnit CU
= getCompileUnit();
386 DICompositeType Ty
= getType();
392 /// Verify - Verify that a global variable descriptor is well formed.
393 bool DIGlobalVariable::Verify() const {
397 if (getDisplayName().empty())
400 if (!getContext().Verify())
403 DICompileUnit CU
= getCompileUnit();
407 DIType Ty
= getType();
411 if (!getGlobal() && !getConstant())
417 /// Verify - Verify that a variable descriptor is well formed.
418 bool DIVariable::Verify() const {
422 if (!getContext().Verify())
425 if (!getCompileUnit().Verify())
428 DIType Ty
= getType();
435 /// Verify - Verify that a location descriptor is well formed.
436 bool DILocation::Verify() const {
440 return DbgNode
->getNumOperands() == 4;
443 /// Verify - Verify that a namespace descriptor is well formed.
444 bool DINameSpace::Verify() const {
447 if (getName().empty())
449 if (!getCompileUnit().Verify())
454 /// getOriginalTypeSize - If this type is derived from a base type then
455 /// return base type size.
456 uint64_t DIDerivedType::getOriginalTypeSize() const {
457 unsigned Tag
= getTag();
458 if (Tag
== dwarf::DW_TAG_member
|| Tag
== dwarf::DW_TAG_typedef
||
459 Tag
== dwarf::DW_TAG_const_type
|| Tag
== dwarf::DW_TAG_volatile_type
||
460 Tag
== dwarf::DW_TAG_restrict_type
) {
461 DIType BaseType
= getTypeDerivedFrom();
462 // If this type is not derived from any type then take conservative
464 if (!BaseType
.isValid())
465 return getSizeInBits();
466 if (BaseType
.isDerivedType())
467 return DIDerivedType(BaseType
).getOriginalTypeSize();
469 return BaseType
.getSizeInBits();
472 return getSizeInBits();
475 /// isInlinedFnArgument - Return true if this variable provides debugging
476 /// information for an inlined function arguments.
477 bool DIVariable::isInlinedFnArgument(const Function
*CurFn
) {
478 assert(CurFn
&& "Invalid function");
479 if (!getContext().isSubprogram())
481 // This variable is not inlined function argument if its scope
482 // does not describe current function.
483 return !(DISubprogram(getContext()).describes(CurFn
));
486 /// describes - Return true if this subprogram provides debugging
487 /// information for the function F.
488 bool DISubprogram::describes(const Function
*F
) {
489 assert(F
&& "Invalid function");
490 if (F
== getFunction())
492 StringRef Name
= getLinkageName();
495 if (F
->getName() == Name
)
500 unsigned DISubprogram::isOptimized() const {
501 assert (DbgNode
&& "Invalid subprogram descriptor!");
502 if (DbgNode
->getNumOperands() == 16)
503 return getUnsignedField(15);
507 StringRef
DIScope::getFilename() const {
510 if (isLexicalBlock())
511 return DILexicalBlock(DbgNode
).getFilename();
513 return DISubprogram(DbgNode
).getFilename();
515 return DICompileUnit(DbgNode
).getFilename();
517 return DINameSpace(DbgNode
).getFilename();
519 return DIType(DbgNode
).getFilename();
521 return DIFile(DbgNode
).getFilename();
522 assert(0 && "Invalid DIScope!");
526 StringRef
DIScope::getDirectory() const {
529 if (isLexicalBlock())
530 return DILexicalBlock(DbgNode
).getDirectory();
532 return DISubprogram(DbgNode
).getDirectory();
534 return DICompileUnit(DbgNode
).getDirectory();
536 return DINameSpace(DbgNode
).getDirectory();
538 return DIType(DbgNode
).getDirectory();
540 return DIFile(DbgNode
).getDirectory();
541 assert(0 && "Invalid DIScope!");
545 //===----------------------------------------------------------------------===//
546 // DIDescriptor: dump routines for all descriptors.
547 //===----------------------------------------------------------------------===//
550 /// print - Print descriptor.
551 void DIDescriptor::print(raw_ostream
&OS
) const {
552 OS
<< "[" << dwarf::TagString(getTag()) << "] ";
553 OS
.write_hex((intptr_t) &*DbgNode
) << ']';
556 /// print - Print compile unit.
557 void DICompileUnit::print(raw_ostream
&OS
) const {
559 OS
<< " [" << dwarf::LanguageString(getLanguage()) << "] ";
561 OS
<< " [" << getDirectory() << "/" << getFilename() << "]";
564 /// print - Print type.
565 void DIType::print(raw_ostream
&OS
) const {
566 if (!DbgNode
) return;
568 StringRef Res
= getName();
570 OS
<< " [" << Res
<< "] ";
572 unsigned Tag
= getTag();
573 OS
<< " [" << dwarf::TagString(Tag
) << "] ";
575 // TODO : Print context
576 getCompileUnit().print(OS
);
578 << "line " << getLineNumber() << ", "
579 << getSizeInBits() << " bits, "
580 << getAlignInBits() << " bit alignment, "
581 << getOffsetInBits() << " bit offset"
586 else if (isProtected())
587 OS
<< " [protected] ";
593 DIBasicType(DbgNode
).print(OS
);
594 else if (isDerivedType())
595 DIDerivedType(DbgNode
).print(OS
);
596 else if (isCompositeType())
597 DICompositeType(DbgNode
).print(OS
);
599 OS
<< "Invalid DIType\n";
606 /// print - Print basic type.
607 void DIBasicType::print(raw_ostream
&OS
) const {
608 OS
<< " [" << dwarf::AttributeEncodingString(getEncoding()) << "] ";
611 /// print - Print derived type.
612 void DIDerivedType::print(raw_ostream
&OS
) const {
613 OS
<< "\n\t Derived From: "; getTypeDerivedFrom().print(OS
);
616 /// print - Print composite type.
617 void DICompositeType::print(raw_ostream
&OS
) const {
618 DIArray A
= getTypeArray();
619 OS
<< " [" << A
.getNumElements() << " elements]";
622 /// print - Print subprogram.
623 void DISubprogram::print(raw_ostream
&OS
) const {
624 StringRef Res
= getName();
626 OS
<< " [" << Res
<< "] ";
628 unsigned Tag
= getTag();
629 OS
<< " [" << dwarf::TagString(Tag
) << "] ";
631 // TODO : Print context
632 getCompileUnit().print(OS
);
633 OS
<< " [" << getLineNumber() << "] ";
644 /// print - Print global variable.
645 void DIGlobalVariable::print(raw_ostream
&OS
) const {
647 StringRef Res
= getName();
649 OS
<< " [" << Res
<< "] ";
651 unsigned Tag
= getTag();
652 OS
<< " [" << dwarf::TagString(Tag
) << "] ";
654 // TODO : Print context
655 getCompileUnit().print(OS
);
656 OS
<< " [" << getLineNumber() << "] ";
664 if (isGlobalVariable())
665 DIGlobalVariable(DbgNode
).print(OS
);
669 /// print - Print variable.
670 void DIVariable::print(raw_ostream
&OS
) const {
671 StringRef Res
= getName();
673 OS
<< " [" << Res
<< "] ";
675 getCompileUnit().print(OS
);
676 OS
<< " [" << getLineNumber() << "] ";
680 // FIXME: Dump complex addresses
683 /// dump - Print descriptor to dbgs() with a newline.
684 void DIDescriptor::dump() const {
685 print(dbgs()); dbgs() << '\n';
688 /// dump - Print compile unit to dbgs() with a newline.
689 void DICompileUnit::dump() const {
690 print(dbgs()); dbgs() << '\n';
693 /// dump - Print type to dbgs() with a newline.
694 void DIType::dump() const {
695 print(dbgs()); dbgs() << '\n';
698 /// dump - Print basic type to dbgs() with a newline.
699 void DIBasicType::dump() const {
700 print(dbgs()); dbgs() << '\n';
703 /// dump - Print derived type to dbgs() with a newline.
704 void DIDerivedType::dump() const {
705 print(dbgs()); dbgs() << '\n';
708 /// dump - Print composite type to dbgs() with a newline.
709 void DICompositeType::dump() const {
710 print(dbgs()); dbgs() << '\n';
713 /// dump - Print subprogram to dbgs() with a newline.
714 void DISubprogram::dump() const {
715 print(dbgs()); dbgs() << '\n';
718 /// dump - Print global variable.
719 void DIGlobalVariable::dump() const {
720 print(dbgs()); dbgs() << '\n';
723 /// dump - Print variable.
724 void DIVariable::dump() const {
725 print(dbgs()); dbgs() << '\n';
728 /// fixupObjcLikeName - Replace contains special characters used
729 /// in a typical Objective-C names with '.' in a given string.
730 static void fixupObjcLikeName(std::string
&Str
) {
731 for (size_t i
= 0, e
= Str
.size(); i
< e
; ++i
) {
733 if (C
== '[' || C
== ']' || C
== ' ' || C
== ':' || C
== '+' ||
734 C
== '(' || C
== ')')
739 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
740 /// suitable to hold function specific information.
741 NamedMDNode
*llvm::getFnSpecificMDNode(const Module
&M
, StringRef FuncName
) {
742 if (FuncName
.find('[') == StringRef::npos
)
743 return M
.getNamedMetadata(Twine("llvm.dbg.lv.", FuncName
));
744 std::string Name
= FuncName
;
745 fixupObjcLikeName(Name
);
746 return M
.getNamedMetadata(Twine("llvm.dbg.lv.", Name
));
749 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
750 /// to hold function specific information.
751 NamedMDNode
*llvm::getOrInsertFnSpecificMDNode(Module
&M
, StringRef FuncName
) {
753 if (FuncName
.find('[') == StringRef::npos
)
754 return M
.getOrInsertNamedMetadata(Twine("llvm.dbg.lv.", FuncName
)
757 std::string Name
= FuncName
;
758 fixupObjcLikeName(Name
);
759 return M
.getOrInsertNamedMetadata(Twine("llvm.dbg.lv.", Name
)
764 //===----------------------------------------------------------------------===//
765 // DebugInfoFinder implementations.
766 //===----------------------------------------------------------------------===//
768 /// processModule - Process entire module and collect debug info.
769 void DebugInfoFinder::processModule(Module
&M
) {
770 for (Module::iterator I
= M
.begin(), E
= M
.end(); I
!= E
; ++I
)
771 for (Function::iterator FI
= (*I
).begin(), FE
= (*I
).end(); FI
!= FE
; ++FI
)
772 for (BasicBlock::iterator BI
= (*FI
).begin(), BE
= (*FI
).end(); BI
!= BE
;
774 if (DbgDeclareInst
*DDI
= dyn_cast
<DbgDeclareInst
>(BI
))
777 DebugLoc Loc
= BI
->getDebugLoc();
781 LLVMContext
&Ctx
= BI
->getContext();
782 DIDescriptor
Scope(Loc
.getScope(Ctx
));
784 if (Scope
.isCompileUnit())
785 addCompileUnit(DICompileUnit(Scope
));
786 else if (Scope
.isSubprogram())
787 processSubprogram(DISubprogram(Scope
));
788 else if (Scope
.isLexicalBlock())
789 processLexicalBlock(DILexicalBlock(Scope
));
791 if (MDNode
*IA
= Loc
.getInlinedAt(Ctx
))
792 processLocation(DILocation(IA
));
795 if (NamedMDNode
*NMD
= M
.getNamedMetadata("llvm.dbg.gv")) {
796 for (unsigned i
= 0, e
= NMD
->getNumOperands(); i
!= e
; ++i
) {
797 DIGlobalVariable
DIG(cast
<MDNode
>(NMD
->getOperand(i
)));
798 if (addGlobalVariable(DIG
)) {
799 addCompileUnit(DIG
.getCompileUnit());
800 processType(DIG
.getType());
805 if (NamedMDNode
*NMD
= M
.getNamedMetadata("llvm.dbg.sp"))
806 for (unsigned i
= 0, e
= NMD
->getNumOperands(); i
!= e
; ++i
)
807 processSubprogram(DISubprogram(NMD
->getOperand(i
)));
810 /// processLocation - Process DILocation.
811 void DebugInfoFinder::processLocation(DILocation Loc
) {
812 if (!Loc
.Verify()) return;
813 DIDescriptor
S(Loc
.getScope());
814 if (S
.isCompileUnit())
815 addCompileUnit(DICompileUnit(S
));
816 else if (S
.isSubprogram())
817 processSubprogram(DISubprogram(S
));
818 else if (S
.isLexicalBlock())
819 processLexicalBlock(DILexicalBlock(S
));
820 processLocation(Loc
.getOrigLocation());
823 /// processType - Process DIType.
824 void DebugInfoFinder::processType(DIType DT
) {
828 addCompileUnit(DT
.getCompileUnit());
829 if (DT
.isCompositeType()) {
830 DICompositeType
DCT(DT
);
831 processType(DCT
.getTypeDerivedFrom());
832 DIArray DA
= DCT
.getTypeArray();
833 for (unsigned i
= 0, e
= DA
.getNumElements(); i
!= e
; ++i
) {
834 DIDescriptor D
= DA
.getElement(i
);
836 processType(DIType(D
));
837 else if (D
.isSubprogram())
838 processSubprogram(DISubprogram(D
));
840 } else if (DT
.isDerivedType()) {
841 DIDerivedType
DDT(DT
);
842 processType(DDT
.getTypeDerivedFrom());
846 /// processLexicalBlock
847 void DebugInfoFinder::processLexicalBlock(DILexicalBlock LB
) {
848 DIScope Context
= LB
.getContext();
849 if (Context
.isLexicalBlock())
850 return processLexicalBlock(DILexicalBlock(Context
));
852 return processSubprogram(DISubprogram(Context
));
855 /// processSubprogram - Process DISubprogram.
856 void DebugInfoFinder::processSubprogram(DISubprogram SP
) {
857 if (!addSubprogram(SP
))
859 addCompileUnit(SP
.getCompileUnit());
860 processType(SP
.getType());
863 /// processDeclare - Process DbgDeclareInst.
864 void DebugInfoFinder::processDeclare(DbgDeclareInst
*DDI
) {
865 MDNode
*N
= dyn_cast
<MDNode
>(DDI
->getVariable());
869 if (!DV
.isVariable())
872 if (!NodesSeen
.insert(DV
))
875 addCompileUnit(DIVariable(N
).getCompileUnit());
876 processType(DIVariable(N
).getType());
879 /// addType - Add type into Tys.
880 bool DebugInfoFinder::addType(DIType DT
) {
884 if (!NodesSeen
.insert(DT
))
891 /// addCompileUnit - Add compile unit into CUs.
892 bool DebugInfoFinder::addCompileUnit(DICompileUnit CU
) {
896 if (!NodesSeen
.insert(CU
))
903 /// addGlobalVariable - Add global variable into GVs.
904 bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG
) {
905 if (!DIDescriptor(DIG
).isGlobalVariable())
908 if (!NodesSeen
.insert(DIG
))
915 // addSubprogram - Add subprgoram into SPs.
916 bool DebugInfoFinder::addSubprogram(DISubprogram SP
) {
917 if (!DIDescriptor(SP
).isSubprogram())
920 if (!NodesSeen
.insert(SP
))
927 /// getDISubprogram - Find subprogram that is enclosing this scope.
928 DISubprogram
llvm::getDISubprogram(const MDNode
*Scope
) {
929 DIDescriptor
D(Scope
);
930 if (D
.isSubprogram())
931 return DISubprogram(Scope
);
933 if (D
.isLexicalBlock())
934 return getDISubprogram(DILexicalBlock(Scope
).getContext());
936 return DISubprogram();
939 /// getDICompositeType - Find underlying composite type.
940 DICompositeType
llvm::getDICompositeType(DIType T
) {
941 if (T
.isCompositeType())
942 return DICompositeType(T
);
944 if (T
.isDerivedType())
945 return getDICompositeType(DIDerivedType(T
).getTypeDerivedFrom());
947 return DICompositeType();