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