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