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" |
Devang Patel | 700a1cb | 2010-07-20 20:24:18 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclTemplate.h" |
Chris Lattner | 3cc5c40 | 2008-11-11 07:01:36 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Anders Carlsson | 19cc4ab | 2009-07-18 19:43:29 +0000 | [diff] [blame] | 21 | #include "clang/AST/RecordLayout.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 22 | #include "clang/Basic/SourceManager.h" |
| 23 | #include "clang/Basic/FileManager.h" |
Mike Stump | 5a86217 | 2009-09-15 21:48:34 +0000 | [diff] [blame] | 24 | #include "clang/Basic/Version.h" |
Chandler Carruth | 06057ce | 2010-06-15 23:19:56 +0000 | [diff] [blame] | 25 | #include "clang/Frontend/CodeGenOptions.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 26 | #include "llvm/Constants.h" |
| 27 | #include "llvm/DerivedTypes.h" |
| 28 | #include "llvm/Instructions.h" |
| 29 | #include "llvm/Intrinsics.h" |
| 30 | #include "llvm/Module.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/StringExtras.h" |
| 32 | #include "llvm/ADT/SmallVector.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Dwarf.h" |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 34 | #include "llvm/System/Path.h" |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 35 | #include "llvm/Target/TargetMachine.h" |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 36 | using namespace clang; |
| 37 | using namespace clang::CodeGen; |
| 38 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 39 | CGDebugInfo::CGDebugInfo(CodeGenModule &CGM) |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 40 | : CGM(CGM), DebugFactory(CGM.getModule()), |
Devang Patel | 7573f8b | 2010-03-09 21:32:27 +0000 | [diff] [blame] | 41 | FwdDeclCount(0), BlockLiteralGenericSet(false) { |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 42 | CreateCompileUnit(); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 45 | CGDebugInfo::~CGDebugInfo() { |
Daniel Dunbar | 66031a5 | 2008-10-17 16:15:48 +0000 | [diff] [blame] | 46 | assert(RegionStack.empty() && "Region stack mismatch, stack not empty!"); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 49 | void CGDebugInfo::setLocation(SourceLocation Loc) { |
| 50 | if (Loc.isValid()) |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 51 | CurLoc = CGM.getContext().getSourceManager().getInstantiationLoc(Loc); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Devang Patel | 3358305 | 2010-01-28 23:15:27 +0000 | [diff] [blame] | 54 | /// getContextDescriptor - Get context info for the decl. |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 55 | llvm::DIDescriptor CGDebugInfo::getContextDescriptor(const Decl *Context, |
Devang Patel | 3358305 | 2010-01-28 23:15:27 +0000 | [diff] [blame] | 56 | llvm::DIDescriptor &CompileUnit) { |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 57 | if (!Context) |
| 58 | return CompileUnit; |
| 59 | |
| 60 | llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator |
| 61 | I = RegionMap.find(Context); |
| 62 | if (I != RegionMap.end()) |
| 63 | return llvm::DIDescriptor(dyn_cast_or_null<llvm::MDNode>(I->second)); |
Devang Patel | 411894b | 2010-02-01 22:40:08 +0000 | [diff] [blame] | 64 | |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 65 | // Check namespace. |
| 66 | if (const NamespaceDecl *NSDecl = dyn_cast<NamespaceDecl>(Context)) |
| 67 | return llvm::DIDescriptor(getOrCreateNameSpace(NSDecl, CompileUnit)); |
Devang Patel | 8b90a78 | 2010-05-13 23:52:37 +0000 | [diff] [blame] | 68 | |
| 69 | if (const RecordDecl *RDecl = dyn_cast<RecordDecl>(Context)) { |
| 70 | if (!RDecl->isDependentType()) { |
| 71 | llvm::DIType Ty = getOrCreateType(CGM.getContext().getTypeDeclType(RDecl), |
| 72 | llvm::DIFile(CompileUnit)); |
| 73 | return llvm::DIDescriptor(Ty); |
| 74 | } |
| 75 | } |
Devang Patel | 979ec2e | 2009-10-06 00:35:31 +0000 | [diff] [blame] | 76 | return CompileUnit; |
| 77 | } |
| 78 | |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 79 | /// getFunctionName - Get function name for the given FunctionDecl. If the |
| 80 | /// name is constructred on demand (e.g. C++ destructor) then the name |
| 81 | /// is stored on the side. |
| 82 | llvm::StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) { |
| 83 | assert (FD && "Invalid FunctionDecl!"); |
| 84 | IdentifierInfo *FII = FD->getIdentifier(); |
| 85 | if (FII) |
| 86 | return FII->getName(); |
| 87 | |
| 88 | // Otherwise construct human readable name for debug info. |
| 89 | std::string NS = FD->getNameAsString(); |
| 90 | |
| 91 | // Copy this name on the side and use its reference. |
Devang Patel | 89f05f8 | 2010-01-28 18:21:00 +0000 | [diff] [blame] | 92 | char *StrPtr = DebugInfoNames.Allocate<char>(NS.length()); |
Benjamin Kramer | 1b627dc | 2010-01-23 18:16:07 +0000 | [diff] [blame] | 93 | memcpy(StrPtr, NS.data(), NS.length()); |
| 94 | return llvm::StringRef(StrPtr, NS.length()); |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Devang Patel | 700a1cb | 2010-07-20 20:24:18 +0000 | [diff] [blame] | 97 | /// getClassName - Get class name including template argument list. |
| 98 | llvm::StringRef |
| 99 | CGDebugInfo::getClassName(RecordDecl *RD) { |
| 100 | ClassTemplateSpecializationDecl *Spec |
| 101 | = dyn_cast<ClassTemplateSpecializationDecl>(RD); |
| 102 | if (!Spec) |
| 103 | return RD->getName(); |
| 104 | |
| 105 | const TemplateArgument *Args; |
| 106 | unsigned NumArgs; |
| 107 | std::string Buffer; |
| 108 | if (TypeSourceInfo *TAW = Spec->getTypeAsWritten()) { |
| 109 | const TemplateSpecializationType *TST = |
| 110 | cast<TemplateSpecializationType>(TAW->getType()); |
| 111 | Args = TST->getArgs(); |
| 112 | NumArgs = TST->getNumArgs(); |
| 113 | } else { |
| 114 | const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs(); |
| 115 | Args = TemplateArgs.getFlatArgumentList(); |
| 116 | NumArgs = TemplateArgs.flat_size(); |
| 117 | } |
| 118 | Buffer = RD->getIdentifier()->getNameStart(); |
| 119 | PrintingPolicy Policy(CGM.getLangOptions()); |
| 120 | Buffer += TemplateSpecializationType::PrintTemplateArgumentList(Args, |
| 121 | NumArgs, |
| 122 | Policy); |
| 123 | |
| 124 | // Copy this name on the side and use its reference. |
| 125 | char *StrPtr = DebugInfoNames.Allocate<char>(Buffer.length()); |
| 126 | memcpy(StrPtr, Buffer.data(), Buffer.length()); |
| 127 | return llvm::StringRef(StrPtr, Buffer.length()); |
| 128 | |
| 129 | } |
| 130 | |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 131 | /// getOrCreateFile - Get the file debug info descriptor for the input location. |
| 132 | llvm::DIFile CGDebugInfo::getOrCreateFile(SourceLocation Loc) { |
Ted Kremenek | 9c25039 | 2010-03-30 00:27:51 +0000 | [diff] [blame] | 133 | if (!Loc.isValid()) |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 134 | // If Location is not valid then use main input file. |
| 135 | return DebugFactory.CreateFile(TheCU.getFilename(), TheCU.getDirectory(), |
| 136 | TheCU); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 137 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 138 | PresumedLoc PLoc = SM.getPresumedLoc(Loc); |
Ted Kremenek | 9c25039 | 2010-03-30 00:27:51 +0000 | [diff] [blame] | 139 | |
| 140 | // Cache the results. |
| 141 | const char *fname = PLoc.getFilename(); |
| 142 | llvm::DenseMap<const char *, llvm::WeakVH>::iterator it = |
| 143 | DIFileCache.find(fname); |
| 144 | |
| 145 | if (it != DIFileCache.end()) { |
| 146 | // Verify that the information still exists. |
| 147 | if (&*it->second) |
| 148 | return llvm::DIFile(cast<llvm::MDNode>(it->second)); |
| 149 | } |
| 150 | |
| 151 | // FIXME: We shouldn't even need to call 'makeAbsolute()' in the cases |
| 152 | // where we can consult the FileEntry. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 153 | llvm::sys::Path AbsFileName(PLoc.getFilename()); |
Benjamin Kramer | 47daf68 | 2009-12-08 11:02:29 +0000 | [diff] [blame] | 154 | AbsFileName.makeAbsolute(); |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 155 | |
Ted Kremenek | 9c25039 | 2010-03-30 00:27:51 +0000 | [diff] [blame] | 156 | llvm::DIFile F = DebugFactory.CreateFile(AbsFileName.getLast(), |
| 157 | AbsFileName.getDirname(), TheCU); |
| 158 | |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 159 | DIFileCache[fname] = F; |
Ted Kremenek | 9c25039 | 2010-03-30 00:27:51 +0000 | [diff] [blame] | 160 | return F; |
| 161 | |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 162 | } |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 163 | |
| 164 | /// getLineNumber - Get line number for the location. If location is invalid |
| 165 | /// then use current location. |
| 166 | unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) { |
| 167 | assert (CurLoc.isValid() && "Invalid current location!"); |
| 168 | SourceManager &SM = CGM.getContext().getSourceManager(); |
| 169 | PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc); |
| 170 | return PLoc.getLine(); |
| 171 | } |
| 172 | |
| 173 | /// getColumnNumber - Get column number for the location. If location is |
| 174 | /// invalid then use current location. |
| 175 | unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc) { |
| 176 | assert (CurLoc.isValid() && "Invalid current location!"); |
| 177 | SourceManager &SM = CGM.getContext().getSourceManager(); |
| 178 | PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc); |
| 179 | return PLoc.getColumn(); |
| 180 | } |
| 181 | |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 182 | /// CreateCompileUnit - Create new compile unit. |
| 183 | void CGDebugInfo::CreateCompileUnit() { |
| 184 | |
| 185 | // Get absolute path name. |
Douglas Gregor | ac91b4c | 2010-03-18 23:46:43 +0000 | [diff] [blame] | 186 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Douglas Gregor | f7ad500 | 2010-03-19 14:49:09 +0000 | [diff] [blame] | 187 | std::string MainFileName = CGM.getCodeGenOpts().MainFileName; |
| 188 | if (MainFileName.empty()) |
Devang Patel | 22fe585 | 2010-03-12 21:04:27 +0000 | [diff] [blame] | 189 | MainFileName = "<unknown>"; |
Douglas Gregor | f7ad500 | 2010-03-19 14:49:09 +0000 | [diff] [blame] | 190 | |
Devang Patel | 22fe585 | 2010-03-12 21:04:27 +0000 | [diff] [blame] | 191 | llvm::sys::Path AbsFileName(MainFileName); |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 192 | AbsFileName.makeAbsolute(); |
Daniel Dunbar | c9abc04 | 2009-04-08 05:11:16 +0000 | [diff] [blame] | 193 | |
Douglas Gregor | f6728fc | 2010-03-22 21:28:29 +0000 | [diff] [blame] | 194 | // The main file name provided via the "-main-file-name" option contains just |
| 195 | // the file name itself with no path information. This file name may have had |
| 196 | // a relative path, so we look into the actual file entry for the main |
| 197 | // file to determine the real absolute path for the file. |
Douglas Gregor | f7ad500 | 2010-03-19 14:49:09 +0000 | [diff] [blame] | 198 | std::string MainFileDir; |
| 199 | if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) |
| 200 | MainFileDir = MainFile->getDir()->getName(); |
| 201 | else |
| 202 | MainFileDir = AbsFileName.getDirname(); |
| 203 | |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 204 | unsigned LangTag; |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 205 | const LangOptions &LO = CGM.getLangOptions(); |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 206 | if (LO.CPlusPlus) { |
| 207 | if (LO.ObjC1) |
| 208 | LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus; |
| 209 | else |
| 210 | LangTag = llvm::dwarf::DW_LANG_C_plus_plus; |
| 211 | } else if (LO.ObjC1) { |
Devang Patel | 8d9aefc | 2009-03-24 20:35:51 +0000 | [diff] [blame] | 212 | LangTag = llvm::dwarf::DW_LANG_ObjC; |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 213 | } else if (LO.C99) { |
Devang Patel | 8d9aefc | 2009-03-24 20:35:51 +0000 | [diff] [blame] | 214 | LangTag = llvm::dwarf::DW_LANG_C99; |
Chris Lattner | 515455a | 2009-03-25 03:28:08 +0000 | [diff] [blame] | 215 | } else { |
| 216 | LangTag = llvm::dwarf::DW_LANG_C89; |
| 217 | } |
Devang Patel | 446c619 | 2009-04-17 21:06:59 +0000 | [diff] [blame] | 218 | |
Benjamin Kramer | 47daf68 | 2009-12-08 11:02:29 +0000 | [diff] [blame] | 219 | const char *Producer = |
Mike Stump | d8945d6 | 2009-10-09 18:38:12 +0000 | [diff] [blame] | 220 | #ifdef CLANG_VENDOR |
| 221 | CLANG_VENDOR |
| 222 | #endif |
| 223 | "clang " CLANG_VERSION_STRING; |
Chris Lattner | 4c2577a | 2009-05-02 01:00:04 +0000 | [diff] [blame] | 224 | |
| 225 | // Figure out which version of the ObjC runtime we have. |
| 226 | unsigned RuntimeVers = 0; |
| 227 | if (LO.ObjC1) |
| 228 | RuntimeVers = LO.ObjCNonFragileABI ? 2 : 1; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 229 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 230 | // Create new compile unit. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 231 | TheCU = DebugFactory.CreateCompileUnit( |
Douglas Gregor | f7ad500 | 2010-03-19 14:49:09 +0000 | [diff] [blame] | 232 | LangTag, AbsFileName.getLast(), MainFileDir, Producer, true, |
Daniel Dunbar | f2d8b9f | 2009-12-18 02:43:17 +0000 | [diff] [blame] | 233 | LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 236 | /// CreateType - Get the Basic type from the cache or create a new |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 237 | /// one if necessary. |
| 238 | llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 239 | llvm::DIFile Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 240 | unsigned Encoding = 0; |
| 241 | switch (BT->getKind()) { |
| 242 | default: |
| 243 | case BuiltinType::Void: |
| 244 | return llvm::DIType(); |
| 245 | case BuiltinType::UChar: |
| 246 | case BuiltinType::Char_U: Encoding = llvm::dwarf::DW_ATE_unsigned_char; break; |
| 247 | case BuiltinType::Char_S: |
| 248 | case BuiltinType::SChar: Encoding = llvm::dwarf::DW_ATE_signed_char; break; |
| 249 | case BuiltinType::UShort: |
| 250 | case BuiltinType::UInt: |
| 251 | case BuiltinType::ULong: |
| 252 | case BuiltinType::ULongLong: Encoding = llvm::dwarf::DW_ATE_unsigned; break; |
| 253 | case BuiltinType::Short: |
| 254 | case BuiltinType::Int: |
| 255 | case BuiltinType::Long: |
| 256 | case BuiltinType::LongLong: Encoding = llvm::dwarf::DW_ATE_signed; break; |
| 257 | case BuiltinType::Bool: Encoding = llvm::dwarf::DW_ATE_boolean; break; |
| 258 | case BuiltinType::Float: |
Devang Patel | 7c173cb | 2009-10-12 22:28:31 +0000 | [diff] [blame] | 259 | case BuiltinType::LongDouble: |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 260 | case BuiltinType::Double: Encoding = llvm::dwarf::DW_ATE_float; break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 261 | } |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 262 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 263 | uint64_t Size = CGM.getContext().getTypeSize(BT); |
| 264 | uint64_t Align = CGM.getContext().getTypeAlign(BT); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 265 | uint64_t Offset = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 266 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 267 | llvm::DIType DbgTy = |
| 268 | DebugFactory.CreateBasicType(Unit, |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 269 | BT->getName(CGM.getContext().getLangOptions()), |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 270 | Unit, 0, Size, Align, |
| 271 | Offset, /*flags*/ 0, Encoding); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 272 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 273 | } |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 274 | |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 275 | llvm::DIType CGDebugInfo::CreateType(const ComplexType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 276 | llvm::DIFile Unit) { |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 277 | // Bit size, align and offset of the type. |
| 278 | unsigned Encoding = llvm::dwarf::DW_ATE_complex_float; |
| 279 | if (Ty->isComplexIntegerType()) |
| 280 | Encoding = llvm::dwarf::DW_ATE_lo_user; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 281 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 282 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 283 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 284 | uint64_t Offset = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 286 | llvm::DIType DbgTy = |
| 287 | DebugFactory.CreateBasicType(Unit, "complex", |
| 288 | Unit, 0, Size, Align, |
| 289 | Offset, /*flags*/ 0, Encoding); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 290 | return DbgTy; |
Chris Lattner | b700377 | 2009-04-23 06:13:01 +0000 | [diff] [blame] | 291 | } |
| 292 | |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 293 | /// CreateCVRType - Get the qualified type from the cache or create |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 294 | /// a new one if necessary. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 295 | llvm::DIType CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DIFile Unit) { |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 296 | QualifierCollector Qc; |
| 297 | const Type *T = Qc.strip(Ty); |
| 298 | |
| 299 | // Ignore these qualifiers for now. |
| 300 | Qc.removeObjCGCAttr(); |
| 301 | Qc.removeAddressSpace(); |
| 302 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 303 | // We will create one Derived type for one qualifier and recurse to handle any |
| 304 | // additional ones. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 305 | unsigned Tag; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 306 | if (Qc.hasConst()) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 307 | Tag = llvm::dwarf::DW_TAG_const_type; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 308 | Qc.removeConst(); |
| 309 | } else if (Qc.hasVolatile()) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 310 | Tag = llvm::dwarf::DW_TAG_volatile_type; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 311 | Qc.removeVolatile(); |
| 312 | } else if (Qc.hasRestrict()) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 313 | Tag = llvm::dwarf::DW_TAG_restrict_type; |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 314 | Qc.removeRestrict(); |
| 315 | } else { |
| 316 | assert(Qc.empty() && "Unknown type qualifier for debug info"); |
| 317 | return getOrCreateType(QualType(T, 0), Unit); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 318 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 319 | |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 320 | llvm::DIType FromTy = getOrCreateType(Qc.apply(T), Unit); |
| 321 | |
Daniel Dunbar | 3845f86 | 2008-10-31 03:54:29 +0000 | [diff] [blame] | 322 | // No need to fill in the Name, Line, Size, Alignment, Offset in case of |
| 323 | // CVR derived types. |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 324 | llvm::DIType DbgTy = |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 325 | DebugFactory.CreateDerivedType(Tag, Unit, "", Unit, |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 326 | 0, 0, 0, 0, 0, FromTy); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 327 | return DbgTy; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 330 | llvm::DIType CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 331 | llvm::DIFile Unit) { |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 332 | llvm::DIType DbgTy = |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 333 | CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty, |
| 334 | Ty->getPointeeType(), Unit); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 335 | return DbgTy; |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 338 | llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 339 | llvm::DIFile Unit) { |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 340 | return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty, |
| 341 | Ty->getPointeeType(), Unit); |
| 342 | } |
| 343 | |
| 344 | llvm::DIType CGDebugInfo::CreatePointerLikeType(unsigned Tag, |
| 345 | const Type *Ty, |
| 346 | QualType PointeeTy, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 347 | llvm::DIFile Unit) { |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 348 | llvm::DIType EltTy = getOrCreateType(PointeeTy, Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 350 | // Bit size, align and offset of the type. |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 351 | |
| 352 | // Size is always the size of a pointer. We can't use getTypeSize here |
| 353 | // because that does not return the correct value for references. |
| 354 | uint64_t Size = |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 355 | CGM.getContext().Target.getPointerWidth(PointeeTy.getAddressSpace()); |
| 356 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 357 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 358 | return |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 359 | DebugFactory.CreateDerivedType(Tag, Unit, "", Unit, |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 360 | 0, Size, Align, 0, 0, EltTy); |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 361 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 364 | llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 365 | llvm::DIFile Unit) { |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 366 | if (BlockLiteralGenericSet) |
| 367 | return BlockLiteralGeneric; |
| 368 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 369 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
| 370 | |
| 371 | llvm::SmallVector<llvm::DIDescriptor, 5> EltTys; |
| 372 | |
| 373 | llvm::DIType FieldTy; |
| 374 | |
| 375 | QualType FType; |
| 376 | uint64_t FieldSize, FieldOffset; |
| 377 | unsigned FieldAlign; |
| 378 | |
| 379 | llvm::DIArray Elements; |
| 380 | llvm::DIType EltTy, DescTy; |
| 381 | |
| 382 | FieldOffset = 0; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 383 | FType = CGM.getContext().UnsignedLongTy; |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 384 | EltTys.push_back(CreateMemberType(Unit, FType, "reserved", &FieldOffset)); |
| 385 | EltTys.push_back(CreateMemberType(Unit, FType, "Size", &FieldOffset)); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 386 | |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 387 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 388 | EltTys.clear(); |
| 389 | |
Mike Stump | 3d363c5 | 2009-10-02 02:30:50 +0000 | [diff] [blame] | 390 | unsigned Flags = llvm::DIType::FlagAppleBlock; |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 391 | unsigned LineNo = getLineNumber(CurLoc); |
Mike Stump | 3d363c5 | 2009-10-02 02:30:50 +0000 | [diff] [blame] | 392 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 393 | EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_descriptor", |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 394 | Unit, LineNo, FieldOffset, 0, 0, |
| 395 | Flags, llvm::DIType(), Elements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 396 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 397 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 398 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 399 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 400 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 401 | DescTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 402 | Unit, "", Unit, |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 403 | LineNo, Size, Align, 0, 0, EltTy); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 404 | |
| 405 | FieldOffset = 0; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 406 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 407 | EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset)); |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 408 | FType = CGM.getContext().IntTy; |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 409 | EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset)); |
| 410 | EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset)); |
Benjamin Kramer | d3651cc | 2010-04-24 20:26:20 +0000 | [diff] [blame] | 411 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 412 | EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset)); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 413 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 414 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 415 | FieldTy = DescTy; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 416 | FieldSize = CGM.getContext().getTypeSize(Ty); |
| 417 | FieldAlign = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 418 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 419 | "__descriptor", Unit, |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 420 | LineNo, FieldSize, FieldAlign, |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 421 | FieldOffset, 0, FieldTy); |
| 422 | EltTys.push_back(FieldTy); |
| 423 | |
| 424 | FieldOffset += FieldSize; |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 425 | Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 426 | |
| 427 | EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_literal_generic", |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 428 | Unit, LineNo, FieldOffset, 0, 0, |
| 429 | Flags, llvm::DIType(), Elements); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 430 | |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 431 | BlockLiteralGenericSet = true; |
| 432 | BlockLiteralGeneric |
| 433 | = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 434 | "", Unit, |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 435 | LineNo, Size, Align, 0, 0, EltTy); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 436 | return BlockLiteralGeneric; |
| 437 | } |
| 438 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 439 | llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 440 | llvm::DIFile Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 441 | // Typedefs are derived from some other type. If we have a typedef of a |
| 442 | // typedef, make sure to emit the whole chain. |
| 443 | llvm::DIType Src = getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 444 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 445 | // We don't set size information, but do specify where the typedef was |
| 446 | // declared. |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 447 | unsigned Line = getLineNumber(Ty->getDecl()->getLocation()); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 448 | |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 449 | llvm::DIDescriptor TyContext |
| 450 | = getContextDescriptor(dyn_cast<Decl>(Ty->getDecl()->getDeclContext()), |
| 451 | Unit); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 452 | llvm::DIType DbgTy = |
Devang Patel | d528905 | 2010-01-29 22:29:31 +0000 | [diff] [blame] | 453 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_typedef, |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 454 | TyContext, |
Devang Patel | d528905 | 2010-01-29 22:29:31 +0000 | [diff] [blame] | 455 | Ty->getDecl()->getName(), Unit, |
| 456 | Line, 0, 0, 0, 0, Src); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 457 | return DbgTy; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 460 | llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 461 | llvm::DIFile Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 462 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 463 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 464 | // Add the result type at least. |
| 465 | EltTys.push_back(getOrCreateType(Ty->getResultType(), Unit)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 466 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 467 | // Set up remainder of arguments if there is a prototype. |
| 468 | // FIXME: IF NOT, HOW IS THIS REPRESENTED? llvm-gcc doesn't represent '...'! |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 469 | if (const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(Ty)) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 470 | for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i) |
| 471 | EltTys.push_back(getOrCreateType(FTP->getArgType(i), Unit)); |
| 472 | } else { |
| 473 | // FIXME: Handle () case in C. llvm-gcc doesn't do it either. |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 474 | } |
| 475 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 476 | llvm::DIArray EltTypeArray = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 477 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 478 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 479 | llvm::DIType DbgTy = |
| 480 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 481 | Unit, "", Unit, |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 482 | 0, 0, 0, 0, 0, |
| 483 | llvm::DIType(), EltTypeArray); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 484 | return DbgTy; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 487 | /// CollectRecordFields - A helper function to collect debug info for |
| 488 | /// record fields. This is used while creating debug info entry for a Record. |
| 489 | void CGDebugInfo:: |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 490 | CollectRecordFields(const RecordDecl *RD, llvm::DIFile Unit, |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 491 | llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys) { |
| 492 | unsigned FieldNo = 0; |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 493 | const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); |
| 494 | for (RecordDecl::field_iterator I = RD->field_begin(), |
| 495 | E = RD->field_end(); |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 496 | I != E; ++I, ++FieldNo) { |
| 497 | FieldDecl *Field = *I; |
| 498 | llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); |
| 499 | |
| 500 | llvm::StringRef FieldName = Field->getName(); |
| 501 | |
Devang Patel | 4835fdd | 2010-02-12 01:31:06 +0000 | [diff] [blame] | 502 | // Ignore unnamed fields. Do not ignore unnamed records. |
| 503 | if (FieldName.empty() && !isa<RecordType>(Field->getType())) |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 504 | continue; |
| 505 | |
| 506 | // Get the location for the field. |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 507 | llvm::DIFile FieldDefUnit = getOrCreateFile(Field->getLocation()); |
| 508 | unsigned FieldLine = getLineNumber(Field->getLocation()); |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 509 | QualType FType = Field->getType(); |
| 510 | uint64_t FieldSize = 0; |
| 511 | unsigned FieldAlign = 0; |
| 512 | if (!FType->isIncompleteArrayType()) { |
| 513 | |
| 514 | // Bit size, align and offset of the type. |
| 515 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 516 | Expr *BitWidth = Field->getBitWidth(); |
| 517 | if (BitWidth) |
| 518 | FieldSize = BitWidth->EvaluateAsInt(CGM.getContext()).getZExtValue(); |
| 519 | |
| 520 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
| 521 | } |
| 522 | |
| 523 | uint64_t FieldOffset = RL.getFieldOffset(FieldNo); |
| 524 | |
Devang Patel | 71f4ff6 | 2010-04-21 23:12:37 +0000 | [diff] [blame] | 525 | unsigned Flags = 0; |
| 526 | AccessSpecifier Access = I->getAccess(); |
| 527 | if (Access == clang::AS_private) |
| 528 | Flags |= llvm::DIType::FlagPrivate; |
| 529 | else if (Access == clang::AS_protected) |
| 530 | Flags |= llvm::DIType::FlagProtected; |
| 531 | |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 532 | // Create a DW_TAG_member node to remember the offset of this field in the |
| 533 | // struct. FIXME: This is an absolutely insane way to capture this |
| 534 | // information. When we gut debug info, this should be fixed. |
| 535 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 536 | FieldName, FieldDefUnit, |
| 537 | FieldLine, FieldSize, FieldAlign, |
Devang Patel | 71f4ff6 | 2010-04-21 23:12:37 +0000 | [diff] [blame] | 538 | FieldOffset, Flags, FieldTy); |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 539 | EltTys.push_back(FieldTy); |
| 540 | } |
| 541 | } |
| 542 | |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 543 | /// getOrCreateMethodType - CXXMethodDecl's type is a FunctionType. This |
| 544 | /// function type is not updated to include implicit "this" pointer. Use this |
| 545 | /// routine to get a method type which includes "this" pointer. |
| 546 | llvm::DIType |
| 547 | CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 548 | llvm::DIFile Unit) { |
Douglas Gregor | 5f970ee | 2010-05-04 18:18:31 +0000 | [diff] [blame] | 549 | llvm::DIType FnTy |
| 550 | = getOrCreateType(QualType(Method->getType()->getAs<FunctionProtoType>(), |
| 551 | 0), |
| 552 | Unit); |
Devang Patel | d774d1e | 2010-01-28 21:43:50 +0000 | [diff] [blame] | 553 | |
| 554 | // Static methods do not need "this" pointer argument. |
| 555 | if (Method->isStatic()) |
| 556 | return FnTy; |
| 557 | |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 558 | // Add "this" pointer. |
| 559 | |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 560 | llvm::DIArray Args = llvm::DICompositeType(FnTy).getTypeArray(); |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 561 | assert (Args.getNumElements() && "Invalid number of arguments!"); |
| 562 | |
| 563 | llvm::SmallVector<llvm::DIDescriptor, 16> Elts; |
| 564 | |
| 565 | // First element is always return type. For 'void' functions it is NULL. |
| 566 | Elts.push_back(Args.getElement(0)); |
| 567 | |
| 568 | // "this" pointer is always first argument. |
| 569 | ASTContext &Context = CGM.getContext(); |
| 570 | QualType ThisPtr = |
| 571 | Context.getPointerType(Context.getTagDeclType(Method->getParent())); |
Devang Patel | 337472d | 2010-02-09 17:57:50 +0000 | [diff] [blame] | 572 | llvm::DIType ThisPtrType = |
| 573 | DebugFactory.CreateArtificialType(getOrCreateType(ThisPtr, Unit)); |
Devang Patel | 769640e | 2010-07-13 00:24:30 +0000 | [diff] [blame] | 574 | |
Devang Patel | 700a1cb | 2010-07-20 20:24:18 +0000 | [diff] [blame] | 575 | unsigned Quals = Method->getTypeQualifiers(); |
| 576 | if (Quals & Qualifiers::Const) |
| 577 | ThisPtrType = |
| 578 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_const_type, |
| 579 | Unit, "", Unit, |
| 580 | 0, 0, 0, 0, 0, ThisPtrType); |
| 581 | if (Quals & Qualifiers::Volatile) |
| 582 | ThisPtrType = |
| 583 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_volatile_type, |
| 584 | Unit, "", Unit, |
| 585 | 0, 0, 0, 0, 0, ThisPtrType); |
| 586 | |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 587 | TypeCache[ThisPtr.getAsOpaquePtr()] = ThisPtrType; |
Devang Patel | 337472d | 2010-02-09 17:57:50 +0000 | [diff] [blame] | 588 | Elts.push_back(ThisPtrType); |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 589 | |
| 590 | // Copy rest of the arguments. |
| 591 | for (unsigned i = 1, e = Args.getNumElements(); i != e; ++i) |
| 592 | Elts.push_back(Args.getElement(i)); |
| 593 | |
| 594 | llvm::DIArray EltTypeArray = |
| 595 | DebugFactory.GetOrCreateArray(Elts.data(), Elts.size()); |
| 596 | |
| 597 | return |
| 598 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 599 | Unit, "", Unit, |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 600 | 0, 0, 0, 0, 0, |
| 601 | llvm::DIType(), EltTypeArray); |
| 602 | } |
| 603 | |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 604 | /// CreateCXXMemberFunction - A helper function to create a DISubprogram for |
| 605 | /// a single member function GlobalDecl. |
| 606 | llvm::DISubprogram |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 607 | CGDebugInfo::CreateCXXMemberFunction(const CXXMethodDecl *Method, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 608 | llvm::DIFile Unit, |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 609 | llvm::DICompositeType &RecordTy) { |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 610 | bool IsCtorOrDtor = |
| 611 | isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method); |
| 612 | |
| 613 | llvm::StringRef MethodName = getFunctionName(Method); |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 614 | llvm::DIType MethodTy = getOrCreateMethodType(Method, Unit); |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 615 | |
| 616 | // Since a single ctor/dtor corresponds to multiple functions, it doesn't |
| 617 | // make sense to give a single ctor/dtor a linkage name. |
Anders Carlsson | 9a20d55 | 2010-06-22 16:16:50 +0000 | [diff] [blame] | 618 | llvm::StringRef MethodLinkageName; |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 619 | if (!IsCtorOrDtor) |
Anders Carlsson | 9a20d55 | 2010-06-22 16:16:50 +0000 | [diff] [blame] | 620 | MethodLinkageName = CGM.getMangledName(Method); |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 621 | |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 622 | // Get the location for the method. |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 623 | llvm::DIFile MethodDefUnit = getOrCreateFile(Method->getLocation()); |
| 624 | unsigned MethodLine = getLineNumber(Method->getLocation()); |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 625 | |
| 626 | // Collect virtual method info. |
| 627 | llvm::DIType ContainingType; |
| 628 | unsigned Virtuality = 0; |
| 629 | unsigned VIndex = 0; |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 630 | |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 631 | if (Method->isVirtual()) { |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 632 | if (Method->isPure()) |
| 633 | Virtuality = llvm::dwarf::DW_VIRTUALITY_pure_virtual; |
| 634 | else |
| 635 | Virtuality = llvm::dwarf::DW_VIRTUALITY_virtual; |
| 636 | |
| 637 | // It doesn't make sense to give a virtual destructor a vtable index, |
| 638 | // since a single destructor has two entries in the vtable. |
| 639 | if (!isa<CXXDestructorDecl>(Method)) |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 640 | VIndex = CGM.getVTables().getMethodVTableIndex(Method); |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 641 | ContainingType = RecordTy; |
| 642 | } |
| 643 | |
| 644 | llvm::DISubprogram SP = |
| 645 | DebugFactory.CreateSubprogram(RecordTy , MethodName, MethodName, |
| 646 | MethodLinkageName, |
| 647 | MethodDefUnit, MethodLine, |
| 648 | MethodTy, /*isLocalToUnit=*/false, |
Devang Patel | a5c5bab | 2010-07-12 22:54:41 +0000 | [diff] [blame] | 649 | /* isDefintion=*/ false, |
Devang Patel | 4089491 | 2010-07-15 22:57:00 +0000 | [diff] [blame] | 650 | Virtuality, VIndex, ContainingType, |
Devang Patel | 15a3d7d | 2010-07-15 23:09:46 +0000 | [diff] [blame] | 651 | Method->isImplicit(), |
| 652 | CGM.getLangOptions().Optimize); |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 653 | |
| 654 | // Don't cache ctors or dtors since we have to emit multiple functions for |
| 655 | // a single ctor or dtor. |
| 656 | if (!IsCtorOrDtor && Method->isThisDeclarationADefinition()) |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 657 | SPCache[Method] = llvm::WeakVH(SP); |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 658 | |
| 659 | return SP; |
| 660 | } |
| 661 | |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 662 | /// CollectCXXMemberFunctions - A helper function to collect debug info for |
| 663 | /// C++ member functions.This is used while creating debug info entry for |
| 664 | /// a Record. |
| 665 | void CGDebugInfo:: |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 666 | CollectCXXMemberFunctions(const CXXRecordDecl *RD, llvm::DIFile Unit, |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 667 | llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys, |
| 668 | llvm::DICompositeType &RecordTy) { |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 669 | for(CXXRecordDecl::method_iterator I = RD->method_begin(), |
| 670 | E = RD->method_end(); I != E; ++I) { |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 671 | const CXXMethodDecl *Method = *I; |
Anders Carlsson | bea9b23 | 2010-01-26 04:40:11 +0000 | [diff] [blame] | 672 | |
Devang Patel | d5322da | 2010-02-09 19:09:28 +0000 | [diff] [blame] | 673 | if (Method->isImplicit() && !Method->isUsed()) |
Anders Carlsson | bea9b23 | 2010-01-26 04:40:11 +0000 | [diff] [blame] | 674 | continue; |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 675 | |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 676 | EltTys.push_back(CreateCXXMemberFunction(Method, Unit, RecordTy)); |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 677 | } |
| 678 | } |
| 679 | |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 680 | /// CollectCXXBases - A helper function to collect debug info for |
| 681 | /// C++ base classes. This is used while creating debug info entry for |
| 682 | /// a Record. |
| 683 | void CGDebugInfo:: |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 684 | CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile Unit, |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 685 | llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys, |
| 686 | llvm::DICompositeType &RecordTy) { |
| 687 | |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 688 | const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); |
| 689 | for (CXXRecordDecl::base_class_const_iterator BI = RD->bases_begin(), |
| 690 | BE = RD->bases_end(); BI != BE; ++BI) { |
Devang Patel | ca7daed | 2010-01-28 21:54:15 +0000 | [diff] [blame] | 691 | unsigned BFlags = 0; |
| 692 | uint64_t BaseOffset; |
| 693 | |
| 694 | const CXXRecordDecl *Base = |
| 695 | cast<CXXRecordDecl>(BI->getType()->getAs<RecordType>()->getDecl()); |
| 696 | |
| 697 | if (BI->isVirtual()) { |
Anders Carlsson | bba1607 | 2010-03-11 07:15:17 +0000 | [diff] [blame] | 698 | // virtual base offset offset is -ve. The code generator emits dwarf |
Devang Patel | d5322da | 2010-02-09 19:09:28 +0000 | [diff] [blame] | 699 | // expression where it expects +ve number. |
Anders Carlsson | af44035 | 2010-03-23 04:11:45 +0000 | [diff] [blame] | 700 | BaseOffset = 0 - CGM.getVTables().getVirtualBaseOffsetOffset(RD, Base); |
Devang Patel | ca7daed | 2010-01-28 21:54:15 +0000 | [diff] [blame] | 701 | BFlags = llvm::DIType::FlagVirtual; |
| 702 | } else |
| 703 | BaseOffset = RL.getBaseClassOffset(Base); |
| 704 | |
| 705 | AccessSpecifier Access = BI->getAccessSpecifier(); |
| 706 | if (Access == clang::AS_private) |
| 707 | BFlags |= llvm::DIType::FlagPrivate; |
| 708 | else if (Access == clang::AS_protected) |
| 709 | BFlags |= llvm::DIType::FlagProtected; |
| 710 | |
| 711 | llvm::DIType DTy = |
| 712 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance, |
| 713 | RecordTy, llvm::StringRef(), |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 714 | Unit, 0, 0, 0, |
Devang Patel | ca7daed | 2010-01-28 21:54:15 +0000 | [diff] [blame] | 715 | BaseOffset, BFlags, |
| 716 | getOrCreateType(BI->getType(), |
| 717 | Unit)); |
| 718 | EltTys.push_back(DTy); |
| 719 | } |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 720 | } |
| 721 | |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 722 | /// getOrCreateVTablePtrType - Return debug info descriptor for vtable. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 723 | llvm::DIType CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile Unit) { |
Devang Patel | 0804e6e | 2010-03-08 20:53:17 +0000 | [diff] [blame] | 724 | if (VTablePtrType.isValid()) |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 725 | return VTablePtrType; |
| 726 | |
| 727 | ASTContext &Context = CGM.getContext(); |
| 728 | |
| 729 | /* Function type */ |
Benjamin Kramer | ad46886 | 2010-03-30 11:36:44 +0000 | [diff] [blame] | 730 | llvm::DIDescriptor STy = getOrCreateType(Context.IntTy, Unit); |
| 731 | llvm::DIArray SElements = DebugFactory.GetOrCreateArray(&STy, 1); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 732 | llvm::DIType SubTy = |
| 733 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 734 | Unit, "", Unit, |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 735 | 0, 0, 0, 0, 0, llvm::DIType(), SElements); |
| 736 | |
| 737 | unsigned Size = Context.getTypeSize(Context.VoidPtrTy); |
| 738 | llvm::DIType vtbl_ptr_type |
| 739 | = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 740 | Unit, "__vtbl_ptr_type", Unit, |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 741 | 0, Size, 0, 0, 0, SubTy); |
| 742 | |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 743 | VTablePtrType = |
| 744 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, |
| 745 | Unit, "", Unit, |
| 746 | 0, Size, 0, 0, 0, vtbl_ptr_type); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 747 | return VTablePtrType; |
| 748 | } |
| 749 | |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 750 | /// getVTableName - Get vtable name for the given Class. |
| 751 | llvm::StringRef CGDebugInfo::getVTableName(const CXXRecordDecl *RD) { |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 752 | // Otherwise construct gdb compatible name name. |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 753 | std::string Name = "_vptr$" + RD->getNameAsString(); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 754 | |
| 755 | // Copy this name on the side and use its reference. |
Devang Patel | 89f05f8 | 2010-01-28 18:21:00 +0000 | [diff] [blame] | 756 | char *StrPtr = DebugInfoNames.Allocate<char>(Name.length()); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 757 | memcpy(StrPtr, Name.data(), Name.length()); |
| 758 | return llvm::StringRef(StrPtr, Name.length()); |
| 759 | } |
| 760 | |
| 761 | |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 762 | /// CollectVTableInfo - If the C++ class has vtable info then insert appropriate |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 763 | /// debug info entry in EltTys vector. |
| 764 | void CGDebugInfo:: |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 765 | CollectVTableInfo(const CXXRecordDecl *RD, llvm::DIFile Unit, |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 766 | llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys) { |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 767 | const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 768 | |
| 769 | // If there is a primary base then it will hold vtable info. |
| 770 | if (RL.getPrimaryBase()) |
| 771 | return; |
| 772 | |
| 773 | // If this class is not dynamic then there is not any vtable info to collect. |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 774 | if (!RD->isDynamicClass()) |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 775 | return; |
| 776 | |
| 777 | unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy); |
| 778 | llvm::DIType VPTR |
| 779 | = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 780 | getVTableName(RD), Unit, |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 781 | 0, Size, 0, 0, 0, |
| 782 | getOrCreateVTablePtrType(Unit)); |
| 783 | EltTys.push_back(VPTR); |
| 784 | } |
| 785 | |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 786 | /// CreateType - get structure or union type. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 787 | llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 788 | llvm::DIFile Unit) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 789 | RecordDecl *RD = Ty->getDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 790 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 791 | unsigned Tag; |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 792 | if (RD->isStruct()) |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 793 | Tag = llvm::dwarf::DW_TAG_structure_type; |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 794 | else if (RD->isUnion()) |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 795 | Tag = llvm::dwarf::DW_TAG_union_type; |
| 796 | else { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 797 | assert(RD->isClass() && "Unknown RecordType!"); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 798 | Tag = llvm::dwarf::DW_TAG_class_type; |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 799 | } |
| 800 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 801 | // Get overall information about the record type for the debug info. |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 802 | llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation()); |
| 803 | unsigned Line = getLineNumber(RD->getLocation()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 804 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 805 | // Records and classes and unions can all be recursive. To handle them, we |
| 806 | // first generate a debug descriptor for the struct as a forward declaration. |
| 807 | // Then (if it is a definition) we go through and get debug info for all of |
| 808 | // its members. Finally, we create a descriptor for the complete type (which |
| 809 | // may refer to the forward decl if the struct is recursive) and replace all |
| 810 | // uses of the forward declaration with the final definition. |
Devang Patel | 0b89799 | 2010-07-08 19:56:29 +0000 | [diff] [blame] | 811 | llvm::DIDescriptor FDContext = |
| 812 | getContextDescriptor(dyn_cast<Decl>(RD->getDeclContext()), Unit); |
| 813 | |
| 814 | // If this is just a forward declaration, construct an appropriately |
| 815 | // marked node and just return it. |
| 816 | if (!RD->getDefinition()) { |
| 817 | llvm::DICompositeType FwdDecl = |
| 818 | DebugFactory.CreateCompositeType(Tag, FDContext, RD->getName(), |
| 819 | DefUnit, Line, 0, 0, 0, |
| 820 | llvm::DIType::FlagFwdDecl, |
| 821 | llvm::DIType(), llvm::DIArray()); |
| 822 | |
| 823 | return FwdDecl; |
| 824 | } |
Devang Patel | d0f251b | 2010-01-20 23:56:40 +0000 | [diff] [blame] | 825 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 826 | // A RD->getName() is not unique. However, the debug info descriptors |
Devang Patel | ce78c97 | 2010-02-01 22:51:29 +0000 | [diff] [blame] | 827 | // are uniqued so use type name to ensure uniquness. |
Benjamin Kramer | fea3d4d | 2010-03-13 12:06:51 +0000 | [diff] [blame] | 828 | llvm::SmallString<128> FwdDeclName; |
| 829 | llvm::raw_svector_ostream(FwdDeclName) << "fwd.type." << FwdDeclCount++; |
Devang Patel | 0ce73f6 | 2009-07-22 18:57:00 +0000 | [diff] [blame] | 830 | llvm::DICompositeType FwdDecl = |
Devang Patel | 7573f8b | 2010-03-09 21:32:27 +0000 | [diff] [blame] | 831 | DebugFactory.CreateCompositeType(Tag, FDContext, FwdDeclName, |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 832 | DefUnit, Line, 0, 0, 0, 0, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 833 | llvm::DIType(), llvm::DIArray()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 834 | |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 835 | llvm::MDNode *MN = FwdDecl; |
| 836 | llvm::TrackingVH<llvm::MDNode> FwdDeclNode = MN; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 837 | // Otherwise, insert it into the TypeCache so that recursive uses will find |
| 838 | // it. |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 839 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl; |
Devang Patel | e4c1ea0 | 2010-03-11 20:01:48 +0000 | [diff] [blame] | 840 | // Push the struct on region stack. |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 841 | RegionStack.push_back(FwdDeclNode); |
| 842 | RegionMap[Ty->getDecl()] = llvm::WeakVH(FwdDecl); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 843 | |
| 844 | // Convert all the elements. |
| 845 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
| 846 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 847 | const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD); |
Devang Patel | 3064afe | 2010-01-28 21:41:35 +0000 | [diff] [blame] | 848 | if (CXXDecl) { |
| 849 | CollectCXXBases(CXXDecl, Unit, EltTys, FwdDecl); |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 850 | CollectVTableInfo(CXXDecl, Unit, EltTys); |
Devang Patel | 3064afe | 2010-01-28 21:41:35 +0000 | [diff] [blame] | 851 | } |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 852 | CollectRecordFields(RD, Unit, EltTys); |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 853 | llvm::MDNode *ContainingType = NULL; |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 854 | if (CXXDecl) { |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 855 | CollectCXXMemberFunctions(CXXDecl, Unit, EltTys, FwdDecl); |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 856 | |
| 857 | // A class's primary base or the class itself contains the vtable. |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 858 | const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 859 | if (const CXXRecordDecl *PBase = RL.getPrimaryBase()) |
| 860 | ContainingType = |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 861 | getOrCreateType(QualType(PBase->getTypeForDecl(), 0), Unit); |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 862 | else if (CXXDecl->isDynamicClass()) |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 863 | ContainingType = FwdDecl; |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 864 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 865 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 866 | llvm::DIArray Elements = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 867 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 868 | |
| 869 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 870 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 871 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 872 | |
Devang Patel | e4c1ea0 | 2010-03-11 20:01:48 +0000 | [diff] [blame] | 873 | RegionStack.pop_back(); |
| 874 | llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator RI = |
| 875 | RegionMap.find(Ty->getDecl()); |
| 876 | if (RI != RegionMap.end()) |
| 877 | RegionMap.erase(RI); |
| 878 | |
Devang Patel | 411894b | 2010-02-01 22:40:08 +0000 | [diff] [blame] | 879 | llvm::DIDescriptor RDContext = |
| 880 | getContextDescriptor(dyn_cast<Decl>(RD->getDeclContext()), Unit); |
Devang Patel | 700a1cb | 2010-07-20 20:24:18 +0000 | [diff] [blame] | 881 | |
| 882 | llvm::StringRef RDName = RD->getName(); |
| 883 | // If this is a class, include the template arguments also. |
| 884 | if (Tag == llvm::dwarf::DW_TAG_class_type) |
| 885 | RDName = getClassName(RD); |
| 886 | |
Devang Patel | 0ce73f6 | 2009-07-22 18:57:00 +0000 | [diff] [blame] | 887 | llvm::DICompositeType RealDecl = |
Devang Patel | 411894b | 2010-02-01 22:40:08 +0000 | [diff] [blame] | 888 | DebugFactory.CreateCompositeType(Tag, RDContext, |
Devang Patel | 700a1cb | 2010-07-20 20:24:18 +0000 | [diff] [blame] | 889 | RDName, |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 890 | DefUnit, Line, Size, Align, 0, 0, |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 891 | llvm::DIType(), Elements, |
| 892 | 0, ContainingType); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 893 | |
| 894 | // Now that we have a real decl for the struct, replace anything using the |
| 895 | // old decl with the new one. This will recursively update the debug info. |
Eli Friedman | 14d6365 | 2009-11-16 21:04:30 +0000 | [diff] [blame] | 896 | llvm::DIDerivedType(FwdDeclNode).replaceAllUsesWith(RealDecl); |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 897 | RegionMap[RD] = llvm::WeakVH(RealDecl); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 898 | return RealDecl; |
| 899 | } |
| 900 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 901 | /// CreateType - get objective-c object type. |
| 902 | llvm::DIType CGDebugInfo::CreateType(const ObjCObjectType *Ty, |
| 903 | llvm::DIFile Unit) { |
| 904 | // Ignore protocols. |
| 905 | return getOrCreateType(Ty->getBaseType(), Unit); |
| 906 | } |
| 907 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 908 | /// CreateType - get objective-c interface type. |
| 909 | llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 910 | llvm::DIFile Unit) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 911 | ObjCInterfaceDecl *ID = Ty->getDecl(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 912 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 913 | |
| 914 | // Get overall information about the record type for the debug info. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 915 | llvm::DIFile DefUnit = getOrCreateFile(ID->getLocation()); |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 916 | unsigned Line = getLineNumber(ID->getLocation()); |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 917 | unsigned RuntimeLang = TheCU.getLanguage(); |
Chris Lattner | ac7c814 | 2009-05-02 01:13:16 +0000 | [diff] [blame] | 918 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 919 | // To handle recursive interface, we |
| 920 | // first generate a debug descriptor for the struct as a forward declaration. |
| 921 | // Then (if it is a definition) we go through and get debug info for all of |
| 922 | // its members. Finally, we create a descriptor for the complete type (which |
| 923 | // may refer to the forward decl if the struct is recursive) and replace all |
| 924 | // uses of the forward declaration with the final definition. |
Devang Patel | 6c1fddf | 2009-07-27 18:42:03 +0000 | [diff] [blame] | 925 | llvm::DICompositeType FwdDecl = |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 926 | DebugFactory.CreateCompositeType(Tag, Unit, ID->getName(), |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 927 | DefUnit, Line, 0, 0, 0, 0, |
Chris Lattner | ac7c814 | 2009-05-02 01:13:16 +0000 | [diff] [blame] | 928 | llvm::DIType(), llvm::DIArray(), |
| 929 | RuntimeLang); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 930 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 931 | // If this is just a forward declaration, return it. |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 932 | if (ID->isForwardDecl()) |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 933 | return FwdDecl; |
| 934 | |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 935 | llvm::MDNode *MN = FwdDecl; |
| 936 | llvm::TrackingVH<llvm::MDNode> FwdDeclNode = MN; |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 937 | // Otherwise, insert it into the TypeCache so that recursive uses will find |
| 938 | // it. |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 939 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl; |
Devang Patel | e4c1ea0 | 2010-03-11 20:01:48 +0000 | [diff] [blame] | 940 | // Push the struct on region stack. |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 941 | RegionStack.push_back(FwdDeclNode); |
| 942 | RegionMap[Ty->getDecl()] = llvm::WeakVH(FwdDecl); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 943 | |
| 944 | // Convert all the elements. |
| 945 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
| 946 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 947 | ObjCInterfaceDecl *SClass = ID->getSuperClass(); |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 948 | if (SClass) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 949 | llvm::DIType SClassTy = |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 950 | getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 951 | llvm::DIType InhTag = |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 952 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 953 | Unit, "", Unit, 0, 0, 0, |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 954 | 0 /* offset */, 0, SClassTy); |
| 955 | EltTys.push_back(InhTag); |
| 956 | } |
| 957 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 958 | const ASTRecordLayout &RL = CGM.getContext().getASTObjCInterfaceLayout(ID); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 959 | |
| 960 | unsigned FieldNo = 0; |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 961 | for (ObjCInterfaceDecl::ivar_iterator I = ID->ivar_begin(), |
| 962 | E = ID->ivar_end(); I != E; ++I, ++FieldNo) { |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 963 | ObjCIvarDecl *Field = *I; |
| 964 | llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); |
| 965 | |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 966 | llvm::StringRef FieldName = Field->getName(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 967 | |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 968 | // Ignore unnamed fields. |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 969 | if (FieldName.empty()) |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 970 | continue; |
| 971 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 972 | // Get the location for the field. |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 973 | llvm::DIFile FieldDefUnit = getOrCreateFile(Field->getLocation()); |
| 974 | unsigned FieldLine = getLineNumber(Field->getLocation()); |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 975 | QualType FType = Field->getType(); |
| 976 | uint64_t FieldSize = 0; |
| 977 | unsigned FieldAlign = 0; |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 978 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 979 | if (!FType->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 980 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 981 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 982 | FieldSize = CGM.getContext().getTypeSize(FType); |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 983 | Expr *BitWidth = Field->getBitWidth(); |
| 984 | if (BitWidth) |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 985 | FieldSize = BitWidth->EvaluateAsInt(CGM.getContext()).getZExtValue(); |
Eli Friedman | 9a901bb | 2009-04-26 19:19:15 +0000 | [diff] [blame] | 986 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 987 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 988 | } |
| 989 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | uint64_t FieldOffset = RL.getFieldOffset(FieldNo); |
| 991 | |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 992 | unsigned Flags = 0; |
| 993 | if (Field->getAccessControl() == ObjCIvarDecl::Protected) |
| 994 | Flags = llvm::DIType::FlagProtected; |
| 995 | else if (Field->getAccessControl() == ObjCIvarDecl::Private) |
| 996 | Flags = llvm::DIType::FlagPrivate; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 997 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 998 | // Create a DW_TAG_member node to remember the offset of this field in the |
| 999 | // struct. FIXME: This is an absolutely insane way to capture this |
| 1000 | // information. When we gut debug info, this should be fixed. |
| 1001 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1002 | FieldName, FieldDefUnit, |
| 1003 | FieldLine, FieldSize, FieldAlign, |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 1004 | FieldOffset, Flags, FieldTy); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1005 | EltTys.push_back(FieldTy); |
| 1006 | } |
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 | llvm::DIArray Elements = |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1009 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1010 | |
Devang Patel | e4c1ea0 | 2010-03-11 20:01:48 +0000 | [diff] [blame] | 1011 | RegionStack.pop_back(); |
| 1012 | llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator RI = |
| 1013 | RegionMap.find(Ty->getDecl()); |
| 1014 | if (RI != RegionMap.end()) |
| 1015 | RegionMap.erase(RI); |
| 1016 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1017 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1018 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 1019 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1020 | |
Devang Patel | 6c1fddf | 2009-07-27 18:42:03 +0000 | [diff] [blame] | 1021 | llvm::DICompositeType RealDecl = |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1022 | DebugFactory.CreateCompositeType(Tag, Unit, ID->getName(), DefUnit, |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 1023 | Line, Size, Align, 0, 0, llvm::DIType(), |
| 1024 | Elements, RuntimeLang); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1025 | |
| 1026 | // Now that we have a real decl for the struct, replace anything using the |
| 1027 | // old decl with the new one. This will recursively update the debug info. |
Devang Patel | ffffb03 | 2009-11-16 20:09:38 +0000 | [diff] [blame] | 1028 | llvm::DIDerivedType(FwdDeclNode).replaceAllUsesWith(RealDecl); |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 1029 | RegionMap[ID] = llvm::WeakVH(RealDecl); |
Devang Patel | fe09eab | 2009-07-13 17:03:14 +0000 | [diff] [blame] | 1030 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1031 | return RealDecl; |
| 1032 | } |
| 1033 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1034 | llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1035 | llvm::DIFile Unit) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1036 | EnumDecl *ED = Ty->getDecl(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1037 | |
| 1038 | llvm::SmallVector<llvm::DIDescriptor, 32> Enumerators; |
| 1039 | |
| 1040 | // Create DIEnumerator elements for each enumerator. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1041 | for (EnumDecl::enumerator_iterator |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1042 | Enum = ED->enumerator_begin(), EnumEnd = ED->enumerator_end(); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1043 | Enum != EnumEnd; ++Enum) { |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 1044 | Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getName(), |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1045 | Enum->getInitVal().getZExtValue())); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1046 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1047 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1048 | // Return a CompositeType for the enum itself. |
| 1049 | llvm::DIArray EltArray = |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1050 | DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1051 | |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1052 | llvm::DIFile DefUnit = getOrCreateFile(ED->getLocation()); |
| 1053 | unsigned Line = getLineNumber(ED->getLocation()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1054 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1055 | // Size and align of the type. |
Eli Friedman | 3189e4b | 2009-05-04 04:39:55 +0000 | [diff] [blame] | 1056 | uint64_t Size = 0; |
| 1057 | unsigned Align = 0; |
| 1058 | if (!Ty->isIncompleteType()) { |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1059 | Size = CGM.getContext().getTypeSize(Ty); |
| 1060 | Align = CGM.getContext().getTypeAlign(Ty); |
Eli Friedman | 3189e4b | 2009-05-04 04:39:55 +0000 | [diff] [blame] | 1061 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1062 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1063 | llvm::DIType DbgTy = |
| 1064 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type, |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1065 | Unit, ED->getName(), DefUnit, Line, |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1066 | Size, Align, 0, 0, |
| 1067 | llvm::DIType(), EltArray); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1068 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | llvm::DIType CGDebugInfo::CreateType(const TagType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1072 | llvm::DIFile Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1073 | if (const RecordType *RT = dyn_cast<RecordType>(Ty)) |
| 1074 | return CreateType(RT, Unit); |
| 1075 | else if (const EnumType *ET = dyn_cast<EnumType>(Ty)) |
| 1076 | return CreateType(ET, Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1077 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1078 | return llvm::DIType(); |
| 1079 | } |
| 1080 | |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1081 | llvm::DIType CGDebugInfo::CreateType(const VectorType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1082 | llvm::DIFile Unit) { |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1083 | llvm::DIType ElementTy = getOrCreateType(Ty->getElementType(), Unit); |
| 1084 | uint64_t NumElems = Ty->getNumElements(); |
| 1085 | if (NumElems > 0) |
| 1086 | --NumElems; |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1087 | |
Benjamin Kramer | ad46886 | 2010-03-30 11:36:44 +0000 | [diff] [blame] | 1088 | llvm::DIDescriptor Subscript = DebugFactory.GetOrCreateSubrange(0, NumElems); |
| 1089 | llvm::DIArray SubscriptArray = DebugFactory.GetOrCreateArray(&Subscript, 1); |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1090 | |
| 1091 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 1092 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
| 1093 | |
| 1094 | return |
| 1095 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_vector_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1096 | Unit, "", Unit, |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1097 | 0, Size, Align, 0, 0, |
| 1098 | ElementTy, SubscriptArray); |
| 1099 | } |
| 1100 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1101 | llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1102 | llvm::DIFile Unit) { |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1103 | uint64_t Size; |
| 1104 | uint64_t Align; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1105 | |
| 1106 | |
Nuno Lopes | 010d514 | 2009-01-28 00:35:17 +0000 | [diff] [blame] | 1107 | // FIXME: make getTypeAlign() aware of VLAs and incomplete array types |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1108 | if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(Ty)) { |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1109 | Size = 0; |
| 1110 | Align = |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1111 | CGM.getContext().getTypeAlign(CGM.getContext().getBaseElementType(VAT)); |
Nuno Lopes | 010d514 | 2009-01-28 00:35:17 +0000 | [diff] [blame] | 1112 | } else if (Ty->isIncompleteArrayType()) { |
| 1113 | Size = 0; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1114 | Align = CGM.getContext().getTypeAlign(Ty->getElementType()); |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1115 | } else { |
| 1116 | // Size and align of the whole array, not the element type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1117 | Size = CGM.getContext().getTypeSize(Ty); |
| 1118 | Align = CGM.getContext().getTypeAlign(Ty); |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1119 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1120 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1121 | // Add the dimensions of the array. FIXME: This loses CV qualifiers from |
| 1122 | // interior arrays, do we care? Why aren't nested arrays represented the |
| 1123 | // obvious/recursive way? |
| 1124 | llvm::SmallVector<llvm::DIDescriptor, 8> Subscripts; |
| 1125 | QualType EltTy(Ty, 0); |
| 1126 | while ((Ty = dyn_cast<ArrayType>(EltTy))) { |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 1127 | uint64_t Upper = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1128 | if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty)) |
Devang Patel | 5a6bfe3 | 2009-08-14 20:57:45 +0000 | [diff] [blame] | 1129 | if (CAT->getSize().getZExtValue()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1130 | Upper = CAT->getSize().getZExtValue() - 1; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1131 | // FIXME: Verify this is right for VLAs. |
| 1132 | Subscripts.push_back(DebugFactory.GetOrCreateSubrange(0, Upper)); |
| 1133 | EltTy = Ty->getElementType(); |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 1134 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1135 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1136 | llvm::DIArray SubscriptArray = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 1137 | DebugFactory.GetOrCreateArray(Subscripts.data(), Subscripts.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1138 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1139 | llvm::DIType DbgTy = |
| 1140 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_array_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1141 | Unit, "", Unit, |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1142 | 0, Size, Align, 0, 0, |
| 1143 | getOrCreateType(EltTy, Unit), |
| 1144 | SubscriptArray); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1145 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1146 | } |
| 1147 | |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 1148 | llvm::DIType CGDebugInfo::CreateType(const LValueReferenceType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1149 | llvm::DIFile Unit) { |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 1150 | return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, |
| 1151 | Ty, Ty->getPointeeType(), Unit); |
| 1152 | } |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1153 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1154 | llvm::DIType CGDebugInfo::CreateType(const MemberPointerType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1155 | llvm::DIFile U) { |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1156 | QualType PointerDiffTy = CGM.getContext().getPointerDiffType(); |
| 1157 | llvm::DIType PointerDiffDITy = getOrCreateType(PointerDiffTy, U); |
| 1158 | |
| 1159 | if (!Ty->getPointeeType()->isFunctionType()) { |
| 1160 | // We have a data member pointer type. |
| 1161 | return PointerDiffDITy; |
| 1162 | } |
| 1163 | |
| 1164 | // We have a member function pointer type. Treat it as a struct with two |
| 1165 | // ptrdiff_t members. |
| 1166 | std::pair<uint64_t, unsigned> Info = CGM.getContext().getTypeInfo(Ty); |
| 1167 | |
| 1168 | uint64_t FieldOffset = 0; |
| 1169 | llvm::DIDescriptor ElementTypes[2]; |
| 1170 | |
| 1171 | // FIXME: This should probably be a function type instead. |
| 1172 | ElementTypes[0] = |
| 1173 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, U, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1174 | "ptr", U, 0, |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1175 | Info.first, Info.second, FieldOffset, 0, |
| 1176 | PointerDiffDITy); |
| 1177 | FieldOffset += Info.first; |
| 1178 | |
| 1179 | ElementTypes[1] = |
| 1180 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, U, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1181 | "ptr", U, 0, |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1182 | Info.first, Info.second, FieldOffset, 0, |
| 1183 | PointerDiffDITy); |
| 1184 | |
| 1185 | llvm::DIArray Elements = |
| 1186 | DebugFactory.GetOrCreateArray(&ElementTypes[0], |
| 1187 | llvm::array_lengthof(ElementTypes)); |
| 1188 | |
| 1189 | return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_structure_type, |
| 1190 | U, llvm::StringRef("test"), |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1191 | U, 0, FieldOffset, |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1192 | 0, 0, 0, llvm::DIType(), Elements); |
| 1193 | } |
| 1194 | |
Douglas Gregor | 840943d | 2009-12-21 20:18:30 +0000 | [diff] [blame] | 1195 | static QualType UnwrapTypeForDebugInfo(QualType T) { |
| 1196 | do { |
| 1197 | QualType LastT = T; |
| 1198 | switch (T->getTypeClass()) { |
| 1199 | default: |
| 1200 | return T; |
| 1201 | case Type::TemplateSpecialization: |
| 1202 | T = cast<TemplateSpecializationType>(T)->desugar(); |
| 1203 | break; |
| 1204 | case Type::TypeOfExpr: { |
| 1205 | TypeOfExprType *Ty = cast<TypeOfExprType>(T); |
| 1206 | T = Ty->getUnderlyingExpr()->getType(); |
| 1207 | break; |
| 1208 | } |
| 1209 | case Type::TypeOf: |
| 1210 | T = cast<TypeOfType>(T)->getUnderlyingType(); |
| 1211 | break; |
| 1212 | case Type::Decltype: |
| 1213 | T = cast<DecltypeType>(T)->getUnderlyingType(); |
| 1214 | break; |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1215 | case Type::Elaborated: |
| 1216 | T = cast<ElaboratedType>(T)->getNamedType(); |
Douglas Gregor | 840943d | 2009-12-21 20:18:30 +0000 | [diff] [blame] | 1217 | break; |
| 1218 | case Type::SubstTemplateTypeParm: |
| 1219 | T = cast<SubstTemplateTypeParmType>(T)->getReplacementType(); |
| 1220 | break; |
Douglas Gregor | 840943d | 2009-12-21 20:18:30 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | assert(T != LastT && "Type unwrapping failed to unwrap!"); |
| 1224 | if (T == LastT) |
| 1225 | return T; |
| 1226 | } while (true); |
| 1227 | |
| 1228 | return T; |
Anders Carlsson | 5b6117a | 2009-11-14 21:08:12 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1231 | /// getOrCreateType - Get the type from the cache or create a new |
| 1232 | /// one if necessary. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1233 | llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1234 | llvm::DIFile Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1235 | if (Ty.isNull()) |
| 1236 | return llvm::DIType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1237 | |
Douglas Gregor | 840943d | 2009-12-21 20:18:30 +0000 | [diff] [blame] | 1238 | // Unwrap the type as needed for debug information. |
| 1239 | Ty = UnwrapTypeForDebugInfo(Ty); |
Anders Carlsson | 5b6117a | 2009-11-14 21:08:12 +0000 | [diff] [blame] | 1240 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 1241 | // Check for existing entry. |
Ted Kremenek | 590838b | 2010-03-29 18:29:57 +0000 | [diff] [blame] | 1242 | llvm::DenseMap<void *, llvm::WeakVH>::iterator it = |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 1243 | TypeCache.find(Ty.getAsOpaquePtr()); |
Daniel Dunbar | 65f13c3 | 2009-09-19 20:17:48 +0000 | [diff] [blame] | 1244 | if (it != TypeCache.end()) { |
| 1245 | // Verify that the debug info still exists. |
| 1246 | if (&*it->second) |
| 1247 | return llvm::DIType(cast<llvm::MDNode>(it->second)); |
| 1248 | } |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1249 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 1250 | // Otherwise create the type. |
| 1251 | llvm::DIType Res = CreateTypeNode(Ty, Unit); |
Anders Carlsson | 0dd57c6 | 2009-11-14 20:52:05 +0000 | [diff] [blame] | 1252 | |
| 1253 | // And update the type cache. |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 1254 | TypeCache[Ty.getAsOpaquePtr()] = Res; |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 1255 | return Res; |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
Anders Carlsson | 0dd57c6 | 2009-11-14 20:52:05 +0000 | [diff] [blame] | 1258 | /// CreateTypeNode - Create a new debug type node. |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1259 | llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1260 | llvm::DIFile Unit) { |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 1261 | // Handle qualifiers, which recursively handles what they refer to. |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 1262 | if (Ty.hasLocalQualifiers()) |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 1263 | return CreateQualifiedType(Ty, Unit); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1264 | |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1265 | const char *Diag = 0; |
| 1266 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1267 | // Work out details of type. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1268 | switch (Ty->getTypeClass()) { |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1269 | #define TYPE(Class, Base) |
| 1270 | #define ABSTRACT_TYPE(Class, Base) |
| 1271 | #define NON_CANONICAL_TYPE(Class, Base) |
| 1272 | #define DEPENDENT_TYPE(Class, Base) case Type::Class: |
| 1273 | #include "clang/AST/TypeNodes.def" |
| 1274 | assert(false && "Dependent types cannot show up in debug information"); |
Argyrios Kyrtzidis | 1bb8a45 | 2009-08-19 01:28:17 +0000 | [diff] [blame] | 1275 | |
Anders Carlsson | bfe6995 | 2009-11-06 18:24:04 +0000 | [diff] [blame] | 1276 | // FIXME: Handle these. |
| 1277 | case Type::ExtVector: |
Anders Carlsson | bfe6995 | 2009-11-06 18:24:04 +0000 | [diff] [blame] | 1278 | return llvm::DIType(); |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1279 | |
| 1280 | case Type::Vector: |
| 1281 | return CreateType(cast<VectorType>(Ty), Unit); |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 1282 | case Type::ObjCObjectPointer: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1283 | return CreateType(cast<ObjCObjectPointerType>(Ty), Unit); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1284 | case Type::ObjCObject: |
| 1285 | return CreateType(cast<ObjCObjectType>(Ty), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1286 | case Type::ObjCInterface: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1287 | return CreateType(cast<ObjCInterfaceType>(Ty), Unit); |
| 1288 | case Type::Builtin: return CreateType(cast<BuiltinType>(Ty), Unit); |
| 1289 | case Type::Complex: return CreateType(cast<ComplexType>(Ty), Unit); |
| 1290 | case Type::Pointer: return CreateType(cast<PointerType>(Ty), Unit); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 1291 | case Type::BlockPointer: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1292 | return CreateType(cast<BlockPointerType>(Ty), Unit); |
| 1293 | case Type::Typedef: return CreateType(cast<TypedefType>(Ty), Unit); |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1294 | case Type::Record: |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1295 | case Type::Enum: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1296 | return CreateType(cast<TagType>(Ty), Unit); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1297 | case Type::FunctionProto: |
| 1298 | case Type::FunctionNoProto: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1299 | return CreateType(cast<FunctionType>(Ty), Unit); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1300 | case Type::ConstantArray: |
| 1301 | case Type::VariableArray: |
| 1302 | case Type::IncompleteArray: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1303 | return CreateType(cast<ArrayType>(Ty), Unit); |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 1304 | |
| 1305 | case Type::LValueReference: |
| 1306 | return CreateType(cast<LValueReferenceType>(Ty), Unit); |
| 1307 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1308 | case Type::MemberPointer: |
| 1309 | return CreateType(cast<MemberPointerType>(Ty), Unit); |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1310 | |
| 1311 | case Type::TemplateSpecialization: |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1312 | case Type::Elaborated: |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1313 | case Type::SubstTemplateTypeParm: |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1314 | case Type::TypeOfExpr: |
| 1315 | case Type::TypeOf: |
Douglas Gregor | 840943d | 2009-12-21 20:18:30 +0000 | [diff] [blame] | 1316 | case Type::Decltype: |
| 1317 | llvm_unreachable("type should have been unwrapped!"); |
| 1318 | return llvm::DIType(); |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1319 | |
| 1320 | case Type::RValueReference: |
| 1321 | // FIXME: Implement! |
| 1322 | Diag = "rvalue references"; |
| 1323 | break; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1324 | } |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1325 | |
| 1326 | assert(Diag && "Fall through without a diagnostic?"); |
| 1327 | unsigned DiagID = CGM.getDiags().getCustomDiagID(Diagnostic::Error, |
| 1328 | "debug information for %0 is not yet supported"); |
| 1329 | CGM.getDiags().Report(FullSourceLoc(), DiagID) |
| 1330 | << Diag; |
| 1331 | return llvm::DIType(); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1334 | /// CreateMemberType - Create new member and increase Offset by FType's size. |
| 1335 | llvm::DIType CGDebugInfo::CreateMemberType(llvm::DIFile Unit, QualType FType, |
| 1336 | llvm::StringRef Name, |
| 1337 | uint64_t *Offset) { |
| 1338 | llvm::DIType FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1339 | uint64_t FieldSize = CGM.getContext().getTypeSize(FType); |
| 1340 | unsigned FieldAlign = CGM.getContext().getTypeAlign(FType); |
| 1341 | llvm::DIType Ty = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, |
| 1342 | Unit, Name, Unit, 0, |
| 1343 | FieldSize, FieldAlign, |
| 1344 | *Offset, 0, FieldTy); |
| 1345 | *Offset += FieldSize; |
| 1346 | return Ty; |
| 1347 | } |
| 1348 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1349 | /// EmitFunctionStart - Constructs the debug code for entering a function - |
| 1350 | /// "llvm.dbg.func.start.". |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1351 | void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1352 | llvm::Function *Fn, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1353 | CGBuilderTy &Builder) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1354 | |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1355 | llvm::StringRef Name; |
Anders Carlsson | 9a20d55 | 2010-06-22 16:16:50 +0000 | [diff] [blame] | 1356 | llvm::StringRef LinkageName; |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1357 | |
| 1358 | const Decl *D = GD.getDecl(); |
| 1359 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 1360 | // If there is a DISubprogram for this function available then use it. |
| 1361 | llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator |
| 1362 | FI = SPCache.find(FD); |
| 1363 | if (FI != SPCache.end()) { |
Devang Patel | 0804e6e | 2010-03-08 20:53:17 +0000 | [diff] [blame] | 1364 | llvm::DIDescriptor SP(dyn_cast_or_null<llvm::MDNode>(FI->second)); |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 1365 | if (SP.isSubprogram() && llvm::DISubprogram(SP).isDefinition()) { |
| 1366 | llvm::MDNode *SPN = SP; |
| 1367 | RegionStack.push_back(SPN); |
| 1368 | RegionMap[D] = llvm::WeakVH(SP); |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 1369 | return; |
| 1370 | } |
| 1371 | } |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1372 | Name = getFunctionName(FD); |
| 1373 | // Use mangled name as linkage name for c/c++ functions. |
Anders Carlsson | 9a20d55 | 2010-06-22 16:16:50 +0000 | [diff] [blame] | 1374 | LinkageName = CGM.getMangledName(GD); |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1375 | } else { |
| 1376 | // Use llvm function name as linkage name. |
| 1377 | Name = Fn->getName(); |
Anders Carlsson | 9a20d55 | 2010-06-22 16:16:50 +0000 | [diff] [blame] | 1378 | LinkageName = Name; |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1379 | } |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1380 | if (!Name.empty() && Name[0] == '\01') |
| 1381 | Name = Name.substr(1); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1382 | |
Devang Patel | 970c618 | 2010-04-24 00:49:16 +0000 | [diff] [blame] | 1383 | // It is expected that CurLoc is set before using EmitFunctionStart. |
| 1384 | // Usually, CurLoc points to the left bracket location of compound |
| 1385 | // statement representing function body. |
| 1386 | llvm::DIFile Unit = getOrCreateFile(CurLoc); |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1387 | unsigned LineNo = getLineNumber(CurLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1388 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1389 | llvm::DISubprogram SP = |
Devang Patel | 970c618 | 2010-04-24 00:49:16 +0000 | [diff] [blame] | 1390 | DebugFactory.CreateSubprogram(Unit, Name, Name, LinkageName, Unit, LineNo, |
Mike Stump | 91cc815 | 2009-10-23 01:52:13 +0000 | [diff] [blame] | 1391 | getOrCreateType(FnType, Unit), |
Devang Patel | 15a3d7d | 2010-07-15 23:09:46 +0000 | [diff] [blame] | 1392 | Fn->hasInternalLinkage(), true/*definition*/, |
| 1393 | 0, 0, llvm::DIType(), |
| 1394 | D->isImplicit(), |
| 1395 | CGM.getLangOptions().Optimize, Fn); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1396 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1397 | // Push function on region stack. |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 1398 | llvm::MDNode *SPN = SP; |
| 1399 | RegionStack.push_back(SPN); |
| 1400 | RegionMap[D] = llvm::WeakVH(SP); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | |
Devang Patel | 4d939e6 | 2010-07-20 22:20:10 +0000 | [diff] [blame^] | 1404 | void CGDebugInfo::EmitStopPoint(CGBuilderTy &Builder) { |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1405 | if (CurLoc.isInvalid() || CurLoc.isMacroID()) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1406 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1407 | // Don't bother if things are the same as last time. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1408 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1409 | if (CurLoc == PrevLoc |
Chris Lattner | 30fc933 | 2009-02-04 01:06:56 +0000 | [diff] [blame] | 1410 | || (SM.getInstantiationLineNumber(CurLoc) == |
| 1411 | SM.getInstantiationLineNumber(PrevLoc) |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1412 | && SM.isFromSameFile(CurLoc, PrevLoc))) |
Devang Patel | 4800ea6 | 2010-04-05 21:09:15 +0000 | [diff] [blame] | 1413 | // New Builder may not be in sync with CGDebugInfo. |
| 1414 | if (!Builder.getCurrentDebugLocation().isUnknown()) |
| 1415 | return; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1416 | |
| 1417 | // Update last state. |
| 1418 | PrevLoc = CurLoc; |
| 1419 | |
Chris Lattner | c603463 | 2010-04-01 06:31:43 +0000 | [diff] [blame] | 1420 | llvm::MDNode *Scope = RegionStack.back(); |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1421 | Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(getLineNumber(CurLoc), |
| 1422 | getColumnNumber(CurLoc), |
Chris Lattner | e541d01 | 2010-04-02 20:21:43 +0000 | [diff] [blame] | 1423 | Scope)); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | /// EmitRegionStart- Constructs the debug code for entering a declarative |
| 1427 | /// region - "llvm.dbg.region.start.". |
Devang Patel | 4d939e6 | 2010-07-20 22:20:10 +0000 | [diff] [blame^] | 1428 | void CGDebugInfo::EmitRegionStart(CGBuilderTy &Builder) { |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1429 | llvm::DIDescriptor D = |
| 1430 | DebugFactory.CreateLexicalBlock(RegionStack.empty() ? |
| 1431 | llvm::DIDescriptor() : |
Devang Patel | d19429f | 2010-02-16 21:41:20 +0000 | [diff] [blame] | 1432 | llvm::DIDescriptor(RegionStack.back()), |
Stuart Hastings | 257d1d3 | 2010-07-19 23:56:31 +0000 | [diff] [blame] | 1433 | getOrCreateFile(CurLoc), |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1434 | getLineNumber(CurLoc), |
| 1435 | getColumnNumber(CurLoc)); |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 1436 | llvm::MDNode *DN = D; |
| 1437 | RegionStack.push_back(DN); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | /// EmitRegionEnd - Constructs the debug code for exiting a declarative |
| 1441 | /// region - "llvm.dbg.region.end." |
Devang Patel | 4d939e6 | 2010-07-20 22:20:10 +0000 | [diff] [blame^] | 1442 | void CGDebugInfo::EmitRegionEnd(CGBuilderTy &Builder) { |
Daniel Dunbar | 5273f51 | 2008-10-17 01:07:56 +0000 | [diff] [blame] | 1443 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1444 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1445 | // Provide an region stop point. |
Devang Patel | 4d939e6 | 2010-07-20 22:20:10 +0000 | [diff] [blame^] | 1446 | EmitStopPoint(Builder); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1447 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1448 | RegionStack.pop_back(); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1451 | // EmitTypeForVarWithBlocksAttr - Build up structure info for the byref. |
| 1452 | // See BuildByRefType. |
| 1453 | llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, |
| 1454 | uint64_t *XOffset) { |
| 1455 | |
| 1456 | llvm::SmallVector<llvm::DIDescriptor, 5> EltTys; |
| 1457 | |
| 1458 | QualType FType; |
| 1459 | uint64_t FieldSize, FieldOffset; |
| 1460 | unsigned FieldAlign; |
| 1461 | |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1462 | llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1463 | QualType Type = VD->getType(); |
| 1464 | |
| 1465 | FieldOffset = 0; |
| 1466 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1467 | EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset)); |
| 1468 | EltTys.push_back(CreateMemberType(Unit, FType, "__forwarding", &FieldOffset)); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1469 | FType = CGM.getContext().IntTy; |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1470 | EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset)); |
| 1471 | EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset)); |
| 1472 | |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1473 | bool HasCopyAndDispose = CGM.BlockRequiresCopying(Type); |
| 1474 | if (HasCopyAndDispose) { |
| 1475 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1476 | EltTys.push_back(CreateMemberType(Unit, FType, "__copy_helper", |
| 1477 | &FieldOffset)); |
| 1478 | EltTys.push_back(CreateMemberType(Unit, FType, "__destroy_helper", |
| 1479 | &FieldOffset)); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | CharUnits Align = CGM.getContext().getDeclAlign(VD); |
| 1483 | if (Align > CharUnits::fromQuantity( |
| 1484 | CGM.getContext().Target.getPointerAlign(0) / 8)) { |
| 1485 | unsigned AlignedOffsetInBytes |
| 1486 | = llvm::RoundUpToAlignment(FieldOffset/8, Align.getQuantity()); |
| 1487 | unsigned NumPaddingBytes |
| 1488 | = AlignedOffsetInBytes - FieldOffset/8; |
| 1489 | |
| 1490 | if (NumPaddingBytes > 0) { |
| 1491 | llvm::APInt pad(32, NumPaddingBytes); |
| 1492 | FType = CGM.getContext().getConstantArrayType(CGM.getContext().CharTy, |
| 1493 | pad, ArrayType::Normal, 0); |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1494 | EltTys.push_back(CreateMemberType(Unit, FType, "", &FieldOffset)); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | FType = Type; |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1499 | llvm::DIType FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1500 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1501 | FieldAlign = Align.getQuantity()*8; |
| 1502 | |
| 1503 | *XOffset = FieldOffset; |
| 1504 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1505 | VD->getName(), Unit, |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1506 | 0, FieldSize, FieldAlign, |
| 1507 | FieldOffset, 0, FieldTy); |
| 1508 | EltTys.push_back(FieldTy); |
| 1509 | FieldOffset += FieldSize; |
| 1510 | |
| 1511 | llvm::DIArray Elements = |
| 1512 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
| 1513 | |
| 1514 | unsigned Flags = llvm::DIType::FlagBlockByrefStruct; |
| 1515 | |
| 1516 | return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_structure_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1517 | Unit, "", Unit, |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1518 | 0, FieldOffset, 0, 0, Flags, |
| 1519 | llvm::DIType(), Elements); |
| 1520 | |
| 1521 | } |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 1522 | /// EmitDeclare - Emit local variable declaration debug info. |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 1523 | void CGDebugInfo::EmitDeclare(const VarDecl *VD, unsigned Tag, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1524 | llvm::Value *Storage, CGBuilderTy &Builder) { |
Daniel Dunbar | 5273f51 | 2008-10-17 01:07:56 +0000 | [diff] [blame] | 1525 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1526 | |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1527 | llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1528 | llvm::DIType Ty; |
| 1529 | uint64_t XOffset = 0; |
| 1530 | if (VD->hasAttr<BlocksAttr>()) |
| 1531 | Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset); |
| 1532 | else |
| 1533 | Ty = getOrCreateType(VD->getType(), Unit); |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1534 | |
Devang Patel | f4e54a2 | 2010-05-07 23:05:55 +0000 | [diff] [blame] | 1535 | // If there is not any debug info for type then do not emit debug info |
| 1536 | // for this variable. |
| 1537 | if (!Ty) |
| 1538 | return; |
| 1539 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1540 | // Get location information. |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1541 | unsigned Line = getLineNumber(VD->getLocation()); |
| 1542 | unsigned Column = getColumnNumber(VD->getLocation()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1543 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1544 | // Create the descriptor for the variable. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1545 | llvm::DIVariable D = |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1546 | DebugFactory.CreateVariable(Tag, llvm::DIDescriptor(RegionStack.back()), |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 1547 | VD->getName(), |
Devang Patel | 44eeeba | 2010-06-05 01:14:40 +0000 | [diff] [blame] | 1548 | Unit, Line, Ty, CGM.getLangOptions().Optimize); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1549 | // Insert an llvm.dbg.declare into the current block. |
Devang Patel | ebf16e8 | 2009-11-11 19:10:19 +0000 | [diff] [blame] | 1550 | llvm::Instruction *Call = |
Devang Patel | a020380 | 2009-11-10 23:07:24 +0000 | [diff] [blame] | 1551 | DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1552 | |
Chris Lattner | c603463 | 2010-04-01 06:31:43 +0000 | [diff] [blame] | 1553 | llvm::MDNode *Scope = RegionStack.back(); |
Chris Lattner | e541d01 | 2010-04-02 20:21:43 +0000 | [diff] [blame] | 1554 | Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope)); |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1557 | /// EmitDeclare - Emit local variable declaration debug info. |
| 1558 | void CGDebugInfo::EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, |
| 1559 | llvm::Value *Storage, CGBuilderTy &Builder, |
| 1560 | CodeGenFunction *CGF) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1561 | const ValueDecl *VD = BDRE->getDecl(); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1562 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1563 | |
Devang Patel | 2b594b9 | 2010-04-26 23:28:46 +0000 | [diff] [blame] | 1564 | if (Builder.GetInsertBlock() == 0) |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1565 | return; |
| 1566 | |
| 1567 | uint64_t XOffset = 0; |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1568 | llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1569 | llvm::DIType Ty; |
| 1570 | if (VD->hasAttr<BlocksAttr>()) |
| 1571 | Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset); |
| 1572 | else |
| 1573 | Ty = getOrCreateType(VD->getType(), Unit); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1574 | |
| 1575 | // Get location information. |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1576 | unsigned Line = getLineNumber(VD->getLocation()); |
| 1577 | unsigned Column = getColumnNumber(VD->getLocation()); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1578 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1579 | CharUnits offset = CGF->BlockDecls[VD]; |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1580 | llvm::SmallVector<llvm::Value *, 9> addr; |
Chris Lattner | 14b1a36 | 2010-01-25 03:29:35 +0000 | [diff] [blame] | 1581 | const llvm::Type *Int64Ty = llvm::Type::getInt64Ty(CGM.getLLVMContext()); |
| 1582 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpDeref)); |
| 1583 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpPlus)); |
| 1584 | addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity())); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1585 | if (BDRE->isByRef()) { |
Chris Lattner | 14b1a36 | 2010-01-25 03:29:35 +0000 | [diff] [blame] | 1586 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpDeref)); |
| 1587 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpPlus)); |
Ken Dyck | 199c3d6 | 2010-01-11 17:06:35 +0000 | [diff] [blame] | 1588 | // offset of __forwarding field |
| 1589 | offset = CharUnits::fromQuantity(CGF->LLVMPointerWidth/8); |
Chris Lattner | 14b1a36 | 2010-01-25 03:29:35 +0000 | [diff] [blame] | 1590 | addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity())); |
| 1591 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpDeref)); |
| 1592 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpPlus)); |
Ken Dyck | 199c3d6 | 2010-01-11 17:06:35 +0000 | [diff] [blame] | 1593 | // offset of x field |
| 1594 | offset = CharUnits::fromQuantity(XOffset/8); |
Chris Lattner | 14b1a36 | 2010-01-25 03:29:35 +0000 | [diff] [blame] | 1595 | addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity())); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | // Create the descriptor for the variable. |
| 1599 | llvm::DIVariable D = |
Chris Lattner | 165714e | 2010-01-25 03:34:56 +0000 | [diff] [blame] | 1600 | DebugFactory.CreateComplexVariable(Tag, |
| 1601 | llvm::DIDescriptor(RegionStack.back()), |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1602 | VD->getName(), Unit, Line, Ty, |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1603 | addr); |
| 1604 | // Insert an llvm.dbg.declare into the current block. |
Devang Patel | ebf16e8 | 2009-11-11 19:10:19 +0000 | [diff] [blame] | 1605 | llvm::Instruction *Call = |
Chris Lattner | 165714e | 2010-01-25 03:34:56 +0000 | [diff] [blame] | 1606 | DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock()); |
Chris Lattner | d5b8902 | 2009-12-28 21:44:41 +0000 | [diff] [blame] | 1607 | |
Chris Lattner | c603463 | 2010-04-01 06:31:43 +0000 | [diff] [blame] | 1608 | llvm::MDNode *Scope = RegionStack.back(); |
Devang Patel | f8e10a5 | 2010-05-10 23:48:38 +0000 | [diff] [blame] | 1609 | Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope)); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1610 | } |
| 1611 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1612 | void CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *VD, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1613 | llvm::Value *Storage, |
| 1614 | CGBuilderTy &Builder) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1615 | EmitDeclare(VD, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1618 | void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable( |
| 1619 | const BlockDeclRefExpr *BDRE, llvm::Value *Storage, CGBuilderTy &Builder, |
| 1620 | CodeGenFunction *CGF) { |
| 1621 | EmitDeclare(BDRE, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder, CGF); |
| 1622 | } |
| 1623 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1624 | /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument |
| 1625 | /// variable declaration. |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1626 | void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *VD, llvm::Value *AI, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1627 | CGBuilderTy &Builder) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1628 | EmitDeclare(VD, llvm::dwarf::DW_TAG_arg_variable, AI, Builder); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1629 | } |
| 1630 | |
| 1631 | |
| 1632 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1633 | /// EmitGlobalVariable - Emit information about a global variable. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1634 | void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 1635 | const VarDecl *D) { |
| 1636 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1637 | // Create global variable debug descriptor. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1638 | llvm::DIFile Unit = getOrCreateFile(D->getLocation()); |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1639 | unsigned LineNo = getLineNumber(D->getLocation()); |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 1640 | |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 1641 | QualType T = D->getType(); |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1642 | if (T->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1643 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1644 | // CodeGen turns int[] into int[1] so we'll do the same here. |
| 1645 | llvm::APSInt ConstVal(32); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1646 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1647 | ConstVal = 1; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1648 | QualType ET = CGM.getContext().getAsArrayType(T)->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1649 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1650 | T = CGM.getContext().getConstantArrayType(ET, ConstVal, |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1651 | ArrayType::Normal, 0); |
| 1652 | } |
Devang Patel | 5d822f0 | 2010-04-29 17:48:37 +0000 | [diff] [blame] | 1653 | llvm::StringRef DeclName = D->getName(); |
Devang Patel | 8b90a78 | 2010-05-13 23:52:37 +0000 | [diff] [blame] | 1654 | llvm::StringRef LinkageName; |
Devang Patel | 0fd3d1f | 2010-05-14 16:55:25 +0000 | [diff] [blame] | 1655 | if (D->getDeclContext() && !isa<FunctionDecl>(D->getDeclContext())) |
Devang Patel | 8b90a78 | 2010-05-13 23:52:37 +0000 | [diff] [blame] | 1656 | LinkageName = Var->getName(); |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 1657 | llvm::DIDescriptor DContext = |
| 1658 | getContextDescriptor(dyn_cast<Decl>(D->getDeclContext()), Unit); |
Devang Patel | 8b90a78 | 2010-05-13 23:52:37 +0000 | [diff] [blame] | 1659 | DebugFactory.CreateGlobalVariable(DContext, DeclName, DeclName, LinkageName, |
| 1660 | Unit, LineNo, getOrCreateType(T, Unit), |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1661 | Var->hasInternalLinkage(), |
| 1662 | true/*definition*/, Var); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1665 | /// EmitGlobalVariable - Emit information about an objective-c interface. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1666 | void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1667 | ObjCInterfaceDecl *ID) { |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1668 | // Create global variable debug descriptor. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1669 | llvm::DIFile Unit = getOrCreateFile(ID->getLocation()); |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1670 | unsigned LineNo = getLineNumber(ID->getLocation()); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1671 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1672 | llvm::StringRef Name = ID->getName(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1673 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1674 | QualType T = CGM.getContext().getObjCInterfaceType(ID); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1675 | if (T->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1676 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1677 | // CodeGen turns int[] into int[1] so we'll do the same here. |
| 1678 | llvm::APSInt ConstVal(32); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1679 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1680 | ConstVal = 1; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1681 | QualType ET = CGM.getContext().getAsArrayType(T)->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1683 | T = CGM.getContext().getConstantArrayType(ET, ConstVal, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1684 | ArrayType::Normal, 0); |
| 1685 | } |
| 1686 | |
Devang Patel | f6a39b7 | 2009-10-20 18:26:30 +0000 | [diff] [blame] | 1687 | DebugFactory.CreateGlobalVariable(Unit, Name, Name, Name, Unit, LineNo, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1688 | getOrCreateType(T, Unit), |
| 1689 | Var->hasInternalLinkage(), |
| 1690 | true/*definition*/, Var); |
| 1691 | } |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame] | 1692 | |
| 1693 | /// getOrCreateNamesSpace - Return namespace descriptor for the given |
| 1694 | /// namespace decl. |
| 1695 | llvm::DINameSpace |
| 1696 | CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl, |
| 1697 | llvm::DIDescriptor Unit) { |
| 1698 | llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH>::iterator I = |
| 1699 | NameSpaceCache.find(NSDecl); |
| 1700 | if (I != NameSpaceCache.end()) |
| 1701 | return llvm::DINameSpace(cast<llvm::MDNode>(I->second)); |
| 1702 | |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1703 | unsigned LineNo = getLineNumber(NSDecl->getLocation()); |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame] | 1704 | |
| 1705 | llvm::DIDescriptor Context = |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 1706 | getContextDescriptor(dyn_cast<Decl>(NSDecl->getDeclContext()), Unit); |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame] | 1707 | llvm::DINameSpace NS = |
| 1708 | DebugFactory.CreateNameSpace(Context, NSDecl->getName(), |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 1709 | llvm::DIFile(Unit), LineNo); |
| 1710 | NameSpaceCache[NSDecl] = llvm::WeakVH(NS); |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame] | 1711 | return NS; |
| 1712 | } |