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