diff options
author | Devang Patel <dpatel@apple.com> | 2010-08-23 22:07:25 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2010-08-23 22:07:25 +0000 |
commit | 6237cea785144d4cdbe2a5e722788e0b4b9b30f9 (patch) | |
tree | a38aee364b68c251233fecdf73115c7b2c9386f2 /lib/CodeGen/CGDebugInfo.cpp | |
parent | aa5f77b2c914b68e6a3737c93db3598907bc64ab (diff) |
Emit debug info for enum constants.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111852 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGDebugInfo.cpp')
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 6b79b3ed43..6f06ed2b02 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -1097,39 +1097,8 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty, llvm::DIFile Unit) { - EnumDecl *ED = Ty->getDecl(); + return CreateEnumType(Ty->getDecl(), Unit); - llvm::SmallVector<llvm::DIDescriptor, 32> Enumerators; - - // Create DIEnumerator elements for each enumerator. - for (EnumDecl::enumerator_iterator - Enum = ED->enumerator_begin(), EnumEnd = ED->enumerator_end(); - Enum != EnumEnd; ++Enum) { - Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getName(), - Enum->getInitVal().getZExtValue())); - } - - // Return a CompositeType for the enum itself. - llvm::DIArray EltArray = - DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size()); - - llvm::DIFile DefUnit = getOrCreateFile(ED->getLocation()); - unsigned Line = getLineNumber(ED->getLocation()); - - // Size and align of the type. - uint64_t Size = 0; - unsigned Align = 0; - if (!Ty->isIncompleteType()) { - Size = CGM.getContext().getTypeSize(Ty); - Align = CGM.getContext().getTypeAlign(Ty); - } - - llvm::DIType DbgTy = - DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type, - Unit, ED->getName(), DefUnit, Line, - Size, Align, 0, 0, - llvm::DIType(), EltArray); - return DbgTy; } llvm::DIType CGDebugInfo::CreateType(const TagType *Ty, @@ -1256,6 +1225,36 @@ llvm::DIType CGDebugInfo::CreateType(const MemberPointerType *Ty, 0, 0, 0, llvm::DIType(), Elements); } +/// CreateEnumType - get enumeration type. +llvm::DIType CGDebugInfo::CreateEnumType(const EnumDecl *ED, llvm::DIFile Unit){ + llvm::SmallVector<llvm::DIDescriptor, 32> Enumerators; + + // Create DIEnumerator elements for each enumerator. + for (EnumDecl::enumerator_iterator + Enum = ED->enumerator_begin(), EnumEnd = ED->enumerator_end(); + Enum != EnumEnd; ++Enum) { + Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getName(), + Enum->getInitVal().getZExtValue())); + } + + // Return a CompositeType for the enum itself. + llvm::DIArray EltArray = + DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size()); + + llvm::DIFile DefUnit = getOrCreateFile(ED->getLocation()); + unsigned Line = getLineNumber(ED->getLocation()); + uint64_t Size = 0; + if (!ED->getTypeForDecl()->isIncompleteType()) + CGM.getContext().getTypeSize(ED->getTypeForDecl()); + + llvm::DIType DbgTy = + DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type, + Unit, ED->getName(), DefUnit, Line, + Size, 0, 0, 0, + llvm::DIType(), EltArray); + return DbgTy; +} + static QualType UnwrapTypeForDebugInfo(QualType T) { do { QualType LastT = T; @@ -1828,6 +1827,10 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); llvm::StringRef Name = VD->getName(); llvm::DIType Ty = getOrCreateType(VD->getType(), Unit); + if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(VD)) { + if (const EnumDecl *ED = dyn_cast<EnumDecl>(ECD->getDeclContext())) + Ty = CreateEnumType(ED, Unit); + } // Do not use DIGlobalVariable for enums. if (Ty.getTag() == llvm::dwarf::DW_TAG_enumeration_type) return; |