Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1 | //===--- CGDebugInfo.cpp - Emit Debug Information for a Module ------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This coordinates the debug information generation while generating code. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CGDebugInfo.h" |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 15 | #include "CodeGenFunction.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 16 | #include "CodeGenModule.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclObjC.h" |
Chris Lattner | 3cc5c40 | 2008-11-11 07:01:36 +0000 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" |
Anders Carlsson | 19cc4ab | 2009-07-18 19:43:29 +0000 | [diff] [blame] | 20 | #include "clang/AST/RecordLayout.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 21 | #include "clang/Basic/SourceManager.h" |
| 22 | #include "clang/Basic/FileManager.h" |
Mike Stump | 5a86217 | 2009-09-15 21:48:34 +0000 | [diff] [blame] | 23 | #include "clang/Basic/Version.h" |
Chandler Carruth | 2811ccf | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 24 | #include "clang/CodeGen/CodeGenOptions.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 25 | #include "llvm/Constants.h" |
| 26 | #include "llvm/DerivedTypes.h" |
| 27 | #include "llvm/Instructions.h" |
| 28 | #include "llvm/Intrinsics.h" |
| 29 | #include "llvm/Module.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/StringExtras.h" |
| 31 | #include "llvm/ADT/SmallVector.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Dwarf.h" |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 33 | #include "llvm/System/Path.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 34 | #include "llvm/Target/TargetMachine.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 35 | using namespace clang; |
| 36 | using namespace clang::CodeGen; |
| 37 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 38 | CGDebugInfo::CGDebugInfo(CodeGenModule &CGM) |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 39 | : CGM(CGM), DebugFactory(CGM.getModule()), |
Devang Patel | 7573f8b | 2010-03-09 21:32:27 +0000 | [diff] [blame^] | 40 | FwdDeclCount(0), BlockLiteralGenericSet(false) { |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 41 | CreateCompileUnit(); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 44 | CGDebugInfo::~CGDebugInfo() { |
Daniel Dunbar | 66031a5 | 2008-10-17 16:15:48 +0000 | [diff] [blame] | 45 | assert(RegionStack.empty() && "Region stack mismatch, stack not empty!"); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 48 | void CGDebugInfo::setLocation(SourceLocation Loc) { |
| 49 | if (Loc.isValid()) |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 50 | CurLoc = CGM.getContext().getSourceManager().getInstantiationLoc(Loc); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Devang Patel | 3358305 | 2010-01-28 23:15:27 +0000 | [diff] [blame] | 53 | /// getContextDescriptor - Get context info for the decl. |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 54 | llvm::DIDescriptor CGDebugInfo::getContextDescriptor(const Decl *Context, |
Devang Patel | 3358305 | 2010-01-28 23:15:27 +0000 | [diff] [blame] | 55 | llvm::DIDescriptor &CompileUnit) { |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 56 | if (!Context) |
| 57 | return CompileUnit; |
| 58 | |
| 59 | llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator |
| 60 | I = RegionMap.find(Context); |
| 61 | if (I != RegionMap.end()) |
| 62 | return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(I->second)); |
Devang Patel | 411894b | 2010-02-01 22:40:08 +0000 | [diff] [blame] | 63 | |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 64 | // Check namespace. |
| 65 | if (const NamespaceDecl *NSDecl = dyn_cast<NamespaceDecl>(Context)) |
| 66 | return llvm::DIDescriptor(getOrCreateNameSpace(NSDecl, CompileUnit)); |
| 67 | |
Devang Patel | 979ec2e | 2009-10-06 00:35:31 +0000 | [diff] [blame] | 68 | return CompileUnit; |
| 69 | } |
| 70 | |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 71 | /// getFunctionName - Get function name for the given FunctionDecl. If the |
| 72 | /// name is constructred on demand (e.g. C++ destructor) then the name |
| 73 | /// is stored on the side. |
| 74 | llvm::StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) { |
| 75 | assert (FD && "Invalid FunctionDecl!"); |
| 76 | IdentifierInfo *FII = FD->getIdentifier(); |
| 77 | if (FII) |
| 78 | return FII->getName(); |
| 79 | |
| 80 | // Otherwise construct human readable name for debug info. |
| 81 | std::string NS = FD->getNameAsString(); |
| 82 | |
| 83 | // Copy this name on the side and use its reference. |
Devang Patel | 89f05f8 | 2010-01-28 18:21:00 +0000 | [diff] [blame] | 84 | char *StrPtr = DebugInfoNames.Allocate<char>(NS.length()); |
Benjamin Kramer | 1b627dc | 2010-01-23 18:16:07 +0000 | [diff] [blame] | 85 | memcpy(StrPtr, NS.data(), NS.length()); |
| 86 | return llvm::StringRef(StrPtr, NS.length()); |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 89 | /// getOrCreateFile - Get the file debug info descriptor for the input location. |
| 90 | llvm::DIFile CGDebugInfo::getOrCreateFile(SourceLocation Loc) { |
| 91 | if (!Loc.isValid()) |
| 92 | // If Location is not valid then use main input file. |
| 93 | return DebugFactory.CreateFile(TheCU.getFilename(), TheCU.getDirectory(), |
| 94 | TheCU); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 95 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 96 | PresumedLoc PLoc = SM.getPresumedLoc(Loc); |
| 97 | llvm::sys::Path AbsFileName(PLoc.getFilename()); |
Benjamin Kramer | 47daf68 | 2009-12-08 11:02:29 +0000 | [diff] [blame] | 98 | AbsFileName.makeAbsolute(); |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 99 | |
Devang Patel | 683f6db | 2010-03-09 19:14:07 +0000 | [diff] [blame] | 100 | return DebugFactory.CreateFile(AbsFileName.getLast(), |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 101 | AbsFileName.getDirname(), TheCU); |
| 102 | } |
| 103 | /// CreateCompileUnit - Create new compile unit. |
| 104 | void CGDebugInfo::CreateCompileUnit() { |
| 105 | |
| 106 | // Get absolute path name. |
| 107 | llvm::sys::Path AbsFileName(CGM.getCodeGenOpts().MainFileName); |
| 108 | AbsFileName.makeAbsolute(); |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 109 | |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 110 | unsigned LangTag; |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 111 | const LangOptions &LO = CGM.getLangOptions(); |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 112 | if (LO.CPlusPlus) { |
| 113 | if (LO.ObjC1) |
| 114 | LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus; |
| 115 | else |
| 116 | LangTag = llvm::dwarf::DW_LANG_C_plus_plus; |
| 117 | } else if (LO.ObjC1) { |
Devang Patel | 8d9aefc | 2009-03-24 20:35:51 +0000 | [diff] [blame] | 118 | LangTag = llvm::dwarf::DW_LANG_ObjC; |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 119 | } else if (LO.C99) { |
Devang Patel | 8d9aefc | 2009-03-24 20:35:51 +0000 | [diff] [blame] | 120 | LangTag = llvm::dwarf::DW_LANG_C99; |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 121 | } else { |
| 122 | LangTag = llvm::dwarf::DW_LANG_C89; |
| 123 | } |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 124 | |
Benjamin Kramer | 47daf68 | 2009-12-08 11:02:29 +0000 | [diff] [blame] | 125 | const char *Producer = |
Mike Stump | d8945d6 | 2009-10-09 18:38:12 +0000 | [diff] [blame] | 126 | #ifdef CLANG_VENDOR |
| 127 | CLANG_VENDOR |
| 128 | #endif |
| 129 | "clang " CLANG_VERSION_STRING; |
Chris Lattner | 4c2577a | 2009-05-02 01:00:04 +0000 | [diff] [blame] | 130 | |
| 131 | // Figure out which version of the ObjC runtime we have. |
| 132 | unsigned RuntimeVers = 0; |
| 133 | if (LO.ObjC1) |
| 134 | RuntimeVers = LO.ObjCNonFragileABI ? 2 : 1; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 135 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 136 | // Create new compile unit. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 137 | TheCU = DebugFactory.CreateCompileUnit( |
| 138 | LangTag, AbsFileName.getLast(), AbsFileName.getDirname(), Producer, true, |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 139 | LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 142 | /// CreateType - Get the Basic type from the cache or create a new |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 143 | /// one if necessary. |
| 144 | llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 145 | llvm::DIFile Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 146 | unsigned Encoding = 0; |
| 147 | switch (BT->getKind()) { |
| 148 | default: |
| 149 | case BuiltinType::Void: |
| 150 | return llvm::DIType(); |
| 151 | case BuiltinType::UChar: |
| 152 | case BuiltinType::Char_U: Encoding = llvm::dwarf::DW_ATE_unsigned_char; break; |
| 153 | case BuiltinType::Char_S: |
| 154 | case BuiltinType::SChar: Encoding = llvm::dwarf::DW_ATE_signed_char; break; |
| 155 | case BuiltinType::UShort: |
| 156 | case BuiltinType::UInt: |
| 157 | case BuiltinType::ULong: |
| 158 | case BuiltinType::ULongLong: Encoding = llvm::dwarf::DW_ATE_unsigned; break; |
| 159 | case BuiltinType::Short: |
| 160 | case BuiltinType::Int: |
| 161 | case BuiltinType::Long: |
| 162 | case BuiltinType::LongLong: Encoding = llvm::dwarf::DW_ATE_signed; break; |
| 163 | case BuiltinType::Bool: Encoding = llvm::dwarf::DW_ATE_boolean; break; |
| 164 | case BuiltinType::Float: |
Devang Patel | 7c173cb | 2009-10-12 22:28:31 +0000 | [diff] [blame] | 165 | case BuiltinType::LongDouble: |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 166 | case BuiltinType::Double: Encoding = llvm::dwarf::DW_ATE_float; break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | } |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 168 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 169 | uint64_t Size = CGM.getContext().getTypeSize(BT); |
| 170 | uint64_t Align = CGM.getContext().getTypeAlign(BT); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 171 | uint64_t Offset = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 172 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 173 | llvm::DIType DbgTy = |
| 174 | DebugFactory.CreateBasicType(Unit, |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 175 | BT->getName(CGM.getContext().getLangOptions()), |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 176 | Unit, 0, Size, Align, |
| 177 | Offset, /*flags*/ 0, Encoding); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 178 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 179 | } |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 180 | |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 181 | llvm::DIType CGDebugInfo::CreateType(const ComplexType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 182 | llvm::DIFile Unit) { |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 183 | // Bit size, align and offset of the type. |
| 184 | unsigned Encoding = llvm::dwarf::DW_ATE_complex_float; |
| 185 | if (Ty->isComplexIntegerType()) |
| 186 | Encoding = llvm::dwarf::DW_ATE_lo_user; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 187 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 188 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 189 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 190 | uint64_t Offset = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 191 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 192 | llvm::DIType DbgTy = |
| 193 | DebugFactory.CreateBasicType(Unit, "complex", |
| 194 | Unit, 0, Size, Align, |
| 195 | Offset, /*flags*/ 0, Encoding); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 196 | return DbgTy; |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 197 | } |
| 198 | |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 199 | /// CreateCVRType - Get the qualified type from the cache or create |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 200 | /// a new one if necessary. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 201 | llvm::DIType CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DIFile Unit) { |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 202 | QualifierCollector Qc; |
| 203 | const Type *T = Qc.strip(Ty); |
| 204 | |
| 205 | // Ignore these qualifiers for now. |
| 206 | Qc.removeObjCGCAttr(); |
| 207 | Qc.removeAddressSpace(); |
| 208 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 209 | // We will create one Derived type for one qualifier and recurse to handle any |
| 210 | // additional ones. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 211 | unsigned Tag; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 212 | if (Qc.hasConst()) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 213 | Tag = llvm::dwarf::DW_TAG_const_type; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 214 | Qc.removeConst(); |
| 215 | } else if (Qc.hasVolatile()) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 216 | Tag = llvm::dwarf::DW_TAG_volatile_type; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 217 | Qc.removeVolatile(); |
| 218 | } else if (Qc.hasRestrict()) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 219 | Tag = llvm::dwarf::DW_TAG_restrict_type; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 220 | Qc.removeRestrict(); |
| 221 | } else { |
| 222 | assert(Qc.empty() && "Unknown type qualifier for debug info"); |
| 223 | return getOrCreateType(QualType(T, 0), Unit); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 224 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 225 | |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 226 | llvm::DIType FromTy = getOrCreateType(Qc.apply(T), Unit); |
| 227 | |
Daniel Dunbar | 3845f86 | 2008-10-31 03:54:29 +0000 | [diff] [blame] | 228 | // No need to fill in the Name, Line, Size, Alignment, Offset in case of |
| 229 | // CVR derived types. |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 230 | llvm::DIType DbgTy = |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 231 | DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DIFile(), |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 232 | 0, 0, 0, 0, 0, FromTy); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 233 | return DbgTy; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 236 | llvm::DIType CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 237 | llvm::DIFile Unit) { |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 238 | llvm::DIType DbgTy = |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 239 | CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty, |
| 240 | Ty->getPointeeType(), Unit); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 241 | return DbgTy; |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 244 | llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 245 | llvm::DIFile Unit) { |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 246 | return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty, |
| 247 | Ty->getPointeeType(), Unit); |
| 248 | } |
| 249 | |
| 250 | llvm::DIType CGDebugInfo::CreatePointerLikeType(unsigned Tag, |
| 251 | const Type *Ty, |
| 252 | QualType PointeeTy, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 253 | llvm::DIFile Unit) { |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 254 | llvm::DIType EltTy = getOrCreateType(PointeeTy, Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 255 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 256 | // Bit size, align and offset of the type. |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 257 | |
| 258 | // Size is always the size of a pointer. We can't use getTypeSize here |
| 259 | // because that does not return the correct value for references. |
| 260 | uint64_t Size = |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 261 | CGM.getContext().Target.getPointerWidth(PointeeTy.getAddressSpace()); |
| 262 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 263 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 264 | return |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 265 | DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DIFile(), |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 266 | 0, Size, Align, 0, 0, EltTy); |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 267 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 270 | llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 271 | llvm::DIFile Unit) { |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 272 | if (BlockLiteralGenericSet) |
| 273 | return BlockLiteralGeneric; |
| 274 | |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 275 | llvm::DIFile DefUnit; |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 276 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
| 277 | |
| 278 | llvm::SmallVector<llvm::DIDescriptor, 5> EltTys; |
| 279 | |
| 280 | llvm::DIType FieldTy; |
| 281 | |
| 282 | QualType FType; |
| 283 | uint64_t FieldSize, FieldOffset; |
| 284 | unsigned FieldAlign; |
| 285 | |
| 286 | llvm::DIArray Elements; |
| 287 | llvm::DIType EltTy, DescTy; |
| 288 | |
| 289 | FieldOffset = 0; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 290 | FType = CGM.getContext().UnsignedLongTy; |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 291 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 292 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 293 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 294 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 295 | "reserved", DefUnit, |
| 296 | 0, FieldSize, FieldAlign, |
| 297 | FieldOffset, 0, FieldTy); |
| 298 | EltTys.push_back(FieldTy); |
| 299 | |
| 300 | FieldOffset += FieldSize; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 301 | FType = CGM.getContext().UnsignedLongTy; |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 302 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 303 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 304 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 305 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 306 | "Size", DefUnit, |
| 307 | 0, FieldSize, FieldAlign, |
| 308 | FieldOffset, 0, FieldTy); |
| 309 | EltTys.push_back(FieldTy); |
| 310 | |
| 311 | FieldOffset += FieldSize; |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 312 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 313 | EltTys.clear(); |
| 314 | |
Mike Stump | 3d363c5 | 2009-10-02 02:30:50 +0000 | [diff] [blame] | 315 | unsigned Flags = llvm::DIType::FlagAppleBlock; |
| 316 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 317 | EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_descriptor", |
Mike Stump | 3d363c5 | 2009-10-02 02:30:50 +0000 | [diff] [blame] | 318 | DefUnit, 0, FieldOffset, 0, 0, Flags, |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 319 | llvm::DIType(), Elements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 320 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 321 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 322 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 323 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 324 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 325 | DescTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 326 | Unit, "", llvm::DIFile(), |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 327 | 0, Size, Align, 0, 0, EltTy); |
| 328 | |
| 329 | FieldOffset = 0; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 330 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 331 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 332 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 333 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 334 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 335 | "__isa", DefUnit, |
| 336 | 0, FieldSize, FieldAlign, |
| 337 | FieldOffset, 0, FieldTy); |
| 338 | EltTys.push_back(FieldTy); |
| 339 | |
| 340 | FieldOffset += FieldSize; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 341 | FType = CGM.getContext().IntTy; |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 342 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 343 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 344 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 345 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 346 | "__flags", DefUnit, |
| 347 | 0, FieldSize, FieldAlign, |
| 348 | FieldOffset, 0, FieldTy); |
| 349 | EltTys.push_back(FieldTy); |
| 350 | |
| 351 | FieldOffset += FieldSize; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 352 | FType = CGM.getContext().IntTy; |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 353 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 354 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 355 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 356 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 357 | "__reserved", DefUnit, |
| 358 | 0, FieldSize, FieldAlign, |
| 359 | FieldOffset, 0, FieldTy); |
| 360 | EltTys.push_back(FieldTy); |
| 361 | |
| 362 | FieldOffset += FieldSize; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 363 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 364 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 365 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 366 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 367 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 368 | "__FuncPtr", DefUnit, |
| 369 | 0, FieldSize, FieldAlign, |
| 370 | FieldOffset, 0, FieldTy); |
| 371 | EltTys.push_back(FieldTy); |
| 372 | |
| 373 | FieldOffset += FieldSize; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 374 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 375 | FieldTy = DescTy; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 376 | FieldSize = CGM.getContext().getTypeSize(Ty); |
| 377 | FieldAlign = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 378 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 379 | "__descriptor", DefUnit, |
| 380 | 0, FieldSize, FieldAlign, |
| 381 | FieldOffset, 0, FieldTy); |
| 382 | EltTys.push_back(FieldTy); |
| 383 | |
| 384 | FieldOffset += FieldSize; |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 385 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 386 | |
| 387 | EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_literal_generic", |
Mike Stump | 944e705 | 2009-10-02 02:23:37 +0000 | [diff] [blame] | 388 | DefUnit, 0, FieldOffset, 0, 0, Flags, |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 389 | llvm::DIType(), Elements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 390 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 391 | BlockLiteralGenericSet = true; |
| 392 | BlockLiteralGeneric |
| 393 | = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 394 | "", llvm::DIFile(), |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 395 | 0, Size, Align, 0, 0, EltTy); |
| 396 | return BlockLiteralGeneric; |
| 397 | } |
| 398 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 399 | llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 400 | llvm::DIFile Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 401 | // Typedefs are derived from some other type. If we have a typedef of a |
| 402 | // typedef, make sure to emit the whole chain. |
| 403 | llvm::DIType Src = getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 404 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 405 | // We don't set size information, but do specify where the typedef was |
| 406 | // declared. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 407 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | d528905 | 2010-01-29 22:29:31 +0000 | [diff] [blame] | 408 | PresumedLoc PLoc = SM.getPresumedLoc(Ty->getDecl()->getLocation()); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 409 | unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 410 | |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 411 | llvm::DIDescriptor TyContext |
| 412 | = getContextDescriptor(dyn_cast<Decl>(Ty->getDecl()->getDeclContext()), |
| 413 | Unit); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 414 | llvm::DIType DbgTy = |
Devang Patel | d528905 | 2010-01-29 22:29:31 +0000 | [diff] [blame] | 415 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_typedef, |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 416 | TyContext, |
Devang Patel | d528905 | 2010-01-29 22:29:31 +0000 | [diff] [blame] | 417 | Ty->getDecl()->getName(), Unit, |
| 418 | Line, 0, 0, 0, 0, Src); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 419 | return DbgTy; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 422 | llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 423 | llvm::DIFile Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 424 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 425 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 426 | // Add the result type at least. |
| 427 | EltTys.push_back(getOrCreateType(Ty->getResultType(), Unit)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 428 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 429 | // Set up remainder of arguments if there is a prototype. |
| 430 | // FIXME: IF NOT, HOW IS THIS REPRESENTED? llvm-gcc doesn't represent '...'! |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 431 | if (const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(Ty)) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 432 | for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i) |
| 433 | EltTys.push_back(getOrCreateType(FTP->getArgType(i), Unit)); |
| 434 | } else { |
| 435 | // FIXME: Handle () case in C. llvm-gcc doesn't do it either. |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 438 | llvm::DIArray EltTypeArray = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 439 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 440 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 441 | llvm::DIType DbgTy = |
| 442 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 443 | Unit, "", llvm::DIFile(), |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 444 | 0, 0, 0, 0, 0, |
| 445 | llvm::DIType(), EltTypeArray); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 446 | return DbgTy; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 447 | } |
| 448 | |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 449 | /// CollectRecordFields - A helper function to collect debug info for |
| 450 | /// record fields. This is used while creating debug info entry for a Record. |
| 451 | void CGDebugInfo:: |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 452 | CollectRecordFields(const RecordDecl *RD, llvm::DIFile Unit, |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 453 | llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys) { |
| 454 | unsigned FieldNo = 0; |
| 455 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 456 | const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); |
| 457 | for (RecordDecl::field_iterator I = RD->field_begin(), |
| 458 | E = RD->field_end(); |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 459 | I != E; ++I, ++FieldNo) { |
| 460 | FieldDecl *Field = *I; |
| 461 | llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); |
| 462 | |
| 463 | llvm::StringRef FieldName = Field->getName(); |
| 464 | |
Devang Patel | 4835fdd | 2010-02-12 01:31:06 +0000 | [diff] [blame] | 465 | // Ignore unnamed fields. Do not ignore unnamed records. |
| 466 | if (FieldName.empty() && !isa<RecordType>(Field->getType())) |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 467 | continue; |
| 468 | |
| 469 | // Get the location for the field. |
| 470 | SourceLocation FieldDefLoc = Field->getLocation(); |
| 471 | PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc); |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 472 | llvm::DIFile FieldDefUnit; |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 473 | unsigned FieldLine = 0; |
| 474 | |
| 475 | if (!PLoc.isInvalid()) { |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 476 | FieldDefUnit = getOrCreateFile(FieldDefLoc); |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 477 | FieldLine = PLoc.getLine(); |
| 478 | } |
| 479 | |
| 480 | QualType FType = Field->getType(); |
| 481 | uint64_t FieldSize = 0; |
| 482 | unsigned FieldAlign = 0; |
| 483 | if (!FType->isIncompleteArrayType()) { |
| 484 | |
| 485 | // Bit size, align and offset of the type. |
| 486 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 487 | Expr *BitWidth = Field->getBitWidth(); |
| 488 | if (BitWidth) |
| 489 | FieldSize = BitWidth->EvaluateAsInt(CGM.getContext()).getZExtValue(); |
| 490 | |
| 491 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
| 492 | } |
| 493 | |
| 494 | uint64_t FieldOffset = RL.getFieldOffset(FieldNo); |
| 495 | |
| 496 | // Create a DW_TAG_member node to remember the offset of this field in the |
| 497 | // struct. FIXME: This is an absolutely insane way to capture this |
| 498 | // information. When we gut debug info, this should be fixed. |
| 499 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 500 | FieldName, FieldDefUnit, |
| 501 | FieldLine, FieldSize, FieldAlign, |
| 502 | FieldOffset, 0, FieldTy); |
| 503 | EltTys.push_back(FieldTy); |
| 504 | } |
| 505 | } |
| 506 | |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 507 | /// getOrCreateMethodType - CXXMethodDecl's type is a FunctionType. This |
| 508 | /// function type is not updated to include implicit "this" pointer. Use this |
| 509 | /// routine to get a method type which includes "this" pointer. |
| 510 | llvm::DIType |
| 511 | CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 512 | llvm::DIFile Unit) { |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 513 | llvm::DIType FnTy = getOrCreateType(Method->getType(), Unit); |
Devang Patel | d774d1e | 2010-01-28 21:43:50 +0000 | [diff] [blame] | 514 | |
| 515 | // Static methods do not need "this" pointer argument. |
| 516 | if (Method->isStatic()) |
| 517 | return FnTy; |
| 518 | |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 519 | // Add "this" pointer. |
| 520 | |
| 521 | llvm::DIArray Args = llvm::DICompositeType(FnTy.getNode()).getTypeArray(); |
| 522 | assert (Args.getNumElements() && "Invalid number of arguments!"); |
| 523 | |
| 524 | llvm::SmallVector<llvm::DIDescriptor, 16> Elts; |
| 525 | |
| 526 | // First element is always return type. For 'void' functions it is NULL. |
| 527 | Elts.push_back(Args.getElement(0)); |
| 528 | |
| 529 | // "this" pointer is always first argument. |
| 530 | ASTContext &Context = CGM.getContext(); |
| 531 | QualType ThisPtr = |
| 532 | Context.getPointerType(Context.getTagDeclType(Method->getParent())); |
Devang Patel | 337472d | 2010-02-09 17:57:50 +0000 | [diff] [blame] | 533 | llvm::DIType ThisPtrType = |
| 534 | DebugFactory.CreateArtificialType(getOrCreateType(ThisPtr, Unit)); |
| 535 | TypeCache[ThisPtr.getAsOpaquePtr()] = ThisPtrType.getNode(); |
| 536 | Elts.push_back(ThisPtrType); |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 537 | |
| 538 | // Copy rest of the arguments. |
| 539 | for (unsigned i = 1, e = Args.getNumElements(); i != e; ++i) |
| 540 | Elts.push_back(Args.getElement(i)); |
| 541 | |
| 542 | llvm::DIArray EltTypeArray = |
| 543 | DebugFactory.GetOrCreateArray(Elts.data(), Elts.size()); |
| 544 | |
| 545 | return |
| 546 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 547 | Unit, "", llvm::DIFile(), |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 548 | 0, 0, 0, 0, 0, |
| 549 | llvm::DIType(), EltTypeArray); |
| 550 | } |
| 551 | |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 552 | /// CreateCXXMemberFunction - A helper function to create a DISubprogram for |
| 553 | /// a single member function GlobalDecl. |
| 554 | llvm::DISubprogram |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 555 | CGDebugInfo::CreateCXXMemberFunction(const CXXMethodDecl *Method, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 556 | llvm::DIFile Unit, |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 557 | llvm::DICompositeType &RecordTy) { |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 558 | bool IsCtorOrDtor = |
| 559 | isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method); |
| 560 | |
| 561 | llvm::StringRef MethodName = getFunctionName(Method); |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 562 | llvm::StringRef MethodLinkageName; |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 563 | llvm::DIType MethodTy = getOrCreateMethodType(Method, Unit); |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 564 | |
| 565 | // Since a single ctor/dtor corresponds to multiple functions, it doesn't |
| 566 | // make sense to give a single ctor/dtor a linkage name. |
| 567 | if (!IsCtorOrDtor) |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 568 | MethodLinkageName = CGM.getMangledName(Method); |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 569 | |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 570 | SourceManager &SM = CGM.getContext().getSourceManager(); |
| 571 | |
| 572 | // Get the location for the method. |
| 573 | SourceLocation MethodDefLoc = Method->getLocation(); |
| 574 | PresumedLoc PLoc = SM.getPresumedLoc(MethodDefLoc); |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 575 | llvm::DIFile MethodDefUnit; |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 576 | unsigned MethodLine = 0; |
| 577 | |
| 578 | if (!PLoc.isInvalid()) { |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 579 | MethodDefUnit = getOrCreateFile(MethodDefLoc); |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 580 | MethodLine = PLoc.getLine(); |
| 581 | } |
| 582 | |
| 583 | // Collect virtual method info. |
| 584 | llvm::DIType ContainingType; |
| 585 | unsigned Virtuality = 0; |
| 586 | unsigned VIndex = 0; |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 587 | |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 588 | if (Method->isVirtual()) { |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 589 | if (Method->isPure()) |
| 590 | Virtuality = llvm::dwarf::DW_VIRTUALITY_pure_virtual; |
| 591 | else |
| 592 | Virtuality = llvm::dwarf::DW_VIRTUALITY_virtual; |
| 593 | |
| 594 | // It doesn't make sense to give a virtual destructor a vtable index, |
| 595 | // since a single destructor has two entries in the vtable. |
| 596 | if (!isa<CXXDestructorDecl>(Method)) |
| 597 | VIndex = CGM.getVtableInfo().getMethodVtableIndex(Method); |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 598 | ContainingType = RecordTy; |
| 599 | } |
| 600 | |
| 601 | llvm::DISubprogram SP = |
| 602 | DebugFactory.CreateSubprogram(RecordTy , MethodName, MethodName, |
| 603 | MethodLinkageName, |
| 604 | MethodDefUnit, MethodLine, |
| 605 | MethodTy, /*isLocalToUnit=*/false, |
| 606 | Method->isThisDeclarationADefinition(), |
| 607 | Virtuality, VIndex, ContainingType); |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 608 | |
| 609 | // Don't cache ctors or dtors since we have to emit multiple functions for |
| 610 | // a single ctor or dtor. |
| 611 | if (!IsCtorOrDtor && Method->isThisDeclarationADefinition()) |
| 612 | SPCache[Method] = llvm::WeakVH(SP.getNode()); |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 613 | |
| 614 | return SP; |
| 615 | } |
| 616 | |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 617 | /// CollectCXXMemberFunctions - A helper function to collect debug info for |
| 618 | /// C++ member functions.This is used while creating debug info entry for |
| 619 | /// a Record. |
| 620 | void CGDebugInfo:: |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 621 | CollectCXXMemberFunctions(const CXXRecordDecl *RD, llvm::DIFile Unit, |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 622 | llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys, |
| 623 | llvm::DICompositeType &RecordTy) { |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 624 | for(CXXRecordDecl::method_iterator I = RD->method_begin(), |
| 625 | E = RD->method_end(); I != E; ++I) { |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 626 | const CXXMethodDecl *Method = *I; |
Anders Carlsson | bea9b23 | 2010-01-26 04:40:11 +0000 | [diff] [blame] | 627 | |
Devang Patel | d5322da | 2010-02-09 19:09:28 +0000 | [diff] [blame] | 628 | if (Method->isImplicit() && !Method->isUsed()) |
Anders Carlsson | bea9b23 | 2010-01-26 04:40:11 +0000 | [diff] [blame] | 629 | continue; |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 630 | |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 631 | EltTys.push_back(CreateCXXMemberFunction(Method, Unit, RecordTy)); |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 635 | /// CollectCXXBases - A helper function to collect debug info for |
| 636 | /// C++ base classes. This is used while creating debug info entry for |
| 637 | /// a Record. |
| 638 | void CGDebugInfo:: |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 639 | CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile Unit, |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 640 | llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys, |
| 641 | llvm::DICompositeType &RecordTy) { |
| 642 | |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 643 | const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); |
| 644 | for (CXXRecordDecl::base_class_const_iterator BI = RD->bases_begin(), |
| 645 | BE = RD->bases_end(); BI != BE; ++BI) { |
Devang Patel | ca7daed | 2010-01-28 21:54:15 +0000 | [diff] [blame] | 646 | unsigned BFlags = 0; |
| 647 | uint64_t BaseOffset; |
| 648 | |
| 649 | const CXXRecordDecl *Base = |
| 650 | cast<CXXRecordDecl>(BI->getType()->getAs<RecordType>()->getDecl()); |
| 651 | |
| 652 | if (BI->isVirtual()) { |
Devang Patel | d5322da | 2010-02-09 19:09:28 +0000 | [diff] [blame] | 653 | // virtual base offset index is -ve. The code generator emits dwarf |
| 654 | // expression where it expects +ve number. |
| 655 | BaseOffset = 0 - CGM.getVtableInfo().getVirtualBaseOffsetIndex(RD, Base); |
Devang Patel | ca7daed | 2010-01-28 21:54:15 +0000 | [diff] [blame] | 656 | BFlags = llvm::DIType::FlagVirtual; |
| 657 | } else |
| 658 | BaseOffset = RL.getBaseClassOffset(Base); |
| 659 | |
| 660 | AccessSpecifier Access = BI->getAccessSpecifier(); |
| 661 | if (Access == clang::AS_private) |
| 662 | BFlags |= llvm::DIType::FlagPrivate; |
| 663 | else if (Access == clang::AS_protected) |
| 664 | BFlags |= llvm::DIType::FlagProtected; |
| 665 | |
| 666 | llvm::DIType DTy = |
| 667 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance, |
| 668 | RecordTy, llvm::StringRef(), |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 669 | llvm::DIFile(), 0, 0, 0, |
Devang Patel | ca7daed | 2010-01-28 21:54:15 +0000 | [diff] [blame] | 670 | BaseOffset, BFlags, |
| 671 | getOrCreateType(BI->getType(), |
| 672 | Unit)); |
| 673 | EltTys.push_back(DTy); |
| 674 | } |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 677 | /// getOrCreateVTablePtrType - Return debug info descriptor for vtable. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 678 | llvm::DIType CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile Unit) { |
Devang Patel | 0804e6e | 2010-03-08 20:53:17 +0000 | [diff] [blame] | 679 | if (VTablePtrType.isValid()) |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 680 | return VTablePtrType; |
| 681 | |
| 682 | ASTContext &Context = CGM.getContext(); |
| 683 | |
| 684 | /* Function type */ |
| 685 | llvm::SmallVector<llvm::DIDescriptor, 16> STys; |
| 686 | STys.push_back(getOrCreateType(Context.IntTy, Unit)); |
| 687 | llvm::DIArray SElements = |
| 688 | DebugFactory.GetOrCreateArray(STys.data(), STys.size()); |
| 689 | llvm::DIType SubTy = |
| 690 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 691 | Unit, "", llvm::DIFile(), |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 692 | 0, 0, 0, 0, 0, llvm::DIType(), SElements); |
| 693 | |
| 694 | unsigned Size = Context.getTypeSize(Context.VoidPtrTy); |
| 695 | llvm::DIType vtbl_ptr_type |
| 696 | = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 697 | Unit, "__vtbl_ptr_type", llvm::DIFile(), |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 698 | 0, Size, 0, 0, 0, SubTy); |
| 699 | |
| 700 | VTablePtrType = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 701 | Unit, "", llvm::DIFile(), |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 702 | 0, Size, 0, 0, 0, vtbl_ptr_type); |
| 703 | return VTablePtrType; |
| 704 | } |
| 705 | |
| 706 | /// getVtableName - Get vtable name for the given Class. |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 707 | llvm::StringRef CGDebugInfo::getVtableName(const CXXRecordDecl *RD) { |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 708 | // Otherwise construct gdb compatible name name. |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 709 | std::string Name = "_vptr$" + RD->getNameAsString(); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 710 | |
| 711 | // Copy this name on the side and use its reference. |
Devang Patel | 89f05f8 | 2010-01-28 18:21:00 +0000 | [diff] [blame] | 712 | char *StrPtr = DebugInfoNames.Allocate<char>(Name.length()); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 713 | memcpy(StrPtr, Name.data(), Name.length()); |
| 714 | return llvm::StringRef(StrPtr, Name.length()); |
| 715 | } |
| 716 | |
| 717 | |
| 718 | /// CollectVtableInfo - If the C++ class has vtable info then insert appropriate |
| 719 | /// debug info entry in EltTys vector. |
| 720 | void CGDebugInfo:: |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 721 | CollectVtableInfo(const CXXRecordDecl *RD, llvm::DIFile Unit, |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 722 | llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys) { |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 723 | const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 724 | |
| 725 | // If there is a primary base then it will hold vtable info. |
| 726 | if (RL.getPrimaryBase()) |
| 727 | return; |
| 728 | |
| 729 | // If this class is not dynamic then there is not any vtable info to collect. |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 730 | if (!RD->isDynamicClass()) |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 731 | return; |
| 732 | |
| 733 | unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy); |
| 734 | llvm::DIType VPTR |
| 735 | = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 736 | getVtableName(RD), llvm::DIFile(), |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 737 | 0, Size, 0, 0, 0, |
| 738 | getOrCreateVTablePtrType(Unit)); |
| 739 | EltTys.push_back(VPTR); |
| 740 | } |
| 741 | |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 742 | /// CreateType - get structure or union type. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 743 | llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 744 | llvm::DIFile Unit) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 745 | RecordDecl *RD = Ty->getDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 746 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 747 | unsigned Tag; |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 748 | if (RD->isStruct()) |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 749 | Tag = llvm::dwarf::DW_TAG_structure_type; |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 750 | else if (RD->isUnion()) |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 751 | Tag = llvm::dwarf::DW_TAG_union_type; |
| 752 | else { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 753 | assert(RD->isClass() && "Unknown RecordType!"); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 754 | Tag = llvm::dwarf::DW_TAG_class_type; |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 755 | } |
| 756 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 757 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 758 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 759 | // Get overall information about the record type for the debug info. |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 760 | PresumedLoc PLoc = SM.getPresumedLoc(RD->getLocation()); |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 761 | llvm::DIFile DefUnit; |
Chris Lattner | d37d9b5 | 2009-05-05 05:16:17 +0000 | [diff] [blame] | 762 | unsigned Line = 0; |
| 763 | if (!PLoc.isInvalid()) { |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 764 | DefUnit = getOrCreateFile(RD->getLocation()); |
Chris Lattner | d37d9b5 | 2009-05-05 05:16:17 +0000 | [diff] [blame] | 765 | Line = PLoc.getLine(); |
| 766 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 767 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 768 | // Records and classes and unions can all be recursive. To handle them, we |
| 769 | // first generate a debug descriptor for the struct as a forward declaration. |
| 770 | // Then (if it is a definition) we go through and get debug info for all of |
| 771 | // its members. Finally, we create a descriptor for the complete type (which |
| 772 | // may refer to the forward decl if the struct is recursive) and replace all |
| 773 | // uses of the forward declaration with the final definition. |
Devang Patel | d0f251b | 2010-01-20 23:56:40 +0000 | [diff] [blame] | 774 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 775 | // A RD->getName() is not unique. However, the debug info descriptors |
Devang Patel | ce78c97 | 2010-02-01 22:51:29 +0000 | [diff] [blame] | 776 | // are uniqued so use type name to ensure uniquness. |
Devang Patel | 7573f8b | 2010-03-09 21:32:27 +0000 | [diff] [blame^] | 777 | char *FwdDeclName = (char *)alloca(65); |
| 778 | sprintf(FwdDeclName, "fwd.type.%d", FwdDeclCount++); |
Devang Patel | 411894b | 2010-02-01 22:40:08 +0000 | [diff] [blame] | 779 | llvm::DIDescriptor FDContext = |
| 780 | getContextDescriptor(dyn_cast<Decl>(RD->getDeclContext()), Unit); |
Devang Patel | 0ce73f6 | 2009-07-22 18:57:00 +0000 | [diff] [blame] | 781 | llvm::DICompositeType FwdDecl = |
Devang Patel | 7573f8b | 2010-03-09 21:32:27 +0000 | [diff] [blame^] | 782 | DebugFactory.CreateCompositeType(Tag, FDContext, FwdDeclName, |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 783 | DefUnit, Line, 0, 0, 0, 0, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 784 | llvm::DIType(), llvm::DIArray()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 785 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 786 | // If this is just a forward declaration, return it. |
Douglas Gregor | 952b017 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 787 | if (!RD->getDefinition()) |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 788 | return FwdDecl; |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 789 | |
Eli Friedman | 14d6365 | 2009-11-16 21:04:30 +0000 | [diff] [blame] | 790 | llvm::TrackingVH<llvm::MDNode> FwdDeclNode = FwdDecl.getNode(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 791 | // Otherwise, insert it into the TypeCache so that recursive uses will find |
| 792 | // it. |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 793 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 794 | |
| 795 | // Convert all the elements. |
| 796 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
| 797 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 798 | const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD); |
Devang Patel | 3064afe | 2010-01-28 21:41:35 +0000 | [diff] [blame] | 799 | if (CXXDecl) { |
| 800 | CollectCXXBases(CXXDecl, Unit, EltTys, FwdDecl); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 801 | CollectVtableInfo(CXXDecl, Unit, EltTys); |
Devang Patel | 3064afe | 2010-01-28 21:41:35 +0000 | [diff] [blame] | 802 | } |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 803 | CollectRecordFields(RD, Unit, EltTys); |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 804 | llvm::MDNode *ContainingType = NULL; |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 805 | if (CXXDecl) { |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 806 | CollectCXXMemberFunctions(CXXDecl, Unit, EltTys, FwdDecl); |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 807 | |
| 808 | // A class's primary base or the class itself contains the vtable. |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 809 | const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 810 | if (const CXXRecordDecl *PBase = RL.getPrimaryBase()) |
| 811 | ContainingType = |
| 812 | getOrCreateType(QualType(PBase->getTypeForDecl(), 0), Unit).getNode(); |
| 813 | else if (CXXDecl->isDynamicClass()) |
| 814 | ContainingType = FwdDecl.getNode(); |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 815 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 816 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 817 | llvm::DIArray Elements = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 818 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 819 | |
| 820 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 821 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 822 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 823 | |
Devang Patel | 411894b | 2010-02-01 22:40:08 +0000 | [diff] [blame] | 824 | llvm::DIDescriptor RDContext = |
| 825 | getContextDescriptor(dyn_cast<Decl>(RD->getDeclContext()), Unit); |
Devang Patel | 0ce73f6 | 2009-07-22 18:57:00 +0000 | [diff] [blame] | 826 | llvm::DICompositeType RealDecl = |
Devang Patel | 411894b | 2010-02-01 22:40:08 +0000 | [diff] [blame] | 827 | DebugFactory.CreateCompositeType(Tag, RDContext, |
| 828 | RD->getName(), |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 829 | DefUnit, Line, Size, Align, 0, 0, |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 830 | llvm::DIType(), Elements, |
| 831 | 0, ContainingType); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 832 | |
| 833 | // Now that we have a real decl for the struct, replace anything using the |
| 834 | // old decl with the new one. This will recursively update the debug info. |
Eli Friedman | 14d6365 | 2009-11-16 21:04:30 +0000 | [diff] [blame] | 835 | llvm::DIDerivedType(FwdDeclNode).replaceAllUsesWith(RealDecl); |
Devang Patel | fe09eab | 2009-07-13 17:03:14 +0000 | [diff] [blame] | 836 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 837 | return RealDecl; |
| 838 | } |
| 839 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 840 | /// CreateType - get objective-c interface type. |
| 841 | llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 842 | llvm::DIFile Unit) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 843 | ObjCInterfaceDecl *ID = Ty->getDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 844 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 845 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 846 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 847 | |
| 848 | // Get overall information about the record type for the debug info. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 849 | llvm::DIFile DefUnit = getOrCreateFile(ID->getLocation()); |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 850 | PresumedLoc PLoc = SM.getPresumedLoc(ID->getLocation()); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 851 | unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
| 852 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 853 | |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 854 | unsigned RuntimeLang = TheCU.getLanguage(); |
Chris Lattner | ac7c814 | 2009-05-02 01:13:16 +0000 | [diff] [blame] | 855 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 856 | // To handle recursive interface, we |
| 857 | // first generate a debug descriptor for the struct as a forward declaration. |
| 858 | // Then (if it is a definition) we go through and get debug info for all of |
| 859 | // its members. Finally, we create a descriptor for the complete type (which |
| 860 | // may refer to the forward decl if the struct is recursive) and replace all |
| 861 | // uses of the forward declaration with the final definition. |
Devang Patel | 6c1fddf | 2009-07-27 18:42:03 +0000 | [diff] [blame] | 862 | llvm::DICompositeType FwdDecl = |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 863 | DebugFactory.CreateCompositeType(Tag, Unit, ID->getName(), |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 864 | DefUnit, Line, 0, 0, 0, 0, |
Chris Lattner | ac7c814 | 2009-05-02 01:13:16 +0000 | [diff] [blame] | 865 | llvm::DIType(), llvm::DIArray(), |
| 866 | RuntimeLang); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 867 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 868 | // If this is just a forward declaration, return it. |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 869 | if (ID->isForwardDecl()) |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 870 | return FwdDecl; |
| 871 | |
Devang Patel | ffffb03 | 2009-11-16 20:09:38 +0000 | [diff] [blame] | 872 | llvm::TrackingVH<llvm::MDNode> FwdDeclNode = FwdDecl.getNode(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 873 | // Otherwise, insert it into the TypeCache so that recursive uses will find |
| 874 | // it. |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 875 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 876 | |
| 877 | // Convert all the elements. |
| 878 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
| 879 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 880 | ObjCInterfaceDecl *SClass = ID->getSuperClass(); |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 881 | if (SClass) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 882 | llvm::DIType SClassTy = |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 883 | getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 884 | llvm::DIType InhTag = |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 885 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 886 | Unit, "", llvm::DIFile(), 0, 0, 0, |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 887 | 0 /* offset */, 0, SClassTy); |
| 888 | EltTys.push_back(InhTag); |
| 889 | } |
| 890 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 891 | const ASTRecordLayout &RL = CGM.getContext().getASTObjCInterfaceLayout(ID); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 892 | |
| 893 | unsigned FieldNo = 0; |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 894 | for (ObjCInterfaceDecl::ivar_iterator I = ID->ivar_begin(), |
| 895 | E = ID->ivar_end(); I != E; ++I, ++FieldNo) { |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 896 | ObjCIvarDecl *Field = *I; |
| 897 | llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); |
| 898 | |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 899 | llvm::StringRef FieldName = Field->getName(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 900 | |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 901 | // Ignore unnamed fields. |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 902 | if (FieldName.empty()) |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 903 | continue; |
| 904 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 905 | // Get the location for the field. |
| 906 | SourceLocation FieldDefLoc = Field->getLocation(); |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 907 | llvm::DIFile FieldDefUnit = getOrCreateFile(FieldDefLoc); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 908 | PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc); |
| 909 | unsigned FieldLine = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
| 910 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 911 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 912 | QualType FType = Field->getType(); |
| 913 | uint64_t FieldSize = 0; |
| 914 | unsigned FieldAlign = 0; |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 915 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 916 | if (!FType->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 917 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 918 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 919 | FieldSize = CGM.getContext().getTypeSize(FType); |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 920 | Expr *BitWidth = Field->getBitWidth(); |
| 921 | if (BitWidth) |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 922 | FieldSize = BitWidth->EvaluateAsInt(CGM.getContext()).getZExtValue(); |
Eli Friedman | 9a901bb | 2009-04-26 19:19:15 +0000 | [diff] [blame] | 923 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 924 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 925 | } |
| 926 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 927 | uint64_t FieldOffset = RL.getFieldOffset(FieldNo); |
| 928 | |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 929 | unsigned Flags = 0; |
| 930 | if (Field->getAccessControl() == ObjCIvarDecl::Protected) |
| 931 | Flags = llvm::DIType::FlagProtected; |
| 932 | else if (Field->getAccessControl() == ObjCIvarDecl::Private) |
| 933 | Flags = llvm::DIType::FlagPrivate; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 934 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 935 | // Create a DW_TAG_member node to remember the offset of this field in the |
| 936 | // struct. FIXME: This is an absolutely insane way to capture this |
| 937 | // information. When we gut debug info, this should be fixed. |
| 938 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 939 | FieldName, FieldDefUnit, |
| 940 | FieldLine, FieldSize, FieldAlign, |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 941 | FieldOffset, Flags, FieldTy); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 942 | EltTys.push_back(FieldTy); |
| 943 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 944 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 945 | llvm::DIArray Elements = |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 946 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 947 | |
| 948 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 949 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 950 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 951 | |
Devang Patel | 6c1fddf | 2009-07-27 18:42:03 +0000 | [diff] [blame] | 952 | llvm::DICompositeType RealDecl = |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 953 | DebugFactory.CreateCompositeType(Tag, Unit, ID->getName(), DefUnit, |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 954 | Line, Size, Align, 0, 0, llvm::DIType(), |
| 955 | Elements, RuntimeLang); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 956 | |
| 957 | // Now that we have a real decl for the struct, replace anything using the |
| 958 | // old decl with the new one. This will recursively update the debug info. |
Devang Patel | ffffb03 | 2009-11-16 20:09:38 +0000 | [diff] [blame] | 959 | llvm::DIDerivedType(FwdDeclNode).replaceAllUsesWith(RealDecl); |
Devang Patel | fe09eab | 2009-07-13 17:03:14 +0000 | [diff] [blame] | 960 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 961 | return RealDecl; |
| 962 | } |
| 963 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 964 | llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 965 | llvm::DIFile Unit) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 966 | EnumDecl *ED = Ty->getDecl(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 967 | |
| 968 | llvm::SmallVector<llvm::DIDescriptor, 32> Enumerators; |
| 969 | |
| 970 | // Create DIEnumerator elements for each enumerator. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 971 | for (EnumDecl::enumerator_iterator |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 972 | Enum = ED->enumerator_begin(), EnumEnd = ED->enumerator_end(); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 973 | Enum != EnumEnd; ++Enum) { |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 974 | Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getName(), |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 975 | Enum->getInitVal().getZExtValue())); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 976 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 977 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 978 | // Return a CompositeType for the enum itself. |
| 979 | llvm::DIArray EltArray = |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 980 | DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 981 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 982 | SourceLocation DefLoc = ED->getLocation(); |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 983 | llvm::DIFile DefUnit = getOrCreateFile(DefLoc); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 984 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 985 | PresumedLoc PLoc = SM.getPresumedLoc(DefLoc); |
| 986 | unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
| 987 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 988 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 989 | // Size and align of the type. |
Eli Friedman | 3189e4b | 2009-05-04 04:39:55 +0000 | [diff] [blame] | 990 | uint64_t Size = 0; |
| 991 | unsigned Align = 0; |
| 992 | if (!Ty->isIncompleteType()) { |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 993 | Size = CGM.getContext().getTypeSize(Ty); |
| 994 | Align = CGM.getContext().getTypeAlign(Ty); |
Eli Friedman | 3189e4b | 2009-05-04 04:39:55 +0000 | [diff] [blame] | 995 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 996 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 997 | llvm::DIType DbgTy = |
| 998 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type, |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 999 | Unit, ED->getName(), DefUnit, Line, |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1000 | Size, Align, 0, 0, |
| 1001 | llvm::DIType(), EltArray); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1002 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | llvm::DIType CGDebugInfo::CreateType(const TagType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1006 | llvm::DIFile Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1007 | if (const RecordType *RT = dyn_cast<RecordType>(Ty)) |
| 1008 | return CreateType(RT, Unit); |
| 1009 | else if (const EnumType *ET = dyn_cast<EnumType>(Ty)) |
| 1010 | return CreateType(ET, Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1011 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1012 | return llvm::DIType(); |
| 1013 | } |
| 1014 | |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1015 | llvm::DIType CGDebugInfo::CreateType(const VectorType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1016 | llvm::DIFile Unit) { |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1017 | llvm::DIType ElementTy = getOrCreateType(Ty->getElementType(), Unit); |
| 1018 | uint64_t NumElems = Ty->getNumElements(); |
| 1019 | if (NumElems > 0) |
| 1020 | --NumElems; |
| 1021 | llvm::SmallVector<llvm::DIDescriptor, 8> Subscripts; |
| 1022 | Subscripts.push_back(DebugFactory.GetOrCreateSubrange(0, NumElems)); |
| 1023 | |
| 1024 | llvm::DIArray SubscriptArray = |
| 1025 | DebugFactory.GetOrCreateArray(Subscripts.data(), Subscripts.size()); |
| 1026 | |
| 1027 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 1028 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
| 1029 | |
| 1030 | return |
| 1031 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_vector_type, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1032 | Unit, "", llvm::DIFile(), |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1033 | 0, Size, Align, 0, 0, |
| 1034 | ElementTy, SubscriptArray); |
| 1035 | } |
| 1036 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1037 | llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1038 | llvm::DIFile Unit) { |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1039 | uint64_t Size; |
| 1040 | uint64_t Align; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1041 | |
| 1042 | |
Nuno Lopes | 010d514 | 2009-01-28 00:35:17 +0000 | [diff] [blame] | 1043 | // FIXME: make getTypeAlign() aware of VLAs and incomplete array types |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1044 | if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(Ty)) { |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1045 | Size = 0; |
| 1046 | Align = |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1047 | CGM.getContext().getTypeAlign(CGM.getContext().getBaseElementType(VAT)); |
Nuno Lopes | 010d514 | 2009-01-28 00:35:17 +0000 | [diff] [blame] | 1048 | } else if (Ty->isIncompleteArrayType()) { |
| 1049 | Size = 0; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1050 | Align = CGM.getContext().getTypeAlign(Ty->getElementType()); |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1051 | } else { |
| 1052 | // Size and align of the whole array, not the element type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1053 | Size = CGM.getContext().getTypeSize(Ty); |
| 1054 | Align = CGM.getContext().getTypeAlign(Ty); |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1055 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1056 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1057 | // Add the dimensions of the array. FIXME: This loses CV qualifiers from |
| 1058 | // interior arrays, do we care? Why aren't nested arrays represented the |
| 1059 | // obvious/recursive way? |
| 1060 | llvm::SmallVector<llvm::DIDescriptor, 8> Subscripts; |
| 1061 | QualType EltTy(Ty, 0); |
| 1062 | while ((Ty = dyn_cast<ArrayType>(EltTy))) { |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 1063 | uint64_t Upper = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1064 | if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty)) |
Devang Patel | 5a6bfe3 | 2009-08-14 20:57:45 +0000 | [diff] [blame] | 1065 | if (CAT->getSize().getZExtValue()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1066 | Upper = CAT->getSize().getZExtValue() - 1; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1067 | // FIXME: Verify this is right for VLAs. |
| 1068 | Subscripts.push_back(DebugFactory.GetOrCreateSubrange(0, Upper)); |
| 1069 | EltTy = Ty->getElementType(); |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 1070 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1071 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1072 | llvm::DIArray SubscriptArray = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 1073 | DebugFactory.GetOrCreateArray(Subscripts.data(), Subscripts.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1074 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1075 | llvm::DIType DbgTy = |
| 1076 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_array_type, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1077 | Unit, "", llvm::DIFile(), |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1078 | 0, Size, Align, 0, 0, |
| 1079 | getOrCreateType(EltTy, Unit), |
| 1080 | SubscriptArray); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1081 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 1084 | llvm::DIType CGDebugInfo::CreateType(const LValueReferenceType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1085 | llvm::DIFile Unit) { |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 1086 | return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, |
| 1087 | Ty, Ty->getPointeeType(), Unit); |
| 1088 | } |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1089 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1090 | llvm::DIType CGDebugInfo::CreateType(const MemberPointerType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1091 | llvm::DIFile U) { |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1092 | QualType PointerDiffTy = CGM.getContext().getPointerDiffType(); |
| 1093 | llvm::DIType PointerDiffDITy = getOrCreateType(PointerDiffTy, U); |
| 1094 | |
| 1095 | if (!Ty->getPointeeType()->isFunctionType()) { |
| 1096 | // We have a data member pointer type. |
| 1097 | return PointerDiffDITy; |
| 1098 | } |
| 1099 | |
| 1100 | // We have a member function pointer type. Treat it as a struct with two |
| 1101 | // ptrdiff_t members. |
| 1102 | std::pair<uint64_t, unsigned> Info = CGM.getContext().getTypeInfo(Ty); |
| 1103 | |
| 1104 | uint64_t FieldOffset = 0; |
| 1105 | llvm::DIDescriptor ElementTypes[2]; |
| 1106 | |
| 1107 | // FIXME: This should probably be a function type instead. |
| 1108 | ElementTypes[0] = |
| 1109 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, U, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1110 | "ptr", llvm::DIFile(), 0, |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1111 | Info.first, Info.second, FieldOffset, 0, |
| 1112 | PointerDiffDITy); |
| 1113 | FieldOffset += Info.first; |
| 1114 | |
| 1115 | ElementTypes[1] = |
| 1116 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, U, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1117 | "ptr", llvm::DIFile(), 0, |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1118 | Info.first, Info.second, FieldOffset, 0, |
| 1119 | PointerDiffDITy); |
| 1120 | |
| 1121 | llvm::DIArray Elements = |
| 1122 | DebugFactory.GetOrCreateArray(&ElementTypes[0], |
| 1123 | llvm::array_lengthof(ElementTypes)); |
| 1124 | |
| 1125 | return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_structure_type, |
| 1126 | U, llvm::StringRef("test"), |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1127 | llvm::DIFile(), 0, FieldOffset, |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1128 | 0, 0, 0, llvm::DIType(), Elements); |
| 1129 | } |
| 1130 | |
Douglas Gregor | 840943d | 2009-12-21 20:18:30 +0000 | [diff] [blame] | 1131 | static QualType UnwrapTypeForDebugInfo(QualType T) { |
| 1132 | do { |
| 1133 | QualType LastT = T; |
| 1134 | switch (T->getTypeClass()) { |
| 1135 | default: |
| 1136 | return T; |
| 1137 | case Type::TemplateSpecialization: |
| 1138 | T = cast<TemplateSpecializationType>(T)->desugar(); |
| 1139 | break; |
| 1140 | case Type::TypeOfExpr: { |
| 1141 | TypeOfExprType *Ty = cast<TypeOfExprType>(T); |
| 1142 | T = Ty->getUnderlyingExpr()->getType(); |
| 1143 | break; |
| 1144 | } |
| 1145 | case Type::TypeOf: |
| 1146 | T = cast<TypeOfType>(T)->getUnderlyingType(); |
| 1147 | break; |
| 1148 | case Type::Decltype: |
| 1149 | T = cast<DecltypeType>(T)->getUnderlyingType(); |
| 1150 | break; |
| 1151 | case Type::QualifiedName: |
| 1152 | T = cast<QualifiedNameType>(T)->getNamedType(); |
| 1153 | break; |
| 1154 | case Type::SubstTemplateTypeParm: |
| 1155 | T = cast<SubstTemplateTypeParmType>(T)->getReplacementType(); |
| 1156 | break; |
| 1157 | case Type::Elaborated: |
| 1158 | T = cast<ElaboratedType>(T)->getUnderlyingType(); |
| 1159 | break; |
| 1160 | } |
| 1161 | |
| 1162 | assert(T != LastT && "Type unwrapping failed to unwrap!"); |
| 1163 | if (T == LastT) |
| 1164 | return T; |
| 1165 | } while (true); |
| 1166 | |
| 1167 | return T; |
Anders Carlsson | 5b6117a | 2009-11-14 21:08:12 +0000 | [diff] [blame] | 1168 | } |
| 1169 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1170 | /// getOrCreateType - Get the type from the cache or create a new |
| 1171 | /// one if necessary. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1172 | llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1173 | llvm::DIFile Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1174 | if (Ty.isNull()) |
| 1175 | return llvm::DIType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1176 | |
Douglas Gregor | 840943d | 2009-12-21 20:18:30 +0000 | [diff] [blame] | 1177 | // Unwrap the type as needed for debug information. |
| 1178 | Ty = UnwrapTypeForDebugInfo(Ty); |
Anders Carlsson | 5b6117a | 2009-11-14 21:08:12 +0000 | [diff] [blame] | 1179 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 1180 | // Check for existing entry. |
Daniel Dunbar | 65f13c3 | 2009-09-19 20:17:48 +0000 | [diff] [blame] | 1181 | std::map<void *, llvm::WeakVH>::iterator it = |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 1182 | TypeCache.find(Ty.getAsOpaquePtr()); |
Daniel Dunbar | 65f13c3 | 2009-09-19 20:17:48 +0000 | [diff] [blame] | 1183 | if (it != TypeCache.end()) { |
| 1184 | // Verify that the debug info still exists. |
| 1185 | if (&*it->second) |
| 1186 | return llvm::DIType(cast<llvm::MDNode>(it->second)); |
| 1187 | } |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1188 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 1189 | // Otherwise create the type. |
| 1190 | llvm::DIType Res = CreateTypeNode(Ty, Unit); |
Anders Carlsson | 0dd57c6 | 2009-11-14 20:52:05 +0000 | [diff] [blame] | 1191 | |
| 1192 | // And update the type cache. |
| 1193 | TypeCache[Ty.getAsOpaquePtr()] = Res.getNode(); |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 1194 | return Res; |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
Anders Carlsson | 0dd57c6 | 2009-11-14 20:52:05 +0000 | [diff] [blame] | 1197 | /// CreateTypeNode - Create a new debug type node. |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1198 | llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1199 | llvm::DIFile Unit) { |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 1200 | // Handle qualifiers, which recursively handles what they refer to. |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 1201 | if (Ty.hasLocalQualifiers()) |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 1202 | return CreateQualifiedType(Ty, Unit); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1203 | |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1204 | const char *Diag = 0; |
| 1205 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1206 | // Work out details of type. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1207 | switch (Ty->getTypeClass()) { |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1208 | #define TYPE(Class, Base) |
| 1209 | #define ABSTRACT_TYPE(Class, Base) |
| 1210 | #define NON_CANONICAL_TYPE(Class, Base) |
| 1211 | #define DEPENDENT_TYPE(Class, Base) case Type::Class: |
| 1212 | #include "clang/AST/TypeNodes.def" |
| 1213 | assert(false && "Dependent types cannot show up in debug information"); |
Argyrios Kyrtzidis | 1bb8a45 | 2009-08-19 01:28:17 +0000 | [diff] [blame] | 1214 | |
Anders Carlsson | bfe6995 | 2009-11-06 18:24:04 +0000 | [diff] [blame] | 1215 | // FIXME: Handle these. |
| 1216 | case Type::ExtVector: |
Anders Carlsson | bfe6995 | 2009-11-06 18:24:04 +0000 | [diff] [blame] | 1217 | return llvm::DIType(); |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1218 | |
| 1219 | case Type::Vector: |
| 1220 | return CreateType(cast<VectorType>(Ty), Unit); |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 1221 | case Type::ObjCObjectPointer: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1222 | return CreateType(cast<ObjCObjectPointerType>(Ty), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1223 | case Type::ObjCInterface: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1224 | return CreateType(cast<ObjCInterfaceType>(Ty), Unit); |
| 1225 | case Type::Builtin: return CreateType(cast<BuiltinType>(Ty), Unit); |
| 1226 | case Type::Complex: return CreateType(cast<ComplexType>(Ty), Unit); |
| 1227 | case Type::Pointer: return CreateType(cast<PointerType>(Ty), Unit); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 1228 | case Type::BlockPointer: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1229 | return CreateType(cast<BlockPointerType>(Ty), Unit); |
| 1230 | case Type::Typedef: return CreateType(cast<TypedefType>(Ty), Unit); |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1231 | case Type::Record: |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1232 | case Type::Enum: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1233 | return CreateType(cast<TagType>(Ty), Unit); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1234 | case Type::FunctionProto: |
| 1235 | case Type::FunctionNoProto: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1236 | return CreateType(cast<FunctionType>(Ty), Unit); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1237 | case Type::ConstantArray: |
| 1238 | case Type::VariableArray: |
| 1239 | case Type::IncompleteArray: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1240 | return CreateType(cast<ArrayType>(Ty), Unit); |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 1241 | |
| 1242 | case Type::LValueReference: |
| 1243 | return CreateType(cast<LValueReferenceType>(Ty), Unit); |
| 1244 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1245 | case Type::MemberPointer: |
| 1246 | return CreateType(cast<MemberPointerType>(Ty), Unit); |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1247 | |
| 1248 | case Type::TemplateSpecialization: |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1249 | case Type::Elaborated: |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1250 | case Type::QualifiedName: |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1251 | case Type::SubstTemplateTypeParm: |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1252 | case Type::TypeOfExpr: |
| 1253 | case Type::TypeOf: |
Douglas Gregor | 840943d | 2009-12-21 20:18:30 +0000 | [diff] [blame] | 1254 | case Type::Decltype: |
| 1255 | llvm_unreachable("type should have been unwrapped!"); |
| 1256 | return llvm::DIType(); |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1257 | |
| 1258 | case Type::RValueReference: |
| 1259 | // FIXME: Implement! |
| 1260 | Diag = "rvalue references"; |
| 1261 | break; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1262 | } |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1263 | |
| 1264 | assert(Diag && "Fall through without a diagnostic?"); |
| 1265 | unsigned DiagID = CGM.getDiags().getCustomDiagID(Diagnostic::Error, |
| 1266 | "debug information for %0 is not yet supported"); |
| 1267 | CGM.getDiags().Report(FullSourceLoc(), DiagID) |
| 1268 | << Diag; |
| 1269 | return llvm::DIType(); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | /// EmitFunctionStart - Constructs the debug code for entering a function - |
| 1273 | /// "llvm.dbg.func.start.". |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1274 | void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1275 | llvm::Function *Fn, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1276 | CGBuilderTy &Builder) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1277 | |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1278 | llvm::StringRef Name; |
| 1279 | llvm::StringRef LinkageName; |
| 1280 | |
| 1281 | const Decl *D = GD.getDecl(); |
| 1282 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 1283 | // If there is a DISubprogram for this function available then use it. |
| 1284 | llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator |
| 1285 | FI = SPCache.find(FD); |
| 1286 | if (FI != SPCache.end()) { |
Devang Patel | 0804e6e | 2010-03-08 20:53:17 +0000 | [diff] [blame] | 1287 | llvm::DIDescriptor SP(dyn_cast_or_null<llvm::MDNode>(FI->second)); |
| 1288 | if (SP.isSubprogram() && llvm::DISubprogram(SP.getNode()).isDefinition()) { |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 1289 | RegionStack.push_back(SP.getNode()); |
Devang Patel | 3dd96a1 | 2010-01-29 18:11:03 +0000 | [diff] [blame] | 1290 | RegionMap[D] = llvm::WeakVH(SP.getNode()); |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 1291 | return; |
| 1292 | } |
| 1293 | } |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1294 | Name = getFunctionName(FD); |
Eli Friedman | 3364e62 | 2010-01-16 00:43:13 +0000 | [diff] [blame] | 1295 | if (!Name.empty() && Name[0] == '\01') |
Devang Patel | aa97d70 | 2010-01-14 21:46:57 +0000 | [diff] [blame] | 1296 | Name = Name.substr(1); |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1297 | // Use mangled name as linkage name for c/c++ functions. |
Devang Patel | aa97d70 | 2010-01-14 21:46:57 +0000 | [diff] [blame] | 1298 | LinkageName = CGM.getMangledName(GD); |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1299 | } else { |
| 1300 | // Use llvm function name as linkage name. |
| 1301 | Name = Fn->getName(); |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1302 | LinkageName = Name; |
Devang Patel | 1758420 | 2010-01-19 00:25:12 +0000 | [diff] [blame] | 1303 | if (!Name.empty() && Name[0] == '\01') |
| 1304 | Name = Name.substr(1); |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1305 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1306 | |
Devang Patel | 98a200b | 2010-01-14 18:06:13 +0000 | [diff] [blame] | 1307 | // It is expected that CurLoc is set before using EmitFunctionStart. |
| 1308 | // Usually, CurLoc points to the left bracket location of compound |
| 1309 | // statement representing function body. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1310 | llvm::DIFile Unit = getOrCreateFile(CurLoc); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1311 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 0f78fea | 2009-04-08 19:47:04 +0000 | [diff] [blame] | 1312 | unsigned LineNo = SM.getPresumedLoc(CurLoc).getLine(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1313 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1314 | llvm::DISubprogram SP = |
Devang Patel | 6dba432 | 2009-07-14 21:31:22 +0000 | [diff] [blame] | 1315 | DebugFactory.CreateSubprogram(Unit, Name, Name, LinkageName, Unit, LineNo, |
Mike Stump | 91cc815 | 2009-10-23 01:52:13 +0000 | [diff] [blame] | 1316 | getOrCreateType(FnType, Unit), |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1317 | Fn->hasInternalLinkage(), true/*definition*/); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1318 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1319 | // Push function on region stack. |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1320 | RegionStack.push_back(SP.getNode()); |
Devang Patel | 3dd96a1 | 2010-01-29 18:11:03 +0000 | [diff] [blame] | 1321 | RegionMap[D] = llvm::WeakVH(SP.getNode()); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1325 | void CGDebugInfo::EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder) { |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1326 | if (CurLoc.isInvalid() || CurLoc.isMacroID()) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1327 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1328 | // Don't bother if things are the same as last time. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1329 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1330 | if (CurLoc == PrevLoc |
Chris Lattner | 30fc933 | 2009-02-04 01:06:56 +0000 | [diff] [blame] | 1331 | || (SM.getInstantiationLineNumber(CurLoc) == |
| 1332 | SM.getInstantiationLineNumber(PrevLoc) |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1333 | && SM.isFromSameFile(CurLoc, PrevLoc))) |
| 1334 | return; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1335 | |
| 1336 | // Update last state. |
| 1337 | PrevLoc = CurLoc; |
| 1338 | |
| 1339 | // Get the appropriate compile unit. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1340 | llvm::DIFile Unit = getOrCreateFile(CurLoc); |
Devang Patel | 0f78fea | 2009-04-08 19:47:04 +0000 | [diff] [blame] | 1341 | PresumedLoc PLoc = SM.getPresumedLoc(CurLoc); |
Devang Patel | bbd9fa4 | 2009-10-06 18:36:08 +0000 | [diff] [blame] | 1342 | |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1343 | llvm::DIDescriptor DR(RegionStack.back()); |
Devang Patel | bbd9fa4 | 2009-10-06 18:36:08 +0000 | [diff] [blame] | 1344 | llvm::DIScope DS = llvm::DIScope(DR.getNode()); |
| 1345 | llvm::DILocation DO(NULL); |
| 1346 | llvm::DILocation DL = |
| 1347 | DebugFactory.CreateLocation(PLoc.getLine(), PLoc.getColumn(), |
| 1348 | DS, DO); |
| 1349 | Builder.SetCurrentDebugLocation(DL.getNode()); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
| 1352 | /// EmitRegionStart- Constructs the debug code for entering a declarative |
| 1353 | /// region - "llvm.dbg.region.start.". |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1354 | void CGDebugInfo::EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder) { |
Devang Patel | d19429f | 2010-02-16 21:41:20 +0000 | [diff] [blame] | 1355 | SourceManager &SM = CGM.getContext().getSourceManager(); |
| 1356 | PresumedLoc PLoc = SM.getPresumedLoc(CurLoc); |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1357 | llvm::DIDescriptor D = |
| 1358 | DebugFactory.CreateLexicalBlock(RegionStack.empty() ? |
| 1359 | llvm::DIDescriptor() : |
Devang Patel | d19429f | 2010-02-16 21:41:20 +0000 | [diff] [blame] | 1360 | llvm::DIDescriptor(RegionStack.back()), |
| 1361 | PLoc.getLine(), PLoc.getColumn()); |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1362 | RegionStack.push_back(D.getNode()); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | /// EmitRegionEnd - Constructs the debug code for exiting a declarative |
| 1366 | /// region - "llvm.dbg.region.end." |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1367 | void CGDebugInfo::EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder) { |
Daniel Dunbar | 5273f51 | 2008-10-17 01:07:56 +0000 | [diff] [blame] | 1368 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1369 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1370 | // Provide an region stop point. |
| 1371 | EmitStopPoint(Fn, Builder); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1372 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1373 | RegionStack.pop_back(); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1376 | // EmitTypeForVarWithBlocksAttr - Build up structure info for the byref. |
| 1377 | // See BuildByRefType. |
| 1378 | llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, |
| 1379 | uint64_t *XOffset) { |
| 1380 | |
| 1381 | llvm::SmallVector<llvm::DIDescriptor, 5> EltTys; |
| 1382 | |
| 1383 | QualType FType; |
| 1384 | uint64_t FieldSize, FieldOffset; |
| 1385 | unsigned FieldAlign; |
| 1386 | |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1387 | llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1388 | QualType Type = VD->getType(); |
| 1389 | |
| 1390 | FieldOffset = 0; |
| 1391 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
| 1392 | llvm::DIType FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1393 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1394 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
| 1395 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1396 | "__isa", llvm::DIFile(), |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1397 | 0, FieldSize, FieldAlign, |
| 1398 | FieldOffset, 0, FieldTy); |
| 1399 | EltTys.push_back(FieldTy); |
| 1400 | FieldOffset += FieldSize; |
| 1401 | |
| 1402 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
| 1403 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1404 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1405 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
| 1406 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1407 | "__forwarding", llvm::DIFile(), |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1408 | 0, FieldSize, FieldAlign, |
| 1409 | FieldOffset, 0, FieldTy); |
| 1410 | EltTys.push_back(FieldTy); |
| 1411 | FieldOffset += FieldSize; |
| 1412 | |
| 1413 | FType = CGM.getContext().IntTy; |
| 1414 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1415 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1416 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
| 1417 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1418 | "__flags", llvm::DIFile(), |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1419 | 0, FieldSize, FieldAlign, |
| 1420 | FieldOffset, 0, FieldTy); |
| 1421 | EltTys.push_back(FieldTy); |
| 1422 | FieldOffset += FieldSize; |
| 1423 | |
| 1424 | FType = CGM.getContext().IntTy; |
| 1425 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1426 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1427 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
| 1428 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1429 | "__size", llvm::DIFile(), |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1430 | 0, FieldSize, FieldAlign, |
| 1431 | FieldOffset, 0, FieldTy); |
| 1432 | EltTys.push_back(FieldTy); |
| 1433 | FieldOffset += FieldSize; |
| 1434 | |
| 1435 | bool HasCopyAndDispose = CGM.BlockRequiresCopying(Type); |
| 1436 | if (HasCopyAndDispose) { |
| 1437 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
| 1438 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1439 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1440 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
| 1441 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1442 | "__copy_helper", |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1443 | llvm::DIFile(), |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1444 | 0, FieldSize, FieldAlign, |
| 1445 | FieldOffset, 0, FieldTy); |
| 1446 | EltTys.push_back(FieldTy); |
| 1447 | FieldOffset += FieldSize; |
| 1448 | |
| 1449 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
| 1450 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1451 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1452 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
| 1453 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1454 | "__destroy_helper", |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1455 | llvm::DIFile(), |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1456 | 0, FieldSize, FieldAlign, |
| 1457 | FieldOffset, 0, FieldTy); |
| 1458 | EltTys.push_back(FieldTy); |
| 1459 | FieldOffset += FieldSize; |
| 1460 | } |
| 1461 | |
| 1462 | CharUnits Align = CGM.getContext().getDeclAlign(VD); |
| 1463 | if (Align > CharUnits::fromQuantity( |
| 1464 | CGM.getContext().Target.getPointerAlign(0) / 8)) { |
| 1465 | unsigned AlignedOffsetInBytes |
| 1466 | = llvm::RoundUpToAlignment(FieldOffset/8, Align.getQuantity()); |
| 1467 | unsigned NumPaddingBytes |
| 1468 | = AlignedOffsetInBytes - FieldOffset/8; |
| 1469 | |
| 1470 | if (NumPaddingBytes > 0) { |
| 1471 | llvm::APInt pad(32, NumPaddingBytes); |
| 1472 | FType = CGM.getContext().getConstantArrayType(CGM.getContext().CharTy, |
| 1473 | pad, ArrayType::Normal, 0); |
| 1474 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1475 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1476 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
| 1477 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1478 | Unit, "", llvm::DIFile(), |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1479 | 0, FieldSize, FieldAlign, |
| 1480 | FieldOffset, 0, FieldTy); |
| 1481 | EltTys.push_back(FieldTy); |
| 1482 | FieldOffset += FieldSize; |
| 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | FType = Type; |
| 1487 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1488 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1489 | FieldAlign = Align.getQuantity()*8; |
| 1490 | |
| 1491 | *XOffset = FieldOffset; |
| 1492 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1493 | VD->getName(), llvm::DIFile(), |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1494 | 0, FieldSize, FieldAlign, |
| 1495 | FieldOffset, 0, FieldTy); |
| 1496 | EltTys.push_back(FieldTy); |
| 1497 | FieldOffset += FieldSize; |
| 1498 | |
| 1499 | llvm::DIArray Elements = |
| 1500 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
| 1501 | |
| 1502 | unsigned Flags = llvm::DIType::FlagBlockByrefStruct; |
| 1503 | |
| 1504 | return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_structure_type, |
| 1505 | Unit, "", |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1506 | llvm::DIFile(), |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1507 | 0, FieldOffset, 0, 0, Flags, |
| 1508 | llvm::DIType(), Elements); |
| 1509 | |
| 1510 | } |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 1511 | /// EmitDeclare - Emit local variable declaration debug info. |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 1512 | void CGDebugInfo::EmitDeclare(const VarDecl *VD, unsigned Tag, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1513 | llvm::Value *Storage, CGBuilderTy &Builder) { |
Daniel Dunbar | 5273f51 | 2008-10-17 01:07:56 +0000 | [diff] [blame] | 1514 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1515 | |
Devang Patel | 0773903 | 2009-03-27 23:16:32 +0000 | [diff] [blame] | 1516 | // Do not emit variable debug information while generating optimized code. |
| 1517 | // The llvm optimizer and code generator are not yet ready to support |
| 1518 | // optimized code debugging. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1519 | const CodeGenOptions &CGO = CGM.getCodeGenOpts(); |
Chandler Carruth | 2811ccf | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 1520 | if (CGO.OptimizationLevel) |
Devang Patel | 0773903 | 2009-03-27 23:16:32 +0000 | [diff] [blame] | 1521 | return; |
| 1522 | |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1523 | llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1524 | llvm::DIType Ty; |
| 1525 | uint64_t XOffset = 0; |
| 1526 | if (VD->hasAttr<BlocksAttr>()) |
| 1527 | Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset); |
| 1528 | else |
| 1529 | Ty = getOrCreateType(VD->getType(), Unit); |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1530 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1531 | // Get location information. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1532 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 1533 | PresumedLoc PLoc = SM.getPresumedLoc(VD->getLocation()); |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1534 | unsigned Line = 0; |
Eli Friedman | 1468ac7 | 2009-11-16 20:33:31 +0000 | [diff] [blame] | 1535 | unsigned Column = 0; |
Devang Patel | d263e7b | 2010-02-10 01:09:50 +0000 | [diff] [blame] | 1536 | if (PLoc.isInvalid()) |
| 1537 | PLoc = SM.getPresumedLoc(CurLoc); |
| 1538 | if (PLoc.isValid()) { |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1539 | Line = PLoc.getLine(); |
Eli Friedman | 1468ac7 | 2009-11-16 20:33:31 +0000 | [diff] [blame] | 1540 | Column = PLoc.getColumn(); |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1541 | Unit = getOrCreateFile(CurLoc); |
Eli Friedman | 1468ac7 | 2009-11-16 20:33:31 +0000 | [diff] [blame] | 1542 | } else { |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1543 | Unit = llvm::DIFile(); |
Eli Friedman | 1468ac7 | 2009-11-16 20:33:31 +0000 | [diff] [blame] | 1544 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1545 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1546 | // Create the descriptor for the variable. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1547 | llvm::DIVariable D = |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1548 | DebugFactory.CreateVariable(Tag, llvm::DIDescriptor(RegionStack.back()), |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 1549 | VD->getName(), |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1550 | Unit, Line, Ty); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1551 | // Insert an llvm.dbg.declare into the current block. |
Devang Patel | ebf16e8 | 2009-11-11 19:10:19 +0000 | [diff] [blame] | 1552 | llvm::Instruction *Call = |
Devang Patel | a020380 | 2009-11-10 23:07:24 +0000 | [diff] [blame] | 1553 | DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1554 | |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1555 | llvm::DIScope DS(RegionStack.back()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1556 | llvm::DILocation DO(NULL); |
Chris Lattner | d5b8902 | 2009-12-28 21:44:41 +0000 | [diff] [blame] | 1557 | llvm::DILocation DL = DebugFactory.CreateLocation(Line, Column, DS, DO); |
| 1558 | |
Chris Lattner | 23e92c0 | 2009-12-28 23:41:39 +0000 | [diff] [blame] | 1559 | Call->setMetadata("dbg", DL.getNode()); |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1562 | /// EmitDeclare - Emit local variable declaration debug info. |
| 1563 | void CGDebugInfo::EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, |
| 1564 | llvm::Value *Storage, CGBuilderTy &Builder, |
| 1565 | CodeGenFunction *CGF) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1566 | const ValueDecl *VD = BDRE->getDecl(); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1567 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1568 | |
| 1569 | // Do not emit variable debug information while generating optimized code. |
| 1570 | // The llvm optimizer and code generator are not yet ready to support |
| 1571 | // optimized code debugging. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1572 | const CodeGenOptions &CGO = CGM.getCodeGenOpts(); |
Chandler Carruth | 2811ccf | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 1573 | if (CGO.OptimizationLevel || Builder.GetInsertBlock() == 0) |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1574 | return; |
| 1575 | |
| 1576 | uint64_t XOffset = 0; |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1577 | llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1578 | llvm::DIType Ty; |
| 1579 | if (VD->hasAttr<BlocksAttr>()) |
| 1580 | Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset); |
| 1581 | else |
| 1582 | Ty = getOrCreateType(VD->getType(), Unit); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1583 | |
| 1584 | // Get location information. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1585 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1586 | PresumedLoc PLoc = SM.getPresumedLoc(VD->getLocation()); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1587 | unsigned Line = 0; |
| 1588 | if (!PLoc.isInvalid()) |
| 1589 | Line = PLoc.getLine(); |
| 1590 | else |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1591 | Unit = llvm::DIFile(); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1592 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1593 | CharUnits offset = CGF->BlockDecls[VD]; |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1594 | llvm::SmallVector<llvm::Value *, 9> addr; |
Chris Lattner | 14b1a36 | 2010-01-25 03:29:35 +0000 | [diff] [blame] | 1595 | const llvm::Type *Int64Ty = llvm::Type::getInt64Ty(CGM.getLLVMContext()); |
| 1596 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpDeref)); |
| 1597 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpPlus)); |
| 1598 | addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity())); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1599 | if (BDRE->isByRef()) { |
Chris Lattner | 14b1a36 | 2010-01-25 03:29:35 +0000 | [diff] [blame] | 1600 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpDeref)); |
| 1601 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpPlus)); |
Ken Dyck | 199c3d6 | 2010-01-11 17:06:35 +0000 | [diff] [blame] | 1602 | // offset of __forwarding field |
| 1603 | offset = CharUnits::fromQuantity(CGF->LLVMPointerWidth/8); |
Chris Lattner | 14b1a36 | 2010-01-25 03:29:35 +0000 | [diff] [blame] | 1604 | addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity())); |
| 1605 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpDeref)); |
| 1606 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpPlus)); |
Ken Dyck | 199c3d6 | 2010-01-11 17:06:35 +0000 | [diff] [blame] | 1607 | // offset of x field |
| 1608 | offset = CharUnits::fromQuantity(XOffset/8); |
Chris Lattner | 14b1a36 | 2010-01-25 03:29:35 +0000 | [diff] [blame] | 1609 | addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity())); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | // Create the descriptor for the variable. |
| 1613 | llvm::DIVariable D = |
Chris Lattner | 165714e | 2010-01-25 03:34:56 +0000 | [diff] [blame] | 1614 | DebugFactory.CreateComplexVariable(Tag, |
| 1615 | llvm::DIDescriptor(RegionStack.back()), |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1616 | VD->getName(), Unit, Line, Ty, |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1617 | addr); |
| 1618 | // Insert an llvm.dbg.declare into the current block. |
Devang Patel | ebf16e8 | 2009-11-11 19:10:19 +0000 | [diff] [blame] | 1619 | llvm::Instruction *Call = |
Chris Lattner | 165714e | 2010-01-25 03:34:56 +0000 | [diff] [blame] | 1620 | DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1621 | |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1622 | llvm::DIScope DS(RegionStack.back()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1623 | llvm::DILocation DO(NULL); |
| 1624 | llvm::DILocation DL = |
| 1625 | DebugFactory.CreateLocation(Line, PLoc.getColumn(), DS, DO); |
Chris Lattner | d5b8902 | 2009-12-28 21:44:41 +0000 | [diff] [blame] | 1626 | |
Chris Lattner | 23e92c0 | 2009-12-28 23:41:39 +0000 | [diff] [blame] | 1627 | Call->setMetadata("dbg", DL.getNode()); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1630 | void CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *VD, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1631 | llvm::Value *Storage, |
| 1632 | CGBuilderTy &Builder) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1633 | EmitDeclare(VD, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1634 | } |
| 1635 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1636 | void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable( |
| 1637 | const BlockDeclRefExpr *BDRE, llvm::Value *Storage, CGBuilderTy &Builder, |
| 1638 | CodeGenFunction *CGF) { |
| 1639 | EmitDeclare(BDRE, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder, CGF); |
| 1640 | } |
| 1641 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1642 | /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument |
| 1643 | /// variable declaration. |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1644 | void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *VD, llvm::Value *AI, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1645 | CGBuilderTy &Builder) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1646 | EmitDeclare(VD, llvm::dwarf::DW_TAG_arg_variable, AI, Builder); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | |
| 1650 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1651 | /// EmitGlobalVariable - Emit information about a global variable. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1652 | void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 1653 | const VarDecl *D) { |
| 1654 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1655 | // Create global variable debug descriptor. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1656 | llvm::DIFile Unit = getOrCreateFile(D->getLocation()); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1657 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 1658 | PresumedLoc PLoc = SM.getPresumedLoc(D->getLocation()); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 1659 | unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 1660 | |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 1661 | QualType T = D->getType(); |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1662 | if (T->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1663 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1664 | // CodeGen turns int[] into int[1] so we'll do the same here. |
| 1665 | llvm::APSInt ConstVal(32); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1666 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1667 | ConstVal = 1; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1668 | QualType ET = CGM.getContext().getAsArrayType(T)->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1669 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1670 | T = CGM.getContext().getConstantArrayType(ET, ConstVal, |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1671 | ArrayType::Normal, 0); |
| 1672 | } |
Sanjiv Gupta | 67b14f0 | 2010-02-25 05:20:44 +0000 | [diff] [blame] | 1673 | llvm::StringRef DeclName = Var->getName(); |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 1674 | llvm::DIDescriptor DContext = |
| 1675 | getContextDescriptor(dyn_cast<Decl>(D->getDeclContext()), Unit); |
| 1676 | DebugFactory.CreateGlobalVariable(DContext, DeclName, |
Devang Patel | 3358305 | 2010-01-28 23:15:27 +0000 | [diff] [blame] | 1677 | DeclName, llvm::StringRef(), Unit, LineNo, |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1678 | getOrCreateType(T, Unit), |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1679 | Var->hasInternalLinkage(), |
| 1680 | true/*definition*/, Var); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1681 | } |
| 1682 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1683 | /// EmitGlobalVariable - Emit information about an objective-c interface. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1684 | void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1685 | ObjCInterfaceDecl *ID) { |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1686 | // Create global variable debug descriptor. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1687 | llvm::DIFile Unit = getOrCreateFile(ID->getLocation()); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1688 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1689 | PresumedLoc PLoc = SM.getPresumedLoc(ID->getLocation()); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 1690 | unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1691 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1692 | llvm::StringRef Name = ID->getName(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1693 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1694 | QualType T = CGM.getContext().getObjCInterfaceType(ID); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1695 | if (T->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1696 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1697 | // CodeGen turns int[] into int[1] so we'll do the same here. |
| 1698 | llvm::APSInt ConstVal(32); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1699 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1700 | ConstVal = 1; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1701 | QualType ET = CGM.getContext().getAsArrayType(T)->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1702 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1703 | T = CGM.getContext().getConstantArrayType(ET, ConstVal, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1704 | ArrayType::Normal, 0); |
| 1705 | } |
| 1706 | |
Devang Patel | f6a39b7 | 2009-10-20 18:26:30 +0000 | [diff] [blame] | 1707 | DebugFactory.CreateGlobalVariable(Unit, Name, Name, Name, Unit, LineNo, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1708 | getOrCreateType(T, Unit), |
| 1709 | Var->hasInternalLinkage(), |
| 1710 | true/*definition*/, Var); |
| 1711 | } |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame] | 1712 | |
| 1713 | /// getOrCreateNamesSpace - Return namespace descriptor for the given |
| 1714 | /// namespace decl. |
| 1715 | llvm::DINameSpace |
| 1716 | CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl, |
| 1717 | llvm::DIDescriptor Unit) { |
| 1718 | llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH>::iterator I = |
| 1719 | NameSpaceCache.find(NSDecl); |
| 1720 | if (I != NameSpaceCache.end()) |
| 1721 | return llvm::DINameSpace(cast<llvm::MDNode>(I->second)); |
| 1722 | |
| 1723 | SourceManager &SM = CGM.getContext().getSourceManager(); |
| 1724 | PresumedLoc PLoc = SM.getPresumedLoc(NSDecl->getLocation()); |
| 1725 | unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
| 1726 | |
| 1727 | llvm::DIDescriptor Context = |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 1728 | getContextDescriptor(dyn_cast<Decl>(NSDecl->getDeclContext()), Unit); |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame] | 1729 | llvm::DINameSpace NS = |
| 1730 | DebugFactory.CreateNameSpace(Context, NSDecl->getName(), |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1731 | llvm::DIFile(Unit.getNode()), LineNo); |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame] | 1732 | NameSpaceCache[NSDecl] = llvm::WeakVH(NS.getNode()); |
| 1733 | return NS; |
| 1734 | } |