diff options
author | Manman Ren <manman.ren@gmail.com> | 2013-10-05 01:43:03 +0000 |
---|---|---|
committer | Manman Ren <manman.ren@gmail.com> | 2013-10-05 01:43:03 +0000 |
commit | c664d76716ba87577b6c2a513ce4fe0712a2d3e2 (patch) | |
tree | 4b0fd93928b742ceb7221f837dff9eac2a78192f /lib | |
parent | af76b1601cc1568aa7c672bca6383760b56d2ac4 (diff) | |
download | llvm-c664d76716ba87577b6c2a513ce4fe0712a2d3e2.tar.gz llvm-c664d76716ba87577b6c2a513ce4fe0712a2d3e2.tar.bz2 llvm-c664d76716ba87577b6c2a513ce4fe0712a2d3e2.tar.xz |
Debug Info: In DIBuilder, the derived-from field of a DW_TAG_pointer_type
is updated to use DITypeRef.
Move isUnsignedDIType and getOriginalTypeSize from DebugInfo.h to be static
helper functions in DwarfCompileUnit. We already have a static helper function
"isTypeSigned" in DwarfCompileUnit, and a pointer to DwarfDebug is added to
resolve the derived-from field. All three functions need to go across link
for derived-from fields, so we need to get hold of a type identifier map.
A pointer to DwarfDebug is also added to DbgVariable in order to resolve the
derived-from field.
Debug info verifier is updated to check a derived-from field is a TypeRef.
Verifier will not go across link for derived-from fields, in debug info finder,
we go across the link to add derived-from fields to types.
Function getDICompositeType is only used by dragonegg and since dragonegg does
not generate identifier for types, we use an empty map to resolve the
derived-from field.
When printing a derived-from field, we use DITypeRef::getName to either return
the type identifier or getName of the DIType.
A paired commit at clang is required due to changes to DIBuilder.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192018 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp | 80 | ||||
-rw-r--r-- | lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 16 | ||||
-rw-r--r-- | lib/CodeGen/AsmPrinter/DwarfDebug.h | 5 | ||||
-rw-r--r-- | lib/IR/DIBuilder.cpp | 2 | ||||
-rw-r--r-- | lib/IR/DebugInfo.cpp | 87 |
5 files changed, 103 insertions, 87 deletions
diff --git a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp index 23e5641b91..4d51e73fd6 100644 --- a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -520,7 +520,7 @@ void CompileUnit::addBlockByrefAddress(const DbgVariable &DV, DIE *Die, if (Tag == dwarf::DW_TAG_pointer_type) { DIDerivedType DTy = DIDerivedType(Ty); - TmpTy = DTy.getTypeDerivedFrom(); + TmpTy = DD->resolve(DTy.getTypeDerivedFrom()); isPointer = true; } @@ -587,9 +587,10 @@ void CompileUnit::addBlockByrefAddress(const DbgVariable &DV, DIE *Die, } /// isTypeSigned - Return true if the type is signed. -static bool isTypeSigned(DIType Ty, int *SizeInBits) { +static bool isTypeSigned(DwarfDebug *DD, DIType Ty, int *SizeInBits) { if (Ty.isDerivedType()) - return isTypeSigned(DIDerivedType(Ty).getTypeDerivedFrom(), SizeInBits); + return isTypeSigned(DD, DD->resolve(DIDerivedType(Ty).getTypeDerivedFrom()), + SizeInBits); if (Ty.isBasicType()) if (DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed || DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed_char) { @@ -599,6 +600,51 @@ static bool isTypeSigned(DIType Ty, int *SizeInBits) { return false; } +/// Return true if type encoding is unsigned. +static bool isUnsignedDIType(DwarfDebug *DD, DIType Ty) { + DIDerivedType DTy(Ty); + if (DTy.isDerivedType()) + return isUnsignedDIType(DD, DD->resolve(DTy.getTypeDerivedFrom())); + + DIBasicType BTy(Ty); + if (BTy.isBasicType()) { + unsigned Encoding = BTy.getEncoding(); + if (Encoding == dwarf::DW_ATE_unsigned || + Encoding == dwarf::DW_ATE_unsigned_char || + Encoding == dwarf::DW_ATE_boolean) + return true; + } + return false; +} + +/// If this type is derived from a base type then return base type size. +static uint64_t getOriginalTypeSize(DwarfDebug *DD, DIDerivedType Ty) { + unsigned Tag = Ty.getTag(); + + if (Tag != dwarf::DW_TAG_member && Tag != dwarf::DW_TAG_typedef && + Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type && + Tag != dwarf::DW_TAG_restrict_type) + return Ty.getSizeInBits(); + + DIType BaseType = DD->resolve(Ty.getTypeDerivedFrom()); + + // If this type is not derived from any type then take conservative approach. + if (!BaseType.isValid()) + return Ty.getSizeInBits(); + + // If this is a derived type, go ahead and get the base type, unless it's a + // reference then it's just the size of the field. Pointer types have no need + // of this since they're a different type of qualification on the type. + if (BaseType.getTag() == dwarf::DW_TAG_reference_type || + BaseType.getTag() == dwarf::DW_TAG_rvalue_reference_type) + return Ty.getSizeInBits(); + + if (BaseType.isDerivedType()) + return getOriginalTypeSize(DD, DIDerivedType(BaseType)); + + return BaseType.getSizeInBits(); +} + /// addConstantValue - Add constant value entry in variable DIE. void CompileUnit::addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty) { @@ -607,7 +653,7 @@ void CompileUnit::addConstantValue(DIE *Die, const MachineOperand &MO, // udata/sdata over dataN as suggested by the DWARF spec) assert(MO.isImm() && "Invalid machine operand!"); int SizeInBits = -1; - bool SignedConstant = isTypeSigned(Ty, &SizeInBits); + bool SignedConstant = isTypeSigned(DD, Ty, &SizeInBits); uint16_t Form; // If we're a signed constant definitely use sdata. @@ -923,7 +969,7 @@ void CompileUnit::constructTypeDIE(DIE &Buffer, DIDerivedType DTy) { uint16_t Tag = Buffer.getTag(); // Map to main type, void will not have a type. - DIType FromTy = DTy.getTypeDerivedFrom(); + DIType FromTy = DD->resolve(DTy.getTypeDerivedFrom()); if (FromTy) addType(&Buffer, FromTy); @@ -998,7 +1044,7 @@ void CompileUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) { Buffer.addChild(ElemDie); } } - DIType DTy = CTy.getTypeDerivedFrom(); + DIType DTy = DD->resolve(CTy.getTypeDerivedFrom()); if (DTy) { addType(&Buffer, DTy); addFlag(&Buffer, dwarf::DW_AT_enum_class); @@ -1064,7 +1110,8 @@ void CompileUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) { DIDerivedType DDTy(Element); if (DDTy.getTag() == dwarf::DW_TAG_friend) { ElemDie = new DIE(dwarf::DW_TAG_friend); - addType(ElemDie, DDTy.getTypeDerivedFrom(), dwarf::DW_AT_friend); + addType(ElemDie, DD->resolve(DDTy.getTypeDerivedFrom()), + dwarf::DW_AT_friend); } else if (DDTy.isStaticMember()) ElemDie = createStaticMemberDIE(DDTy); else @@ -1205,7 +1252,7 @@ CompileUnit::getOrCreateTemplateValueParameterDIE(DITemplateValueParameter VP) { addString(ParamDIE, dwarf::DW_AT_name, VP.getName()); if (Value *Val = VP.getValue()) { if (ConstantInt *CI = dyn_cast<ConstantInt>(Val)) - addConstantValue(ParamDIE, CI, VP.getType().isUnsignedDIType()); + addConstantValue(ParamDIE, CI, isUnsignedDIType(DD, VP.getType())); else if (GlobalValue *GV = dyn_cast<GlobalValue>(Val)) { // For declaration non-type template parameters (such as global values and // functions) @@ -1499,7 +1546,7 @@ void CompileUnit::createGlobalVariableDIE(const MDNode *N) { // emitting AT_const_value multiple times, we only add AT_const_value when // it is not a static member. if (!IsStaticMember) - addConstantValue(VariableDIE, CI, GTy.isUnsignedDIType()); + addConstantValue(VariableDIE, CI, isUnsignedDIType(DD, GTy)); } else if (const ConstantExpr *CE = getMergedGlobalExpr(N->getOperand(11))) { addToAccelTable = true; // GV is a merged global. @@ -1559,7 +1606,7 @@ void CompileUnit::constructArrayTypeDIE(DIE &Buffer, addFlag(&Buffer, dwarf::DW_AT_GNU_vector); // Emit the element type. - addType(&Buffer, CTy->getTypeDerivedFrom()); + addType(&Buffer, DD->resolve(CTy->getTypeDerivedFrom())); // Get an anonymous type for index type. // FIXME: This type should be passed down from the front end @@ -1663,7 +1710,7 @@ DIE *CompileUnit::constructVariableDIE(DbgVariable *DV, addConstantFPValue(VariableDie, DVInsn->getOperand(0)); else if (DVInsn->getOperand(0).isCImm()) addConstantValue(VariableDie, DVInsn->getOperand(0).getCImm(), - DV->getType().isUnsignedDIType()); + isUnsignedDIType(DD, DV->getType())); DV->setDIE(VariableDie); return VariableDie; @@ -1691,7 +1738,7 @@ DIE *CompileUnit::createMemberDIE(DIDerivedType DT) { if (!Name.empty()) addString(MemberDie, dwarf::DW_AT_name, Name); - addType(MemberDie, DT.getTypeDerivedFrom()); + addType(MemberDie, DD->resolve(DT.getTypeDerivedFrom())); addSourceLine(MemberDie, DT); @@ -1699,11 +1746,12 @@ DIE *CompileUnit::createMemberDIE(DIDerivedType DT) { addUInt(MemLocationDie, 0, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst); uint64_t Size = DT.getSizeInBits(); - uint64_t FieldSize = DT.getOriginalTypeSize(); + uint64_t FieldSize = getOriginalTypeSize(DD, DT); if (Size != FieldSize) { // Handle bitfield. - addUInt(MemberDie, dwarf::DW_AT_byte_size, 0, DT.getOriginalTypeSize()>>3); + addUInt(MemberDie, dwarf::DW_AT_byte_size, 0, + getOriginalTypeSize(DD, DT)>>3); addUInt(MemberDie, dwarf::DW_AT_bit_size, 0, DT.getSizeInBits()); uint64_t Offset = DT.getOffsetInBits(); @@ -1778,7 +1826,7 @@ DIE *CompileUnit::createStaticMemberDIE(const DIDerivedType DT) { return NULL; DIE *StaticMemberDIE = new DIE(DT.getTag()); - DIType Ty = DT.getTypeDerivedFrom(); + DIType Ty = DD->resolve(DT.getTypeDerivedFrom()); addString(StaticMemberDIE, dwarf::DW_AT_name, DT.getName()); addType(StaticMemberDIE, Ty); @@ -1799,7 +1847,7 @@ DIE *CompileUnit::createStaticMemberDIE(const DIDerivedType DT) { dwarf::DW_ACCESS_public); if (const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT.getConstant())) - addConstantValue(StaticMemberDIE, CI, Ty.isUnsignedDIType()); + addConstantValue(StaticMemberDIE, CI, isUnsignedDIType(DD, Ty)); if (const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT.getConstant())) addConstantFPValue(StaticMemberDIE, CFP); diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index 4a1d47728d..48e44c017a 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -149,13 +149,13 @@ DIType DbgVariable::getType() const { uint16_t tag = Ty.getTag(); if (tag == dwarf::DW_TAG_pointer_type) - subType = DIDerivedType(Ty).getTypeDerivedFrom(); + subType = DD->resolve(DIDerivedType(Ty).getTypeDerivedFrom()); DIArray Elements = DICompositeType(subType).getTypeArray(); for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) { DIDerivedType DT = DIDerivedType(Elements.getElement(i)); if (getName() == DT.getName()) - return (DT.getTypeDerivedFrom()); + return (DD->resolve(DT.getTypeDerivedFrom())); } } return Ty; @@ -992,7 +992,7 @@ void DwarfDebug::collectDeadVariables() { for (unsigned vi = 0, ve = Variables.getNumElements(); vi != ve; ++vi) { DIVariable DV(Variables.getElement(vi)); if (!DV.isVariable()) continue; - DbgVariable NewVar(DV, NULL); + DbgVariable NewVar(DV, NULL, this); if (DIE *VariableDIE = SPCU->constructVariableDIE(&NewVar, Scope->isAbstractScope())) ScopeDIE->addChild(VariableDIE); @@ -1251,7 +1251,7 @@ DbgVariable *DwarfDebug::findAbstractVariable(DIVariable &DV, if (!Scope) return NULL; - AbsDbgVariable = new DbgVariable(Var, NULL); + AbsDbgVariable = new DbgVariable(Var, NULL, this); addScopeVariable(Scope, AbsDbgVariable); AbstractVariables[Var] = AbsDbgVariable; return AbsDbgVariable; @@ -1300,7 +1300,7 @@ DwarfDebug::collectVariableInfoFromMMITable(const MachineFunction *MF, continue; DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second); - DbgVariable *RegVar = new DbgVariable(DV, AbsDbgVariable); + DbgVariable *RegVar = new DbgVariable(DV, AbsDbgVariable, this); RegVar->setFrameIndex(VP.first); if (!addCurrentFnArgument(MF, RegVar, Scope)) addScopeVariable(Scope, RegVar); @@ -1385,7 +1385,7 @@ DwarfDebug::collectVariableInfo(const MachineFunction *MF, Processed.insert(DV); assert(MInsn->isDebugValue() && "History must begin with debug value"); DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc()); - DbgVariable *RegVar = new DbgVariable(DV, AbsVar); + DbgVariable *RegVar = new DbgVariable(DV, AbsVar, this); if (!addCurrentFnArgument(MF, RegVar, Scope)) addScopeVariable(Scope, RegVar); if (AbsVar) @@ -1448,7 +1448,7 @@ DwarfDebug::collectVariableInfo(const MachineFunction *MF, if (!DV || !DV.isVariable() || !Processed.insert(DV)) continue; if (LexicalScope *Scope = LScopes.findLexicalScope(DV.getContext())) - addScopeVariable(Scope, new DbgVariable(DV, NULL)); + addScopeVariable(Scope, new DbgVariable(DV, NULL, this)); } } @@ -1844,7 +1844,7 @@ void DwarfDebug::endFunction(const MachineFunction *MF) { if (AbstractVariables.lookup(CleanDV)) continue; if (LexicalScope *Scope = LScopes.findAbstractScope(DV.getContext())) - addScopeVariable(Scope, new DbgVariable(DV, NULL)); + addScopeVariable(Scope, new DbgVariable(DV, NULL, this)); } } if (ProcessedSPNodes.count(AScope->getScopeNode()) == 0) diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.h b/lib/CodeGen/AsmPrinter/DwarfDebug.h index c4c450d0d5..e8ca9d2783 100644 --- a/lib/CodeGen/AsmPrinter/DwarfDebug.h +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -150,11 +150,12 @@ class DbgVariable { DbgVariable *AbsVar; // Corresponding Abstract variable, if any. const MachineInstr *MInsn; // DBG_VALUE instruction of the variable. int FrameIndex; + DwarfDebug *DD; public: // AbsVar may be NULL. - DbgVariable(DIVariable V, DbgVariable *AV) + DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD) : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0), - FrameIndex(~0) {} + FrameIndex(~0), DD(DD) {} // Accessors. DIVariable getVariable() const { return Var; } diff --git a/lib/IR/DIBuilder.cpp b/lib/IR/DIBuilder.cpp index 0cd4ac6f46..b051fcc6f9 100644 --- a/lib/IR/DIBuilder.cpp +++ b/lib/IR/DIBuilder.cpp @@ -303,7 +303,7 @@ DIBuilder::createPointerType(DIType PointeeTy, uint64_t SizeInBits, ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), ConstantInt::get(Type::getInt64Ty(VMContext), 0), // Offset ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Flags - PointeeTy + PointeeTy.getRef() }; return DIDerivedType(MDNode::get(VMContext, Elts)); } diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 42267081c9..f5e7e2674f 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -368,23 +368,6 @@ void DIType::replaceAllUsesWith(MDNode *D) { } } -/// isUnsignedDIType - Return true if type encoding is unsigned. -bool DIType::isUnsignedDIType() { - DIDerivedType DTy(DbgNode); - if (DTy.Verify()) - return DTy.getTypeDerivedFrom().isUnsignedDIType(); - - DIBasicType BTy(DbgNode); - if (BTy.Verify()) { - unsigned Encoding = BTy.getEncoding(); - if (Encoding == dwarf::DW_ATE_unsigned || - Encoding == dwarf::DW_ATE_unsigned_char || - Encoding == dwarf::DW_ATE_boolean) - return true; - } - return false; -} - /// Verify - Verify that a compile unit is well formed. bool DICompileUnit::Verify() const { if (!isCompileUnit()) @@ -493,8 +476,8 @@ bool DIBasicType::Verify() const { /// Verify - Verify that a derived type descriptor is well formed. bool DIDerivedType::Verify() const { - // Make sure DerivedFrom @ field 9 is MDNode. - if (!fieldIsMDNode(DbgNode, 9)) + // Make sure DerivedFrom @ field 9 is TypeRef. + if (!fieldIsTypeRef(DbgNode, 9)) return false; if (getTag() == dwarf::DW_TAG_ptr_to_member_type) // Make sure ClassType @ field 10 is a TypeRef. @@ -510,8 +493,8 @@ bool DICompositeType::Verify() const { if (!isCompositeType()) return false; - // Make sure DerivedFrom @ field 9 and ContainingType @ field 12 are MDNodes. - if (!fieldIsMDNode(DbgNode, 9)) + // Make sure DerivedFrom @ field 9 and ContainingType @ field 12 are TypeRef. + if (!fieldIsTypeRef(DbgNode, 9)) return false; if (!fieldIsTypeRef(DbgNode, 12)) return false; @@ -520,12 +503,6 @@ bool DICompositeType::Verify() const { if (!fieldIsMDString(DbgNode, 14)) return false; - // If this is an array type verify that we have a DIType in the derived type - // field as that's the type of our element. - if (getTag() == dwarf::DW_TAG_array_type) - if (!DIType(getTypeDerivedFrom())) - return false; - return DbgNode->getNumOperands() == 15; } @@ -638,35 +615,6 @@ bool DIImportedEntity::Verify() const { (DbgNode->getNumOperands() == 4 || DbgNode->getNumOperands() == 5); } -/// getOriginalTypeSize - If this type is derived from a base type then -/// return base type size. -uint64_t DIDerivedType::getOriginalTypeSize() const { - uint16_t Tag = getTag(); - - if (Tag != dwarf::DW_TAG_member && Tag != dwarf::DW_TAG_typedef && - Tag != dwarf::DW_TAG_const_type && Tag != dwarf::DW_TAG_volatile_type && - Tag != dwarf::DW_TAG_restrict_type) - return getSizeInBits(); - - DIType BaseType = getTypeDerivedFrom(); - - // If this type is not derived from any type then take conservative approach. - if (!BaseType.isValid()) - return getSizeInBits(); - - // If this is a derived type, go ahead and get the base type, unless it's a - // reference then it's just the size of the field. Pointer types have no need - // of this since they're a different type of qualification on the type. - if (BaseType.getTag() == dwarf::DW_TAG_reference_type || - BaseType.getTag() == dwarf::DW_TAG_rvalue_reference_type) - return getSizeInBits(); - - if (BaseType.isDerivedType()) - return DIDerivedType(BaseType).getOriginalTypeSize(); - - return BaseType.getSizeInBits(); -} - /// getObjCProperty - Return property node, if this ivar is associated with one. MDNode *DIDerivedType::getObjCProperty() const { return getNodeField(DbgNode, 10); @@ -808,6 +756,19 @@ DIScopeRef DIScope::getContext() const { return DIScopeRef(NULL); } +// If the scope node has a name, return that, else return an empty string. +StringRef DIScope::getName() const { + if (isType()) + return DIType(DbgNode).getName(); + if (isSubprogram()) + return DISubprogram(DbgNode).getName(); + if (isNameSpace()) + return DINameSpace(DbgNode).getName(); + assert((isLexicalBlock() || isLexicalBlockFile() || isFile() || + isCompileUnit()) && "Unhandled type of scope."); + return StringRef(); +} + StringRef DIScope::getFilename() const { if (!DbgNode) return StringRef(); @@ -942,8 +903,14 @@ DICompositeType llvm::getDICompositeType(DIType T) { if (T.isCompositeType()) return DICompositeType(T); - if (T.isDerivedType()) - return getDICompositeType(DIDerivedType(T).getTypeDerivedFrom()); + if (T.isDerivedType()) { + // This function is currently used by dragonegg and dragonegg does + // not generate identifier for types, so using an empty map to resolve + // DerivedFrom should be fine. + DITypeIdentifierMap EmptyMap; + return getDICompositeType(DIDerivedType(T).getTypeDerivedFrom() + .resolve(EmptyMap)); + } return DICompositeType(); } @@ -1044,7 +1011,7 @@ void DebugInfoFinder::processType(DIType DT) { processScope(DT.getContext().resolve(TypeIdentifierMap)); if (DT.isCompositeType()) { DICompositeType DCT(DT); - processType(DCT.getTypeDerivedFrom()); + processType(DCT.getTypeDerivedFrom().resolve(TypeIdentifierMap)); DIArray DA = DCT.getTypeArray(); for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) { DIDescriptor D = DA.getElement(i); @@ -1055,7 +1022,7 @@ void DebugInfoFinder::processType(DIType DT) { } } else if (DT.isDerivedType()) { DIDerivedType DDT(DT); - processType(DDT.getTypeDerivedFrom()); + processType(DDT.getTypeDerivedFrom().resolve(TypeIdentifierMap)); } } |