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