diff options
author | Devang Patel <dpatel@apple.com> | 2010-03-08 19:20:38 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2010-03-08 19:20:38 +0000 |
commit | 0ef3fa6aabc80995c8a0bd829c85c89ef2d4c32d (patch) | |
tree | ac2bdb8ae1dae16aa3bf10c28e20c5a0ff80a1f9 /lib/Analysis/DebugInfo.cpp | |
parent | dd6fbd11368b9d9ae82f8620a4aa7af9b8baf47c (diff) |
Revert r97947.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97963 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/DebugInfo.cpp')
-rw-r--r-- | lib/Analysis/DebugInfo.cpp | 145 |
1 files changed, 81 insertions, 64 deletions
diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index 98082ffb18..5cfe666b15 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -132,12 +132,13 @@ unsigned DIVariable::getNumAddrElements() const { /// isBasicType - Return true if the specified tag is legal for /// DIBasicType. bool DIDescriptor::isBasicType() const { - return DbgNode && getTag() == dwarf::DW_TAG_base_type; + assert(!isNull() && "Invalid descriptor!"); + return getTag() == dwarf::DW_TAG_base_type; } /// isDerivedType - Return true if the specified tag is legal for DIDerivedType. bool DIDescriptor::isDerivedType() const { - if (!DbgNode) return false; + assert(!isNull() && "Invalid descriptor!"); switch (getTag()) { case dwarf::DW_TAG_typedef: case dwarf::DW_TAG_pointer_type: @@ -157,7 +158,7 @@ bool DIDescriptor::isDerivedType() const { /// isCompositeType - Return true if the specified tag is legal for /// DICompositeType. bool DIDescriptor::isCompositeType() const { - if (!DbgNode) return false; + assert(!isNull() && "Invalid descriptor!"); switch (getTag()) { case dwarf::DW_TAG_array_type: case dwarf::DW_TAG_structure_type: @@ -174,7 +175,7 @@ bool DIDescriptor::isCompositeType() const { /// isVariable - Return true if the specified tag is legal for DIVariable. bool DIDescriptor::isVariable() const { - if (!DbgNode) return false; + assert(!isNull() && "Invalid descriptor!"); switch (getTag()) { case dwarf::DW_TAG_auto_variable: case dwarf::DW_TAG_arg_variable: @@ -193,13 +194,15 @@ bool DIDescriptor::isType() const { /// isSubprogram - Return true if the specified tag is legal for /// DISubprogram. bool DIDescriptor::isSubprogram() const { - return DbgNode && getTag() == dwarf::DW_TAG_subprogram; + assert(!isNull() && "Invalid descriptor!"); + return getTag() == dwarf::DW_TAG_subprogram; } /// isGlobalVariable - Return true if the specified tag is legal for /// DIGlobalVariable. bool DIDescriptor::isGlobalVariable() const { - return DbgNode && getTag() == dwarf::DW_TAG_variable; + assert(!isNull() && "Invalid descriptor!"); + return getTag() == dwarf::DW_TAG_variable; } /// isGlobal - Return true if the specified tag is legal for DIGlobal. @@ -210,7 +213,7 @@ bool DIDescriptor::isGlobal() const { /// isScope - Return true if the specified tag is one of the scope /// related tag. bool DIDescriptor::isScope() const { - if (!DbgNode) return false; + assert(!isNull() && "Invalid descriptor!"); switch (getTag()) { case dwarf::DW_TAG_compile_unit: case dwarf::DW_TAG_lexical_block: @@ -225,27 +228,32 @@ bool DIDescriptor::isScope() const { /// isCompileUnit - Return true if the specified tag is DW_TAG_compile_unit. bool DIDescriptor::isCompileUnit() const { - return DbgNode && getTag() == dwarf::DW_TAG_compile_unit; + assert(!isNull() && "Invalid descriptor!"); + return getTag() == dwarf::DW_TAG_compile_unit; } /// isNameSpace - Return true if the specified tag is DW_TAG_namespace. bool DIDescriptor::isNameSpace() const { - return DbgNode && getTag() == dwarf::DW_TAG_namespace; + assert(!isNull() && "Invalid descriptor!"); + return getTag() == dwarf::DW_TAG_namespace; } /// isLexicalBlock - Return true if the specified tag is DW_TAG_lexical_block. bool DIDescriptor::isLexicalBlock() const { - return DbgNode && getTag() == dwarf::DW_TAG_lexical_block; + assert(!isNull() && "Invalid descriptor!"); + return getTag() == dwarf::DW_TAG_lexical_block; } /// isSubrange - Return true if the specified tag is DW_TAG_subrange_type. bool DIDescriptor::isSubrange() const { - return DbgNode && getTag() == dwarf::DW_TAG_subrange_type; + assert(!isNull() && "Invalid descriptor!"); + return getTag() == dwarf::DW_TAG_subrange_type; } /// isEnumerator - Return true if the specified tag is DW_TAG_enumerator. bool DIDescriptor::isEnumerator() const { - return DbgNode && getTag() == dwarf::DW_TAG_enumerator; + assert(!isNull() && "Invalid descriptor!"); + return getTag() == dwarf::DW_TAG_enumerator; } //===----------------------------------------------------------------------===// @@ -260,8 +268,7 @@ DIType::DIType(MDNode *N) : DIDescriptor(N) { } unsigned DIArray::getNumElements() const { - if (!DbgNode) - return 0; + assert(DbgNode && "Invalid DIArray"); return DbgNode->getNumOperands(); } @@ -269,9 +276,11 @@ unsigned DIArray::getNumElements() const { /// this descriptor. After this completes, the current debug info value /// is erased. void DIDerivedType::replaceAllUsesWith(DIDescriptor &D) { - if (!DbgNode) + if (isNull()) return; + assert(!D.isNull() && "Can not replace with null"); + // Since we use a TrackingVH for the node, its easy for clients to manufacture // legitimate situations where they want to replaceAllUsesWith() on something // which, due to uniquing, has merged with the source. We shield clients from @@ -286,7 +295,7 @@ void DIDerivedType::replaceAllUsesWith(DIDescriptor &D) { /// Verify - Verify that a compile unit is well formed. bool DICompileUnit::Verify() const { - if (!DbgNode) + if (isNull()) return false; StringRef N = getFilename(); if (N.empty()) @@ -297,36 +306,36 @@ bool DICompileUnit::Verify() const { /// Verify - Verify that a type descriptor is well formed. bool DIType::Verify() const { - if (!DbgNode) + if (isNull()) return false; - if (!getContext().Verify()) + if (getContext().isNull()) return false; DICompileUnit CU = getCompileUnit(); - if (!CU.Verify()) + if (!CU.isNull() && !CU.Verify()) return false; return true; } /// Verify - Verify that a composite type descriptor is well formed. bool DICompositeType::Verify() const { - if (!DbgNode) + if (isNull()) return false; - if (!getContext().Verify()) + if (getContext().isNull()) return false; DICompileUnit CU = getCompileUnit(); - if (!CU.Verify()) + if (!CU.isNull() && !CU.Verify()) return false; return true; } /// Verify - Verify that a subprogram descriptor is well formed. bool DISubprogram::Verify() const { - if (!DbgNode) + if (isNull()) return false; - if (!getContext().Verify()) + if (getContext().isNull()) return false; DICompileUnit CU = getCompileUnit(); @@ -334,24 +343,24 @@ bool DISubprogram::Verify() const { return false; DICompositeType Ty = getType(); - if (!Ty.Verify()) + if (!Ty.isNull() && !Ty.Verify()) return false; return true; } /// Verify - Verify that a global variable descriptor is well formed. bool DIGlobalVariable::Verify() const { - if (!DbgNode) + if (isNull()) return false; if (getDisplayName().empty()) return false; - if (!getContext().Verify()) + if (getContext().isNull()) return false; DICompileUnit CU = getCompileUnit(); - if (!CU.Verify()) + if (!CU.isNull() && !CU.Verify()) return false; DIType Ty = getType(); @@ -366,10 +375,10 @@ bool DIGlobalVariable::Verify() const { /// Verify - Verify that a variable descriptor is well formed. bool DIVariable::Verify() const { - if (!DbgNode) + if (isNull()) return false; - if (!getContext().Verify()) + if (getContext().isNull()) return false; DIType Ty = getType(); @@ -379,14 +388,6 @@ bool DIVariable::Verify() const { return true; } -/// Verify - Verify that a location descriptor is well formed. -bool DILocation::Verify() const { - if (!DbgNode) - return false; - - return DbgNode->getNumOperands() == 4; -} - /// getOriginalTypeSize - If this type is derived from a base type then /// return base type size. uint64_t DIDerivedType::getOriginalTypeSize() const { @@ -397,7 +398,7 @@ uint64_t DIDerivedType::getOriginalTypeSize() const { DIType BaseType = getTypeDerivedFrom(); // If this type is not derived from any type then take conservative // approach. - if (!BaseType.isValid()) + if (BaseType.isNull()) return getSizeInBits(); if (BaseType.isDerivedType()) return DIDerivedType(BaseType.getNode()).getOriginalTypeSize(); @@ -467,7 +468,7 @@ void DICompileUnit::dump() const { /// dump - Print type. void DIType::dump() const { - if (!DbgNode) return; + if (isNull()) return; StringRef Res = getName(); if (!Res.empty()) @@ -520,6 +521,8 @@ void DIDerivedType::dump() const { /// dump - Print composite type. void DICompositeType::dump() const { DIArray A = getTypeArray(); + if (A.isNull()) + return; dbgs() << " [" << A.getNumElements() << " elements]"; } @@ -1152,8 +1155,9 @@ void DebugInfoFinder::processModule(Module &M) { /// processLocation - Process DILocation. void DebugInfoFinder::processLocation(DILocation Loc) { - if (!Loc.Verify()) return; - DIDescriptor S(Loc.getScope().getNode()); + if (Loc.isNull()) return; + DIScope S(Loc.getScope().getNode()); + if (S.isNull()) return; if (S.isCompileUnit()) addCompileUnit(DICompileUnit(S.getNode())); else if (S.isSubprogram()) @@ -1173,21 +1177,26 @@ void DebugInfoFinder::processType(DIType DT) { DICompositeType DCT(DT.getNode()); processType(DCT.getTypeDerivedFrom()); DIArray DA = DCT.getTypeArray(); - for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) { - DIDescriptor D = DA.getElement(i); - if (D.isType()) - processType(DIType(D.getNode())); - else if (D.isSubprogram()) - processSubprogram(DISubprogram(D.getNode())); - } + if (!DA.isNull()) + for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) { + DIDescriptor D = DA.getElement(i); + DIType TyE = DIType(D.getNode()); + if (!TyE.isNull()) + processType(TyE); + else + processSubprogram(DISubprogram(D.getNode())); + } } else if (DT.isDerivedType()) { DIDerivedType DDT(DT.getNode()); - processType(DDT.getTypeDerivedFrom()); + if (!DDT.isNull()) + processType(DDT.getTypeDerivedFrom()); } } /// processLexicalBlock void DebugInfoFinder::processLexicalBlock(DILexicalBlock LB) { + if (LB.isNull()) + return; DIScope Context = LB.getContext(); if (Context.isLexicalBlock()) return processLexicalBlock(DILexicalBlock(Context.getNode())); @@ -1197,6 +1206,8 @@ void DebugInfoFinder::processLexicalBlock(DILexicalBlock LB) { /// processSubprogram - Process DISubprogram. void DebugInfoFinder::processSubprogram(DISubprogram SP) { + if (SP.isNull()) + return; if (!addSubprogram(SP)) return; addCompileUnit(SP.getCompileUnit()); @@ -1205,23 +1216,20 @@ void DebugInfoFinder::processSubprogram(DISubprogram SP) { /// processDeclare - Process DbgDeclareInst. void DebugInfoFinder::processDeclare(DbgDeclareInst *DDI) { - MDNode *N = dyn_cast<MDNode>(DDI->getVariable()); - if (!N) return; - - DIDescriptor DV(N); - if (!DV.isVariable()) + DIVariable DV(cast<MDNode>(DDI->getVariable())); + if (DV.isNull()) return; if (!NodesSeen.insert(DV.getNode())) return; - addCompileUnit(DIVariable(N).getCompileUnit()); - processType(DIVariable(N).getType()); + addCompileUnit(DV.getCompileUnit()); + processType(DV.getType()); } /// addType - Add type into Tys. bool DebugInfoFinder::addType(DIType DT) { - if (!DT.isValid()) + if (DT.isNull()) return false; if (!NodesSeen.insert(DT.getNode())) @@ -1233,7 +1241,7 @@ bool DebugInfoFinder::addType(DIType DT) { /// addCompileUnit - Add compile unit into CUs. bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) { - if (!CU.Verify()) + if (CU.isNull()) return false; if (!NodesSeen.insert(CU.getNode())) @@ -1245,7 +1253,7 @@ bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) { /// addGlobalVariable - Add global variable into GVs. bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) { - if (!DIDescriptor(DIG.getNode()).isGlobalVariable()) + if (DIG.isNull()) return false; if (!NodesSeen.insert(DIG.getNode())) @@ -1257,7 +1265,7 @@ bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) { // addSubprogram - Add subprgoram into SPs. bool DebugInfoFinder::addSubprogram(DISubprogram SP) { - if (!DIDescriptor(SP.getNode()).isSubprogram()) + if (SP.isNull()) return false; if (!NodesSeen.insert(SP.getNode())) @@ -1275,10 +1283,10 @@ static Value *findDbgGlobalDeclare(GlobalVariable *V) { return 0; for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { - DIDescriptor DIG(cast_or_null<MDNode>(NMD->getOperand(i))); - if (!DIG.isGlobalVariable()) + DIGlobalVariable DIG(cast_or_null<MDNode>(NMD->getOperand(i))); + if (DIG.isNull()) continue; - if (DIGlobalVariable(DIG.getNode()).getGlobal() == V) + if (DIG.getGlobal() == V) return DIG.getNode(); } return 0; @@ -1370,6 +1378,12 @@ DebugLoc llvm::ExtractDebugLocation(DILocation &Loc, /// getDISubprogram - Find subprogram that is enclosing this scope. DISubprogram llvm::getDISubprogram(MDNode *Scope) { DIDescriptor D(Scope); + if (D.isNull()) + return DISubprogram(); + + if (D.isCompileUnit()) + return DISubprogram(); + if (D.isSubprogram()) return DISubprogram(Scope); @@ -1381,6 +1395,9 @@ DISubprogram llvm::getDISubprogram(MDNode *Scope) { /// getDICompositeType - Find underlying composite type. DICompositeType llvm::getDICompositeType(DIType T) { + if (T.isNull()) + return DICompositeType(); + if (T.isCompositeType()) return DICompositeType(T.getNode()); |