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) |
| 39 | : CGM(CGM), isMainCompileUnitCreated(false), DebugFactory(CGM.getModule()), |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 40 | BlockLiteralGenericSet(false) { |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 43 | CGDebugInfo::~CGDebugInfo() { |
Daniel Dunbar | 66031a5 | 2008-10-17 16:15:48 +0000 | [diff] [blame] | 44 | assert(RegionStack.empty() && "Region stack mismatch, stack not empty!"); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 47 | void CGDebugInfo::setLocation(SourceLocation Loc) { |
| 48 | if (Loc.isValid()) |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 49 | CurLoc = CGM.getContext().getSourceManager().getInstantiationLoc(Loc); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Devang Patel | 979ec2e | 2009-10-06 00:35:31 +0000 | [diff] [blame] | 52 | /// getContext - Get context info for the decl. |
| 53 | llvm::DIDescriptor CGDebugInfo::getContext(const VarDecl *Decl, |
| 54 | llvm::DIDescriptor &CompileUnit) { |
| 55 | if (Decl->isFileVarDecl()) |
| 56 | return CompileUnit; |
| 57 | if (Decl->getDeclContext()->isFunctionOrMethod()) { |
| 58 | // Find the last subprogram in region stack. |
| 59 | for (unsigned RI = RegionStack.size(), RE = 0; RI != RE; --RI) { |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 60 | llvm::DIDescriptor R(RegionStack[RI - 1]); |
Devang Patel | 979ec2e | 2009-10-06 00:35:31 +0000 | [diff] [blame] | 61 | if (R.isSubprogram()) |
| 62 | return R; |
| 63 | } |
| 64 | } |
| 65 | return CompileUnit; |
| 66 | } |
| 67 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 68 | /// getOrCreateCompileUnit - Get the compile unit from the cache or create a new |
Daniel Dunbar | 25f51dd | 2008-10-24 08:38:36 +0000 | [diff] [blame] | 69 | /// one if necessary. This returns null for invalid source locations. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 70 | llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) { |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 71 | // Get source file information. |
| 72 | const char *FileName = "<unknown>"; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 73 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Chris Lattner | adb1a6f | 2009-04-19 06:50:29 +0000 | [diff] [blame] | 74 | unsigned FID = 0; |
Daniel Dunbar | 831570c | 2009-01-22 00:09:25 +0000 | [diff] [blame] | 75 | if (Loc.isValid()) { |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 76 | PresumedLoc PLoc = SM.getPresumedLoc(Loc); |
| 77 | FileName = PLoc.getFilename(); |
| 78 | FID = PLoc.getIncludeLoc().getRawEncoding(); |
Daniel Dunbar | 831570c | 2009-01-22 00:09:25 +0000 | [diff] [blame] | 79 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 80 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 81 | // See if this compile unit has been used before. |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 82 | llvm::DICompileUnit &Unit = CompileUnitCache[FID]; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 83 | if (!Unit.isNull()) return Unit; |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 84 | |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 85 | // Get absolute path name. |
| 86 | llvm::sys::Path AbsFileName(FileName); |
Benjamin Kramer | 47daf68 | 2009-12-08 11:02:29 +0000 | [diff] [blame] | 87 | AbsFileName.makeAbsolute(); |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 88 | |
Devang Patel | 72240d7 | 2009-06-26 18:32:22 +0000 | [diff] [blame] | 89 | // See if thie compile unit is representing main source file. Each source |
| 90 | // file has corresponding compile unit. There is only one main source |
| 91 | // file at a time. |
| 92 | bool isMain = false; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 93 | const LangOptions &LO = CGM.getLangOptions(); |
| 94 | const CodeGenOptions &CGO = CGM.getCodeGenOpts(); |
Devang Patel | 72240d7 | 2009-06-26 18:32:22 +0000 | [diff] [blame] | 95 | if (isMainCompileUnitCreated == false) { |
Daniel Dunbar | 7d065d0 | 2009-11-29 02:38:34 +0000 | [diff] [blame] | 96 | if (!CGO.MainFileName.empty()) { |
| 97 | if (AbsFileName.getLast() == CGO.MainFileName) |
Devang Patel | 72240d7 | 2009-06-26 18:32:22 +0000 | [diff] [blame] | 98 | isMain = true; |
| 99 | } else { |
| 100 | if (Loc.isValid() && SM.isFromMainFile(Loc)) |
| 101 | isMain = true; |
| 102 | } |
| 103 | if (isMain) |
| 104 | isMainCompileUnitCreated = true; |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 105 | } |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 106 | |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 107 | unsigned LangTag; |
| 108 | if (LO.CPlusPlus) { |
| 109 | if (LO.ObjC1) |
| 110 | LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus; |
| 111 | else |
| 112 | LangTag = llvm::dwarf::DW_LANG_C_plus_plus; |
| 113 | } else if (LO.ObjC1) { |
Devang Patel | 8d9aefc | 2009-03-24 20:35:51 +0000 | [diff] [blame] | 114 | LangTag = llvm::dwarf::DW_LANG_ObjC; |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 115 | } else if (LO.C99) { |
Devang Patel | 8d9aefc | 2009-03-24 20:35:51 +0000 | [diff] [blame] | 116 | LangTag = llvm::dwarf::DW_LANG_C99; |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 117 | } else { |
| 118 | LangTag = llvm::dwarf::DW_LANG_C89; |
| 119 | } |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 120 | |
Benjamin Kramer | 47daf68 | 2009-12-08 11:02:29 +0000 | [diff] [blame] | 121 | const char *Producer = |
Mike Stump | d8945d6 | 2009-10-09 18:38:12 +0000 | [diff] [blame] | 122 | #ifdef CLANG_VENDOR |
| 123 | CLANG_VENDOR |
| 124 | #endif |
| 125 | "clang " CLANG_VERSION_STRING; |
Chris Lattner | 4c2577a | 2009-05-02 01:00:04 +0000 | [diff] [blame] | 126 | |
| 127 | // Figure out which version of the ObjC runtime we have. |
| 128 | unsigned RuntimeVers = 0; |
| 129 | if (LO.ObjC1) |
| 130 | RuntimeVers = LO.ObjCNonFragileABI ? 2 : 1; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 131 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 132 | // Create new compile unit. |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 133 | return Unit = DebugFactory.CreateCompileUnit( |
| 134 | LangTag, AbsFileName.getLast(), AbsFileName.getDirname(), Producer, isMain, |
| 135 | LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 138 | /// CreateType - Get the Basic type from the cache or create a new |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 139 | /// one if necessary. |
| 140 | llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT, |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 141 | llvm::DICompileUnit Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 142 | unsigned Encoding = 0; |
| 143 | switch (BT->getKind()) { |
| 144 | default: |
| 145 | case BuiltinType::Void: |
| 146 | return llvm::DIType(); |
| 147 | case BuiltinType::UChar: |
| 148 | case BuiltinType::Char_U: Encoding = llvm::dwarf::DW_ATE_unsigned_char; break; |
| 149 | case BuiltinType::Char_S: |
| 150 | case BuiltinType::SChar: Encoding = llvm::dwarf::DW_ATE_signed_char; break; |
| 151 | case BuiltinType::UShort: |
| 152 | case BuiltinType::UInt: |
| 153 | case BuiltinType::ULong: |
| 154 | case BuiltinType::ULongLong: Encoding = llvm::dwarf::DW_ATE_unsigned; break; |
| 155 | case BuiltinType::Short: |
| 156 | case BuiltinType::Int: |
| 157 | case BuiltinType::Long: |
| 158 | case BuiltinType::LongLong: Encoding = llvm::dwarf::DW_ATE_signed; break; |
| 159 | case BuiltinType::Bool: Encoding = llvm::dwarf::DW_ATE_boolean; break; |
| 160 | case BuiltinType::Float: |
Devang Patel | 7c173cb | 2009-10-12 22:28:31 +0000 | [diff] [blame] | 161 | case BuiltinType::LongDouble: |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 162 | case BuiltinType::Double: Encoding = llvm::dwarf::DW_ATE_float; break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | } |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 164 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 165 | uint64_t Size = CGM.getContext().getTypeSize(BT); |
| 166 | uint64_t Align = CGM.getContext().getTypeAlign(BT); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 167 | uint64_t Offset = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 168 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 169 | llvm::DIType DbgTy = |
| 170 | DebugFactory.CreateBasicType(Unit, |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 171 | BT->getName(CGM.getContext().getLangOptions()), |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 172 | Unit, 0, Size, Align, |
| 173 | Offset, /*flags*/ 0, Encoding); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 174 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 175 | } |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 176 | |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 177 | llvm::DIType CGDebugInfo::CreateType(const ComplexType *Ty, |
| 178 | llvm::DICompileUnit Unit) { |
| 179 | // Bit size, align and offset of the type. |
| 180 | unsigned Encoding = llvm::dwarf::DW_ATE_complex_float; |
| 181 | if (Ty->isComplexIntegerType()) |
| 182 | Encoding = llvm::dwarf::DW_ATE_lo_user; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 184 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 185 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 186 | uint64_t Offset = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 187 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 188 | llvm::DIType DbgTy = |
| 189 | DebugFactory.CreateBasicType(Unit, "complex", |
| 190 | Unit, 0, Size, Align, |
| 191 | Offset, /*flags*/ 0, Encoding); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 192 | return DbgTy; |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 193 | } |
| 194 | |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 195 | /// CreateCVRType - Get the qualified type from the cache or create |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 196 | /// a new one if necessary. |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 197 | llvm::DIType CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DICompileUnit Unit) { |
| 198 | QualifierCollector Qc; |
| 199 | const Type *T = Qc.strip(Ty); |
| 200 | |
| 201 | // Ignore these qualifiers for now. |
| 202 | Qc.removeObjCGCAttr(); |
| 203 | Qc.removeAddressSpace(); |
| 204 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 205 | // We will create one Derived type for one qualifier and recurse to handle any |
| 206 | // additional ones. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 207 | unsigned Tag; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 208 | if (Qc.hasConst()) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 209 | Tag = llvm::dwarf::DW_TAG_const_type; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 210 | Qc.removeConst(); |
| 211 | } else if (Qc.hasVolatile()) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 212 | Tag = llvm::dwarf::DW_TAG_volatile_type; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 213 | Qc.removeVolatile(); |
| 214 | } else if (Qc.hasRestrict()) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 215 | Tag = llvm::dwarf::DW_TAG_restrict_type; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 216 | Qc.removeRestrict(); |
| 217 | } else { |
| 218 | assert(Qc.empty() && "Unknown type qualifier for debug info"); |
| 219 | return getOrCreateType(QualType(T, 0), Unit); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 220 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 221 | |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 222 | llvm::DIType FromTy = getOrCreateType(Qc.apply(T), Unit); |
| 223 | |
Daniel Dunbar | 3845f86 | 2008-10-31 03:54:29 +0000 | [diff] [blame] | 224 | // No need to fill in the Name, Line, Size, Alignment, Offset in case of |
| 225 | // CVR derived types. |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 226 | llvm::DIType DbgTy = |
| 227 | DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(), |
| 228 | 0, 0, 0, 0, 0, FromTy); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 229 | return DbgTy; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 232 | llvm::DIType CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty, |
| 233 | llvm::DICompileUnit Unit) { |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 234 | llvm::DIType DbgTy = |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 235 | CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty, |
| 236 | Ty->getPointeeType(), Unit); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 237 | return DbgTy; |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 238 | } |
| 239 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 240 | llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty, |
| 241 | llvm::DICompileUnit Unit) { |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 242 | return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty, |
| 243 | Ty->getPointeeType(), Unit); |
| 244 | } |
| 245 | |
| 246 | llvm::DIType CGDebugInfo::CreatePointerLikeType(unsigned Tag, |
| 247 | const Type *Ty, |
| 248 | QualType PointeeTy, |
| 249 | llvm::DICompileUnit Unit) { |
| 250 | llvm::DIType EltTy = getOrCreateType(PointeeTy, Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 251 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 252 | // Bit size, align and offset of the type. |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 253 | |
| 254 | // Size is always the size of a pointer. We can't use getTypeSize here |
| 255 | // because that does not return the correct value for references. |
| 256 | uint64_t Size = |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 257 | CGM.getContext().Target.getPointerWidth(PointeeTy.getAddressSpace()); |
| 258 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 259 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 260 | return |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 261 | DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(), |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 262 | 0, Size, Align, 0, 0, EltTy); |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 263 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 266 | llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, |
| 267 | llvm::DICompileUnit Unit) { |
| 268 | if (BlockLiteralGenericSet) |
| 269 | return BlockLiteralGeneric; |
| 270 | |
| 271 | llvm::DICompileUnit DefUnit; |
| 272 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
| 273 | |
| 274 | llvm::SmallVector<llvm::DIDescriptor, 5> EltTys; |
| 275 | |
| 276 | llvm::DIType FieldTy; |
| 277 | |
| 278 | QualType FType; |
| 279 | uint64_t FieldSize, FieldOffset; |
| 280 | unsigned FieldAlign; |
| 281 | |
| 282 | llvm::DIArray Elements; |
| 283 | llvm::DIType EltTy, DescTy; |
| 284 | |
| 285 | FieldOffset = 0; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 286 | FType = CGM.getContext().UnsignedLongTy; |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 287 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 288 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 289 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 290 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 291 | "reserved", DefUnit, |
| 292 | 0, FieldSize, FieldAlign, |
| 293 | FieldOffset, 0, FieldTy); |
| 294 | EltTys.push_back(FieldTy); |
| 295 | |
| 296 | FieldOffset += FieldSize; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 297 | FType = CGM.getContext().UnsignedLongTy; |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 298 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 299 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 300 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 301 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 302 | "Size", DefUnit, |
| 303 | 0, FieldSize, FieldAlign, |
| 304 | FieldOffset, 0, FieldTy); |
| 305 | EltTys.push_back(FieldTy); |
| 306 | |
| 307 | FieldOffset += FieldSize; |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 308 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 309 | EltTys.clear(); |
| 310 | |
Mike Stump | 3d363c5 | 2009-10-02 02:30:50 +0000 | [diff] [blame] | 311 | unsigned Flags = llvm::DIType::FlagAppleBlock; |
| 312 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 313 | EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_descriptor", |
Mike Stump | 3d363c5 | 2009-10-02 02:30:50 +0000 | [diff] [blame] | 314 | DefUnit, 0, FieldOffset, 0, 0, Flags, |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 315 | llvm::DIType(), Elements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 316 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 317 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 318 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 319 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
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 | DescTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, |
| 322 | Unit, "", llvm::DICompileUnit(), |
| 323 | 0, Size, Align, 0, 0, EltTy); |
| 324 | |
| 325 | FieldOffset = 0; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 326 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 327 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 328 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 329 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 330 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 331 | "__isa", DefUnit, |
| 332 | 0, FieldSize, FieldAlign, |
| 333 | FieldOffset, 0, FieldTy); |
| 334 | EltTys.push_back(FieldTy); |
| 335 | |
| 336 | FieldOffset += FieldSize; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 337 | FType = CGM.getContext().IntTy; |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 338 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 339 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 340 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 341 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 342 | "__flags", DefUnit, |
| 343 | 0, FieldSize, FieldAlign, |
| 344 | FieldOffset, 0, FieldTy); |
| 345 | EltTys.push_back(FieldTy); |
| 346 | |
| 347 | FieldOffset += FieldSize; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 348 | FType = CGM.getContext().IntTy; |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 349 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 350 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 351 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 352 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 353 | "__reserved", DefUnit, |
| 354 | 0, FieldSize, FieldAlign, |
| 355 | FieldOffset, 0, FieldTy); |
| 356 | EltTys.push_back(FieldTy); |
| 357 | |
| 358 | FieldOffset += FieldSize; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 359 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 360 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 361 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 362 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 363 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 364 | "__FuncPtr", DefUnit, |
| 365 | 0, FieldSize, FieldAlign, |
| 366 | FieldOffset, 0, FieldTy); |
| 367 | EltTys.push_back(FieldTy); |
| 368 | |
| 369 | FieldOffset += FieldSize; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 370 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 371 | FieldTy = DescTy; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 372 | FieldSize = CGM.getContext().getTypeSize(Ty); |
| 373 | FieldAlign = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 374 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 375 | "__descriptor", DefUnit, |
| 376 | 0, FieldSize, FieldAlign, |
| 377 | FieldOffset, 0, FieldTy); |
| 378 | EltTys.push_back(FieldTy); |
| 379 | |
| 380 | FieldOffset += FieldSize; |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 381 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 382 | |
| 383 | EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_literal_generic", |
Mike Stump | 944e705 | 2009-10-02 02:23:37 +0000 | [diff] [blame] | 384 | DefUnit, 0, FieldOffset, 0, 0, Flags, |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 385 | llvm::DIType(), Elements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 386 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 387 | BlockLiteralGenericSet = true; |
| 388 | BlockLiteralGeneric |
| 389 | = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit, |
| 390 | "", llvm::DICompileUnit(), |
| 391 | 0, Size, Align, 0, 0, EltTy); |
| 392 | return BlockLiteralGeneric; |
| 393 | } |
| 394 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 395 | llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty, |
| 396 | llvm::DICompileUnit Unit) { |
| 397 | // Typedefs are derived from some other type. If we have a typedef of a |
| 398 | // typedef, make sure to emit the whole chain. |
| 399 | llvm::DIType Src = getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 400 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 401 | // We don't set size information, but do specify where the typedef was |
| 402 | // declared. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 403 | SourceLocation DefLoc = Ty->getDecl()->getLocation(); |
| 404 | llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(DefLoc); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 405 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 406 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 407 | PresumedLoc PLoc = SM.getPresumedLoc(DefLoc); |
| 408 | unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 409 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 410 | llvm::DIType DbgTy = |
| 411 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_typedef, Unit, |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 412 | Ty->getDecl()->getName(), |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 413 | DefUnit, Line, 0, 0, 0, 0, Src); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 414 | return DbgTy; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 417 | llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty, |
| 418 | llvm::DICompileUnit Unit) { |
| 419 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 420 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 421 | // Add the result type at least. |
| 422 | EltTys.push_back(getOrCreateType(Ty->getResultType(), Unit)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 423 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 424 | // Set up remainder of arguments if there is a prototype. |
| 425 | // FIXME: IF NOT, HOW IS THIS REPRESENTED? llvm-gcc doesn't represent '...'! |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 426 | if (const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(Ty)) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 427 | for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i) |
| 428 | EltTys.push_back(getOrCreateType(FTP->getArgType(i), Unit)); |
| 429 | } else { |
| 430 | // FIXME: Handle () case in C. llvm-gcc doesn't do it either. |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 433 | llvm::DIArray EltTypeArray = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 434 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 435 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 436 | llvm::DIType DbgTy = |
| 437 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, |
| 438 | Unit, "", llvm::DICompileUnit(), |
| 439 | 0, 0, 0, 0, 0, |
| 440 | llvm::DIType(), EltTypeArray); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 441 | return DbgTy; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 444 | /// CreateType - get structure or union type. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 445 | llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, |
| 446 | llvm::DICompileUnit Unit) { |
Douglas Gregor | a4c46df | 2008-12-11 17:59:21 +0000 | [diff] [blame] | 447 | RecordDecl *Decl = Ty->getDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 448 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 449 | unsigned Tag; |
| 450 | if (Decl->isStruct()) |
| 451 | Tag = llvm::dwarf::DW_TAG_structure_type; |
| 452 | else if (Decl->isUnion()) |
| 453 | Tag = llvm::dwarf::DW_TAG_union_type; |
| 454 | else { |
| 455 | assert(Decl->isClass() && "Unknown RecordType!"); |
| 456 | Tag = llvm::dwarf::DW_TAG_class_type; |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 459 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 460 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 461 | // Get overall information about the record type for the debug info. |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 462 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
Chris Lattner | d37d9b5 | 2009-05-05 05:16:17 +0000 | [diff] [blame] | 463 | llvm::DICompileUnit DefUnit; |
| 464 | unsigned Line = 0; |
| 465 | if (!PLoc.isInvalid()) { |
| 466 | DefUnit = getOrCreateCompileUnit(Decl->getLocation()); |
| 467 | Line = PLoc.getLine(); |
| 468 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 470 | // Records and classes and unions can all be recursive. To handle them, we |
| 471 | // first generate a debug descriptor for the struct as a forward declaration. |
| 472 | // Then (if it is a definition) we go through and get debug info for all of |
| 473 | // its members. Finally, we create a descriptor for the complete type (which |
| 474 | // may refer to the forward decl if the struct is recursive) and replace all |
| 475 | // uses of the forward declaration with the final definition. |
Devang Patel | 0ce73f6 | 2009-07-22 18:57:00 +0000 | [diff] [blame] | 476 | llvm::DICompositeType FwdDecl = |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 477 | DebugFactory.CreateCompositeType(Tag, Unit, Decl->getName(), |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 478 | DefUnit, Line, 0, 0, 0, 0, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 479 | llvm::DIType(), llvm::DIArray()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 480 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 481 | // If this is just a forward declaration, return it. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 482 | if (!Decl->getDefinition(CGM.getContext())) |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 483 | return FwdDecl; |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 484 | |
Eli Friedman | 14d6365 | 2009-11-16 21:04:30 +0000 | [diff] [blame] | 485 | llvm::TrackingVH<llvm::MDNode> FwdDeclNode = FwdDecl.getNode(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 486 | // Otherwise, insert it into the TypeCache so that recursive uses will find |
| 487 | // it. |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 488 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 489 | |
| 490 | // Convert all the elements. |
| 491 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
| 492 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 493 | const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(Decl); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 494 | |
| 495 | unsigned FieldNo = 0; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 496 | for (RecordDecl::field_iterator I = Decl->field_begin(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 497 | E = Decl->field_end(); |
Douglas Gregor | a4c46df | 2008-12-11 17:59:21 +0000 | [diff] [blame] | 498 | I != E; ++I, ++FieldNo) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 499 | FieldDecl *Field = *I; |
| 500 | llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 501 | |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 502 | llvm::StringRef FieldName = Field->getName(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 503 | |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 504 | // Ignore unnamed fields. |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 505 | if (FieldName.empty()) |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 506 | continue; |
| 507 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 508 | // Get the location for the field. |
| 509 | SourceLocation FieldDefLoc = Field->getLocation(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 510 | PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc); |
Chris Lattner | d37d9b5 | 2009-05-05 05:16:17 +0000 | [diff] [blame] | 511 | llvm::DICompileUnit FieldDefUnit; |
| 512 | unsigned FieldLine = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 513 | |
Chris Lattner | d37d9b5 | 2009-05-05 05:16:17 +0000 | [diff] [blame] | 514 | if (!PLoc.isInvalid()) { |
| 515 | FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc); |
| 516 | FieldLine = PLoc.getLine(); |
| 517 | } |
Devang Patel | ec9b5d5 | 2009-03-16 23:47:53 +0000 | [diff] [blame] | 518 | |
| 519 | QualType FType = Field->getType(); |
| 520 | uint64_t FieldSize = 0; |
| 521 | unsigned FieldAlign = 0; |
| 522 | if (!FType->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 523 | |
Devang Patel | ec9b5d5 | 2009-03-16 23:47:53 +0000 | [diff] [blame] | 524 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 525 | FieldSize = CGM.getContext().getTypeSize(FType); |
Devang Patel | ec9b5d5 | 2009-03-16 23:47:53 +0000 | [diff] [blame] | 526 | Expr *BitWidth = Field->getBitWidth(); |
| 527 | if (BitWidth) |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 528 | FieldSize = BitWidth->EvaluateAsInt(CGM.getContext()).getZExtValue(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 529 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 530 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Devang Patel | ec9b5d5 | 2009-03-16 23:47:53 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 533 | uint64_t FieldOffset = RL.getFieldOffset(FieldNo); |
| 534 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 535 | // Create a DW_TAG_member node to remember the offset of this field in the |
| 536 | // struct. FIXME: This is an absolutely insane way to capture this |
| 537 | // information. When we gut debug info, this should be fixed. |
| 538 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 539 | FieldName, FieldDefUnit, |
| 540 | FieldLine, FieldSize, FieldAlign, |
| 541 | FieldOffset, 0, FieldTy); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 542 | EltTys.push_back(FieldTy); |
| 543 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 545 | llvm::DIArray Elements = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 546 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 547 | |
| 548 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 549 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 550 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 551 | |
Devang Patel | 0ce73f6 | 2009-07-22 18:57:00 +0000 | [diff] [blame] | 552 | llvm::DICompositeType RealDecl = |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 553 | DebugFactory.CreateCompositeType(Tag, Unit, Decl->getName(), |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 554 | DefUnit, Line, Size, Align, 0, 0, |
| 555 | llvm::DIType(), Elements); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 556 | |
| 557 | // Now that we have a real decl for the struct, replace anything using the |
| 558 | // 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] | 559 | llvm::DIDerivedType(FwdDeclNode).replaceAllUsesWith(RealDecl); |
Devang Patel | fe09eab | 2009-07-13 17:03:14 +0000 | [diff] [blame] | 560 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 561 | return RealDecl; |
| 562 | } |
| 563 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 564 | /// CreateType - get objective-c interface type. |
| 565 | llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, |
| 566 | llvm::DICompileUnit Unit) { |
| 567 | ObjCInterfaceDecl *Decl = Ty->getDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 568 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 569 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 570 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 571 | |
| 572 | // Get overall information about the record type for the debug info. |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 573 | llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(Decl->getLocation()); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 574 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
| 575 | unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
| 576 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 577 | |
Daniel Dunbar | d86d336 | 2009-05-18 20:51:58 +0000 | [diff] [blame] | 578 | unsigned RuntimeLang = DefUnit.getLanguage(); |
Chris Lattner | ac7c814 | 2009-05-02 01:13:16 +0000 | [diff] [blame] | 579 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 580 | // To handle recursive interface, we |
| 581 | // first generate a debug descriptor for the struct as a forward declaration. |
| 582 | // Then (if it is a definition) we go through and get debug info for all of |
| 583 | // its members. Finally, we create a descriptor for the complete type (which |
| 584 | // may refer to the forward decl if the struct is recursive) and replace all |
| 585 | // uses of the forward declaration with the final definition. |
Devang Patel | 6c1fddf | 2009-07-27 18:42:03 +0000 | [diff] [blame] | 586 | llvm::DICompositeType FwdDecl = |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 587 | DebugFactory.CreateCompositeType(Tag, Unit, Decl->getName(), |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 588 | DefUnit, Line, 0, 0, 0, 0, |
Chris Lattner | ac7c814 | 2009-05-02 01:13:16 +0000 | [diff] [blame] | 589 | llvm::DIType(), llvm::DIArray(), |
| 590 | RuntimeLang); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 591 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 592 | // If this is just a forward declaration, return it. |
| 593 | if (Decl->isForwardDecl()) |
| 594 | return FwdDecl; |
| 595 | |
Devang Patel | ffffb03 | 2009-11-16 20:09:38 +0000 | [diff] [blame] | 596 | llvm::TrackingVH<llvm::MDNode> FwdDeclNode = FwdDecl.getNode(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 597 | // Otherwise, insert it into the TypeCache so that recursive uses will find |
| 598 | // it. |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 599 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 600 | |
| 601 | // Convert all the elements. |
| 602 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
| 603 | |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 604 | ObjCInterfaceDecl *SClass = Decl->getSuperClass(); |
| 605 | if (SClass) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 606 | llvm::DIType SClassTy = |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 607 | getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 608 | llvm::DIType InhTag = |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 609 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance, |
Chris Lattner | 9e55b8a | 2009-05-05 05:05:36 +0000 | [diff] [blame] | 610 | Unit, "", llvm::DICompileUnit(), 0, 0, 0, |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 611 | 0 /* offset */, 0, SClassTy); |
| 612 | EltTys.push_back(InhTag); |
| 613 | } |
| 614 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 615 | const ASTRecordLayout &RL = CGM.getContext().getASTObjCInterfaceLayout(Decl); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 616 | |
| 617 | unsigned FieldNo = 0; |
| 618 | for (ObjCInterfaceDecl::ivar_iterator I = Decl->ivar_begin(), |
| 619 | E = Decl->ivar_end(); I != E; ++I, ++FieldNo) { |
| 620 | ObjCIvarDecl *Field = *I; |
| 621 | llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); |
| 622 | |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 623 | llvm::StringRef FieldName = Field->getName(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 624 | |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 625 | // Ignore unnamed fields. |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 626 | if (FieldName.empty()) |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 627 | continue; |
| 628 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 629 | // Get the location for the field. |
| 630 | SourceLocation FieldDefLoc = Field->getLocation(); |
| 631 | llvm::DICompileUnit FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 632 | PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc); |
| 633 | unsigned FieldLine = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
| 634 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 636 | QualType FType = Field->getType(); |
| 637 | uint64_t FieldSize = 0; |
| 638 | unsigned FieldAlign = 0; |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 639 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 640 | if (!FType->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 641 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 642 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 643 | FieldSize = CGM.getContext().getTypeSize(FType); |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 644 | Expr *BitWidth = Field->getBitWidth(); |
| 645 | if (BitWidth) |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 646 | FieldSize = BitWidth->EvaluateAsInt(CGM.getContext()).getZExtValue(); |
Eli Friedman | 9a901bb | 2009-04-26 19:19:15 +0000 | [diff] [blame] | 647 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 648 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 651 | uint64_t FieldOffset = RL.getFieldOffset(FieldNo); |
| 652 | |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 653 | unsigned Flags = 0; |
| 654 | if (Field->getAccessControl() == ObjCIvarDecl::Protected) |
| 655 | Flags = llvm::DIType::FlagProtected; |
| 656 | else if (Field->getAccessControl() == ObjCIvarDecl::Private) |
| 657 | Flags = llvm::DIType::FlagPrivate; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 658 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 659 | // Create a DW_TAG_member node to remember the offset of this field in the |
| 660 | // struct. FIXME: This is an absolutely insane way to capture this |
| 661 | // information. When we gut debug info, this should be fixed. |
| 662 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 663 | FieldName, FieldDefUnit, |
| 664 | FieldLine, FieldSize, FieldAlign, |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 665 | FieldOffset, Flags, FieldTy); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 666 | EltTys.push_back(FieldTy); |
| 667 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 668 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 669 | llvm::DIArray Elements = |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 670 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 671 | |
| 672 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 673 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 674 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 675 | |
Devang Patel | 6c1fddf | 2009-07-27 18:42:03 +0000 | [diff] [blame] | 676 | llvm::DICompositeType RealDecl = |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 677 | DebugFactory.CreateCompositeType(Tag, Unit, Decl->getName(), DefUnit, |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 678 | Line, Size, Align, 0, 0, llvm::DIType(), |
| 679 | Elements, RuntimeLang); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 680 | |
| 681 | // Now that we have a real decl for the struct, replace anything using the |
| 682 | // 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] | 683 | llvm::DIDerivedType(FwdDeclNode).replaceAllUsesWith(RealDecl); |
Devang Patel | fe09eab | 2009-07-13 17:03:14 +0000 | [diff] [blame] | 684 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 685 | return RealDecl; |
| 686 | } |
| 687 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 688 | llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty, |
| 689 | llvm::DICompileUnit Unit) { |
| 690 | EnumDecl *Decl = Ty->getDecl(); |
| 691 | |
| 692 | llvm::SmallVector<llvm::DIDescriptor, 32> Enumerators; |
| 693 | |
| 694 | // Create DIEnumerator elements for each enumerator. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 695 | for (EnumDecl::enumerator_iterator |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 696 | Enum = Decl->enumerator_begin(), EnumEnd = Decl->enumerator_end(); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 697 | Enum != EnumEnd; ++Enum) { |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 698 | Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getName(), |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 699 | Enum->getInitVal().getZExtValue())); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 700 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 702 | // Return a CompositeType for the enum itself. |
| 703 | llvm::DIArray EltArray = |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 704 | DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 705 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 706 | SourceLocation DefLoc = Decl->getLocation(); |
| 707 | llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(DefLoc); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 708 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 709 | PresumedLoc PLoc = SM.getPresumedLoc(DefLoc); |
| 710 | unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
| 711 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 712 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 713 | // Size and align of the type. |
Eli Friedman | 3189e4b | 2009-05-04 04:39:55 +0000 | [diff] [blame] | 714 | uint64_t Size = 0; |
| 715 | unsigned Align = 0; |
| 716 | if (!Ty->isIncompleteType()) { |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 717 | Size = CGM.getContext().getTypeSize(Ty); |
| 718 | Align = CGM.getContext().getTypeAlign(Ty); |
Eli Friedman | 3189e4b | 2009-05-04 04:39:55 +0000 | [diff] [blame] | 719 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 720 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 721 | llvm::DIType DbgTy = |
| 722 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type, |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 723 | Unit, Decl->getName(), DefUnit, Line, |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 724 | Size, Align, 0, 0, |
| 725 | llvm::DIType(), EltArray); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 726 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | llvm::DIType CGDebugInfo::CreateType(const TagType *Ty, |
| 730 | llvm::DICompileUnit Unit) { |
| 731 | if (const RecordType *RT = dyn_cast<RecordType>(Ty)) |
| 732 | return CreateType(RT, Unit); |
| 733 | else if (const EnumType *ET = dyn_cast<EnumType>(Ty)) |
| 734 | return CreateType(ET, Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 735 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 736 | return llvm::DIType(); |
| 737 | } |
| 738 | |
| 739 | llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty, |
| 740 | llvm::DICompileUnit Unit) { |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 741 | uint64_t Size; |
| 742 | uint64_t Align; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 743 | |
| 744 | |
Nuno Lopes | 010d514 | 2009-01-28 00:35:17 +0000 | [diff] [blame] | 745 | // FIXME: make getTypeAlign() aware of VLAs and incomplete array types |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 746 | if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(Ty)) { |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 747 | Size = 0; |
| 748 | Align = |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 749 | CGM.getContext().getTypeAlign(CGM.getContext().getBaseElementType(VAT)); |
Nuno Lopes | 010d514 | 2009-01-28 00:35:17 +0000 | [diff] [blame] | 750 | } else if (Ty->isIncompleteArrayType()) { |
| 751 | Size = 0; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 752 | Align = CGM.getContext().getTypeAlign(Ty->getElementType()); |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 753 | } else { |
| 754 | // Size and align of the whole array, not the element type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 755 | Size = CGM.getContext().getTypeSize(Ty); |
| 756 | Align = CGM.getContext().getTypeAlign(Ty); |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 757 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 758 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 759 | // Add the dimensions of the array. FIXME: This loses CV qualifiers from |
| 760 | // interior arrays, do we care? Why aren't nested arrays represented the |
| 761 | // obvious/recursive way? |
| 762 | llvm::SmallVector<llvm::DIDescriptor, 8> Subscripts; |
| 763 | QualType EltTy(Ty, 0); |
| 764 | while ((Ty = dyn_cast<ArrayType>(EltTy))) { |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 765 | uint64_t Upper = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 766 | if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty)) |
Devang Patel | 5a6bfe3 | 2009-08-14 20:57:45 +0000 | [diff] [blame] | 767 | if (CAT->getSize().getZExtValue()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 768 | Upper = CAT->getSize().getZExtValue() - 1; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 769 | // FIXME: Verify this is right for VLAs. |
| 770 | Subscripts.push_back(DebugFactory.GetOrCreateSubrange(0, Upper)); |
| 771 | EltTy = Ty->getElementType(); |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 772 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 773 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 774 | llvm::DIArray SubscriptArray = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 775 | DebugFactory.GetOrCreateArray(Subscripts.data(), Subscripts.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 776 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 777 | llvm::DIType DbgTy = |
| 778 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_array_type, |
| 779 | Unit, "", llvm::DICompileUnit(), |
| 780 | 0, Size, Align, 0, 0, |
| 781 | getOrCreateType(EltTy, Unit), |
| 782 | SubscriptArray); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 783 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 784 | } |
| 785 | |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 786 | llvm::DIType CGDebugInfo::CreateType(const LValueReferenceType *Ty, |
| 787 | llvm::DICompileUnit Unit) { |
| 788 | return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, |
| 789 | Ty, Ty->getPointeeType(), Unit); |
| 790 | } |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 791 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 792 | llvm::DIType CGDebugInfo::CreateType(const MemberPointerType *Ty, |
| 793 | llvm::DICompileUnit U) { |
| 794 | QualType PointerDiffTy = CGM.getContext().getPointerDiffType(); |
| 795 | llvm::DIType PointerDiffDITy = getOrCreateType(PointerDiffTy, U); |
| 796 | |
| 797 | if (!Ty->getPointeeType()->isFunctionType()) { |
| 798 | // We have a data member pointer type. |
| 799 | return PointerDiffDITy; |
| 800 | } |
| 801 | |
| 802 | // We have a member function pointer type. Treat it as a struct with two |
| 803 | // ptrdiff_t members. |
| 804 | std::pair<uint64_t, unsigned> Info = CGM.getContext().getTypeInfo(Ty); |
| 805 | |
| 806 | uint64_t FieldOffset = 0; |
| 807 | llvm::DIDescriptor ElementTypes[2]; |
| 808 | |
| 809 | // FIXME: This should probably be a function type instead. |
| 810 | ElementTypes[0] = |
| 811 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, U, |
| 812 | "ptr", llvm::DICompileUnit(), 0, |
| 813 | Info.first, Info.second, FieldOffset, 0, |
| 814 | PointerDiffDITy); |
| 815 | FieldOffset += Info.first; |
| 816 | |
| 817 | ElementTypes[1] = |
| 818 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, U, |
| 819 | "ptr", llvm::DICompileUnit(), 0, |
| 820 | Info.first, Info.second, FieldOffset, 0, |
| 821 | PointerDiffDITy); |
| 822 | |
| 823 | llvm::DIArray Elements = |
| 824 | DebugFactory.GetOrCreateArray(&ElementTypes[0], |
| 825 | llvm::array_lengthof(ElementTypes)); |
| 826 | |
| 827 | return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_structure_type, |
| 828 | U, llvm::StringRef("test"), |
| 829 | llvm::DICompileUnit(), 0, FieldOffset, |
| 830 | 0, 0, 0, llvm::DIType(), Elements); |
| 831 | } |
| 832 | |
Anders Carlsson | 5b6117a | 2009-11-14 21:08:12 +0000 | [diff] [blame] | 833 | static QualType CanonicalizeTypeForDebugInfo(QualType T) { |
| 834 | switch (T->getTypeClass()) { |
| 835 | default: |
| 836 | return T; |
| 837 | case Type::TemplateSpecialization: |
| 838 | return cast<TemplateSpecializationType>(T)->desugar(); |
| 839 | case Type::TypeOfExpr: { |
| 840 | TypeOfExprType *Ty = cast<TypeOfExprType>(T); |
| 841 | return CanonicalizeTypeForDebugInfo(Ty->getUnderlyingExpr()->getType()); |
| 842 | } |
| 843 | case Type::TypeOf: |
| 844 | return cast<TypeOfType>(T)->getUnderlyingType(); |
| 845 | case Type::Decltype: |
| 846 | return cast<DecltypeType>(T)->getUnderlyingType(); |
| 847 | case Type::QualifiedName: |
| 848 | return cast<QualifiedNameType>(T)->getNamedType(); |
| 849 | case Type::SubstTemplateTypeParm: |
| 850 | return cast<SubstTemplateTypeParmType>(T)->getReplacementType(); |
| 851 | case Type::Elaborated: |
| 852 | return cast<ElaboratedType>(T)->getUnderlyingType(); |
| 853 | } |
| 854 | } |
| 855 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 856 | /// getOrCreateType - Get the type from the cache or create a new |
| 857 | /// one if necessary. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 858 | llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, |
| 859 | llvm::DICompileUnit Unit) { |
| 860 | if (Ty.isNull()) |
| 861 | return llvm::DIType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 862 | |
Anders Carlsson | 5b6117a | 2009-11-14 21:08:12 +0000 | [diff] [blame] | 863 | // Canonicalize the type. |
| 864 | Ty = CanonicalizeTypeForDebugInfo(Ty); |
| 865 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 866 | // Check for existing entry. |
Daniel Dunbar | 65f13c3 | 2009-09-19 20:17:48 +0000 | [diff] [blame] | 867 | std::map<void *, llvm::WeakVH>::iterator it = |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 868 | TypeCache.find(Ty.getAsOpaquePtr()); |
Daniel Dunbar | 65f13c3 | 2009-09-19 20:17:48 +0000 | [diff] [blame] | 869 | if (it != TypeCache.end()) { |
| 870 | // Verify that the debug info still exists. |
| 871 | if (&*it->second) |
| 872 | return llvm::DIType(cast<llvm::MDNode>(it->second)); |
| 873 | } |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 874 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 875 | // Otherwise create the type. |
| 876 | llvm::DIType Res = CreateTypeNode(Ty, Unit); |
Anders Carlsson | 0dd57c6 | 2009-11-14 20:52:05 +0000 | [diff] [blame] | 877 | |
| 878 | // And update the type cache. |
| 879 | TypeCache[Ty.getAsOpaquePtr()] = Res.getNode(); |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 880 | return Res; |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 881 | } |
| 882 | |
Anders Carlsson | 0dd57c6 | 2009-11-14 20:52:05 +0000 | [diff] [blame] | 883 | /// CreateTypeNode - Create a new debug type node. |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 884 | llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, |
| 885 | llvm::DICompileUnit Unit) { |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 886 | // Handle qualifiers, which recursively handles what they refer to. |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 887 | if (Ty.hasLocalQualifiers()) |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 888 | return CreateQualifiedType(Ty, Unit); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 889 | |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame^] | 890 | const char *Diag = 0; |
| 891 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 892 | // Work out details of type. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 893 | switch (Ty->getTypeClass()) { |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 894 | #define TYPE(Class, Base) |
| 895 | #define ABSTRACT_TYPE(Class, Base) |
| 896 | #define NON_CANONICAL_TYPE(Class, Base) |
| 897 | #define DEPENDENT_TYPE(Class, Base) case Type::Class: |
| 898 | #include "clang/AST/TypeNodes.def" |
| 899 | assert(false && "Dependent types cannot show up in debug information"); |
Argyrios Kyrtzidis | 1bb8a45 | 2009-08-19 01:28:17 +0000 | [diff] [blame] | 900 | |
Anders Carlsson | bfe6995 | 2009-11-06 18:24:04 +0000 | [diff] [blame] | 901 | // FIXME: Handle these. |
| 902 | case Type::ExtVector: |
| 903 | case Type::Vector: |
Anders Carlsson | ba578cb | 2009-11-07 01:19:37 +0000 | [diff] [blame] | 904 | case Type::FixedWidthInt: |
Anders Carlsson | bfe6995 | 2009-11-06 18:24:04 +0000 | [diff] [blame] | 905 | return llvm::DIType(); |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame^] | 906 | |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 907 | case Type::ObjCObjectPointer: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 908 | return CreateType(cast<ObjCObjectPointerType>(Ty), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 909 | case Type::ObjCInterface: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 910 | return CreateType(cast<ObjCInterfaceType>(Ty), Unit); |
| 911 | case Type::Builtin: return CreateType(cast<BuiltinType>(Ty), Unit); |
| 912 | case Type::Complex: return CreateType(cast<ComplexType>(Ty), Unit); |
| 913 | case Type::Pointer: return CreateType(cast<PointerType>(Ty), Unit); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 914 | case Type::BlockPointer: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 915 | return CreateType(cast<BlockPointerType>(Ty), Unit); |
| 916 | case Type::Typedef: return CreateType(cast<TypedefType>(Ty), Unit); |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 917 | case Type::Record: |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 918 | case Type::Enum: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 919 | return CreateType(cast<TagType>(Ty), Unit); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 920 | case Type::FunctionProto: |
| 921 | case Type::FunctionNoProto: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 922 | return CreateType(cast<FunctionType>(Ty), Unit); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 923 | case Type::ConstantArray: |
| 924 | case Type::VariableArray: |
| 925 | case Type::IncompleteArray: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 926 | return CreateType(cast<ArrayType>(Ty), Unit); |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 927 | |
| 928 | case Type::LValueReference: |
| 929 | return CreateType(cast<LValueReferenceType>(Ty), Unit); |
| 930 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 931 | case Type::MemberPointer: |
| 932 | return CreateType(cast<MemberPointerType>(Ty), Unit); |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame^] | 933 | |
| 934 | case Type::TemplateSpecialization: |
| 935 | // DWARF can't represent template specialization types; instead, |
| 936 | // we drill down to the canonical type, which will be a record type. |
| 937 | return CreateType(cast<RecordType>(CGM.getContext().getCanonicalType(Ty)), |
| 938 | Unit); |
| 939 | |
| 940 | case Type::Elaborated: |
| 941 | // DWARF can't represent elaborated type specifiers any differently from |
| 942 | // the underlying type, so create a type node for the underlying type. |
| 943 | return CreateTypeNode(cast<ElaboratedType>(Ty)->getUnderlyingType(), Unit); |
| 944 | |
| 945 | case Type::QualifiedName: |
| 946 | // DWARF can't represent qualified names any differently from the type |
| 947 | // being named, so create a type node for that type. |
| 948 | return CreateTypeNode(cast<QualifiedNameType>(Ty)->getNamedType(), Unit); |
| 949 | |
| 950 | case Type::SubstTemplateTypeParm: |
| 951 | // DWARF can't represent substituted template type parameter types, |
| 952 | // so create a type node for the type that the template type parameter was |
| 953 | // replaced with. |
| 954 | return CreateTypeNode(cast<SubstTemplateTypeParmType>(Ty) |
| 955 | ->getReplacementType(), |
| 956 | Unit); |
| 957 | |
| 958 | case Type::TypeOfExpr: |
| 959 | case Type::TypeOf: |
| 960 | // FIXME: Implement! |
| 961 | Diag = "typeof"; |
| 962 | break; |
| 963 | |
| 964 | case Type::RValueReference: |
| 965 | // FIXME: Implement! |
| 966 | Diag = "rvalue references"; |
| 967 | break; |
| 968 | |
| 969 | case Type::Decltype: |
| 970 | // FIXME: Implement! |
| 971 | Diag = "decltype"; |
| 972 | break; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 973 | } |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame^] | 974 | |
| 975 | assert(Diag && "Fall through without a diagnostic?"); |
| 976 | unsigned DiagID = CGM.getDiags().getCustomDiagID(Diagnostic::Error, |
| 977 | "debug information for %0 is not yet supported"); |
| 978 | CGM.getDiags().Report(FullSourceLoc(), DiagID) |
| 979 | << Diag; |
| 980 | return llvm::DIType(); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | /// EmitFunctionStart - Constructs the debug code for entering a function - |
| 984 | /// "llvm.dbg.func.start.". |
Benjamin Kramer | 155fd79 | 2009-12-08 14:04:35 +0000 | [diff] [blame] | 985 | void CGDebugInfo::EmitFunctionStart(llvm::StringRef Name, QualType FnType, |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 986 | llvm::Function *Fn, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 987 | CGBuilderTy &Builder) { |
Benjamin Kramer | 155fd79 | 2009-12-08 14:04:35 +0000 | [diff] [blame] | 988 | llvm::StringRef LinkageName(Name); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 989 | |
Daniel Dunbar | a289393 | 2009-05-13 23:08:57 +0000 | [diff] [blame] | 990 | // Skip the asm prefix if it exists. |
Daniel Dunbar | bbd53af | 2009-05-14 01:45:24 +0000 | [diff] [blame] | 991 | // |
| 992 | // FIXME: This should probably be the unmangled name? |
Daniel Dunbar | a289393 | 2009-05-13 23:08:57 +0000 | [diff] [blame] | 993 | if (Name[0] == '\01') |
Benjamin Kramer | 155fd79 | 2009-12-08 14:04:35 +0000 | [diff] [blame] | 994 | Name = Name.substr(1); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 995 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 996 | // FIXME: Why is this using CurLoc??? |
| 997 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 998 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 0f78fea | 2009-04-08 19:47:04 +0000 | [diff] [blame] | 999 | unsigned LineNo = SM.getPresumedLoc(CurLoc).getLine(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1000 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1001 | llvm::DISubprogram SP = |
Devang Patel | 6dba432 | 2009-07-14 21:31:22 +0000 | [diff] [blame] | 1002 | DebugFactory.CreateSubprogram(Unit, Name, Name, LinkageName, Unit, LineNo, |
Mike Stump | 91cc815 | 2009-10-23 01:52:13 +0000 | [diff] [blame] | 1003 | getOrCreateType(FnType, Unit), |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1004 | Fn->hasInternalLinkage(), true/*definition*/); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1005 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1006 | // Push function on region stack. |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1007 | RegionStack.push_back(SP.getNode()); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1011 | void CGDebugInfo::EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder) { |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1012 | if (CurLoc.isInvalid() || CurLoc.isMacroID()) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1013 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1014 | // Don't bother if things are the same as last time. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1015 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1016 | if (CurLoc == PrevLoc |
Chris Lattner | 30fc933 | 2009-02-04 01:06:56 +0000 | [diff] [blame] | 1017 | || (SM.getInstantiationLineNumber(CurLoc) == |
| 1018 | SM.getInstantiationLineNumber(PrevLoc) |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1019 | && SM.isFromSameFile(CurLoc, PrevLoc))) |
| 1020 | return; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1021 | |
| 1022 | // Update last state. |
| 1023 | PrevLoc = CurLoc; |
| 1024 | |
| 1025 | // Get the appropriate compile unit. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1026 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc); |
Devang Patel | 0f78fea | 2009-04-08 19:47:04 +0000 | [diff] [blame] | 1027 | PresumedLoc PLoc = SM.getPresumedLoc(CurLoc); |
Devang Patel | bbd9fa4 | 2009-10-06 18:36:08 +0000 | [diff] [blame] | 1028 | |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1029 | llvm::DIDescriptor DR(RegionStack.back()); |
Devang Patel | bbd9fa4 | 2009-10-06 18:36:08 +0000 | [diff] [blame] | 1030 | llvm::DIScope DS = llvm::DIScope(DR.getNode()); |
| 1031 | llvm::DILocation DO(NULL); |
| 1032 | llvm::DILocation DL = |
| 1033 | DebugFactory.CreateLocation(PLoc.getLine(), PLoc.getColumn(), |
| 1034 | DS, DO); |
| 1035 | Builder.SetCurrentDebugLocation(DL.getNode()); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | /// EmitRegionStart- Constructs the debug code for entering a declarative |
| 1039 | /// region - "llvm.dbg.region.start.". |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1040 | void CGDebugInfo::EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder) { |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1041 | llvm::DIDescriptor D = |
| 1042 | DebugFactory.CreateLexicalBlock(RegionStack.empty() ? |
| 1043 | llvm::DIDescriptor() : |
| 1044 | llvm::DIDescriptor(RegionStack.back())); |
| 1045 | RegionStack.push_back(D.getNode()); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | /// EmitRegionEnd - Constructs the debug code for exiting a declarative |
| 1049 | /// region - "llvm.dbg.region.end." |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1050 | void CGDebugInfo::EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder) { |
Daniel Dunbar | 5273f51 | 2008-10-17 01:07:56 +0000 | [diff] [blame] | 1051 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1052 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1053 | // Provide an region stop point. |
| 1054 | EmitStopPoint(Fn, Builder); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1055 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1056 | RegionStack.pop_back(); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 1059 | /// EmitDeclare - Emit local variable declaration debug info. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1060 | void CGDebugInfo::EmitDeclare(const VarDecl *Decl, unsigned Tag, |
| 1061 | llvm::Value *Storage, CGBuilderTy &Builder) { |
Daniel Dunbar | 5273f51 | 2008-10-17 01:07:56 +0000 | [diff] [blame] | 1062 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1063 | |
Devang Patel | 0773903 | 2009-03-27 23:16:32 +0000 | [diff] [blame] | 1064 | // Do not emit variable debug information while generating optimized code. |
| 1065 | // The llvm optimizer and code generator are not yet ready to support |
| 1066 | // optimized code debugging. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1067 | const CodeGenOptions &CGO = CGM.getCodeGenOpts(); |
Chandler Carruth | 2811ccf | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 1068 | if (CGO.OptimizationLevel) |
Devang Patel | 0773903 | 2009-03-27 23:16:32 +0000 | [diff] [blame] | 1069 | return; |
| 1070 | |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1071 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation()); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1072 | QualType Type = Decl->getType(); |
| 1073 | llvm::DIType Ty = getOrCreateType(Type, Unit); |
| 1074 | if (Decl->hasAttr<BlocksAttr>()) { |
| 1075 | llvm::DICompileUnit DefUnit; |
| 1076 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
| 1077 | |
| 1078 | llvm::SmallVector<llvm::DIDescriptor, 5> EltTys; |
| 1079 | |
| 1080 | llvm::DIType FieldTy; |
| 1081 | |
| 1082 | QualType FType; |
| 1083 | uint64_t FieldSize, FieldOffset; |
| 1084 | unsigned FieldAlign; |
| 1085 | |
| 1086 | llvm::DIArray Elements; |
| 1087 | llvm::DIType EltTy; |
| 1088 | |
| 1089 | // Build up structure for the byref. See BuildByRefType. |
| 1090 | FieldOffset = 0; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1091 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1092 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1093 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1094 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1095 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1096 | "__isa", DefUnit, |
| 1097 | 0, FieldSize, FieldAlign, |
| 1098 | FieldOffset, 0, FieldTy); |
| 1099 | EltTys.push_back(FieldTy); |
| 1100 | FieldOffset += FieldSize; |
| 1101 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1102 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1103 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1104 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1105 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1106 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1107 | "__forwarding", DefUnit, |
| 1108 | 0, FieldSize, FieldAlign, |
| 1109 | FieldOffset, 0, FieldTy); |
| 1110 | EltTys.push_back(FieldTy); |
| 1111 | FieldOffset += FieldSize; |
| 1112 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1113 | FType = CGM.getContext().getFixedWidthIntType(32, true); // Int32Ty; |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1114 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1115 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1116 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1117 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1118 | "__flags", DefUnit, |
| 1119 | 0, FieldSize, FieldAlign, |
| 1120 | FieldOffset, 0, FieldTy); |
| 1121 | EltTys.push_back(FieldTy); |
| 1122 | FieldOffset += FieldSize; |
| 1123 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1124 | FType = CGM.getContext().getFixedWidthIntType(32, true); // Int32Ty; |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1125 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1126 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1127 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1128 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1129 | "__size", DefUnit, |
| 1130 | 0, FieldSize, FieldAlign, |
| 1131 | FieldOffset, 0, FieldTy); |
| 1132 | EltTys.push_back(FieldTy); |
| 1133 | FieldOffset += FieldSize; |
| 1134 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1135 | bool HasCopyAndDispose = CGM.BlockRequiresCopying(Type); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1136 | if (HasCopyAndDispose) { |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1137 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1138 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1139 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1140 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1141 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1142 | "__copy_helper", DefUnit, |
| 1143 | 0, FieldSize, FieldAlign, |
| 1144 | FieldOffset, 0, FieldTy); |
| 1145 | EltTys.push_back(FieldTy); |
| 1146 | FieldOffset += FieldSize; |
| 1147 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1148 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1149 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1150 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1151 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1152 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1153 | "__destroy_helper", DefUnit, |
| 1154 | 0, FieldSize, FieldAlign, |
| 1155 | FieldOffset, 0, FieldTy); |
| 1156 | EltTys.push_back(FieldTy); |
| 1157 | FieldOffset += FieldSize; |
| 1158 | } |
| 1159 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1160 | unsigned Align = CGM.getContext().getDeclAlignInBytes(Decl); |
| 1161 | if (Align > CGM.getContext().Target.getPointerAlign(0) / 8) { |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1162 | unsigned AlignedOffsetInBytes |
Mike Stump | fd47b31 | 2009-09-22 02:44:17 +0000 | [diff] [blame] | 1163 | = llvm::RoundUpToAlignment(FieldOffset/8, Align); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1164 | unsigned NumPaddingBytes |
Mike Stump | fd47b31 | 2009-09-22 02:44:17 +0000 | [diff] [blame] | 1165 | = AlignedOffsetInBytes - FieldOffset/8; |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1166 | |
| 1167 | if (NumPaddingBytes > 0) { |
| 1168 | llvm::APInt pad(32, NumPaddingBytes); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1169 | FType = CGM.getContext().getConstantArrayType(CGM.getContext().CharTy, |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1170 | pad, ArrayType::Normal, 0); |
| 1171 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1172 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1173 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1174 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, |
| 1175 | Unit, "", DefUnit, |
| 1176 | 0, FieldSize, FieldAlign, |
| 1177 | FieldOffset, 0, FieldTy); |
| 1178 | EltTys.push_back(FieldTy); |
| 1179 | FieldOffset += FieldSize; |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | FType = Type; |
| 1184 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1185 | FieldSize = CGM.getContext().getTypeSize(FType); |
Mike Stump | fd47b31 | 2009-09-22 02:44:17 +0000 | [diff] [blame] | 1186 | FieldAlign = Align*8; |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1187 | |
| 1188 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 1189 | Decl->getName(), DefUnit, |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1190 | 0, FieldSize, FieldAlign, |
| 1191 | FieldOffset, 0, FieldTy); |
| 1192 | EltTys.push_back(FieldTy); |
| 1193 | FieldOffset += FieldSize; |
| 1194 | |
| 1195 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
| 1196 | |
| 1197 | unsigned Flags = llvm::DIType::FlagBlockByrefStruct; |
| 1198 | |
| 1199 | Ty = DebugFactory.CreateCompositeType(Tag, Unit, "", |
| 1200 | llvm::DICompileUnit(), |
| 1201 | 0, FieldOffset, 0, 0, Flags, |
| 1202 | llvm::DIType(), Elements); |
| 1203 | } |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1204 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1205 | // Get location information. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1206 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 1207 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1208 | unsigned Line = 0; |
Eli Friedman | 1468ac7 | 2009-11-16 20:33:31 +0000 | [diff] [blame] | 1209 | unsigned Column = 0; |
| 1210 | if (!PLoc.isInvalid()) { |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1211 | Line = PLoc.getLine(); |
Eli Friedman | 1468ac7 | 2009-11-16 20:33:31 +0000 | [diff] [blame] | 1212 | Column = PLoc.getColumn(); |
| 1213 | } else { |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1214 | Unit = llvm::DICompileUnit(); |
Eli Friedman | 1468ac7 | 2009-11-16 20:33:31 +0000 | [diff] [blame] | 1215 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1216 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1217 | // Create the descriptor for the variable. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1218 | llvm::DIVariable D = |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1219 | DebugFactory.CreateVariable(Tag, llvm::DIDescriptor(RegionStack.back()), |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 1220 | Decl->getName(), |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1221 | Unit, Line, Ty); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1222 | // Insert an llvm.dbg.declare into the current block. |
Devang Patel | ebf16e8 | 2009-11-11 19:10:19 +0000 | [diff] [blame] | 1223 | llvm::Instruction *Call = |
Devang Patel | a020380 | 2009-11-10 23:07:24 +0000 | [diff] [blame] | 1224 | DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1225 | |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1226 | llvm::DIScope DS(RegionStack.back()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1227 | llvm::DILocation DO(NULL); |
| 1228 | llvm::DILocation DL = |
Eli Friedman | 1468ac7 | 2009-11-16 20:33:31 +0000 | [diff] [blame] | 1229 | DebugFactory.CreateLocation(Line, Column, DS, DO); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1230 | Builder.SetDebugLocation(Call, DL.getNode()); |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 1231 | } |
| 1232 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1233 | /// EmitDeclare - Emit local variable declaration debug info. |
| 1234 | void CGDebugInfo::EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, |
| 1235 | llvm::Value *Storage, CGBuilderTy &Builder, |
| 1236 | CodeGenFunction *CGF) { |
| 1237 | const ValueDecl *Decl = BDRE->getDecl(); |
| 1238 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1239 | |
| 1240 | // Do not emit variable debug information while generating optimized code. |
| 1241 | // The llvm optimizer and code generator are not yet ready to support |
| 1242 | // optimized code debugging. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1243 | const CodeGenOptions &CGO = CGM.getCodeGenOpts(); |
Chandler Carruth | 2811ccf | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 1244 | if (CGO.OptimizationLevel || Builder.GetInsertBlock() == 0) |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1245 | return; |
| 1246 | |
| 1247 | uint64_t XOffset = 0; |
| 1248 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation()); |
| 1249 | QualType Type = Decl->getType(); |
| 1250 | llvm::DIType Ty = getOrCreateType(Type, Unit); |
| 1251 | if (Decl->hasAttr<BlocksAttr>()) { |
| 1252 | llvm::DICompileUnit DefUnit; |
| 1253 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
| 1254 | |
| 1255 | llvm::SmallVector<llvm::DIDescriptor, 5> EltTys; |
| 1256 | |
| 1257 | llvm::DIType FieldTy; |
| 1258 | |
| 1259 | QualType FType; |
| 1260 | uint64_t FieldSize, FieldOffset; |
| 1261 | unsigned FieldAlign; |
| 1262 | |
| 1263 | llvm::DIArray Elements; |
| 1264 | llvm::DIType EltTy; |
| 1265 | |
| 1266 | // Build up structure for the byref. See BuildByRefType. |
| 1267 | FieldOffset = 0; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1268 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1269 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1270 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1271 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1272 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1273 | "__isa", DefUnit, |
| 1274 | 0, FieldSize, FieldAlign, |
| 1275 | FieldOffset, 0, FieldTy); |
| 1276 | EltTys.push_back(FieldTy); |
| 1277 | FieldOffset += FieldSize; |
| 1278 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1279 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1280 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1281 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1282 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1283 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1284 | "__forwarding", DefUnit, |
| 1285 | 0, FieldSize, FieldAlign, |
| 1286 | FieldOffset, 0, FieldTy); |
| 1287 | EltTys.push_back(FieldTy); |
| 1288 | FieldOffset += FieldSize; |
| 1289 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1290 | FType = CGM.getContext().getFixedWidthIntType(32, true); // Int32Ty; |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1291 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1292 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1293 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1294 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1295 | "__flags", DefUnit, |
| 1296 | 0, FieldSize, FieldAlign, |
| 1297 | FieldOffset, 0, FieldTy); |
| 1298 | EltTys.push_back(FieldTy); |
| 1299 | FieldOffset += FieldSize; |
| 1300 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1301 | FType = CGM.getContext().getFixedWidthIntType(32, true); // Int32Ty; |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1302 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1303 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1304 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1305 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1306 | "__size", DefUnit, |
| 1307 | 0, FieldSize, FieldAlign, |
| 1308 | FieldOffset, 0, FieldTy); |
| 1309 | EltTys.push_back(FieldTy); |
| 1310 | FieldOffset += FieldSize; |
| 1311 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1312 | bool HasCopyAndDispose = CGM.BlockRequiresCopying(Type); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1313 | if (HasCopyAndDispose) { |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1314 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1315 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1316 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1317 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1318 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1319 | "__copy_helper", DefUnit, |
| 1320 | 0, FieldSize, FieldAlign, |
| 1321 | FieldOffset, 0, FieldTy); |
| 1322 | EltTys.push_back(FieldTy); |
| 1323 | FieldOffset += FieldSize; |
| 1324 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1325 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1326 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1327 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1328 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1329 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1330 | "__destroy_helper", DefUnit, |
| 1331 | 0, FieldSize, FieldAlign, |
| 1332 | FieldOffset, 0, FieldTy); |
| 1333 | EltTys.push_back(FieldTy); |
| 1334 | FieldOffset += FieldSize; |
| 1335 | } |
| 1336 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1337 | unsigned Align = CGM.getContext().getDeclAlignInBytes(Decl); |
| 1338 | if (Align > CGM.getContext().Target.getPointerAlign(0) / 8) { |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1339 | unsigned AlignedOffsetInBytes |
| 1340 | = llvm::RoundUpToAlignment(FieldOffset/8, Align); |
| 1341 | unsigned NumPaddingBytes |
| 1342 | = AlignedOffsetInBytes - FieldOffset/8; |
| 1343 | |
| 1344 | if (NumPaddingBytes > 0) { |
| 1345 | llvm::APInt pad(32, NumPaddingBytes); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1346 | FType = CGM.getContext().getConstantArrayType(CGM.getContext().CharTy, |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1347 | pad, ArrayType::Normal, 0); |
| 1348 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1349 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1350 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1351 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, |
| 1352 | Unit, "", DefUnit, |
| 1353 | 0, FieldSize, FieldAlign, |
| 1354 | FieldOffset, 0, FieldTy); |
| 1355 | EltTys.push_back(FieldTy); |
| 1356 | FieldOffset += FieldSize; |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | FType = Type; |
| 1361 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1362 | FieldSize = CGM.getContext().getTypeSize(FType); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1363 | FieldAlign = Align*8; |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1364 | |
| 1365 | XOffset = FieldOffset; |
| 1366 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 1367 | Decl->getName(), DefUnit, |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1368 | 0, FieldSize, FieldAlign, |
| 1369 | FieldOffset, 0, FieldTy); |
| 1370 | EltTys.push_back(FieldTy); |
| 1371 | FieldOffset += FieldSize; |
| 1372 | |
| 1373 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
| 1374 | |
| 1375 | unsigned Flags = llvm::DIType::FlagBlockByrefStruct; |
| 1376 | |
| 1377 | Ty = DebugFactory.CreateCompositeType(Tag, Unit, "", |
| 1378 | llvm::DICompileUnit(), |
| 1379 | 0, FieldOffset, 0, 0, Flags, |
| 1380 | llvm::DIType(), Elements); |
| 1381 | } |
| 1382 | |
| 1383 | // Get location information. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1384 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1385 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
| 1386 | unsigned Line = 0; |
| 1387 | if (!PLoc.isInvalid()) |
| 1388 | Line = PLoc.getLine(); |
| 1389 | else |
| 1390 | Unit = llvm::DICompileUnit(); |
| 1391 | |
| 1392 | uint64_t offset = CGF->BlockDecls[Decl]; |
| 1393 | llvm::SmallVector<llvm::Value *, 9> addr; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1394 | llvm::LLVMContext &VMContext = CGM.getLLVMContext(); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1395 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1396 | llvm::DIFactory::OpDeref)); |
| 1397 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1398 | llvm::DIFactory::OpPlus)); |
| 1399 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1400 | offset)); |
| 1401 | if (BDRE->isByRef()) { |
| 1402 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1403 | llvm::DIFactory::OpDeref)); |
| 1404 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1405 | llvm::DIFactory::OpPlus)); |
| 1406 | offset = CGF->LLVMPointerWidth/8; // offset of __forwarding field |
| 1407 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1408 | offset)); |
| 1409 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1410 | llvm::DIFactory::OpDeref)); |
| 1411 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1412 | llvm::DIFactory::OpPlus)); |
| 1413 | offset = XOffset/8; // offset of x field |
| 1414 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1415 | offset)); |
| 1416 | } |
| 1417 | |
| 1418 | // Create the descriptor for the variable. |
| 1419 | llvm::DIVariable D = |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1420 | DebugFactory.CreateComplexVariable(Tag, llvm::DIDescriptor(RegionStack.back()), |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 1421 | Decl->getName(), Unit, Line, Ty, |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1422 | addr); |
| 1423 | // Insert an llvm.dbg.declare into the current block. |
Devang Patel | ebf16e8 | 2009-11-11 19:10:19 +0000 | [diff] [blame] | 1424 | llvm::Instruction *Call = |
| 1425 | DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertPoint()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1426 | |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1427 | llvm::DIScope DS(RegionStack.back()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1428 | llvm::DILocation DO(NULL); |
| 1429 | llvm::DILocation DL = |
| 1430 | DebugFactory.CreateLocation(Line, PLoc.getColumn(), DS, DO); |
| 1431 | Builder.SetDebugLocation(Call, DL.getNode()); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1434 | void CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *Decl, |
| 1435 | llvm::Value *Storage, |
| 1436 | CGBuilderTy &Builder) { |
| 1437 | EmitDeclare(Decl, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder); |
| 1438 | } |
| 1439 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1440 | void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable( |
| 1441 | const BlockDeclRefExpr *BDRE, llvm::Value *Storage, CGBuilderTy &Builder, |
| 1442 | CodeGenFunction *CGF) { |
| 1443 | EmitDeclare(BDRE, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder, CGF); |
| 1444 | } |
| 1445 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1446 | /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument |
| 1447 | /// variable declaration. |
| 1448 | void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, |
| 1449 | CGBuilderTy &Builder) { |
| 1450 | EmitDeclare(Decl, llvm::dwarf::DW_TAG_arg_variable, AI, Builder); |
| 1451 | } |
| 1452 | |
| 1453 | |
| 1454 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1455 | /// EmitGlobalVariable - Emit information about a global variable. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1456 | void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1457 | const VarDecl *Decl) { |
Devang Patel | 0773903 | 2009-03-27 23:16:32 +0000 | [diff] [blame] | 1458 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1459 | // Create global variable debug descriptor. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1460 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation()); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1461 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 1462 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
| 1463 | unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 1464 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1465 | QualType T = Decl->getType(); |
| 1466 | if (T->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1467 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1468 | // CodeGen turns int[] into int[1] so we'll do the same here. |
| 1469 | llvm::APSInt ConstVal(32); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1470 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1471 | ConstVal = 1; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1472 | QualType ET = CGM.getContext().getAsArrayType(T)->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1473 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1474 | T = CGM.getContext().getConstantArrayType(ET, ConstVal, |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1475 | ArrayType::Normal, 0); |
| 1476 | } |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 1477 | llvm::StringRef DeclName = Decl->getName(); |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 1478 | DebugFactory.CreateGlobalVariable(getContext(Decl, Unit), DeclName, DeclName, |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 1479 | llvm::StringRef(), Unit, LineNo, |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1480 | getOrCreateType(T, Unit), |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1481 | Var->hasInternalLinkage(), |
| 1482 | true/*definition*/, Var); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1483 | } |
| 1484 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1485 | /// EmitGlobalVariable - Emit information about an objective-c interface. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1486 | void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1487 | ObjCInterfaceDecl *Decl) { |
| 1488 | // Create global variable debug descriptor. |
| 1489 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation()); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1490 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 1491 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
| 1492 | unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1493 | |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 1494 | llvm::StringRef Name = Decl->getName(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1495 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1496 | QualType T = CGM.getContext().getObjCInterfaceType(Decl); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1497 | if (T->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1498 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1499 | // CodeGen turns int[] into int[1] so we'll do the same here. |
| 1500 | llvm::APSInt ConstVal(32); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1501 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1502 | ConstVal = 1; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1503 | QualType ET = CGM.getContext().getAsArrayType(T)->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1504 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1505 | T = CGM.getContext().getConstantArrayType(ET, ConstVal, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1506 | ArrayType::Normal, 0); |
| 1507 | } |
| 1508 | |
Devang Patel | f6a39b7 | 2009-10-20 18:26:30 +0000 | [diff] [blame] | 1509 | DebugFactory.CreateGlobalVariable(Unit, Name, Name, Name, Unit, LineNo, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1510 | getOrCreateType(T, Unit), |
| 1511 | Var->hasInternalLinkage(), |
| 1512 | true/*definition*/, Var); |
| 1513 | } |