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" |
| 15 | #include "CodeGenModule.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclObjC.h" |
Chris Lattner | 3cc5c40 | 2008-11-11 07:01:36 +0000 | [diff] [blame] | 18 | #include "clang/AST/Expr.h" |
Anders Carlsson | 19cc4ab | 2009-07-18 19:43:29 +0000 | [diff] [blame] | 19 | #include "clang/AST/RecordLayout.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 20 | #include "clang/Basic/SourceManager.h" |
| 21 | #include "clang/Basic/FileManager.h" |
Mike Stump | 5a86217 | 2009-09-15 21:48:34 +0000 | [diff] [blame] | 22 | #include "clang/Basic/Version.h" |
Devang Patel | 0773903 | 2009-03-27 23:16:32 +0000 | [diff] [blame] | 23 | #include "clang/Frontend/CompileOptions.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 24 | #include "llvm/Constants.h" |
| 25 | #include "llvm/DerivedTypes.h" |
| 26 | #include "llvm/Instructions.h" |
| 27 | #include "llvm/Intrinsics.h" |
| 28 | #include "llvm/Module.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/StringExtras.h" |
| 30 | #include "llvm/ADT/SmallVector.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Dwarf.h" |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 32 | #include "llvm/System/Path.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 33 | #include "llvm/Target/TargetMachine.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 34 | using namespace clang; |
| 35 | using namespace clang::CodeGen; |
| 36 | |
Devang Patel | 6dba432 | 2009-07-14 21:31:22 +0000 | [diff] [blame] | 37 | CGDebugInfo::CGDebugInfo(CodeGenModule *m) |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 38 | : M(m), isMainCompileUnitCreated(false), DebugFactory(M->getModule()), |
| 39 | BlockLiteralGenericSet(false) { |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 42 | CGDebugInfo::~CGDebugInfo() { |
Daniel Dunbar | 66031a5 | 2008-10-17 16:15:48 +0000 | [diff] [blame] | 43 | assert(RegionStack.empty() && "Region stack mismatch, stack not empty!"); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 46 | void CGDebugInfo::setLocation(SourceLocation Loc) { |
| 47 | if (Loc.isValid()) |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 48 | CurLoc = M->getContext().getSourceManager().getInstantiationLoc(Loc); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 51 | /// getOrCreateCompileUnit - Get the compile unit from the cache or create a new |
Daniel Dunbar | 25f51dd | 2008-10-24 08:38:36 +0000 | [diff] [blame] | 52 | /// one if necessary. This returns null for invalid source locations. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 53 | llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) { |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 54 | // Get source file information. |
| 55 | const char *FileName = "<unknown>"; |
Devang Patel | 7782022 | 2009-02-24 23:16:03 +0000 | [diff] [blame] | 56 | SourceManager &SM = M->getContext().getSourceManager(); |
Chris Lattner | adb1a6f | 2009-04-19 06:50:29 +0000 | [diff] [blame] | 57 | unsigned FID = 0; |
Daniel Dunbar | 831570c | 2009-01-22 00:09:25 +0000 | [diff] [blame] | 58 | if (Loc.isValid()) { |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 59 | PresumedLoc PLoc = SM.getPresumedLoc(Loc); |
| 60 | FileName = PLoc.getFilename(); |
| 61 | FID = PLoc.getIncludeLoc().getRawEncoding(); |
Daniel Dunbar | 831570c | 2009-01-22 00:09:25 +0000 | [diff] [blame] | 62 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 64 | // See if this compile unit has been used before. |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 65 | llvm::DICompileUnit &Unit = CompileUnitCache[FID]; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 66 | if (!Unit.isNull()) return Unit; |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 67 | |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 68 | // Get absolute path name. |
| 69 | llvm::sys::Path AbsFileName(FileName); |
| 70 | if (!AbsFileName.isAbsolute()) { |
| 71 | llvm::sys::Path tmp = llvm::sys::Path::GetCurrentDirectory(); |
| 72 | tmp.appendComponent(FileName); |
| 73 | AbsFileName = tmp; |
| 74 | } |
| 75 | |
Devang Patel | 72240d7 | 2009-06-26 18:32:22 +0000 | [diff] [blame] | 76 | // See if thie compile unit is representing main source file. Each source |
| 77 | // file has corresponding compile unit. There is only one main source |
| 78 | // file at a time. |
| 79 | bool isMain = false; |
| 80 | const LangOptions &LO = M->getLangOptions(); |
| 81 | const char *MainFileName = LO.getMainFileName(); |
| 82 | if (isMainCompileUnitCreated == false) { |
| 83 | if (MainFileName) { |
| 84 | if (!strcmp(AbsFileName.getLast().c_str(), MainFileName)) |
| 85 | isMain = true; |
| 86 | } else { |
| 87 | if (Loc.isValid() && SM.isFromMainFile(Loc)) |
| 88 | isMain = true; |
| 89 | } |
| 90 | if (isMain) |
| 91 | isMainCompileUnitCreated = true; |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 92 | } |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 93 | |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 94 | unsigned LangTag; |
| 95 | if (LO.CPlusPlus) { |
| 96 | if (LO.ObjC1) |
| 97 | LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus; |
| 98 | else |
| 99 | LangTag = llvm::dwarf::DW_LANG_C_plus_plus; |
| 100 | } else if (LO.ObjC1) { |
Devang Patel | 8d9aefc | 2009-03-24 20:35:51 +0000 | [diff] [blame] | 101 | LangTag = llvm::dwarf::DW_LANG_ObjC; |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 102 | } else if (LO.C99) { |
Devang Patel | 8d9aefc | 2009-03-24 20:35:51 +0000 | [diff] [blame] | 103 | LangTag = llvm::dwarf::DW_LANG_C99; |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 104 | } else { |
| 105 | LangTag = llvm::dwarf::DW_LANG_C89; |
| 106 | } |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 107 | |
Mike Stump | 5a86217 | 2009-09-15 21:48:34 +0000 | [diff] [blame] | 108 | std::string Producer = "clang " CLANG_VERSION_STRING; |
Chris Lattner | b95ee58 | 2009-05-02 01:04:13 +0000 | [diff] [blame] | 109 | bool isOptimized = LO.Optimize; |
Chris Lattner | 4c2577a | 2009-05-02 01:00:04 +0000 | [diff] [blame] | 110 | const char *Flags = ""; // FIXME: Encode command line options. |
| 111 | |
| 112 | // Figure out which version of the ObjC runtime we have. |
| 113 | unsigned RuntimeVers = 0; |
| 114 | if (LO.ObjC1) |
| 115 | RuntimeVers = LO.ObjCNonFragileABI ? 2 : 1; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 116 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 117 | // Create new compile unit. |
Devang Patel | 72240d7 | 2009-06-26 18:32:22 +0000 | [diff] [blame] | 118 | return Unit = DebugFactory.CreateCompileUnit(LangTag, AbsFileName.getLast(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 119 | AbsFileName.getDirname(), |
Devang Patel | 72240d7 | 2009-06-26 18:32:22 +0000 | [diff] [blame] | 120 | Producer, isMain, isOptimized, |
| 121 | Flags, RuntimeVers); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 124 | /// CreateType - Get the Basic type from the cache or create a new |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 125 | /// one if necessary. |
| 126 | llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT, |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 127 | llvm::DICompileUnit Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 128 | unsigned Encoding = 0; |
| 129 | switch (BT->getKind()) { |
| 130 | default: |
| 131 | case BuiltinType::Void: |
| 132 | return llvm::DIType(); |
| 133 | case BuiltinType::UChar: |
| 134 | case BuiltinType::Char_U: Encoding = llvm::dwarf::DW_ATE_unsigned_char; break; |
| 135 | case BuiltinType::Char_S: |
| 136 | case BuiltinType::SChar: Encoding = llvm::dwarf::DW_ATE_signed_char; break; |
| 137 | case BuiltinType::UShort: |
| 138 | case BuiltinType::UInt: |
| 139 | case BuiltinType::ULong: |
| 140 | case BuiltinType::ULongLong: Encoding = llvm::dwarf::DW_ATE_unsigned; break; |
| 141 | case BuiltinType::Short: |
| 142 | case BuiltinType::Int: |
| 143 | case BuiltinType::Long: |
| 144 | case BuiltinType::LongLong: Encoding = llvm::dwarf::DW_ATE_signed; break; |
| 145 | case BuiltinType::Bool: Encoding = llvm::dwarf::DW_ATE_boolean; break; |
| 146 | case BuiltinType::Float: |
| 147 | case BuiltinType::Double: Encoding = llvm::dwarf::DW_ATE_float; break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 148 | } |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 149 | // Bit size, align and offset of the type. |
| 150 | uint64_t Size = M->getContext().getTypeSize(BT); |
| 151 | uint64_t Align = M->getContext().getTypeAlign(BT); |
| 152 | uint64_t Offset = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 153 | |
| 154 | return DebugFactory.CreateBasicType(Unit, |
Chris Lattner | e4f2142 | 2009-06-30 01:26:17 +0000 | [diff] [blame] | 155 | BT->getName(M->getContext().getLangOptions()), |
Douglas Gregor | d249e1d1f | 2009-05-29 20:38:28 +0000 | [diff] [blame] | 156 | Unit, 0, Size, Align, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 157 | Offset, /*flags*/ 0, Encoding); |
| 158 | } |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 159 | |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 160 | llvm::DIType CGDebugInfo::CreateType(const ComplexType *Ty, |
| 161 | llvm::DICompileUnit Unit) { |
| 162 | // Bit size, align and offset of the type. |
| 163 | unsigned Encoding = llvm::dwarf::DW_ATE_complex_float; |
| 164 | if (Ty->isComplexIntegerType()) |
| 165 | Encoding = llvm::dwarf::DW_ATE_lo_user; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 166 | |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 167 | uint64_t Size = M->getContext().getTypeSize(Ty); |
| 168 | uint64_t Align = M->getContext().getTypeAlign(Ty); |
| 169 | uint64_t Offset = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 170 | |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 171 | return DebugFactory.CreateBasicType(Unit, "complex", |
| 172 | Unit, 0, Size, Align, |
| 173 | Offset, /*flags*/ 0, Encoding); |
| 174 | } |
| 175 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 176 | /// getOrCreateCVRType - Get the CVR qualified type from the cache or create |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 177 | /// a new one if necessary. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 178 | llvm::DIType CGDebugInfo::CreateCVRType(QualType Ty, llvm::DICompileUnit Unit) { |
| 179 | // We will create one Derived type for one qualifier and recurse to handle any |
| 180 | // additional ones. |
| 181 | llvm::DIType FromTy; |
| 182 | unsigned Tag; |
| 183 | if (Ty.isConstQualified()) { |
| 184 | Tag = llvm::dwarf::DW_TAG_const_type; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 185 | Ty.removeConst(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 186 | FromTy = getOrCreateType(Ty, Unit); |
| 187 | } else if (Ty.isVolatileQualified()) { |
| 188 | Tag = llvm::dwarf::DW_TAG_volatile_type; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 189 | Ty.removeVolatile(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 190 | FromTy = getOrCreateType(Ty, Unit); |
| 191 | } else { |
| 192 | assert(Ty.isRestrictQualified() && "Unknown type qualifier for debug info"); |
| 193 | Tag = llvm::dwarf::DW_TAG_restrict_type; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 194 | Ty.removeRestrict(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 195 | FromTy = getOrCreateType(Ty, Unit); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 196 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 197 | |
Daniel Dunbar | 3845f86 | 2008-10-31 03:54:29 +0000 | [diff] [blame] | 198 | // No need to fill in the Name, Line, Size, Alignment, Offset in case of |
| 199 | // CVR derived types. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 200 | return DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(), |
| 201 | 0, 0, 0, 0, 0, FromTy); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 204 | llvm::DIType CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty, |
| 205 | llvm::DICompileUnit Unit) { |
| 206 | llvm::DIType EltTy = getOrCreateType(Ty->getPointeeType(), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 207 | |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 208 | // Bit size, align and offset of the type. |
| 209 | uint64_t Size = M->getContext().getTypeSize(Ty); |
| 210 | uint64_t Align = M->getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 211 | |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 212 | return DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit, |
| 213 | "", llvm::DICompileUnit(), |
| 214 | 0, Size, Align, 0, 0, EltTy); |
| 215 | } |
| 216 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 217 | llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty, |
| 218 | llvm::DICompileUnit Unit) { |
| 219 | llvm::DIType EltTy = getOrCreateType(Ty->getPointeeType(), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 220 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 221 | // Bit size, align and offset of the type. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 222 | uint64_t Size = M->getContext().getTypeSize(Ty); |
| 223 | uint64_t Align = M->getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 225 | return DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit, |
| 226 | "", llvm::DICompileUnit(), |
| 227 | 0, Size, Align, 0, 0, EltTy); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 230 | llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, |
| 231 | llvm::DICompileUnit Unit) { |
| 232 | if (BlockLiteralGenericSet) |
| 233 | return BlockLiteralGeneric; |
| 234 | |
| 235 | llvm::DICompileUnit DefUnit; |
| 236 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
| 237 | |
| 238 | llvm::SmallVector<llvm::DIDescriptor, 5> EltTys; |
| 239 | |
| 240 | llvm::DIType FieldTy; |
| 241 | |
| 242 | QualType FType; |
| 243 | uint64_t FieldSize, FieldOffset; |
| 244 | unsigned FieldAlign; |
| 245 | |
| 246 | llvm::DIArray Elements; |
| 247 | llvm::DIType EltTy, DescTy; |
| 248 | |
| 249 | FieldOffset = 0; |
| 250 | FType = M->getContext().UnsignedLongTy; |
| 251 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 252 | FieldSize = M->getContext().getTypeSize(FType); |
| 253 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 254 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 255 | "reserved", DefUnit, |
| 256 | 0, FieldSize, FieldAlign, |
| 257 | FieldOffset, 0, FieldTy); |
| 258 | EltTys.push_back(FieldTy); |
| 259 | |
| 260 | FieldOffset += FieldSize; |
| 261 | FType = M->getContext().UnsignedLongTy; |
| 262 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 263 | FieldSize = M->getContext().getTypeSize(FType); |
| 264 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 265 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 266 | "Size", DefUnit, |
| 267 | 0, FieldSize, FieldAlign, |
| 268 | FieldOffset, 0, FieldTy); |
| 269 | EltTys.push_back(FieldTy); |
| 270 | |
| 271 | FieldOffset += FieldSize; |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 272 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 273 | EltTys.clear(); |
| 274 | |
| 275 | EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_descriptor", |
| 276 | DefUnit, 0, FieldOffset, 0, 0, 0, |
| 277 | llvm::DIType(), Elements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 278 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 279 | // Bit size, align and offset of the type. |
| 280 | uint64_t Size = M->getContext().getTypeSize(Ty); |
| 281 | uint64_t Align = M->getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 283 | DescTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, |
| 284 | Unit, "", llvm::DICompileUnit(), |
| 285 | 0, Size, Align, 0, 0, EltTy); |
| 286 | |
| 287 | FieldOffset = 0; |
| 288 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 289 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 290 | FieldSize = M->getContext().getTypeSize(FType); |
| 291 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 292 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 293 | "__isa", DefUnit, |
| 294 | 0, FieldSize, FieldAlign, |
| 295 | FieldOffset, 0, FieldTy); |
| 296 | EltTys.push_back(FieldTy); |
| 297 | |
| 298 | FieldOffset += FieldSize; |
| 299 | FType = M->getContext().IntTy; |
| 300 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 301 | FieldSize = M->getContext().getTypeSize(FType); |
| 302 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 303 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 304 | "__flags", DefUnit, |
| 305 | 0, FieldSize, FieldAlign, |
| 306 | FieldOffset, 0, FieldTy); |
| 307 | EltTys.push_back(FieldTy); |
| 308 | |
| 309 | FieldOffset += FieldSize; |
| 310 | FType = M->getContext().IntTy; |
| 311 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 312 | FieldSize = M->getContext().getTypeSize(FType); |
| 313 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 314 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 315 | "__reserved", DefUnit, |
| 316 | 0, FieldSize, FieldAlign, |
| 317 | FieldOffset, 0, FieldTy); |
| 318 | EltTys.push_back(FieldTy); |
| 319 | |
| 320 | FieldOffset += FieldSize; |
| 321 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 322 | FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 323 | FieldSize = M->getContext().getTypeSize(FType); |
| 324 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 325 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 326 | "__FuncPtr", DefUnit, |
| 327 | 0, FieldSize, FieldAlign, |
| 328 | FieldOffset, 0, FieldTy); |
| 329 | EltTys.push_back(FieldTy); |
| 330 | |
| 331 | FieldOffset += FieldSize; |
| 332 | FType = M->getContext().getPointerType(M->getContext().VoidTy); |
| 333 | FieldTy = DescTy; |
| 334 | FieldSize = M->getContext().getTypeSize(Ty); |
| 335 | FieldAlign = M->getContext().getTypeAlign(Ty); |
| 336 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 337 | "__descriptor", DefUnit, |
| 338 | 0, FieldSize, FieldAlign, |
| 339 | FieldOffset, 0, FieldTy); |
| 340 | EltTys.push_back(FieldTy); |
| 341 | |
| 342 | FieldOffset += FieldSize; |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 343 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 344 | |
| 345 | EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_literal_generic", |
| 346 | DefUnit, 0, FieldOffset, 0, 0, 0, |
| 347 | llvm::DIType(), Elements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 348 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 349 | BlockLiteralGenericSet = true; |
| 350 | BlockLiteralGeneric |
| 351 | = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit, |
| 352 | "", llvm::DICompileUnit(), |
| 353 | 0, Size, Align, 0, 0, EltTy); |
| 354 | return BlockLiteralGeneric; |
| 355 | } |
| 356 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 357 | llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty, |
| 358 | llvm::DICompileUnit Unit) { |
| 359 | // Typedefs are derived from some other type. If we have a typedef of a |
| 360 | // typedef, make sure to emit the whole chain. |
| 361 | llvm::DIType Src = getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 362 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 363 | // We don't set size information, but do specify where the typedef was |
| 364 | // declared. |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 365 | std::string TyName = Ty->getDecl()->getNameAsString(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 366 | SourceLocation DefLoc = Ty->getDecl()->getLocation(); |
| 367 | llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(DefLoc); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 368 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 369 | SourceManager &SM = M->getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 370 | PresumedLoc PLoc = SM.getPresumedLoc(DefLoc); |
| 371 | unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 372 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 373 | return DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_typedef, Unit, |
| 374 | TyName, DefUnit, Line, 0, 0, 0, 0, Src); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 375 | } |
| 376 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 377 | llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty, |
| 378 | llvm::DICompileUnit Unit) { |
| 379 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 380 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 381 | // Add the result type at least. |
| 382 | EltTys.push_back(getOrCreateType(Ty->getResultType(), Unit)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 383 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 384 | // Set up remainder of arguments if there is a prototype. |
| 385 | // FIXME: IF NOT, HOW IS THIS REPRESENTED? llvm-gcc doesn't represent '...'! |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 386 | if (const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(Ty)) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 387 | for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i) |
| 388 | EltTys.push_back(getOrCreateType(FTP->getArgType(i), Unit)); |
| 389 | } else { |
| 390 | // FIXME: Handle () case in C. llvm-gcc doesn't do it either. |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 393 | llvm::DIArray EltTypeArray = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 394 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 395 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 396 | return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, |
| 397 | Unit, "", llvm::DICompileUnit(), |
| 398 | 0, 0, 0, 0, 0, |
| 399 | llvm::DIType(), EltTypeArray); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 402 | /// CreateType - get structure or union type. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 403 | llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, |
| 404 | llvm::DICompileUnit Unit) { |
Douglas Gregor | a4c46df | 2008-12-11 17:59:21 +0000 | [diff] [blame] | 405 | RecordDecl *Decl = Ty->getDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 406 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 407 | unsigned Tag; |
| 408 | if (Decl->isStruct()) |
| 409 | Tag = llvm::dwarf::DW_TAG_structure_type; |
| 410 | else if (Decl->isUnion()) |
| 411 | Tag = llvm::dwarf::DW_TAG_union_type; |
| 412 | else { |
| 413 | assert(Decl->isClass() && "Unknown RecordType!"); |
| 414 | Tag = llvm::dwarf::DW_TAG_class_type; |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 417 | SourceManager &SM = M->getContext().getSourceManager(); |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 418 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 419 | // Get overall information about the record type for the debug info. |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 420 | std::string Name = Decl->getNameAsString(); |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 421 | |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 422 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
Chris Lattner | d37d9b5 | 2009-05-05 05:16:17 +0000 | [diff] [blame] | 423 | llvm::DICompileUnit DefUnit; |
| 424 | unsigned Line = 0; |
| 425 | if (!PLoc.isInvalid()) { |
| 426 | DefUnit = getOrCreateCompileUnit(Decl->getLocation()); |
| 427 | Line = PLoc.getLine(); |
| 428 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 429 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 430 | // Records and classes and unions can all be recursive. To handle them, we |
| 431 | // first generate a debug descriptor for the struct as a forward declaration. |
| 432 | // Then (if it is a definition) we go through and get debug info for all of |
| 433 | // its members. Finally, we create a descriptor for the complete type (which |
| 434 | // may refer to the forward decl if the struct is recursive) and replace all |
| 435 | // uses of the forward declaration with the final definition. |
Devang Patel | 0ce73f6 | 2009-07-22 18:57:00 +0000 | [diff] [blame] | 436 | llvm::DICompositeType FwdDecl = |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 437 | DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, 0, 0, 0, 0, |
| 438 | llvm::DIType(), llvm::DIArray()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 439 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 440 | // If this is just a forward declaration, return it. |
| 441 | if (!Decl->getDefinition(M->getContext())) |
| 442 | return FwdDecl; |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 443 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 444 | // Otherwise, insert it into the TypeCache so that recursive uses will find |
| 445 | // it. |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame^] | 446 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 447 | |
| 448 | // Convert all the elements. |
| 449 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
| 450 | |
| 451 | const ASTRecordLayout &RL = M->getContext().getASTRecordLayout(Decl); |
| 452 | |
| 453 | unsigned FieldNo = 0; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 454 | for (RecordDecl::field_iterator I = Decl->field_begin(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 455 | E = Decl->field_end(); |
Douglas Gregor | a4c46df | 2008-12-11 17:59:21 +0000 | [diff] [blame] | 456 | I != E; ++I, ++FieldNo) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 457 | FieldDecl *Field = *I; |
| 458 | llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 459 | |
| 460 | std::string FieldName = Field->getNameAsString(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 461 | |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 462 | // Ignore unnamed fields. |
| 463 | if (FieldName.empty()) |
| 464 | continue; |
| 465 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 466 | // Get the location for the field. |
| 467 | SourceLocation FieldDefLoc = Field->getLocation(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 468 | PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc); |
Chris Lattner | d37d9b5 | 2009-05-05 05:16:17 +0000 | [diff] [blame] | 469 | llvm::DICompileUnit FieldDefUnit; |
| 470 | unsigned FieldLine = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 471 | |
Chris Lattner | d37d9b5 | 2009-05-05 05:16:17 +0000 | [diff] [blame] | 472 | if (!PLoc.isInvalid()) { |
| 473 | FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc); |
| 474 | FieldLine = PLoc.getLine(); |
| 475 | } |
Devang Patel | ec9b5d5 | 2009-03-16 23:47:53 +0000 | [diff] [blame] | 476 | |
| 477 | QualType FType = Field->getType(); |
| 478 | uint64_t FieldSize = 0; |
| 479 | unsigned FieldAlign = 0; |
| 480 | if (!FType->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 481 | |
Devang Patel | ec9b5d5 | 2009-03-16 23:47:53 +0000 | [diff] [blame] | 482 | // Bit size, align and offset of the type. |
| 483 | FieldSize = M->getContext().getTypeSize(FType); |
| 484 | Expr *BitWidth = Field->getBitWidth(); |
| 485 | if (BitWidth) |
Eli Friedman | 9a901bb | 2009-04-26 19:19:15 +0000 | [diff] [blame] | 486 | FieldSize = BitWidth->EvaluateAsInt(M->getContext()).getZExtValue(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 487 | |
Devang Patel | ec9b5d5 | 2009-03-16 23:47:53 +0000 | [diff] [blame] | 488 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 489 | } |
| 490 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 491 | uint64_t FieldOffset = RL.getFieldOffset(FieldNo); |
| 492 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 493 | // Create a DW_TAG_member node to remember the offset of this field in the |
| 494 | // struct. FIXME: This is an absolutely insane way to capture this |
| 495 | // information. When we gut debug info, this should be fixed. |
| 496 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 497 | FieldName, FieldDefUnit, |
| 498 | FieldLine, FieldSize, FieldAlign, |
| 499 | FieldOffset, 0, FieldTy); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 500 | EltTys.push_back(FieldTy); |
| 501 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 503 | llvm::DIArray Elements = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 504 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 505 | |
| 506 | // Bit size, align and offset of the type. |
| 507 | uint64_t Size = M->getContext().getTypeSize(Ty); |
| 508 | uint64_t Align = M->getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 509 | |
Devang Patel | 0ce73f6 | 2009-07-22 18:57:00 +0000 | [diff] [blame] | 510 | llvm::DICompositeType RealDecl = |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 511 | DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, Size, |
| 512 | Align, 0, 0, llvm::DIType(), Elements); |
| 513 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame^] | 514 | // Update TypeCache. |
| 515 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl.getNode(); |
| 516 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 517 | // Now that we have a real decl for the struct, replace anything using the |
| 518 | // 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] | 519 | FwdDecl.replaceAllUsesWith(RealDecl); |
Devang Patel | fe09eab | 2009-07-13 17:03:14 +0000 | [diff] [blame] | 520 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 521 | return RealDecl; |
| 522 | } |
| 523 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 524 | /// CreateType - get objective-c interface type. |
| 525 | llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, |
| 526 | llvm::DICompileUnit Unit) { |
| 527 | ObjCInterfaceDecl *Decl = Ty->getDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 528 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 529 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
| 530 | SourceManager &SM = M->getContext().getSourceManager(); |
| 531 | |
| 532 | // Get overall information about the record type for the debug info. |
| 533 | std::string Name = Decl->getNameAsString(); |
| 534 | |
| 535 | llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(Decl->getLocation()); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 536 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
| 537 | unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
| 538 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | |
Daniel Dunbar | d86d336 | 2009-05-18 20:51:58 +0000 | [diff] [blame] | 540 | unsigned RuntimeLang = DefUnit.getLanguage(); |
Chris Lattner | ac7c814 | 2009-05-02 01:13:16 +0000 | [diff] [blame] | 541 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 542 | // To handle recursive interface, we |
| 543 | // first generate a debug descriptor for the struct as a forward declaration. |
| 544 | // Then (if it is a definition) we go through and get debug info for all of |
| 545 | // its members. Finally, we create a descriptor for the complete type (which |
| 546 | // may refer to the forward decl if the struct is recursive) and replace all |
| 547 | // uses of the forward declaration with the final definition. |
Devang Patel | 6c1fddf | 2009-07-27 18:42:03 +0000 | [diff] [blame] | 548 | llvm::DICompositeType FwdDecl = |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 549 | DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, 0, 0, 0, 0, |
Chris Lattner | ac7c814 | 2009-05-02 01:13:16 +0000 | [diff] [blame] | 550 | llvm::DIType(), llvm::DIArray(), |
| 551 | RuntimeLang); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 552 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 553 | // If this is just a forward declaration, return it. |
| 554 | if (Decl->isForwardDecl()) |
| 555 | return FwdDecl; |
| 556 | |
| 557 | // Otherwise, insert it into the TypeCache so that recursive uses will find |
| 558 | // it. |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame^] | 559 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 560 | |
| 561 | // Convert all the elements. |
| 562 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
| 563 | |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 564 | ObjCInterfaceDecl *SClass = Decl->getSuperClass(); |
| 565 | if (SClass) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 566 | llvm::DIType SClassTy = |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 567 | getOrCreateType(M->getContext().getObjCInterfaceType(SClass), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 568 | llvm::DIType InhTag = |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 569 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance, |
Chris Lattner | 9e55b8a | 2009-05-05 05:05:36 +0000 | [diff] [blame] | 570 | Unit, "", llvm::DICompileUnit(), 0, 0, 0, |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 571 | 0 /* offset */, 0, SClassTy); |
| 572 | EltTys.push_back(InhTag); |
| 573 | } |
| 574 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 575 | const ASTRecordLayout &RL = M->getContext().getASTObjCInterfaceLayout(Decl); |
| 576 | |
| 577 | unsigned FieldNo = 0; |
| 578 | for (ObjCInterfaceDecl::ivar_iterator I = Decl->ivar_begin(), |
| 579 | E = Decl->ivar_end(); I != E; ++I, ++FieldNo) { |
| 580 | ObjCIvarDecl *Field = *I; |
| 581 | llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); |
| 582 | |
| 583 | std::string FieldName = Field->getNameAsString(); |
| 584 | |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 585 | // Ignore unnamed fields. |
| 586 | if (FieldName.empty()) |
| 587 | continue; |
| 588 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 589 | // Get the location for the field. |
| 590 | SourceLocation FieldDefLoc = Field->getLocation(); |
| 591 | llvm::DICompileUnit FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 592 | PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc); |
| 593 | unsigned FieldLine = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
| 594 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 595 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 596 | QualType FType = Field->getType(); |
| 597 | uint64_t FieldSize = 0; |
| 598 | unsigned FieldAlign = 0; |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 599 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 600 | if (!FType->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 601 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 602 | // Bit size, align and offset of the type. |
| 603 | FieldSize = M->getContext().getTypeSize(FType); |
| 604 | Expr *BitWidth = Field->getBitWidth(); |
| 605 | if (BitWidth) |
Eli Friedman | 9a901bb | 2009-04-26 19:19:15 +0000 | [diff] [blame] | 606 | FieldSize = BitWidth->EvaluateAsInt(M->getContext()).getZExtValue(); |
| 607 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 608 | FieldAlign = M->getContext().getTypeAlign(FType); |
| 609 | } |
| 610 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 611 | uint64_t FieldOffset = RL.getFieldOffset(FieldNo); |
| 612 | |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 613 | unsigned Flags = 0; |
| 614 | if (Field->getAccessControl() == ObjCIvarDecl::Protected) |
| 615 | Flags = llvm::DIType::FlagProtected; |
| 616 | else if (Field->getAccessControl() == ObjCIvarDecl::Private) |
| 617 | Flags = llvm::DIType::FlagPrivate; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 618 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 619 | // Create a DW_TAG_member node to remember the offset of this field in the |
| 620 | // struct. FIXME: This is an absolutely insane way to capture this |
| 621 | // information. When we gut debug info, this should be fixed. |
| 622 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 623 | FieldName, FieldDefUnit, |
| 624 | FieldLine, FieldSize, FieldAlign, |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 625 | FieldOffset, Flags, FieldTy); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 626 | EltTys.push_back(FieldTy); |
| 627 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 628 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 629 | llvm::DIArray Elements = |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 630 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 631 | |
| 632 | // Bit size, align and offset of the type. |
| 633 | uint64_t Size = M->getContext().getTypeSize(Ty); |
| 634 | uint64_t Align = M->getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Devang Patel | 6c1fddf | 2009-07-27 18:42:03 +0000 | [diff] [blame] | 636 | llvm::DICompositeType RealDecl = |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 637 | DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, Size, |
Chris Lattner | ac7c814 | 2009-05-02 01:13:16 +0000 | [diff] [blame] | 638 | Align, 0, 0, llvm::DIType(), Elements, |
| 639 | RuntimeLang); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 640 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame^] | 641 | // Update TypeCache. |
| 642 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl.getNode(); |
| 643 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 644 | // Now that we have a real decl for the struct, replace anything using the |
| 645 | // 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] | 646 | FwdDecl.replaceAllUsesWith(RealDecl); |
Devang Patel | fe09eab | 2009-07-13 17:03:14 +0000 | [diff] [blame] | 647 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 648 | return RealDecl; |
| 649 | } |
| 650 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 651 | llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty, |
| 652 | llvm::DICompileUnit Unit) { |
| 653 | EnumDecl *Decl = Ty->getDecl(); |
| 654 | |
| 655 | llvm::SmallVector<llvm::DIDescriptor, 32> Enumerators; |
| 656 | |
| 657 | // Create DIEnumerator elements for each enumerator. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 658 | for (EnumDecl::enumerator_iterator |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 659 | Enum = Decl->enumerator_begin(), EnumEnd = Decl->enumerator_end(); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 660 | Enum != EnumEnd; ++Enum) { |
| 661 | Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getNameAsString(), |
| 662 | Enum->getInitVal().getZExtValue())); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 663 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 664 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 665 | // Return a CompositeType for the enum itself. |
| 666 | llvm::DIArray EltArray = |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 667 | DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 668 | |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 669 | std::string EnumName = Decl->getNameAsString(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 670 | SourceLocation DefLoc = Decl->getLocation(); |
| 671 | llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(DefLoc); |
| 672 | SourceManager &SM = M->getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 673 | PresumedLoc PLoc = SM.getPresumedLoc(DefLoc); |
| 674 | unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
| 675 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 676 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 677 | // Size and align of the type. |
Eli Friedman | 3189e4b | 2009-05-04 04:39:55 +0000 | [diff] [blame] | 678 | uint64_t Size = 0; |
| 679 | unsigned Align = 0; |
| 680 | if (!Ty->isIncompleteType()) { |
| 681 | Size = M->getContext().getTypeSize(Ty); |
| 682 | Align = M->getContext().getTypeAlign(Ty); |
| 683 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 684 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 685 | return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type, |
| 686 | Unit, EnumName, DefUnit, Line, |
| 687 | Size, Align, 0, 0, |
| 688 | llvm::DIType(), EltArray); |
| 689 | } |
| 690 | |
| 691 | llvm::DIType CGDebugInfo::CreateType(const TagType *Ty, |
| 692 | llvm::DICompileUnit Unit) { |
| 693 | if (const RecordType *RT = dyn_cast<RecordType>(Ty)) |
| 694 | return CreateType(RT, Unit); |
| 695 | else if (const EnumType *ET = dyn_cast<EnumType>(Ty)) |
| 696 | return CreateType(ET, Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 697 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 698 | return llvm::DIType(); |
| 699 | } |
| 700 | |
| 701 | llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty, |
| 702 | llvm::DICompileUnit Unit) { |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 703 | uint64_t Size; |
| 704 | uint64_t Align; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 705 | |
| 706 | |
Nuno Lopes | 010d514 | 2009-01-28 00:35:17 +0000 | [diff] [blame] | 707 | // FIXME: make getTypeAlign() aware of VLAs and incomplete array types |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 708 | if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(Ty)) { |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 709 | Size = 0; |
| 710 | Align = |
Nuno Lopes | 010d514 | 2009-01-28 00:35:17 +0000 | [diff] [blame] | 711 | M->getContext().getTypeAlign(M->getContext().getBaseElementType(VAT)); |
| 712 | } else if (Ty->isIncompleteArrayType()) { |
| 713 | Size = 0; |
| 714 | Align = M->getContext().getTypeAlign(Ty->getElementType()); |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 715 | } else { |
| 716 | // Size and align of the whole array, not the element type. |
| 717 | Size = M->getContext().getTypeSize(Ty); |
| 718 | Align = M->getContext().getTypeAlign(Ty); |
| 719 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 720 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 721 | // Add the dimensions of the array. FIXME: This loses CV qualifiers from |
| 722 | // interior arrays, do we care? Why aren't nested arrays represented the |
| 723 | // obvious/recursive way? |
| 724 | llvm::SmallVector<llvm::DIDescriptor, 8> Subscripts; |
| 725 | QualType EltTy(Ty, 0); |
| 726 | while ((Ty = dyn_cast<ArrayType>(EltTy))) { |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 727 | uint64_t Upper = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 728 | if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty)) |
Devang Patel | 5a6bfe3 | 2009-08-14 20:57:45 +0000 | [diff] [blame] | 729 | if (CAT->getSize().getZExtValue()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 730 | Upper = CAT->getSize().getZExtValue() - 1; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 731 | // FIXME: Verify this is right for VLAs. |
| 732 | Subscripts.push_back(DebugFactory.GetOrCreateSubrange(0, Upper)); |
| 733 | EltTy = Ty->getElementType(); |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 734 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 735 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 736 | llvm::DIArray SubscriptArray = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 737 | DebugFactory.GetOrCreateArray(Subscripts.data(), Subscripts.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 738 | |
| 739 | return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_array_type, |
| 740 | Unit, "", llvm::DICompileUnit(), |
| 741 | 0, Size, Align, 0, 0, |
| 742 | getOrCreateType(EltTy, Unit), |
| 743 | SubscriptArray); |
| 744 | } |
| 745 | |
| 746 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 747 | /// getOrCreateType - Get the type from the cache or create a new |
| 748 | /// one if necessary. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 749 | llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, |
| 750 | llvm::DICompileUnit Unit) { |
| 751 | if (Ty.isNull()) |
| 752 | return llvm::DIType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 753 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame^] | 754 | // Check for existing entry. |
| 755 | std::map<void *, llvm::AssertingVH<llvm::MDNode> >::iterator it = |
| 756 | TypeCache.find(Ty.getAsOpaquePtr()); |
| 757 | if (it != TypeCache.end()) |
| 758 | return llvm::DIType(it->second); |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 759 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame^] | 760 | // Otherwise create the type. |
| 761 | llvm::DIType Res = CreateTypeNode(Ty, Unit); |
| 762 | TypeCache.insert(std::make_pair(Ty.getAsOpaquePtr(), Res.getNode())); |
| 763 | return Res; |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | /// getOrCreateTypeNode - Get the type metadata node from the cache or create a |
| 767 | /// new one if necessary. |
| 768 | llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, |
| 769 | llvm::DICompileUnit Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 770 | // Handle CVR qualifiers, which recursively handles what they refer to. |
| 771 | if (Ty.getCVRQualifiers()) |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 772 | return CreateCVRType(Ty, Unit); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 773 | |
| 774 | // Work out details of type. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 775 | switch (Ty->getTypeClass()) { |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 776 | #define TYPE(Class, Base) |
| 777 | #define ABSTRACT_TYPE(Class, Base) |
| 778 | #define NON_CANONICAL_TYPE(Class, Base) |
| 779 | #define DEPENDENT_TYPE(Class, Base) case Type::Class: |
| 780 | #include "clang/AST/TypeNodes.def" |
| 781 | assert(false && "Dependent types cannot show up in debug information"); |
Argyrios Kyrtzidis | 1bb8a45 | 2009-08-19 01:28:17 +0000 | [diff] [blame] | 782 | |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 783 | default: |
Sebastian Redl | 7c80bd6 | 2009-03-16 23:22:08 +0000 | [diff] [blame] | 784 | case Type::LValueReference: |
| 785 | case Type::RValueReference: |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 786 | case Type::Vector: |
| 787 | case Type::ExtVector: |
Fariborz Jahanian | f11284a | 2009-02-17 18:27:45 +0000 | [diff] [blame] | 788 | case Type::ExtQual: |
Eli Friedman | 00524e3 | 2009-02-27 23:15:07 +0000 | [diff] [blame] | 789 | case Type::FixedWidthInt: |
Eli Friedman | 00524e3 | 2009-02-27 23:15:07 +0000 | [diff] [blame] | 790 | case Type::MemberPointer: |
Douglas Gregor | 7532dc6 | 2009-03-30 22:58:21 +0000 | [diff] [blame] | 791 | case Type::TemplateSpecialization: |
Douglas Gregor | e4e5b05 | 2009-03-19 00:18:19 +0000 | [diff] [blame] | 792 | case Type::QualifiedName: |
Eli Friedman | 00524e3 | 2009-02-27 23:15:07 +0000 | [diff] [blame] | 793 | // Unsupported types |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 794 | return llvm::DIType(); |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 795 | case Type::ObjCObjectPointer: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 796 | return CreateType(cast<ObjCObjectPointerType>(Ty), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 797 | case Type::ObjCInterface: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 798 | return CreateType(cast<ObjCInterfaceType>(Ty), Unit); |
| 799 | case Type::Builtin: return CreateType(cast<BuiltinType>(Ty), Unit); |
| 800 | case Type::Complex: return CreateType(cast<ComplexType>(Ty), Unit); |
| 801 | case Type::Pointer: return CreateType(cast<PointerType>(Ty), Unit); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 802 | case Type::BlockPointer: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 803 | return CreateType(cast<BlockPointerType>(Ty), Unit); |
| 804 | case Type::Typedef: return CreateType(cast<TypedefType>(Ty), Unit); |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 805 | case Type::Record: |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 806 | case Type::Enum: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 807 | return CreateType(cast<TagType>(Ty), Unit); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 808 | case Type::FunctionProto: |
| 809 | case Type::FunctionNoProto: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 810 | return CreateType(cast<FunctionType>(Ty), Unit); |
John McCall | 7da2431 | 2009-09-05 00:15:47 +0000 | [diff] [blame] | 811 | case Type::Elaborated: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 812 | return getOrCreateType(cast<ElaboratedType>(Ty)->getUnderlyingType(), |
| 813 | Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 814 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 815 | case Type::ConstantArray: |
Douglas Gregor | 7e7eb3d | 2009-07-06 15:59:29 +0000 | [diff] [blame] | 816 | case Type::ConstantArrayWithExpr: |
| 817 | case Type::ConstantArrayWithoutExpr: |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 818 | case Type::VariableArray: |
| 819 | case Type::IncompleteArray: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 820 | return CreateType(cast<ArrayType>(Ty), Unit); |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 821 | case Type::TypeOfExpr: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 822 | return getOrCreateType(cast<TypeOfExprType>(Ty)->getUnderlyingExpr() |
| 823 | ->getType(), Unit); |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 824 | case Type::TypeOf: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 825 | return getOrCreateType(cast<TypeOfType>(Ty)->getUnderlyingType(), Unit); |
Anders Carlsson | 395b475 | 2009-06-24 19:06:50 +0000 | [diff] [blame] | 826 | case Type::Decltype: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 827 | return getOrCreateType(cast<DecltypeType>(Ty)->getUnderlyingType(), Unit); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 828 | } |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | /// EmitFunctionStart - Constructs the debug code for entering a function - |
| 832 | /// "llvm.dbg.func.start.". |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 833 | void CGDebugInfo::EmitFunctionStart(const char *Name, QualType ReturnType, |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 834 | llvm::Function *Fn, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 835 | CGBuilderTy &Builder) { |
Devang Patel | 6dba432 | 2009-07-14 21:31:22 +0000 | [diff] [blame] | 836 | const char *LinkageName = Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 837 | |
Daniel Dunbar | a289393 | 2009-05-13 23:08:57 +0000 | [diff] [blame] | 838 | // Skip the asm prefix if it exists. |
Daniel Dunbar | bbd53af | 2009-05-14 01:45:24 +0000 | [diff] [blame] | 839 | // |
| 840 | // FIXME: This should probably be the unmangled name? |
Daniel Dunbar | a289393 | 2009-05-13 23:08:57 +0000 | [diff] [blame] | 841 | if (Name[0] == '\01') |
| 842 | ++Name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 844 | // FIXME: Why is this using CurLoc??? |
| 845 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 846 | SourceManager &SM = M->getContext().getSourceManager(); |
Devang Patel | 0f78fea | 2009-04-08 19:47:04 +0000 | [diff] [blame] | 847 | unsigned LineNo = SM.getPresumedLoc(CurLoc).getLine(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 848 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 849 | llvm::DISubprogram SP = |
Devang Patel | 6dba432 | 2009-07-14 21:31:22 +0000 | [diff] [blame] | 850 | DebugFactory.CreateSubprogram(Unit, Name, Name, LinkageName, Unit, LineNo, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 851 | getOrCreateType(ReturnType, Unit), |
| 852 | Fn->hasInternalLinkage(), true/*definition*/); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 853 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 854 | DebugFactory.InsertSubprogramStart(SP, Builder.GetInsertBlock()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 855 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 856 | // Push function on region stack. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 857 | RegionStack.push_back(SP); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 861 | void CGDebugInfo::EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder) { |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 862 | if (CurLoc.isInvalid() || CurLoc.isMacroID()) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 863 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 864 | // Don't bother if things are the same as last time. |
| 865 | SourceManager &SM = M->getContext().getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 866 | if (CurLoc == PrevLoc |
Chris Lattner | 30fc933 | 2009-02-04 01:06:56 +0000 | [diff] [blame] | 867 | || (SM.getInstantiationLineNumber(CurLoc) == |
| 868 | SM.getInstantiationLineNumber(PrevLoc) |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 869 | && SM.isFromSameFile(CurLoc, PrevLoc))) |
| 870 | return; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 871 | |
| 872 | // Update last state. |
| 873 | PrevLoc = CurLoc; |
| 874 | |
| 875 | // Get the appropriate compile unit. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 876 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc); |
Devang Patel | 0f78fea | 2009-04-08 19:47:04 +0000 | [diff] [blame] | 877 | PresumedLoc PLoc = SM.getPresumedLoc(CurLoc); |
| 878 | DebugFactory.InsertStopPoint(Unit, PLoc.getLine(), PLoc.getColumn(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 879 | Builder.GetInsertBlock()); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | /// EmitRegionStart- Constructs the debug code for entering a declarative |
| 883 | /// region - "llvm.dbg.region.start.". |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 884 | void CGDebugInfo::EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder) { |
| 885 | llvm::DIDescriptor D; |
Daniel Dunbar | 5273f51 | 2008-10-17 01:07:56 +0000 | [diff] [blame] | 886 | if (!RegionStack.empty()) |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 887 | D = RegionStack.back(); |
Devang Patel | 49a8b98 | 2009-08-31 22:00:32 +0000 | [diff] [blame] | 888 | D = DebugFactory.CreateLexicalBlock(D); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 889 | RegionStack.push_back(D); |
| 890 | DebugFactory.InsertRegionStart(D, Builder.GetInsertBlock()); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | /// EmitRegionEnd - Constructs the debug code for exiting a declarative |
| 894 | /// region - "llvm.dbg.region.end." |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 895 | void CGDebugInfo::EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder) { |
Daniel Dunbar | 5273f51 | 2008-10-17 01:07:56 +0000 | [diff] [blame] | 896 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 897 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 898 | // Provide an region stop point. |
| 899 | EmitStopPoint(Fn, Builder); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 900 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 901 | DebugFactory.InsertRegionEnd(RegionStack.back(), Builder.GetInsertBlock()); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 902 | RegionStack.pop_back(); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 903 | } |
| 904 | |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 905 | /// EmitDeclare - Emit local variable declaration debug info. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 906 | void CGDebugInfo::EmitDeclare(const VarDecl *Decl, unsigned Tag, |
| 907 | llvm::Value *Storage, CGBuilderTy &Builder) { |
Daniel Dunbar | 5273f51 | 2008-10-17 01:07:56 +0000 | [diff] [blame] | 908 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 909 | |
Devang Patel | 0773903 | 2009-03-27 23:16:32 +0000 | [diff] [blame] | 910 | // Do not emit variable debug information while generating optimized code. |
| 911 | // The llvm optimizer and code generator are not yet ready to support |
| 912 | // optimized code debugging. |
| 913 | const CompileOptions &CO = M->getCompileOpts(); |
| 914 | if (CO.OptimizationLevel) |
| 915 | return; |
| 916 | |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 917 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation()); |
| 918 | llvm::DIType Ty = getOrCreateType(Decl->getType(), Unit); |
| 919 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 920 | // Get location information. |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 921 | SourceManager &SM = M->getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 922 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 923 | unsigned Line = 0; |
| 924 | if (!PLoc.isInvalid()) |
| 925 | Line = PLoc.getLine(); |
| 926 | else |
| 927 | Unit = llvm::DICompileUnit(); |
| 928 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 929 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 930 | // Create the descriptor for the variable. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 931 | llvm::DIVariable D = |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 932 | DebugFactory.CreateVariable(Tag, RegionStack.back(),Decl->getNameAsString(), |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 933 | Unit, Line, Ty); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 934 | // Insert an llvm.dbg.declare into the current block. |
| 935 | DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock()); |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 936 | } |
| 937 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 938 | void CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *Decl, |
| 939 | llvm::Value *Storage, |
| 940 | CGBuilderTy &Builder) { |
| 941 | EmitDeclare(Decl, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder); |
| 942 | } |
| 943 | |
| 944 | /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument |
| 945 | /// variable declaration. |
| 946 | void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, |
| 947 | CGBuilderTy &Builder) { |
| 948 | EmitDeclare(Decl, llvm::dwarf::DW_TAG_arg_variable, AI, Builder); |
| 949 | } |
| 950 | |
| 951 | |
| 952 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 953 | /// EmitGlobalVariable - Emit information about a global variable. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 954 | void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 955 | const VarDecl *Decl) { |
Devang Patel | 0773903 | 2009-03-27 23:16:32 +0000 | [diff] [blame] | 956 | |
| 957 | // Do not emit variable debug information while generating optimized code. |
| 958 | // The llvm optimizer and code generator are not yet ready to support |
| 959 | // optimized code debugging. |
| 960 | const CompileOptions &CO = M->getCompileOpts(); |
| 961 | if (CO.OptimizationLevel) |
| 962 | return; |
| 963 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 964 | // Create global variable debug descriptor. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 965 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation()); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 966 | SourceManager &SM = M->getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 967 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
| 968 | unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 969 | |
| 970 | std::string Name = Decl->getNameAsString(); |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 971 | |
| 972 | QualType T = Decl->getType(); |
| 973 | if (T->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 974 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 975 | // CodeGen turns int[] into int[1] so we'll do the same here. |
| 976 | llvm::APSInt ConstVal(32); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 977 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 978 | ConstVal = 1; |
| 979 | QualType ET = M->getContext().getAsArrayType(T)->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 980 | |
| 981 | T = M->getContext().getConstantArrayType(ET, ConstVal, |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 982 | ArrayType::Normal, 0); |
| 983 | } |
| 984 | |
Devang Patel | 6dba432 | 2009-07-14 21:31:22 +0000 | [diff] [blame] | 985 | DebugFactory.CreateGlobalVariable(Unit, Name, Name, "", Unit, LineNo, |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 986 | getOrCreateType(T, Unit), |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 987 | Var->hasInternalLinkage(), |
| 988 | true/*definition*/, Var); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 989 | } |
| 990 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 991 | /// EmitGlobalVariable - Emit information about an objective-c interface. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 992 | void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 993 | ObjCInterfaceDecl *Decl) { |
| 994 | // Create global variable debug descriptor. |
| 995 | llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation()); |
| 996 | SourceManager &SM = M->getContext().getSourceManager(); |
Devang Patel | 4f6fa23 | 2009-04-17 21:35:15 +0000 | [diff] [blame] | 997 | PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation()); |
| 998 | unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 999 | |
| 1000 | std::string Name = Decl->getNameAsString(); |
| 1001 | |
Chris Lattner | 03d9f34 | 2009-04-01 06:23:52 +0000 | [diff] [blame] | 1002 | QualType T = M->getContext().getObjCInterfaceType(Decl); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1003 | if (T->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1004 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1005 | // CodeGen turns int[] into int[1] so we'll do the same here. |
| 1006 | llvm::APSInt ConstVal(32); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1007 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1008 | ConstVal = 1; |
| 1009 | QualType ET = M->getContext().getAsArrayType(T)->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1010 | |
| 1011 | T = M->getContext().getConstantArrayType(ET, ConstVal, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1012 | ArrayType::Normal, 0); |
| 1013 | } |
| 1014 | |
Devang Patel | 6dba432 | 2009-07-14 21:31:22 +0000 | [diff] [blame] | 1015 | DebugFactory.CreateGlobalVariable(Unit, Name, Name, "", Unit, LineNo, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1016 | getOrCreateType(T, Unit), |
| 1017 | Var->hasInternalLinkage(), |
| 1018 | true/*definition*/, Var); |
| 1019 | } |