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