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