Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1 | //===--- CGDebugInfo.cpp - Emit Debug Information for a Module ------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This coordinates the debug information generation while generating code. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CGDebugInfo.h" |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 15 | #include "CodeGenFunction.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 16 | #include "CodeGenModule.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclObjC.h" |
Chris Lattner | 3cc5c40 | 2008-11-11 07:01:36 +0000 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" |
Anders Carlsson | 19cc4ab | 2009-07-18 19:43:29 +0000 | [diff] [blame] | 20 | #include "clang/AST/RecordLayout.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 21 | #include "clang/Basic/SourceManager.h" |
| 22 | #include "clang/Basic/FileManager.h" |
Mike Stump | 5a86217 | 2009-09-15 21:48:34 +0000 | [diff] [blame] | 23 | #include "clang/Basic/Version.h" |
Chandler Carruth | 2811ccf | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 24 | #include "clang/CodeGen/CodeGenOptions.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 25 | #include "llvm/Constants.h" |
| 26 | #include "llvm/DerivedTypes.h" |
| 27 | #include "llvm/Instructions.h" |
| 28 | #include "llvm/Intrinsics.h" |
| 29 | #include "llvm/Module.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/StringExtras.h" |
| 31 | #include "llvm/ADT/SmallVector.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 32 | #include "llvm/Support/Dwarf.h" |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 33 | #include "llvm/System/Path.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 34 | #include "llvm/Target/TargetMachine.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 35 | using namespace clang; |
| 36 | using namespace clang::CodeGen; |
| 37 | |
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) { |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 60 | llvm::DIDescriptor R(RegionStack[RI - 1]); |
Devang Patel | 979ec2e | 2009-10-06 00:35:31 +0000 | [diff] [blame] | 61 | if (R.isSubprogram()) |
| 62 | return R; |
| 63 | } |
| 64 | } |
| 65 | return CompileUnit; |
| 66 | } |
| 67 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 68 | /// getOrCreateCompileUnit - Get the compile unit from the cache or create a new |
Daniel Dunbar | 25f51dd | 2008-10-24 08:38:36 +0000 | [diff] [blame] | 69 | /// one if necessary. This returns null for invalid source locations. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 70 | llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) { |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 71 | // Get source file information. |
| 72 | const char *FileName = "<unknown>"; |
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 | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 139 | return Unit = DebugFactory.CreateCompileUnit(LangTag, |
| 140 | AbsFileName.getLast().c_str(), |
| 141 | AbsFileName.getDirname().c_str(), |
| 142 | Producer.c_str(), isMain, |
| 143 | isOptimized, Flags, RuntimeVers); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 146 | /// CreateType - Get the Basic type from the cache or create a new |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 147 | /// one if necessary. |
| 148 | llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT, |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 149 | llvm::DICompileUnit Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 150 | unsigned Encoding = 0; |
| 151 | switch (BT->getKind()) { |
| 152 | default: |
| 153 | case BuiltinType::Void: |
| 154 | return llvm::DIType(); |
| 155 | case BuiltinType::UChar: |
| 156 | case BuiltinType::Char_U: Encoding = llvm::dwarf::DW_ATE_unsigned_char; break; |
| 157 | case BuiltinType::Char_S: |
| 158 | case BuiltinType::SChar: Encoding = llvm::dwarf::DW_ATE_signed_char; break; |
| 159 | case BuiltinType::UShort: |
| 160 | case BuiltinType::UInt: |
| 161 | case BuiltinType::ULong: |
| 162 | case BuiltinType::ULongLong: Encoding = llvm::dwarf::DW_ATE_unsigned; break; |
| 163 | case BuiltinType::Short: |
| 164 | case BuiltinType::Int: |
| 165 | case BuiltinType::Long: |
| 166 | case BuiltinType::LongLong: Encoding = llvm::dwarf::DW_ATE_signed; break; |
| 167 | case BuiltinType::Bool: Encoding = llvm::dwarf::DW_ATE_boolean; break; |
| 168 | case BuiltinType::Float: |
Devang Patel | 7c173cb | 2009-10-12 22:28:31 +0000 | [diff] [blame] | 169 | case BuiltinType::LongDouble: |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 170 | case BuiltinType::Double: Encoding = llvm::dwarf::DW_ATE_float; break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 171 | } |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 172 | // Bit size, align and offset of the type. |
| 173 | uint64_t Size = M->getContext().getTypeSize(BT); |
| 174 | uint64_t Align = M->getContext().getTypeAlign(BT); |
| 175 | uint64_t Offset = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 176 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 177 | llvm::DIType DbgTy = |
| 178 | DebugFactory.CreateBasicType(Unit, |
| 179 | BT->getName(M->getContext().getLangOptions()), |
| 180 | Unit, 0, Size, Align, |
| 181 | Offset, /*flags*/ 0, Encoding); |
| 182 | |
| 183 | TypeCache[QualType(BT, 0).getAsOpaquePtr()] = DbgTy.getNode(); |
| 184 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 185 | } |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 186 | |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 187 | llvm::DIType CGDebugInfo::CreateType(const ComplexType *Ty, |
| 188 | llvm::DICompileUnit Unit) { |
| 189 | // Bit size, align and offset of the type. |
| 190 | unsigned Encoding = llvm::dwarf::DW_ATE_complex_float; |
| 191 | if (Ty->isComplexIntegerType()) |
| 192 | Encoding = llvm::dwarf::DW_ATE_lo_user; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 193 | |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 194 | uint64_t Size = M->getContext().getTypeSize(Ty); |
| 195 | uint64_t Align = M->getContext().getTypeAlign(Ty); |
| 196 | uint64_t Offset = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 197 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 198 | llvm::DIType DbgTy = |
| 199 | DebugFactory.CreateBasicType(Unit, "complex", |
| 200 | Unit, 0, Size, Align, |
| 201 | Offset, /*flags*/ 0, Encoding); |
| 202 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = DbgTy.getNode(); |
| 203 | return DbgTy; |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 204 | } |
| 205 | |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 206 | /// CreateCVRType - Get the qualified type from the cache or create |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 207 | /// a new one if necessary. |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 208 | llvm::DIType CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DICompileUnit Unit) { |
| 209 | QualifierCollector Qc; |
| 210 | const Type *T = Qc.strip(Ty); |
| 211 | |
| 212 | // Ignore these qualifiers for now. |
| 213 | Qc.removeObjCGCAttr(); |
| 214 | Qc.removeAddressSpace(); |
| 215 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 216 | // We will create one Derived type for one qualifier and recurse to handle any |
| 217 | // additional ones. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 218 | unsigned Tag; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 219 | if (Qc.hasConst()) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 220 | Tag = llvm::dwarf::DW_TAG_const_type; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 221 | Qc.removeConst(); |
| 222 | } else if (Qc.hasVolatile()) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 223 | Tag = llvm::dwarf::DW_TAG_volatile_type; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 224 | Qc.removeVolatile(); |
| 225 | } else if (Qc.hasRestrict()) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 226 | Tag = llvm::dwarf::DW_TAG_restrict_type; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 227 | Qc.removeRestrict(); |
| 228 | } else { |
| 229 | assert(Qc.empty() && "Unknown type qualifier for debug info"); |
| 230 | return getOrCreateType(QualType(T, 0), Unit); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 231 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 232 | |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 233 | llvm::DIType FromTy = getOrCreateType(Qc.apply(T), Unit); |
| 234 | |
Daniel Dunbar | 3845f86 | 2008-10-31 03:54:29 +0000 | [diff] [blame] | 235 | // No need to fill in the Name, Line, Size, Alignment, Offset in case of |
| 236 | // CVR derived types. |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 237 | llvm::DIType DbgTy = |
| 238 | DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(), |
| 239 | 0, 0, 0, 0, 0, FromTy); |
| 240 | TypeCache[Ty.getAsOpaquePtr()] = DbgTy.getNode(); |
| 241 | return DbgTy; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 244 | llvm::DIType CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty, |
| 245 | llvm::DICompileUnit Unit) { |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 246 | llvm::DIType DbgTy = |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 247 | CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty, |
| 248 | Ty->getPointeeType(), Unit); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 249 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = DbgTy.getNode(); |
| 250 | return DbgTy; |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 253 | llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty, |
| 254 | llvm::DICompileUnit Unit) { |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 255 | return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty, |
| 256 | Ty->getPointeeType(), Unit); |
| 257 | } |
| 258 | |
| 259 | llvm::DIType CGDebugInfo::CreatePointerLikeType(unsigned Tag, |
| 260 | const Type *Ty, |
| 261 | QualType PointeeTy, |
| 262 | llvm::DICompileUnit Unit) { |
| 263 | llvm::DIType EltTy = getOrCreateType(PointeeTy, Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 264 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 265 | // Bit size, align and offset of the type. |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 266 | |
| 267 | // Size is always the size of a pointer. We can't use getTypeSize here |
| 268 | // because that does not return the correct value for references. |
| 269 | uint64_t Size = |
| 270 | M->getContext().Target.getPointerWidth(PointeeTy.getAddressSpace()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 271 | uint64_t Align = M->getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 272 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 273 | return |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 274 | DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(), |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 275 | 0, Size, Align, 0, 0, EltTy); |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 276 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 279 | llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, |
| 280 | llvm::DICompileUnit Unit) { |
| 281 | if (BlockLiteralGenericSet) |
| 282 | return BlockLiteralGeneric; |
| 283 | |
| 284 | llvm::DICompileUnit DefUnit; |
| 285 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
| 286 | |
| 287 | llvm::SmallVector<llvm::DIDescriptor, 5> EltTys; |
| 288 | |
| 289 | llvm::DIType FieldTy; |
| 290 | |
| 291 | QualType FType; |
| 292 | uint64_t FieldSize, FieldOffset; |
| 293 | unsigned FieldAlign; |
| 294 | |
| 295 | llvm::DIArray Elements; |
| 296 | llvm::DIType EltTy, DescTy; |
| 297 | |
| 298 | FieldOffset = 0; |
| 299 | FType = M->getContext().UnsignedLongTy; |
| 300 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 301 | FieldSize = M->getContext().getTypeSize(FType); |
| 302 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 303 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 304 | "reserved", DefUnit, |
| 305 | 0, FieldSize, FieldAlign, |
| 306 | FieldOffset, 0, FieldTy); |
| 307 | EltTys.push_back(FieldTy); |
| 308 | |
| 309 | FieldOffset += FieldSize; |
| 310 | FType = M->getContext().UnsignedLongTy; |
| 311 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 312 | FieldSize = M->getContext().getTypeSize(FType); |
| 313 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 314 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 315 | "Size", DefUnit, |
| 316 | 0, FieldSize, FieldAlign, |
| 317 | FieldOffset, 0, FieldTy); |
| 318 | EltTys.push_back(FieldTy); |
| 319 | |
| 320 | FieldOffset += FieldSize; |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 321 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 322 | EltTys.clear(); |
| 323 | |
Mike Stump | 3d363c5 | 2009-10-02 02:30:50 +0000 | [diff] [blame] | 324 | unsigned Flags = llvm::DIType::FlagAppleBlock; |
| 325 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 326 | EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_descriptor", |
Mike Stump | 3d363c5 | 2009-10-02 02:30:50 +0000 | [diff] [blame] | 327 | DefUnit, 0, FieldOffset, 0, 0, Flags, |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 328 | llvm::DIType(), Elements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 329 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 330 | // Bit size, align and offset of the type. |
| 331 | uint64_t Size = M->getContext().getTypeSize(Ty); |
| 332 | uint64_t Align = M->getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 333 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 334 | DescTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, |
| 335 | Unit, "", llvm::DICompileUnit(), |
| 336 | 0, Size, Align, 0, 0, EltTy); |
| 337 | |
| 338 | FieldOffset = 0; |
| 339 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 340 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 341 | FieldSize = M->getContext().getTypeSize(FType); |
| 342 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 343 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 344 | "__isa", DefUnit, |
| 345 | 0, FieldSize, FieldAlign, |
| 346 | FieldOffset, 0, FieldTy); |
| 347 | EltTys.push_back(FieldTy); |
| 348 | |
| 349 | FieldOffset += FieldSize; |
| 350 | FType = M->getContext().IntTy; |
| 351 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 352 | FieldSize = M->getContext().getTypeSize(FType); |
| 353 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 354 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 355 | "__flags", DefUnit, |
| 356 | 0, FieldSize, FieldAlign, |
| 357 | FieldOffset, 0, FieldTy); |
| 358 | EltTys.push_back(FieldTy); |
| 359 | |
| 360 | FieldOffset += FieldSize; |
| 361 | FType = M->getContext().IntTy; |
| 362 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 363 | FieldSize = M->getContext().getTypeSize(FType); |
| 364 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 365 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 366 | "__reserved", DefUnit, |
| 367 | 0, FieldSize, FieldAlign, |
| 368 | FieldOffset, 0, FieldTy); |
| 369 | EltTys.push_back(FieldTy); |
| 370 | |
| 371 | FieldOffset += FieldSize; |
| 372 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 373 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 374 | FieldSize = M->getContext().getTypeSize(FType); |
| 375 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 376 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 377 | "__FuncPtr", DefUnit, |
| 378 | 0, FieldSize, FieldAlign, |
| 379 | FieldOffset, 0, FieldTy); |
| 380 | EltTys.push_back(FieldTy); |
| 381 | |
| 382 | FieldOffset += FieldSize; |
| 383 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 384 | FieldTy = DescTy; |
| 385 | FieldSize = M->getContext().getTypeSize(Ty); |
| 386 | FieldAlign = M->getContext().getTypeAlign(Ty); |
| 387 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 388 | "__descriptor", DefUnit, |
| 389 | 0, FieldSize, FieldAlign, |
| 390 | FieldOffset, 0, FieldTy); |
| 391 | EltTys.push_back(FieldTy); |
| 392 | |
| 393 | FieldOffset += FieldSize; |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 394 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 395 | |
| 396 | EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_literal_generic", |
Mike Stump | 944e705 | 2009-10-02 02:23:37 +0000 | [diff] [blame] | 397 | DefUnit, 0, FieldOffset, 0, 0, Flags, |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 398 | llvm::DIType(), Elements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 399 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 400 | BlockLiteralGenericSet = true; |
| 401 | BlockLiteralGeneric |
| 402 | = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit, |
| 403 | "", llvm::DICompileUnit(), |
| 404 | 0, Size, Align, 0, 0, EltTy); |
| 405 | return BlockLiteralGeneric; |
| 406 | } |
| 407 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 408 | llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty, |
| 409 | llvm::DICompileUnit Unit) { |
| 410 | // Typedefs are derived from some other type. If we have a typedef of a |
| 411 | // typedef, make sure to emit the whole chain. |
| 412 | llvm::DIType Src = getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 413 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 414 | // We don't set size information, but do specify where the typedef was |
| 415 | // declared. |
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, |
Devang Patel | 11169ad | 2009-11-12 17:49:47 +0000 | [diff] [blame] | 425 | Ty->getDecl()->getNameAsCString(), |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 426 | DefUnit, Line, 0, 0, 0, 0, Src); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 427 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = DbgTy.getNode(); |
| 428 | return DbgTy; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 431 | llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty, |
| 432 | llvm::DICompileUnit Unit) { |
| 433 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 434 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 435 | // Add the result type at least. |
| 436 | EltTys.push_back(getOrCreateType(Ty->getResultType(), Unit)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 437 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 438 | // Set up remainder of arguments if there is a prototype. |
| 439 | // FIXME: IF NOT, HOW IS THIS REPRESENTED? llvm-gcc doesn't represent '...'! |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 440 | if (const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(Ty)) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 441 | for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i) |
| 442 | EltTys.push_back(getOrCreateType(FTP->getArgType(i), Unit)); |
| 443 | } else { |
| 444 | // FIXME: Handle () case in C. llvm-gcc doesn't do it either. |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 447 | llvm::DIArray EltTypeArray = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 448 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 449 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 450 | llvm::DIType DbgTy = |
| 451 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, |
| 452 | Unit, "", llvm::DICompileUnit(), |
| 453 | 0, 0, 0, 0, 0, |
| 454 | llvm::DIType(), EltTypeArray); |
| 455 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = DbgTy.getNode(); |
| 456 | return DbgTy; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 459 | /// CreateType - get structure or union type. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 460 | llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, |
| 461 | llvm::DICompileUnit Unit) { |
Douglas Gregor | a4c46df | 2008-12-11 17:59:21 +0000 | [diff] [blame] | 462 | RecordDecl *Decl = Ty->getDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 463 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 464 | unsigned Tag; |
| 465 | if (Decl->isStruct()) |
| 466 | Tag = llvm::dwarf::DW_TAG_structure_type; |
| 467 | else if (Decl->isUnion()) |
| 468 | Tag = llvm::dwarf::DW_TAG_union_type; |
| 469 | else { |
| 470 | assert(Decl->isClass() && "Unknown RecordType!"); |
| 471 | Tag = llvm::dwarf::DW_TAG_class_type; |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 474 | SourceManager &SM = M->getContext().getSourceManager(); |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 475 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 476 | // Get overall information about the record type for the debug info. |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 477 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
Chris Lattner | d37d9b5 | 2009-05-05 05:16:17 +0000 | [diff] [blame] | 478 | llvm::DICompileUnit DefUnit; |
| 479 | unsigned Line = 0; |
| 480 | if (!PLoc.isInvalid()) { |
| 481 | DefUnit = getOrCreateCompileUnit(Decl->getLocation()); |
| 482 | Line = PLoc.getLine(); |
| 483 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 484 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 485 | // Records and classes and unions can all be recursive. To handle them, we |
| 486 | // first generate a debug descriptor for the struct as a forward declaration. |
| 487 | // Then (if it is a definition) we go through and get debug info for all of |
| 488 | // its members. Finally, we create a descriptor for the complete type (which |
| 489 | // may refer to the forward decl if the struct is recursive) and replace all |
| 490 | // uses of the forward declaration with the final definition. |
Devang Patel | 0ce73f6 | 2009-07-22 18:57:00 +0000 | [diff] [blame] | 491 | llvm::DICompositeType FwdDecl = |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 492 | DebugFactory.CreateCompositeType(Tag, Unit, Decl->getNameAsString().data(), |
| 493 | DefUnit, Line, 0, 0, 0, 0, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 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 | |
Devang Patel | 11169ad | 2009-11-12 17:49:47 +0000 | [diff] [blame] | 516 | const char *FieldName = Field->getNameAsCString(); |
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. |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 519 | if (!FieldName) |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 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 = |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 567 | DebugFactory.CreateCompositeType(Tag, Unit, Decl->getNameAsString().data(), |
| 568 | DefUnit, Line, Size, Align, 0, 0, |
| 569 | llvm::DIType(), Elements); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 570 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 571 | // Update TypeCache. |
| 572 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl.getNode(); |
| 573 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 574 | // Now that we have a real decl for the struct, replace anything using the |
| 575 | // 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] | 576 | FwdDecl.replaceAllUsesWith(RealDecl); |
Devang Patel | fe09eab | 2009-07-13 17:03:14 +0000 | [diff] [blame] | 577 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 578 | return RealDecl; |
| 579 | } |
| 580 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 581 | /// CreateType - get objective-c interface type. |
| 582 | llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, |
| 583 | llvm::DICompileUnit Unit) { |
| 584 | ObjCInterfaceDecl *Decl = Ty->getDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 585 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 586 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
| 587 | SourceManager &SM = M->getContext().getSourceManager(); |
| 588 | |
| 589 | // Get overall information about the record type for the debug info. |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 590 | llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(Decl->getLocation()); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 591 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
| 592 | unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
| 593 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 594 | |
Daniel Dunbar | d86d336 | 2009-05-18 20:51:58 +0000 | [diff] [blame] | 595 | unsigned RuntimeLang = DefUnit.getLanguage(); |
Chris Lattner | ac7c814 | 2009-05-02 01:13:16 +0000 | [diff] [blame] | 596 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 597 | // To handle recursive interface, we |
| 598 | // first generate a debug descriptor for the struct as a forward declaration. |
| 599 | // Then (if it is a definition) we go through and get debug info for all of |
| 600 | // its members. Finally, we create a descriptor for the complete type (which |
| 601 | // may refer to the forward decl if the struct is recursive) and replace all |
| 602 | // uses of the forward declaration with the final definition. |
Devang Patel | 6c1fddf | 2009-07-27 18:42:03 +0000 | [diff] [blame] | 603 | llvm::DICompositeType FwdDecl = |
Devang Patel | 11169ad | 2009-11-12 17:49:47 +0000 | [diff] [blame] | 604 | DebugFactory.CreateCompositeType(Tag, Unit, Decl->getNameAsCString(), |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 605 | 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 | |
Devang Patel | 11169ad | 2009-11-12 17:49:47 +0000 | [diff] [blame] | 639 | const char *FieldName = Field->getNameAsCString(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 640 | |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 641 | // Ignore unnamed fields. |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 642 | if (!FieldName) |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 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 | 11169ad | 2009-11-12 17:49:47 +0000 | [diff] [blame] | 693 | DebugFactory.CreateCompositeType(Tag, Unit, Decl->getNameAsCString(), DefUnit, |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 694 | Line, Size, Align, 0, 0, llvm::DIType(), |
| 695 | Elements, 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) { |
Devang Patel | 11169ad | 2009-11-12 17:49:47 +0000 | [diff] [blame] | 717 | Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getNameAsCString(), |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 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 | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 725 | SourceLocation DefLoc = Decl->getLocation(); |
| 726 | llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(DefLoc); |
| 727 | SourceManager &SM = M->getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 728 | PresumedLoc PLoc = SM.getPresumedLoc(DefLoc); |
| 729 | unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
| 730 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 731 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 732 | // Size and align of the type. |
Eli Friedman | 3189e4b | 2009-05-04 04:39:55 +0000 | [diff] [blame] | 733 | uint64_t Size = 0; |
| 734 | unsigned Align = 0; |
| 735 | if (!Ty->isIncompleteType()) { |
| 736 | Size = M->getContext().getTypeSize(Ty); |
| 737 | Align = M->getContext().getTypeAlign(Ty); |
| 738 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 739 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 740 | llvm::DIType DbgTy = |
| 741 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type, |
Devang Patel | 11169ad | 2009-11-12 17:49:47 +0000 | [diff] [blame] | 742 | Unit, Decl->getNameAsCString(), DefUnit, Line, |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 743 | Size, Align, 0, 0, |
| 744 | llvm::DIType(), EltArray); |
| 745 | |
| 746 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = DbgTy.getNode(); |
| 747 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | llvm::DIType CGDebugInfo::CreateType(const TagType *Ty, |
| 751 | llvm::DICompileUnit Unit) { |
| 752 | if (const RecordType *RT = dyn_cast<RecordType>(Ty)) |
| 753 | return CreateType(RT, Unit); |
| 754 | else if (const EnumType *ET = dyn_cast<EnumType>(Ty)) |
| 755 | return CreateType(ET, Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 757 | return llvm::DIType(); |
| 758 | } |
| 759 | |
| 760 | llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty, |
| 761 | llvm::DICompileUnit Unit) { |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 762 | uint64_t Size; |
| 763 | uint64_t Align; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 764 | |
| 765 | |
Nuno Lopes | 010d514 | 2009-01-28 00:35:17 +0000 | [diff] [blame] | 766 | // FIXME: make getTypeAlign() aware of VLAs and incomplete array types |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 767 | if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(Ty)) { |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 768 | Size = 0; |
| 769 | Align = |
Nuno Lopes | 010d514 | 2009-01-28 00:35:17 +0000 | [diff] [blame] | 770 | M->getContext().getTypeAlign(M->getContext().getBaseElementType(VAT)); |
| 771 | } else if (Ty->isIncompleteArrayType()) { |
| 772 | Size = 0; |
| 773 | Align = M->getContext().getTypeAlign(Ty->getElementType()); |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 774 | } else { |
| 775 | // Size and align of the whole array, not the element type. |
| 776 | Size = M->getContext().getTypeSize(Ty); |
| 777 | Align = M->getContext().getTypeAlign(Ty); |
| 778 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 779 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 780 | // Add the dimensions of the array. FIXME: This loses CV qualifiers from |
| 781 | // interior arrays, do we care? Why aren't nested arrays represented the |
| 782 | // obvious/recursive way? |
| 783 | llvm::SmallVector<llvm::DIDescriptor, 8> Subscripts; |
| 784 | QualType EltTy(Ty, 0); |
| 785 | while ((Ty = dyn_cast<ArrayType>(EltTy))) { |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 786 | uint64_t Upper = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 787 | if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty)) |
Devang Patel | 5a6bfe3 | 2009-08-14 20:57:45 +0000 | [diff] [blame] | 788 | if (CAT->getSize().getZExtValue()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 789 | Upper = CAT->getSize().getZExtValue() - 1; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 790 | // FIXME: Verify this is right for VLAs. |
| 791 | Subscripts.push_back(DebugFactory.GetOrCreateSubrange(0, Upper)); |
| 792 | EltTy = Ty->getElementType(); |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 793 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 794 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 795 | llvm::DIArray SubscriptArray = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 796 | DebugFactory.GetOrCreateArray(Subscripts.data(), Subscripts.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 797 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 798 | llvm::DIType DbgTy = |
| 799 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_array_type, |
| 800 | Unit, "", llvm::DICompileUnit(), |
| 801 | 0, Size, Align, 0, 0, |
| 802 | getOrCreateType(EltTy, Unit), |
| 803 | SubscriptArray); |
| 804 | |
| 805 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = DbgTy.getNode(); |
| 806 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 807 | } |
| 808 | |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 809 | llvm::DIType CGDebugInfo::CreateType(const LValueReferenceType *Ty, |
| 810 | llvm::DICompileUnit Unit) { |
| 811 | return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, |
| 812 | Ty, Ty->getPointeeType(), Unit); |
| 813 | } |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 814 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 815 | /// getOrCreateType - Get the type from the cache or create a new |
| 816 | /// one if necessary. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 817 | llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, |
| 818 | llvm::DICompileUnit Unit) { |
| 819 | if (Ty.isNull()) |
| 820 | return llvm::DIType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 821 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 822 | // Check for existing entry. |
Daniel Dunbar | 65f13c3 | 2009-09-19 20:17:48 +0000 | [diff] [blame] | 823 | std::map<void *, llvm::WeakVH>::iterator it = |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 824 | TypeCache.find(Ty.getAsOpaquePtr()); |
Daniel Dunbar | 65f13c3 | 2009-09-19 20:17:48 +0000 | [diff] [blame] | 825 | if (it != TypeCache.end()) { |
| 826 | // Verify that the debug info still exists. |
| 827 | if (&*it->second) |
| 828 | return llvm::DIType(cast<llvm::MDNode>(it->second)); |
| 829 | } |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 830 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 831 | // Otherwise create the type. |
| 832 | llvm::DIType Res = CreateTypeNode(Ty, Unit); |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 833 | return Res; |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | /// getOrCreateTypeNode - Get the type metadata node from the cache or create a |
| 837 | /// new one if necessary. |
| 838 | llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, |
| 839 | llvm::DICompileUnit Unit) { |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 840 | // Handle qualifiers, which recursively handles what they refer to. |
| 841 | if (Ty.hasQualifiers()) |
| 842 | return CreateQualifiedType(Ty, Unit); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 843 | |
| 844 | // Work out details of type. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 845 | switch (Ty->getTypeClass()) { |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 846 | #define TYPE(Class, Base) |
| 847 | #define ABSTRACT_TYPE(Class, Base) |
| 848 | #define NON_CANONICAL_TYPE(Class, Base) |
| 849 | #define DEPENDENT_TYPE(Class, Base) case Type::Class: |
| 850 | #include "clang/AST/TypeNodes.def" |
| 851 | assert(false && "Dependent types cannot show up in debug information"); |
Argyrios Kyrtzidis | 1bb8a45 | 2009-08-19 01:28:17 +0000 | [diff] [blame] | 852 | |
Anders Carlsson | bfe6995 | 2009-11-06 18:24:04 +0000 | [diff] [blame] | 853 | // FIXME: Handle these. |
| 854 | case Type::ExtVector: |
| 855 | case Type::Vector: |
Anders Carlsson | ba578cb | 2009-11-07 01:19:37 +0000 | [diff] [blame] | 856 | case Type::FixedWidthInt: |
Anders Carlsson | bfe6995 | 2009-11-06 18:24:04 +0000 | [diff] [blame] | 857 | return llvm::DIType(); |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 858 | default: |
Anders Carlsson | ba578cb | 2009-11-07 01:19:37 +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 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 937 | // Push function on region stack. |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 938 | RegionStack.push_back(SP.getNode()); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 942 | void CGDebugInfo::EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder) { |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 943 | if (CurLoc.isInvalid() || CurLoc.isMacroID()) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 944 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 945 | // Don't bother if things are the same as last time. |
| 946 | SourceManager &SM = M->getContext().getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 947 | if (CurLoc == PrevLoc |
Chris Lattner | 30fc933 | 2009-02-04 01:06:56 +0000 | [diff] [blame] | 948 | || (SM.getInstantiationLineNumber(CurLoc) == |
| 949 | SM.getInstantiationLineNumber(PrevLoc) |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 950 | && SM.isFromSameFile(CurLoc, PrevLoc))) |
| 951 | return; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 952 | |
| 953 | // Update last state. |
| 954 | PrevLoc = CurLoc; |
| 955 | |
| 956 | // Get the appropriate compile unit. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 957 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc); |
Devang Patel | 0f78fea | 2009-04-08 19:47:04 +0000 | [diff] [blame] | 958 | PresumedLoc PLoc = SM.getPresumedLoc(CurLoc); |
Devang Patel | bbd9fa4 | 2009-10-06 18:36:08 +0000 | [diff] [blame] | 959 | |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 960 | llvm::DIDescriptor DR(RegionStack.back()); |
Devang Patel | bbd9fa4 | 2009-10-06 18:36:08 +0000 | [diff] [blame] | 961 | llvm::DIScope DS = llvm::DIScope(DR.getNode()); |
| 962 | llvm::DILocation DO(NULL); |
| 963 | llvm::DILocation DL = |
| 964 | DebugFactory.CreateLocation(PLoc.getLine(), PLoc.getColumn(), |
| 965 | DS, DO); |
| 966 | Builder.SetCurrentDebugLocation(DL.getNode()); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | /// EmitRegionStart- Constructs the debug code for entering a declarative |
| 970 | /// region - "llvm.dbg.region.start.". |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 971 | void CGDebugInfo::EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder) { |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 972 | llvm::DIDescriptor D = |
| 973 | DebugFactory.CreateLexicalBlock(RegionStack.empty() ? |
| 974 | llvm::DIDescriptor() : |
| 975 | llvm::DIDescriptor(RegionStack.back())); |
| 976 | RegionStack.push_back(D.getNode()); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | /// EmitRegionEnd - Constructs the debug code for exiting a declarative |
| 980 | /// region - "llvm.dbg.region.end." |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 981 | void CGDebugInfo::EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder) { |
Daniel Dunbar | 5273f51 | 2008-10-17 01:07:56 +0000 | [diff] [blame] | 982 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 983 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 984 | // Provide an region stop point. |
| 985 | EmitStopPoint(Fn, Builder); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 986 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 987 | RegionStack.pop_back(); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 988 | } |
| 989 | |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 990 | /// EmitDeclare - Emit local variable declaration debug info. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 991 | void CGDebugInfo::EmitDeclare(const VarDecl *Decl, unsigned Tag, |
| 992 | llvm::Value *Storage, CGBuilderTy &Builder) { |
Daniel Dunbar | 5273f51 | 2008-10-17 01:07:56 +0000 | [diff] [blame] | 993 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 994 | |
Devang Patel | 0773903 | 2009-03-27 23:16:32 +0000 | [diff] [blame] | 995 | // Do not emit variable debug information while generating optimized code. |
| 996 | // The llvm optimizer and code generator are not yet ready to support |
| 997 | // optimized code debugging. |
Chandler Carruth | 2811ccf | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 998 | const CodeGenOptions &CGO = M->getCodeGenOpts(); |
| 999 | if (CGO.OptimizationLevel) |
Devang Patel | 0773903 | 2009-03-27 23:16:32 +0000 | [diff] [blame] | 1000 | return; |
| 1001 | |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1002 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation()); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1003 | QualType Type = Decl->getType(); |
| 1004 | llvm::DIType Ty = getOrCreateType(Type, Unit); |
| 1005 | if (Decl->hasAttr<BlocksAttr>()) { |
| 1006 | llvm::DICompileUnit DefUnit; |
| 1007 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
| 1008 | |
| 1009 | llvm::SmallVector<llvm::DIDescriptor, 5> EltTys; |
| 1010 | |
| 1011 | llvm::DIType FieldTy; |
| 1012 | |
| 1013 | QualType FType; |
| 1014 | uint64_t FieldSize, FieldOffset; |
| 1015 | unsigned FieldAlign; |
| 1016 | |
| 1017 | llvm::DIArray Elements; |
| 1018 | llvm::DIType EltTy; |
| 1019 | |
| 1020 | // Build up structure for the byref. See BuildByRefType. |
| 1021 | FieldOffset = 0; |
| 1022 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 1023 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1024 | FieldSize = M->getContext().getTypeSize(FType); |
| 1025 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1026 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1027 | "__isa", DefUnit, |
| 1028 | 0, FieldSize, FieldAlign, |
| 1029 | FieldOffset, 0, FieldTy); |
| 1030 | EltTys.push_back(FieldTy); |
| 1031 | FieldOffset += FieldSize; |
| 1032 | |
| 1033 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 1034 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1035 | FieldSize = M->getContext().getTypeSize(FType); |
| 1036 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1037 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1038 | "__forwarding", DefUnit, |
| 1039 | 0, FieldSize, FieldAlign, |
| 1040 | FieldOffset, 0, FieldTy); |
| 1041 | EltTys.push_back(FieldTy); |
| 1042 | FieldOffset += FieldSize; |
| 1043 | |
| 1044 | FType = M->getContext().getFixedWidthIntType(32, true); // Int32Ty; |
| 1045 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1046 | FieldSize = M->getContext().getTypeSize(FType); |
| 1047 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1048 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1049 | "__flags", DefUnit, |
| 1050 | 0, FieldSize, FieldAlign, |
| 1051 | FieldOffset, 0, FieldTy); |
| 1052 | EltTys.push_back(FieldTy); |
| 1053 | FieldOffset += FieldSize; |
| 1054 | |
| 1055 | FType = M->getContext().getFixedWidthIntType(32, true); // Int32Ty; |
| 1056 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1057 | FieldSize = M->getContext().getTypeSize(FType); |
| 1058 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1059 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1060 | "__size", DefUnit, |
| 1061 | 0, FieldSize, FieldAlign, |
| 1062 | FieldOffset, 0, FieldTy); |
| 1063 | EltTys.push_back(FieldTy); |
| 1064 | FieldOffset += FieldSize; |
| 1065 | |
| 1066 | bool HasCopyAndDispose = M->BlockRequiresCopying(Type); |
| 1067 | if (HasCopyAndDispose) { |
| 1068 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 1069 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1070 | FieldSize = M->getContext().getTypeSize(FType); |
| 1071 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1072 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1073 | "__copy_helper", DefUnit, |
| 1074 | 0, FieldSize, FieldAlign, |
| 1075 | FieldOffset, 0, FieldTy); |
| 1076 | EltTys.push_back(FieldTy); |
| 1077 | FieldOffset += FieldSize; |
| 1078 | |
| 1079 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 1080 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1081 | FieldSize = M->getContext().getTypeSize(FType); |
| 1082 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1083 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1084 | "__destroy_helper", DefUnit, |
| 1085 | 0, FieldSize, FieldAlign, |
| 1086 | FieldOffset, 0, FieldTy); |
| 1087 | EltTys.push_back(FieldTy); |
| 1088 | FieldOffset += FieldSize; |
| 1089 | } |
| 1090 | |
| 1091 | unsigned Align = M->getContext().getDeclAlignInBytes(Decl); |
| 1092 | if (Align > M->getContext().Target.getPointerAlign(0) / 8) { |
| 1093 | unsigned AlignedOffsetInBytes |
Mike Stump | fd47b31 | 2009-09-22 02:44:17 +0000 | [diff] [blame] | 1094 | = llvm::RoundUpToAlignment(FieldOffset/8, Align); |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1095 | unsigned NumPaddingBytes |
Mike Stump | fd47b31 | 2009-09-22 02:44:17 +0000 | [diff] [blame] | 1096 | = AlignedOffsetInBytes - FieldOffset/8; |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1097 | |
| 1098 | if (NumPaddingBytes > 0) { |
| 1099 | llvm::APInt pad(32, NumPaddingBytes); |
| 1100 | FType = M->getContext().getConstantArrayType(M->getContext().CharTy, |
| 1101 | pad, ArrayType::Normal, 0); |
| 1102 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1103 | FieldSize = M->getContext().getTypeSize(FType); |
| 1104 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1105 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, |
| 1106 | Unit, "", DefUnit, |
| 1107 | 0, FieldSize, FieldAlign, |
| 1108 | FieldOffset, 0, FieldTy); |
| 1109 | EltTys.push_back(FieldTy); |
| 1110 | FieldOffset += FieldSize; |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | FType = Type; |
| 1115 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1116 | FieldSize = M->getContext().getTypeSize(FType); |
Mike Stump | fd47b31 | 2009-09-22 02:44:17 +0000 | [diff] [blame] | 1117 | FieldAlign = Align*8; |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1118 | |
| 1119 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Devang Patel | 11169ad | 2009-11-12 17:49:47 +0000 | [diff] [blame] | 1120 | Decl->getNameAsCString(), DefUnit, |
Mike Stump | 39605b4 | 2009-09-22 02:12:52 +0000 | [diff] [blame] | 1121 | 0, FieldSize, FieldAlign, |
| 1122 | FieldOffset, 0, FieldTy); |
| 1123 | EltTys.push_back(FieldTy); |
| 1124 | FieldOffset += FieldSize; |
| 1125 | |
| 1126 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
| 1127 | |
| 1128 | unsigned Flags = llvm::DIType::FlagBlockByrefStruct; |
| 1129 | |
| 1130 | Ty = DebugFactory.CreateCompositeType(Tag, Unit, "", |
| 1131 | llvm::DICompileUnit(), |
| 1132 | 0, FieldOffset, 0, 0, Flags, |
| 1133 | llvm::DIType(), Elements); |
| 1134 | } |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1135 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1136 | // Get location information. |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 1137 | SourceManager &SM = M->getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 1138 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1139 | unsigned Line = 0; |
| 1140 | if (!PLoc.isInvalid()) |
| 1141 | Line = PLoc.getLine(); |
| 1142 | else |
| 1143 | Unit = llvm::DICompileUnit(); |
| 1144 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1145 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1146 | // Create the descriptor for the variable. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1147 | llvm::DIVariable D = |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1148 | DebugFactory.CreateVariable(Tag, llvm::DIDescriptor(RegionStack.back()), |
| 1149 | Decl->getNameAsCString(), |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1150 | Unit, Line, Ty); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1151 | // Insert an llvm.dbg.declare into the current block. |
Devang Patel | ebf16e8 | 2009-11-11 19:10:19 +0000 | [diff] [blame] | 1152 | llvm::Instruction *Call = |
Devang Patel | a020380 | 2009-11-10 23:07:24 +0000 | [diff] [blame] | 1153 | DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1154 | |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1155 | llvm::DIScope DS(RegionStack.back()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1156 | llvm::DILocation DO(NULL); |
| 1157 | llvm::DILocation DL = |
| 1158 | DebugFactory.CreateLocation(Line, PLoc.getColumn(), DS, DO); |
| 1159 | Builder.SetDebugLocation(Call, DL.getNode()); |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1162 | /// EmitDeclare - Emit local variable declaration debug info. |
| 1163 | void CGDebugInfo::EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, |
| 1164 | llvm::Value *Storage, CGBuilderTy &Builder, |
| 1165 | CodeGenFunction *CGF) { |
| 1166 | const ValueDecl *Decl = BDRE->getDecl(); |
| 1167 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1168 | |
| 1169 | // Do not emit variable debug information while generating optimized code. |
| 1170 | // The llvm optimizer and code generator are not yet ready to support |
| 1171 | // optimized code debugging. |
Chandler Carruth | 2811ccf | 2009-11-12 17:24:48 +0000 | [diff] [blame] | 1172 | const CodeGenOptions &CGO = M->getCodeGenOpts(); |
| 1173 | if (CGO.OptimizationLevel || Builder.GetInsertBlock() == 0) |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1174 | return; |
| 1175 | |
| 1176 | uint64_t XOffset = 0; |
| 1177 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation()); |
| 1178 | QualType Type = Decl->getType(); |
| 1179 | llvm::DIType Ty = getOrCreateType(Type, Unit); |
| 1180 | if (Decl->hasAttr<BlocksAttr>()) { |
| 1181 | llvm::DICompileUnit DefUnit; |
| 1182 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
| 1183 | |
| 1184 | llvm::SmallVector<llvm::DIDescriptor, 5> EltTys; |
| 1185 | |
| 1186 | llvm::DIType FieldTy; |
| 1187 | |
| 1188 | QualType FType; |
| 1189 | uint64_t FieldSize, FieldOffset; |
| 1190 | unsigned FieldAlign; |
| 1191 | |
| 1192 | llvm::DIArray Elements; |
| 1193 | llvm::DIType EltTy; |
| 1194 | |
| 1195 | // Build up structure for the byref. See BuildByRefType. |
| 1196 | FieldOffset = 0; |
| 1197 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 1198 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1199 | FieldSize = M->getContext().getTypeSize(FType); |
| 1200 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1201 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1202 | "__isa", DefUnit, |
| 1203 | 0, FieldSize, FieldAlign, |
| 1204 | FieldOffset, 0, FieldTy); |
| 1205 | EltTys.push_back(FieldTy); |
| 1206 | FieldOffset += FieldSize; |
| 1207 | |
| 1208 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 1209 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1210 | FieldSize = M->getContext().getTypeSize(FType); |
| 1211 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1212 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1213 | "__forwarding", DefUnit, |
| 1214 | 0, FieldSize, FieldAlign, |
| 1215 | FieldOffset, 0, FieldTy); |
| 1216 | EltTys.push_back(FieldTy); |
| 1217 | FieldOffset += FieldSize; |
| 1218 | |
| 1219 | FType = M->getContext().getFixedWidthIntType(32, true); // Int32Ty; |
| 1220 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1221 | FieldSize = M->getContext().getTypeSize(FType); |
| 1222 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1223 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1224 | "__flags", DefUnit, |
| 1225 | 0, FieldSize, FieldAlign, |
| 1226 | FieldOffset, 0, FieldTy); |
| 1227 | EltTys.push_back(FieldTy); |
| 1228 | FieldOffset += FieldSize; |
| 1229 | |
| 1230 | FType = M->getContext().getFixedWidthIntType(32, true); // Int32Ty; |
| 1231 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1232 | FieldSize = M->getContext().getTypeSize(FType); |
| 1233 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1234 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1235 | "__size", DefUnit, |
| 1236 | 0, FieldSize, FieldAlign, |
| 1237 | FieldOffset, 0, FieldTy); |
| 1238 | EltTys.push_back(FieldTy); |
| 1239 | FieldOffset += FieldSize; |
| 1240 | |
| 1241 | bool HasCopyAndDispose = M->BlockRequiresCopying(Type); |
| 1242 | if (HasCopyAndDispose) { |
| 1243 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 1244 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1245 | FieldSize = M->getContext().getTypeSize(FType); |
| 1246 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1247 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1248 | "__copy_helper", DefUnit, |
| 1249 | 0, FieldSize, FieldAlign, |
| 1250 | FieldOffset, 0, FieldTy); |
| 1251 | EltTys.push_back(FieldTy); |
| 1252 | FieldOffset += FieldSize; |
| 1253 | |
| 1254 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 1255 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1256 | FieldSize = M->getContext().getTypeSize(FType); |
| 1257 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1258 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1259 | "__destroy_helper", DefUnit, |
| 1260 | 0, FieldSize, FieldAlign, |
| 1261 | FieldOffset, 0, FieldTy); |
| 1262 | EltTys.push_back(FieldTy); |
| 1263 | FieldOffset += FieldSize; |
| 1264 | } |
| 1265 | |
| 1266 | unsigned Align = M->getContext().getDeclAlignInBytes(Decl); |
| 1267 | if (Align > M->getContext().Target.getPointerAlign(0) / 8) { |
| 1268 | unsigned AlignedOffsetInBytes |
| 1269 | = llvm::RoundUpToAlignment(FieldOffset/8, Align); |
| 1270 | unsigned NumPaddingBytes |
| 1271 | = AlignedOffsetInBytes - FieldOffset/8; |
| 1272 | |
| 1273 | if (NumPaddingBytes > 0) { |
| 1274 | llvm::APInt pad(32, NumPaddingBytes); |
| 1275 | FType = M->getContext().getConstantArrayType(M->getContext().CharTy, |
| 1276 | pad, ArrayType::Normal, 0); |
| 1277 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1278 | FieldSize = M->getContext().getTypeSize(FType); |
| 1279 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 1280 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, |
| 1281 | Unit, "", DefUnit, |
| 1282 | 0, FieldSize, FieldAlign, |
| 1283 | FieldOffset, 0, FieldTy); |
| 1284 | EltTys.push_back(FieldTy); |
| 1285 | FieldOffset += FieldSize; |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | FType = Type; |
| 1290 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1291 | FieldSize = M->getContext().getTypeSize(FType); |
| 1292 | FieldAlign = Align*8; |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1293 | |
| 1294 | XOffset = FieldOffset; |
| 1295 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Devang Patel | 11169ad | 2009-11-12 17:49:47 +0000 | [diff] [blame] | 1296 | Decl->getNameAsCString(), DefUnit, |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1297 | 0, FieldSize, FieldAlign, |
| 1298 | FieldOffset, 0, FieldTy); |
| 1299 | EltTys.push_back(FieldTy); |
| 1300 | FieldOffset += FieldSize; |
| 1301 | |
| 1302 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
| 1303 | |
| 1304 | unsigned Flags = llvm::DIType::FlagBlockByrefStruct; |
| 1305 | |
| 1306 | Ty = DebugFactory.CreateCompositeType(Tag, Unit, "", |
| 1307 | llvm::DICompileUnit(), |
| 1308 | 0, FieldOffset, 0, 0, Flags, |
| 1309 | llvm::DIType(), Elements); |
| 1310 | } |
| 1311 | |
| 1312 | // Get location information. |
| 1313 | SourceManager &SM = M->getContext().getSourceManager(); |
| 1314 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
| 1315 | unsigned Line = 0; |
| 1316 | if (!PLoc.isInvalid()) |
| 1317 | Line = PLoc.getLine(); |
| 1318 | else |
| 1319 | Unit = llvm::DICompileUnit(); |
| 1320 | |
| 1321 | uint64_t offset = CGF->BlockDecls[Decl]; |
| 1322 | llvm::SmallVector<llvm::Value *, 9> addr; |
| 1323 | llvm::LLVMContext &VMContext = M->getLLVMContext(); |
| 1324 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1325 | llvm::DIFactory::OpDeref)); |
| 1326 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1327 | llvm::DIFactory::OpPlus)); |
| 1328 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1329 | offset)); |
| 1330 | if (BDRE->isByRef()) { |
| 1331 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1332 | llvm::DIFactory::OpDeref)); |
| 1333 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1334 | llvm::DIFactory::OpPlus)); |
| 1335 | offset = CGF->LLVMPointerWidth/8; // offset of __forwarding field |
| 1336 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1337 | offset)); |
| 1338 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1339 | llvm::DIFactory::OpDeref)); |
| 1340 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1341 | llvm::DIFactory::OpPlus)); |
| 1342 | offset = XOffset/8; // offset of x field |
| 1343 | addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), |
| 1344 | offset)); |
| 1345 | } |
| 1346 | |
| 1347 | // Create the descriptor for the variable. |
| 1348 | llvm::DIVariable D = |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1349 | DebugFactory.CreateComplexVariable(Tag, llvm::DIDescriptor(RegionStack.back()), |
Devang Patel | 11169ad | 2009-11-12 17:49:47 +0000 | [diff] [blame] | 1350 | Decl->getNameAsCString(), Unit, Line, Ty, |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1351 | addr); |
| 1352 | // Insert an llvm.dbg.declare into the current block. |
Devang Patel | ebf16e8 | 2009-11-11 19:10:19 +0000 | [diff] [blame] | 1353 | llvm::Instruction *Call = |
| 1354 | DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertPoint()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1355 | |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1356 | llvm::DIScope DS(RegionStack.back()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1357 | llvm::DILocation DO(NULL); |
| 1358 | llvm::DILocation DL = |
| 1359 | DebugFactory.CreateLocation(Line, PLoc.getColumn(), DS, DO); |
| 1360 | Builder.SetDebugLocation(Call, DL.getNode()); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1363 | void CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *Decl, |
| 1364 | llvm::Value *Storage, |
| 1365 | CGBuilderTy &Builder) { |
| 1366 | EmitDeclare(Decl, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder); |
| 1367 | } |
| 1368 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1369 | void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable( |
| 1370 | const BlockDeclRefExpr *BDRE, llvm::Value *Storage, CGBuilderTy &Builder, |
| 1371 | CodeGenFunction *CGF) { |
| 1372 | EmitDeclare(BDRE, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder, CGF); |
| 1373 | } |
| 1374 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1375 | /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument |
| 1376 | /// variable declaration. |
| 1377 | void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, |
| 1378 | CGBuilderTy &Builder) { |
| 1379 | EmitDeclare(Decl, llvm::dwarf::DW_TAG_arg_variable, AI, Builder); |
| 1380 | } |
| 1381 | |
| 1382 | |
| 1383 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1384 | /// EmitGlobalVariable - Emit information about a global variable. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1385 | void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1386 | const VarDecl *Decl) { |
Devang Patel | 0773903 | 2009-03-27 23:16:32 +0000 | [diff] [blame] | 1387 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1388 | // Create global variable debug descriptor. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1389 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation()); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1390 | SourceManager &SM = M->getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 1391 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
| 1392 | unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 1393 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1394 | QualType T = Decl->getType(); |
| 1395 | if (T->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1396 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1397 | // CodeGen turns int[] into int[1] so we'll do the same here. |
| 1398 | llvm::APSInt ConstVal(32); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1399 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1400 | ConstVal = 1; |
| 1401 | QualType ET = M->getContext().getAsArrayType(T)->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1402 | |
| 1403 | T = M->getContext().getConstantArrayType(ET, ConstVal, |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1404 | ArrayType::Normal, 0); |
| 1405 | } |
Devang Patel | 11169ad | 2009-11-12 17:49:47 +0000 | [diff] [blame] | 1406 | const char *DeclName = Decl->getNameAsCString(); |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 1407 | DebugFactory.CreateGlobalVariable(getContext(Decl, Unit), DeclName, DeclName, |
Devang Patel | 0284fdc | 2009-11-07 00:10:18 +0000 | [diff] [blame] | 1408 | NULL, Unit, LineNo, |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1409 | getOrCreateType(T, Unit), |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1410 | Var->hasInternalLinkage(), |
| 1411 | true/*definition*/, Var); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1412 | } |
| 1413 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1414 | /// EmitGlobalVariable - Emit information about an objective-c interface. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1415 | void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1416 | ObjCInterfaceDecl *Decl) { |
| 1417 | // Create global variable debug descriptor. |
| 1418 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation()); |
| 1419 | SourceManager &SM = M->getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 1420 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
| 1421 | unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1422 | |
Devang Patel | 11169ad | 2009-11-12 17:49:47 +0000 | [diff] [blame] | 1423 | const char *Name = Decl->getNameAsCString(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1424 | |
Chris Lattner | 03d9f34 | 2009-04-01 06:23:52 +0000 | [diff] [blame] | 1425 | QualType T = M->getContext().getObjCInterfaceType(Decl); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1426 | if (T->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1427 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1428 | // CodeGen turns int[] into int[1] so we'll do the same here. |
| 1429 | llvm::APSInt ConstVal(32); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1430 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1431 | ConstVal = 1; |
| 1432 | QualType ET = M->getContext().getAsArrayType(T)->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1433 | |
| 1434 | T = M->getContext().getConstantArrayType(ET, ConstVal, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1435 | ArrayType::Normal, 0); |
| 1436 | } |
| 1437 | |
Devang Patel | f6a39b7 | 2009-10-20 18:26:30 +0000 | [diff] [blame] | 1438 | DebugFactory.CreateGlobalVariable(Unit, Name, Name, Name, Unit, LineNo, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1439 | getOrCreateType(T, Unit), |
| 1440 | Var->hasInternalLinkage(), |
| 1441 | true/*definition*/, Var); |
| 1442 | } |