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()), |
Dan Gohman | 4cac5b4 | 2010-08-20 22:02:57 +0000 | [diff] [blame] | 41 | 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); |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 556 | llvm::StringRef FieldName = Field->getName(); |
| 557 | |
Devang Patel | 4835fdd | 2010-02-12 01:31:06 +0000 | [diff] [blame] | 558 | // Ignore unnamed fields. Do not ignore unnamed records. |
| 559 | if (FieldName.empty() && !isa<RecordType>(Field->getType())) |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 560 | continue; |
| 561 | |
| 562 | // Get the location for the field. |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 563 | llvm::DIFile FieldDefUnit = getOrCreateFile(Field->getLocation()); |
| 564 | unsigned FieldLine = getLineNumber(Field->getLocation()); |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 565 | QualType FType = Field->getType(); |
| 566 | uint64_t FieldSize = 0; |
| 567 | unsigned FieldAlign = 0; |
| 568 | if (!FType->isIncompleteArrayType()) { |
| 569 | |
| 570 | // Bit size, align and offset of the type. |
| 571 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 572 | Expr *BitWidth = Field->getBitWidth(); |
| 573 | if (BitWidth) |
| 574 | FieldSize = BitWidth->EvaluateAsInt(CGM.getContext()).getZExtValue(); |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 575 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
| 576 | } |
| 577 | |
| 578 | uint64_t FieldOffset = RL.getFieldOffset(FieldNo); |
| 579 | |
Devang Patel | 71f4ff6 | 2010-04-21 23:12:37 +0000 | [diff] [blame] | 580 | unsigned Flags = 0; |
| 581 | AccessSpecifier Access = I->getAccess(); |
| 582 | if (Access == clang::AS_private) |
| 583 | Flags |= llvm::DIType::FlagPrivate; |
| 584 | else if (Access == clang::AS_protected) |
| 585 | Flags |= llvm::DIType::FlagProtected; |
| 586 | |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 587 | // Create a DW_TAG_member node to remember the offset of this field in the |
| 588 | // struct. FIXME: This is an absolutely insane way to capture this |
| 589 | // information. When we gut debug info, this should be fixed. |
| 590 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 591 | FieldName, FieldDefUnit, |
| 592 | FieldLine, FieldSize, FieldAlign, |
Devang Patel | 71f4ff6 | 2010-04-21 23:12:37 +0000 | [diff] [blame] | 593 | FieldOffset, Flags, FieldTy); |
Devang Patel | 428deb5 | 2010-01-19 00:00:59 +0000 | [diff] [blame] | 594 | EltTys.push_back(FieldTy); |
| 595 | } |
| 596 | } |
| 597 | |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 598 | /// getOrCreateMethodType - CXXMethodDecl's type is a FunctionType. This |
| 599 | /// function type is not updated to include implicit "this" pointer. Use this |
| 600 | /// routine to get a method type which includes "this" pointer. |
| 601 | llvm::DIType |
| 602 | CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 603 | llvm::DIFile Unit) { |
Douglas Gregor | 5f970ee | 2010-05-04 18:18:31 +0000 | [diff] [blame] | 604 | llvm::DIType FnTy |
| 605 | = getOrCreateType(QualType(Method->getType()->getAs<FunctionProtoType>(), |
| 606 | 0), |
| 607 | Unit); |
Devang Patel | d774d1e | 2010-01-28 21:43:50 +0000 | [diff] [blame] | 608 | |
| 609 | // Static methods do not need "this" pointer argument. |
| 610 | if (Method->isStatic()) |
| 611 | return FnTy; |
| 612 | |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 613 | // Add "this" pointer. |
| 614 | |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 615 | llvm::DIArray Args = llvm::DICompositeType(FnTy).getTypeArray(); |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 616 | assert (Args.getNumElements() && "Invalid number of arguments!"); |
| 617 | |
| 618 | llvm::SmallVector<llvm::DIDescriptor, 16> Elts; |
| 619 | |
| 620 | // First element is always return type. For 'void' functions it is NULL. |
| 621 | Elts.push_back(Args.getElement(0)); |
| 622 | |
| 623 | // "this" pointer is always first argument. |
| 624 | ASTContext &Context = CGM.getContext(); |
| 625 | QualType ThisPtr = |
| 626 | Context.getPointerType(Context.getTagDeclType(Method->getParent())); |
Devang Patel | 337472d | 2010-02-09 17:57:50 +0000 | [diff] [blame] | 627 | llvm::DIType ThisPtrType = |
| 628 | DebugFactory.CreateArtificialType(getOrCreateType(ThisPtr, Unit)); |
Devang Patel | 769640e | 2010-07-13 00:24:30 +0000 | [diff] [blame] | 629 | |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 630 | TypeCache[ThisPtr.getAsOpaquePtr()] = ThisPtrType; |
Devang Patel | 337472d | 2010-02-09 17:57:50 +0000 | [diff] [blame] | 631 | Elts.push_back(ThisPtrType); |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 632 | |
| 633 | // Copy rest of the arguments. |
| 634 | for (unsigned i = 1, e = Args.getNumElements(); i != e; ++i) |
| 635 | Elts.push_back(Args.getElement(i)); |
| 636 | |
| 637 | llvm::DIArray EltTypeArray = |
| 638 | DebugFactory.GetOrCreateArray(Elts.data(), Elts.size()); |
| 639 | |
| 640 | return |
| 641 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 642 | Unit, "", Unit, |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 643 | 0, 0, 0, 0, 0, |
| 644 | llvm::DIType(), EltTypeArray); |
| 645 | } |
| 646 | |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 647 | /// CreateCXXMemberFunction - A helper function to create a DISubprogram for |
| 648 | /// a single member function GlobalDecl. |
| 649 | llvm::DISubprogram |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 650 | CGDebugInfo::CreateCXXMemberFunction(const CXXMethodDecl *Method, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 651 | llvm::DIFile Unit, |
Dan Gohman | 4cac5b4 | 2010-08-20 22:02:57 +0000 | [diff] [blame] | 652 | llvm::DIType RecordTy) { |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 653 | bool IsCtorOrDtor = |
| 654 | isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method); |
| 655 | |
| 656 | llvm::StringRef MethodName = getFunctionName(Method); |
Devang Patel | a6da192 | 2010-01-28 00:28:01 +0000 | [diff] [blame] | 657 | llvm::DIType MethodTy = getOrCreateMethodType(Method, Unit); |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 658 | |
| 659 | // Since a single ctor/dtor corresponds to multiple functions, it doesn't |
| 660 | // make sense to give a single ctor/dtor a linkage name. |
Anders Carlsson | 9a20d55 | 2010-06-22 16:16:50 +0000 | [diff] [blame] | 661 | llvm::StringRef MethodLinkageName; |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 662 | if (!IsCtorOrDtor) |
Anders Carlsson | 9a20d55 | 2010-06-22 16:16:50 +0000 | [diff] [blame] | 663 | MethodLinkageName = CGM.getMangledName(Method); |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 664 | |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 665 | // Get the location for the method. |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 666 | llvm::DIFile MethodDefUnit = getOrCreateFile(Method->getLocation()); |
| 667 | unsigned MethodLine = getLineNumber(Method->getLocation()); |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 668 | |
| 669 | // Collect virtual method info. |
| 670 | llvm::DIType ContainingType; |
| 671 | unsigned Virtuality = 0; |
| 672 | unsigned VIndex = 0; |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 673 | |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 674 | if (Method->isVirtual()) { |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 675 | if (Method->isPure()) |
| 676 | Virtuality = llvm::dwarf::DW_VIRTUALITY_pure_virtual; |
| 677 | else |
| 678 | Virtuality = llvm::dwarf::DW_VIRTUALITY_virtual; |
| 679 | |
| 680 | // It doesn't make sense to give a virtual destructor a vtable index, |
| 681 | // since a single destructor has two entries in the vtable. |
| 682 | if (!isa<CXXDestructorDecl>(Method)) |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 683 | VIndex = CGM.getVTables().getMethodVTableIndex(Method); |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 684 | ContainingType = RecordTy; |
| 685 | } |
| 686 | |
| 687 | llvm::DISubprogram SP = |
| 688 | DebugFactory.CreateSubprogram(RecordTy , MethodName, MethodName, |
| 689 | MethodLinkageName, |
| 690 | MethodDefUnit, MethodLine, |
| 691 | MethodTy, /*isLocalToUnit=*/false, |
Devang Patel | a5c5bab | 2010-07-12 22:54:41 +0000 | [diff] [blame] | 692 | /* isDefintion=*/ false, |
Devang Patel | 4089491 | 2010-07-15 22:57:00 +0000 | [diff] [blame] | 693 | Virtuality, VIndex, ContainingType, |
Devang Patel | 15a3d7d | 2010-07-15 23:09:46 +0000 | [diff] [blame] | 694 | Method->isImplicit(), |
| 695 | CGM.getLangOptions().Optimize); |
Anders Carlsson | 4433f1c | 2010-01-26 05:19:50 +0000 | [diff] [blame] | 696 | |
| 697 | // Don't cache ctors or dtors since we have to emit multiple functions for |
| 698 | // a single ctor or dtor. |
| 699 | if (!IsCtorOrDtor && Method->isThisDeclarationADefinition()) |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 700 | SPCache[Method] = llvm::WeakVH(SP); |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 701 | |
| 702 | return SP; |
| 703 | } |
| 704 | |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 705 | /// CollectCXXMemberFunctions - A helper function to collect debug info for |
| 706 | /// C++ member functions.This is used while creating debug info entry for |
| 707 | /// a Record. |
| 708 | void CGDebugInfo:: |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 709 | CollectCXXMemberFunctions(const CXXRecordDecl *RD, llvm::DIFile Unit, |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 710 | llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys, |
Dan Gohman | 4cac5b4 | 2010-08-20 22:02:57 +0000 | [diff] [blame] | 711 | llvm::DIType RecordTy) { |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 712 | for(CXXRecordDecl::method_iterator I = RD->method_begin(), |
| 713 | E = RD->method_end(); I != E; ++I) { |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 714 | const CXXMethodDecl *Method = *I; |
Anders Carlsson | bea9b23 | 2010-01-26 04:40:11 +0000 | [diff] [blame] | 715 | |
Devang Patel | d5322da | 2010-02-09 19:09:28 +0000 | [diff] [blame] | 716 | if (Method->isImplicit() && !Method->isUsed()) |
Anders Carlsson | bea9b23 | 2010-01-26 04:40:11 +0000 | [diff] [blame] | 717 | continue; |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 718 | |
Anders Carlsson | d6f9a0d | 2010-01-26 04:49:33 +0000 | [diff] [blame] | 719 | EltTys.push_back(CreateCXXMemberFunction(Method, Unit, RecordTy)); |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 723 | /// CollectCXXBases - A helper function to collect debug info for |
| 724 | /// C++ base classes. This is used while creating debug info entry for |
| 725 | /// a Record. |
| 726 | void CGDebugInfo:: |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 727 | CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile Unit, |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 728 | llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys, |
Dan Gohman | 4cac5b4 | 2010-08-20 22:02:57 +0000 | [diff] [blame] | 729 | llvm::DIType RecordTy) { |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 730 | |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 731 | const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); |
| 732 | for (CXXRecordDecl::base_class_const_iterator BI = RD->bases_begin(), |
| 733 | BE = RD->bases_end(); BI != BE; ++BI) { |
Devang Patel | ca7daed | 2010-01-28 21:54:15 +0000 | [diff] [blame] | 734 | unsigned BFlags = 0; |
| 735 | uint64_t BaseOffset; |
| 736 | |
| 737 | const CXXRecordDecl *Base = |
| 738 | cast<CXXRecordDecl>(BI->getType()->getAs<RecordType>()->getDecl()); |
| 739 | |
| 740 | if (BI->isVirtual()) { |
Anders Carlsson | bba1607 | 2010-03-11 07:15:17 +0000 | [diff] [blame] | 741 | // virtual base offset offset is -ve. The code generator emits dwarf |
Devang Patel | d5322da | 2010-02-09 19:09:28 +0000 | [diff] [blame] | 742 | // expression where it expects +ve number. |
Anders Carlsson | af44035 | 2010-03-23 04:11:45 +0000 | [diff] [blame] | 743 | BaseOffset = 0 - CGM.getVTables().getVirtualBaseOffsetOffset(RD, Base); |
Devang Patel | ca7daed | 2010-01-28 21:54:15 +0000 | [diff] [blame] | 744 | BFlags = llvm::DIType::FlagVirtual; |
| 745 | } else |
| 746 | BaseOffset = RL.getBaseClassOffset(Base); |
| 747 | |
| 748 | AccessSpecifier Access = BI->getAccessSpecifier(); |
| 749 | if (Access == clang::AS_private) |
| 750 | BFlags |= llvm::DIType::FlagPrivate; |
| 751 | else if (Access == clang::AS_protected) |
| 752 | BFlags |= llvm::DIType::FlagProtected; |
| 753 | |
| 754 | llvm::DIType DTy = |
| 755 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance, |
| 756 | RecordTy, llvm::StringRef(), |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 757 | Unit, 0, 0, 0, |
Devang Patel | ca7daed | 2010-01-28 21:54:15 +0000 | [diff] [blame] | 758 | BaseOffset, BFlags, |
| 759 | getOrCreateType(BI->getType(), |
| 760 | Unit)); |
| 761 | EltTys.push_back(DTy); |
| 762 | } |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 763 | } |
| 764 | |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 765 | /// getOrCreateVTablePtrType - Return debug info descriptor for vtable. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 766 | llvm::DIType CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile Unit) { |
Devang Patel | 0804e6e | 2010-03-08 20:53:17 +0000 | [diff] [blame] | 767 | if (VTablePtrType.isValid()) |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 768 | return VTablePtrType; |
| 769 | |
| 770 | ASTContext &Context = CGM.getContext(); |
| 771 | |
| 772 | /* Function type */ |
Benjamin Kramer | ad46886 | 2010-03-30 11:36:44 +0000 | [diff] [blame] | 773 | llvm::DIDescriptor STy = getOrCreateType(Context.IntTy, Unit); |
| 774 | llvm::DIArray SElements = DebugFactory.GetOrCreateArray(&STy, 1); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 775 | llvm::DIType SubTy = |
| 776 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 777 | Unit, "", Unit, |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 778 | 0, 0, 0, 0, 0, llvm::DIType(), SElements); |
| 779 | |
| 780 | unsigned Size = Context.getTypeSize(Context.VoidPtrTy); |
| 781 | llvm::DIType vtbl_ptr_type |
| 782 | = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 783 | Unit, "__vtbl_ptr_type", Unit, |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 784 | 0, Size, 0, 0, 0, SubTy); |
| 785 | |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 786 | VTablePtrType = |
| 787 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, |
| 788 | Unit, "", Unit, |
| 789 | 0, Size, 0, 0, 0, vtbl_ptr_type); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 790 | return VTablePtrType; |
| 791 | } |
| 792 | |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 793 | /// getVTableName - Get vtable name for the given Class. |
| 794 | llvm::StringRef CGDebugInfo::getVTableName(const CXXRecordDecl *RD) { |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 795 | // Otherwise construct gdb compatible name name. |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 796 | std::string Name = "_vptr$" + RD->getNameAsString(); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 797 | |
| 798 | // Copy this name on the side and use its reference. |
Devang Patel | 89f05f8 | 2010-01-28 18:21:00 +0000 | [diff] [blame] | 799 | char *StrPtr = DebugInfoNames.Allocate<char>(Name.length()); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 800 | memcpy(StrPtr, Name.data(), Name.length()); |
| 801 | return llvm::StringRef(StrPtr, Name.length()); |
| 802 | } |
| 803 | |
| 804 | |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 805 | /// CollectVTableInfo - If the C++ class has vtable info then insert appropriate |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 806 | /// debug info entry in EltTys vector. |
| 807 | void CGDebugInfo:: |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 808 | CollectVTableInfo(const CXXRecordDecl *RD, llvm::DIFile Unit, |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 809 | llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys) { |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 810 | const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 811 | |
| 812 | // If there is a primary base then it will hold vtable info. |
| 813 | if (RL.getPrimaryBase()) |
| 814 | return; |
| 815 | |
| 816 | // 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] | 817 | if (!RD->isDynamicClass()) |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 818 | return; |
| 819 | |
| 820 | unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy); |
| 821 | llvm::DIType VPTR |
| 822 | = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 823 | getVTableName(RD), Unit, |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 824 | 0, Size, 0, 0, 0, |
| 825 | getOrCreateVTablePtrType(Unit)); |
| 826 | EltTys.push_back(VPTR); |
| 827 | } |
| 828 | |
Devang Patel | 65e99f2 | 2009-02-25 01:36:11 +0000 | [diff] [blame] | 829 | /// CreateType - get structure or union type. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 830 | llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 831 | llvm::DIFile Unit) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 832 | RecordDecl *RD = Ty->getDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 833 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 834 | unsigned Tag; |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 835 | if (RD->isStruct()) |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 836 | Tag = llvm::dwarf::DW_TAG_structure_type; |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 837 | else if (RD->isUnion()) |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 838 | Tag = llvm::dwarf::DW_TAG_union_type; |
| 839 | else { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 840 | assert(RD->isClass() && "Unknown RecordType!"); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 841 | Tag = llvm::dwarf::DW_TAG_class_type; |
Sanjiv Gupta | f58c27a | 2008-06-07 04:46:53 +0000 | [diff] [blame] | 842 | } |
| 843 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 844 | // Get overall information about the record type for the debug info. |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 845 | llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation()); |
| 846 | unsigned Line = getLineNumber(RD->getLocation()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 847 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 848 | // Records and classes and unions can all be recursive. To handle them, we |
| 849 | // first generate a debug descriptor for the struct as a forward declaration. |
| 850 | // Then (if it is a definition) we go through and get debug info for all of |
| 851 | // its members. Finally, we create a descriptor for the complete type (which |
| 852 | // may refer to the forward decl if the struct is recursive) and replace all |
| 853 | // uses of the forward declaration with the final definition. |
Devang Patel | 0b89799 | 2010-07-08 19:56:29 +0000 | [diff] [blame] | 854 | llvm::DIDescriptor FDContext = |
| 855 | getContextDescriptor(dyn_cast<Decl>(RD->getDeclContext()), Unit); |
| 856 | |
| 857 | // If this is just a forward declaration, construct an appropriately |
| 858 | // marked node and just return it. |
| 859 | if (!RD->getDefinition()) { |
| 860 | llvm::DICompositeType FwdDecl = |
| 861 | DebugFactory.CreateCompositeType(Tag, FDContext, RD->getName(), |
| 862 | DefUnit, Line, 0, 0, 0, |
| 863 | llvm::DIType::FlagFwdDecl, |
| 864 | llvm::DIType(), llvm::DIArray()); |
| 865 | |
| 866 | return FwdDecl; |
| 867 | } |
Devang Patel | d0f251b | 2010-01-20 23:56:40 +0000 | [diff] [blame] | 868 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 869 | // A RD->getName() is not unique. However, the debug info descriptors |
Devang Patel | ce78c97 | 2010-02-01 22:51:29 +0000 | [diff] [blame] | 870 | // are uniqued so use type name to ensure uniquness. |
Dan Gohman | 8696837 | 2010-08-20 22:39:57 +0000 | [diff] [blame^] | 871 | llvm::DIType FwdDecl = DebugFactory.CreateTemporaryType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 872 | |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 873 | llvm::MDNode *MN = FwdDecl; |
| 874 | llvm::TrackingVH<llvm::MDNode> FwdDeclNode = MN; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 875 | // Otherwise, insert it into the TypeCache so that recursive uses will find |
| 876 | // it. |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 877 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl; |
Devang Patel | e4c1ea0 | 2010-03-11 20:01:48 +0000 | [diff] [blame] | 878 | // Push the struct on region stack. |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 879 | RegionStack.push_back(FwdDeclNode); |
| 880 | RegionMap[Ty->getDecl()] = llvm::WeakVH(FwdDecl); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 881 | |
| 882 | // Convert all the elements. |
| 883 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
| 884 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 885 | const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD); |
Devang Patel | 3064afe | 2010-01-28 21:41:35 +0000 | [diff] [blame] | 886 | if (CXXDecl) { |
| 887 | CollectCXXBases(CXXDecl, Unit, EltTys, FwdDecl); |
Anders Carlsson | 046c294 | 2010-04-17 20:15:18 +0000 | [diff] [blame] | 888 | CollectVTableInfo(CXXDecl, Unit, EltTys); |
Devang Patel | 3064afe | 2010-01-28 21:41:35 +0000 | [diff] [blame] | 889 | } |
Devang Patel | dabc3e9 | 2010-08-12 00:02:44 +0000 | [diff] [blame] | 890 | |
| 891 | // Collect static variables with initializers. |
| 892 | for (RecordDecl::decl_iterator I = RD->decls_begin(), E = RD->decls_end(); |
| 893 | I != E; ++I) |
| 894 | if (const VarDecl *V = dyn_cast<VarDecl>(*I)) { |
| 895 | if (const Expr *Init = V->getInit()) { |
| 896 | Expr::EvalResult Result; |
| 897 | if (Init->Evaluate(Result, CGM.getContext()) && Result.Val.isInt()) { |
| 898 | llvm::ConstantInt *CI |
| 899 | = llvm::ConstantInt::get(CGM.getLLVMContext(), Result.Val.getInt()); |
| 900 | |
| 901 | // Create the descriptor for static variable. |
| 902 | llvm::DIFile VUnit = getOrCreateFile(V->getLocation()); |
| 903 | llvm::StringRef VName = V->getName(); |
| 904 | llvm::DIType VTy = getOrCreateType(V->getType(), VUnit); |
| 905 | // Do not use DIGlobalVariable for enums. |
| 906 | if (VTy.getTag() != llvm::dwarf::DW_TAG_enumeration_type) { |
| 907 | DebugFactory.CreateGlobalVariable(FwdDecl, VName, VName, VName, VUnit, |
| 908 | getLineNumber(V->getLocation()), |
| 909 | VTy, true, true, CI); |
| 910 | } |
| 911 | } |
| 912 | } |
| 913 | } |
| 914 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 915 | CollectRecordFields(RD, Unit, EltTys); |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 916 | llvm::MDNode *ContainingType = NULL; |
Devang Patel | 4ce3f20 | 2010-01-28 18:11:52 +0000 | [diff] [blame] | 917 | if (CXXDecl) { |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 918 | CollectCXXMemberFunctions(CXXDecl, Unit, EltTys, FwdDecl); |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 919 | |
| 920 | // A class's primary base or the class itself contains the vtable. |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 921 | const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD); |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 922 | if (const CXXRecordDecl *PBase = RL.getPrimaryBase()) |
| 923 | ContainingType = |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 924 | getOrCreateType(QualType(PBase->getTypeForDecl(), 0), Unit); |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 925 | else if (CXXDecl->isDynamicClass()) |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 926 | ContainingType = FwdDecl; |
Devang Patel | a245c5b | 2010-01-25 23:32:18 +0000 | [diff] [blame] | 927 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 928 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 929 | llvm::DIArray Elements = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 930 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 931 | |
| 932 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 933 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 934 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 935 | |
Devang Patel | e4c1ea0 | 2010-03-11 20:01:48 +0000 | [diff] [blame] | 936 | RegionStack.pop_back(); |
| 937 | llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator RI = |
| 938 | RegionMap.find(Ty->getDecl()); |
| 939 | if (RI != RegionMap.end()) |
| 940 | RegionMap.erase(RI); |
| 941 | |
Devang Patel | 411894b | 2010-02-01 22:40:08 +0000 | [diff] [blame] | 942 | llvm::DIDescriptor RDContext = |
| 943 | getContextDescriptor(dyn_cast<Decl>(RD->getDeclContext()), Unit); |
Devang Patel | 700a1cb | 2010-07-20 20:24:18 +0000 | [diff] [blame] | 944 | |
| 945 | llvm::StringRef RDName = RD->getName(); |
| 946 | // If this is a class, include the template arguments also. |
| 947 | if (Tag == llvm::dwarf::DW_TAG_class_type) |
| 948 | RDName = getClassName(RD); |
| 949 | |
Devang Patel | 0ce73f6 | 2009-07-22 18:57:00 +0000 | [diff] [blame] | 950 | llvm::DICompositeType RealDecl = |
Devang Patel | 411894b | 2010-02-01 22:40:08 +0000 | [diff] [blame] | 951 | DebugFactory.CreateCompositeType(Tag, RDContext, |
Devang Patel | 700a1cb | 2010-07-20 20:24:18 +0000 | [diff] [blame] | 952 | RDName, |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 953 | DefUnit, Line, Size, Align, 0, 0, |
Devang Patel | 0ac8f31 | 2010-01-28 00:54:21 +0000 | [diff] [blame] | 954 | llvm::DIType(), Elements, |
| 955 | 0, ContainingType); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 956 | |
| 957 | // Now that we have a real decl for the struct, replace anything using the |
| 958 | // old decl with the new one. This will recursively update the debug info. |
Dan Gohman | 4cac5b4 | 2010-08-20 22:02:57 +0000 | [diff] [blame] | 959 | llvm::DIType(FwdDeclNode).replaceAllUsesWith(RealDecl); |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 960 | RegionMap[RD] = llvm::WeakVH(RealDecl); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 961 | return RealDecl; |
| 962 | } |
| 963 | |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 964 | /// CreateType - get objective-c object type. |
| 965 | llvm::DIType CGDebugInfo::CreateType(const ObjCObjectType *Ty, |
| 966 | llvm::DIFile Unit) { |
| 967 | // Ignore protocols. |
| 968 | return getOrCreateType(Ty->getBaseType(), Unit); |
| 969 | } |
| 970 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 971 | /// CreateType - get objective-c interface type. |
| 972 | llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 973 | llvm::DIFile Unit) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 974 | ObjCInterfaceDecl *ID = Ty->getDecl(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 975 | unsigned Tag = llvm::dwarf::DW_TAG_structure_type; |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 976 | |
| 977 | // Get overall information about the record type for the debug info. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 978 | llvm::DIFile DefUnit = getOrCreateFile(ID->getLocation()); |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 979 | unsigned Line = getLineNumber(ID->getLocation()); |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 980 | unsigned RuntimeLang = TheCU.getLanguage(); |
Chris Lattner | ac7c814 | 2009-05-02 01:13:16 +0000 | [diff] [blame] | 981 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 982 | // To handle recursive interface, we |
| 983 | // first generate a debug descriptor for the struct as a forward declaration. |
| 984 | // Then (if it is a definition) we go through and get debug info for all of |
| 985 | // its members. Finally, we create a descriptor for the complete type (which |
| 986 | // may refer to the forward decl if the struct is recursive) and replace all |
| 987 | // uses of the forward declaration with the final definition. |
Dan Gohman | 8696837 | 2010-08-20 22:39:57 +0000 | [diff] [blame^] | 988 | llvm::DIType FwdDecl = DebugFactory.CreateTemporaryType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 989 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 990 | // If this is just a forward declaration, return it. |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 991 | if (ID->isForwardDecl()) |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 992 | return FwdDecl; |
| 993 | |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 994 | llvm::MDNode *MN = FwdDecl; |
| 995 | llvm::TrackingVH<llvm::MDNode> FwdDeclNode = MN; |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 996 | // Otherwise, insert it into the TypeCache so that recursive uses will find |
| 997 | // it. |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 998 | TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl; |
Devang Patel | e4c1ea0 | 2010-03-11 20:01:48 +0000 | [diff] [blame] | 999 | // Push the struct on region stack. |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 1000 | RegionStack.push_back(FwdDeclNode); |
| 1001 | RegionMap[Ty->getDecl()] = llvm::WeakVH(FwdDecl); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1002 | |
| 1003 | // Convert all the elements. |
| 1004 | llvm::SmallVector<llvm::DIDescriptor, 16> EltTys; |
| 1005 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1006 | ObjCInterfaceDecl *SClass = ID->getSuperClass(); |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 1007 | if (SClass) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1008 | llvm::DIType SClassTy = |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1009 | getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1010 | llvm::DIType InhTag = |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 1011 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1012 | Unit, "", Unit, 0, 0, 0, |
Devang Patel | fbe899f | 2009-03-10 21:30:26 +0000 | [diff] [blame] | 1013 | 0 /* offset */, 0, SClassTy); |
| 1014 | EltTys.push_back(InhTag); |
| 1015 | } |
| 1016 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1017 | const ASTRecordLayout &RL = CGM.getContext().getASTObjCInterfaceLayout(ID); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1018 | |
| 1019 | unsigned FieldNo = 0; |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1020 | for (ObjCInterfaceDecl::ivar_iterator I = ID->ivar_begin(), |
| 1021 | E = ID->ivar_end(); I != E; ++I, ++FieldNo) { |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1022 | ObjCIvarDecl *Field = *I; |
| 1023 | llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit); |
| 1024 | |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 1025 | llvm::StringRef FieldName = Field->getName(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1026 | |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 1027 | // Ignore unnamed fields. |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 1028 | if (FieldName.empty()) |
Devang Patel | de13502 | 2009-04-27 22:40:36 +0000 | [diff] [blame] | 1029 | continue; |
| 1030 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1031 | // Get the location for the field. |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1032 | llvm::DIFile FieldDefUnit = getOrCreateFile(Field->getLocation()); |
| 1033 | unsigned FieldLine = getLineNumber(Field->getLocation()); |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 1034 | QualType FType = Field->getType(); |
| 1035 | uint64_t FieldSize = 0; |
| 1036 | unsigned FieldAlign = 0; |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 1037 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 1038 | if (!FType->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1039 | |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 1040 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1041 | FieldSize = CGM.getContext().getTypeSize(FType); |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 1042 | Expr *BitWidth = Field->getBitWidth(); |
| 1043 | if (BitWidth) |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1044 | FieldSize = BitWidth->EvaluateAsInt(CGM.getContext()).getZExtValue(); |
Eli Friedman | 9a901bb | 2009-04-26 19:19:15 +0000 | [diff] [blame] | 1045 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1046 | FieldAlign = CGM.getContext().getTypeAlign(FType); |
Devang Patel | 99c20eb | 2009-03-20 18:24:39 +0000 | [diff] [blame] | 1047 | } |
| 1048 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1049 | uint64_t FieldOffset = RL.getFieldOffset(FieldNo); |
| 1050 | |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 1051 | unsigned Flags = 0; |
| 1052 | if (Field->getAccessControl() == ObjCIvarDecl::Protected) |
| 1053 | Flags = llvm::DIType::FlagProtected; |
| 1054 | else if (Field->getAccessControl() == ObjCIvarDecl::Private) |
| 1055 | Flags = llvm::DIType::FlagPrivate; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1056 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1057 | // Create a DW_TAG_member node to remember the offset of this field in the |
| 1058 | // struct. FIXME: This is an absolutely insane way to capture this |
| 1059 | // information. When we gut debug info, this should be fixed. |
| 1060 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
| 1061 | FieldName, FieldDefUnit, |
| 1062 | FieldLine, FieldSize, FieldAlign, |
Devang Patel | c20482b | 2009-03-19 00:23:53 +0000 | [diff] [blame] | 1063 | FieldOffset, Flags, FieldTy); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1064 | EltTys.push_back(FieldTy); |
| 1065 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1066 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1067 | llvm::DIArray Elements = |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1068 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1069 | |
Devang Patel | e4c1ea0 | 2010-03-11 20:01:48 +0000 | [diff] [blame] | 1070 | RegionStack.pop_back(); |
| 1071 | llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator RI = |
| 1072 | RegionMap.find(Ty->getDecl()); |
| 1073 | if (RI != RegionMap.end()) |
| 1074 | RegionMap.erase(RI); |
| 1075 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1076 | // Bit size, align and offset of the type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1077 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 1078 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1079 | |
Devang Patel | 6c1fddf | 2009-07-27 18:42:03 +0000 | [diff] [blame] | 1080 | llvm::DICompositeType RealDecl = |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1081 | DebugFactory.CreateCompositeType(Tag, Unit, ID->getName(), DefUnit, |
Devang Patel | ab71ff5 | 2009-11-12 00:51:46 +0000 | [diff] [blame] | 1082 | Line, Size, Align, 0, 0, llvm::DIType(), |
| 1083 | Elements, RuntimeLang); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1084 | |
| 1085 | // Now that we have a real decl for the struct, replace anything using the |
| 1086 | // old decl with the new one. This will recursively update the debug info. |
Dan Gohman | 4cac5b4 | 2010-08-20 22:02:57 +0000 | [diff] [blame] | 1087 | llvm::DIType(FwdDeclNode).replaceAllUsesWith(RealDecl); |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 1088 | RegionMap[ID] = llvm::WeakVH(RealDecl); |
Devang Patel | fe09eab | 2009-07-13 17:03:14 +0000 | [diff] [blame] | 1089 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1090 | return RealDecl; |
| 1091 | } |
| 1092 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1093 | llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1094 | llvm::DIFile Unit) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1095 | EnumDecl *ED = Ty->getDecl(); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1096 | |
| 1097 | llvm::SmallVector<llvm::DIDescriptor, 32> Enumerators; |
| 1098 | |
| 1099 | // Create DIEnumerator elements for each enumerator. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1100 | for (EnumDecl::enumerator_iterator |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1101 | Enum = ED->enumerator_begin(), EnumEnd = ED->enumerator_end(); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1102 | Enum != EnumEnd; ++Enum) { |
Devang Patel | 7362162 | 2009-11-25 17:37:31 +0000 | [diff] [blame] | 1103 | Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getName(), |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1104 | Enum->getInitVal().getZExtValue())); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1105 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1107 | // Return a CompositeType for the enum itself. |
| 1108 | llvm::DIArray EltArray = |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 1109 | DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1110 | |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1111 | llvm::DIFile DefUnit = getOrCreateFile(ED->getLocation()); |
| 1112 | unsigned Line = getLineNumber(ED->getLocation()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1113 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1114 | // Size and align of the type. |
Eli Friedman | 3189e4b | 2009-05-04 04:39:55 +0000 | [diff] [blame] | 1115 | uint64_t Size = 0; |
| 1116 | unsigned Align = 0; |
| 1117 | if (!Ty->isIncompleteType()) { |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1118 | Size = CGM.getContext().getTypeSize(Ty); |
| 1119 | Align = CGM.getContext().getTypeAlign(Ty); |
Eli Friedman | 3189e4b | 2009-05-04 04:39:55 +0000 | [diff] [blame] | 1120 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1121 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1122 | llvm::DIType DbgTy = |
| 1123 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type, |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1124 | Unit, ED->getName(), DefUnit, Line, |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1125 | Size, Align, 0, 0, |
| 1126 | llvm::DIType(), EltArray); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1127 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | llvm::DIType CGDebugInfo::CreateType(const TagType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1131 | llvm::DIFile Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1132 | if (const RecordType *RT = dyn_cast<RecordType>(Ty)) |
| 1133 | return CreateType(RT, Unit); |
| 1134 | else if (const EnumType *ET = dyn_cast<EnumType>(Ty)) |
| 1135 | return CreateType(ET, Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1136 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1137 | return llvm::DIType(); |
| 1138 | } |
| 1139 | |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1140 | llvm::DIType CGDebugInfo::CreateType(const VectorType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1141 | llvm::DIFile Unit) { |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1142 | llvm::DIType ElementTy = getOrCreateType(Ty->getElementType(), Unit); |
| 1143 | uint64_t NumElems = Ty->getNumElements(); |
| 1144 | if (NumElems > 0) |
| 1145 | --NumElems; |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1146 | |
Benjamin Kramer | ad46886 | 2010-03-30 11:36:44 +0000 | [diff] [blame] | 1147 | llvm::DIDescriptor Subscript = DebugFactory.GetOrCreateSubrange(0, NumElems); |
| 1148 | llvm::DIArray SubscriptArray = DebugFactory.GetOrCreateArray(&Subscript, 1); |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1149 | |
| 1150 | uint64_t Size = CGM.getContext().getTypeSize(Ty); |
| 1151 | uint64_t Align = CGM.getContext().getTypeAlign(Ty); |
| 1152 | |
| 1153 | return |
| 1154 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_vector_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1155 | Unit, "", Unit, |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1156 | 0, Size, Align, 0, 0, |
| 1157 | ElementTy, SubscriptArray); |
| 1158 | } |
| 1159 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1160 | llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1161 | llvm::DIFile Unit) { |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1162 | uint64_t Size; |
| 1163 | uint64_t Align; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1164 | |
| 1165 | |
Nuno Lopes | 010d514 | 2009-01-28 00:35:17 +0000 | [diff] [blame] | 1166 | // FIXME: make getTypeAlign() aware of VLAs and incomplete array types |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1167 | if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(Ty)) { |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1168 | Size = 0; |
| 1169 | Align = |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1170 | CGM.getContext().getTypeAlign(CGM.getContext().getBaseElementType(VAT)); |
Nuno Lopes | 010d514 | 2009-01-28 00:35:17 +0000 | [diff] [blame] | 1171 | } else if (Ty->isIncompleteArrayType()) { |
| 1172 | Size = 0; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1173 | Align = CGM.getContext().getTypeAlign(Ty->getElementType()); |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1174 | } else { |
| 1175 | // Size and align of the whole array, not the element type. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1176 | Size = CGM.getContext().getTypeSize(Ty); |
| 1177 | Align = CGM.getContext().getTypeAlign(Ty); |
Anders Carlsson | 835c909 | 2009-01-05 01:23:29 +0000 | [diff] [blame] | 1178 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1179 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1180 | // Add the dimensions of the array. FIXME: This loses CV qualifiers from |
| 1181 | // interior arrays, do we care? Why aren't nested arrays represented the |
| 1182 | // obvious/recursive way? |
| 1183 | llvm::SmallVector<llvm::DIDescriptor, 8> Subscripts; |
| 1184 | QualType EltTy(Ty, 0); |
| 1185 | while ((Ty = dyn_cast<ArrayType>(EltTy))) { |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 1186 | uint64_t Upper = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1187 | if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty)) |
Devang Patel | 5a6bfe3 | 2009-08-14 20:57:45 +0000 | [diff] [blame] | 1188 | if (CAT->getSize().getZExtValue()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1189 | Upper = CAT->getSize().getZExtValue() - 1; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1190 | // FIXME: Verify this is right for VLAs. |
| 1191 | Subscripts.push_back(DebugFactory.GetOrCreateSubrange(0, Upper)); |
| 1192 | EltTy = Ty->getElementType(); |
Sanjiv Gupta | 507de85 | 2008-06-09 10:47:41 +0000 | [diff] [blame] | 1193 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1194 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1195 | llvm::DIArray SubscriptArray = |
Daniel Dunbar | ca308df | 2009-05-26 19:40:20 +0000 | [diff] [blame] | 1196 | DebugFactory.GetOrCreateArray(Subscripts.data(), Subscripts.size()); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1197 | |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1198 | llvm::DIType DbgTy = |
| 1199 | DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_array_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1200 | Unit, "", Unit, |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1201 | 0, Size, Align, 0, 0, |
| 1202 | getOrCreateType(EltTy, Unit), |
| 1203 | SubscriptArray); |
Devang Patel | ca80a5f | 2009-10-20 19:55:01 +0000 | [diff] [blame] | 1204 | return DbgTy; |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 1207 | llvm::DIType CGDebugInfo::CreateType(const LValueReferenceType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1208 | llvm::DIFile Unit) { |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 1209 | return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, |
| 1210 | Ty, Ty->getPointeeType(), Unit); |
| 1211 | } |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1212 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1213 | llvm::DIType CGDebugInfo::CreateType(const MemberPointerType *Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1214 | llvm::DIFile U) { |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1215 | QualType PointerDiffTy = CGM.getContext().getPointerDiffType(); |
| 1216 | llvm::DIType PointerDiffDITy = getOrCreateType(PointerDiffTy, U); |
| 1217 | |
| 1218 | if (!Ty->getPointeeType()->isFunctionType()) { |
| 1219 | // We have a data member pointer type. |
| 1220 | return PointerDiffDITy; |
| 1221 | } |
| 1222 | |
| 1223 | // We have a member function pointer type. Treat it as a struct with two |
| 1224 | // ptrdiff_t members. |
| 1225 | std::pair<uint64_t, unsigned> Info = CGM.getContext().getTypeInfo(Ty); |
| 1226 | |
| 1227 | uint64_t FieldOffset = 0; |
| 1228 | llvm::DIDescriptor ElementTypes[2]; |
| 1229 | |
| 1230 | // FIXME: This should probably be a function type instead. |
| 1231 | ElementTypes[0] = |
| 1232 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, U, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1233 | "ptr", U, 0, |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1234 | Info.first, Info.second, FieldOffset, 0, |
| 1235 | PointerDiffDITy); |
| 1236 | FieldOffset += Info.first; |
| 1237 | |
| 1238 | ElementTypes[1] = |
| 1239 | DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, U, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1240 | "ptr", U, 0, |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1241 | Info.first, Info.second, FieldOffset, 0, |
| 1242 | PointerDiffDITy); |
| 1243 | |
| 1244 | llvm::DIArray Elements = |
| 1245 | DebugFactory.GetOrCreateArray(&ElementTypes[0], |
| 1246 | llvm::array_lengthof(ElementTypes)); |
| 1247 | |
| 1248 | return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_structure_type, |
| 1249 | U, llvm::StringRef("test"), |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1250 | U, 0, FieldOffset, |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1251 | 0, 0, 0, llvm::DIType(), Elements); |
| 1252 | } |
| 1253 | |
Douglas Gregor | 840943d | 2009-12-21 20:18:30 +0000 | [diff] [blame] | 1254 | static QualType UnwrapTypeForDebugInfo(QualType T) { |
| 1255 | do { |
| 1256 | QualType LastT = T; |
| 1257 | switch (T->getTypeClass()) { |
| 1258 | default: |
| 1259 | return T; |
| 1260 | case Type::TemplateSpecialization: |
| 1261 | T = cast<TemplateSpecializationType>(T)->desugar(); |
| 1262 | break; |
| 1263 | case Type::TypeOfExpr: { |
| 1264 | TypeOfExprType *Ty = cast<TypeOfExprType>(T); |
| 1265 | T = Ty->getUnderlyingExpr()->getType(); |
| 1266 | break; |
| 1267 | } |
| 1268 | case Type::TypeOf: |
| 1269 | T = cast<TypeOfType>(T)->getUnderlyingType(); |
| 1270 | break; |
| 1271 | case Type::Decltype: |
| 1272 | T = cast<DecltypeType>(T)->getUnderlyingType(); |
| 1273 | break; |
Abramo Bagnara | 465d41b | 2010-05-11 21:36:43 +0000 | [diff] [blame] | 1274 | case Type::Elaborated: |
| 1275 | T = cast<ElaboratedType>(T)->getNamedType(); |
Douglas Gregor | 840943d | 2009-12-21 20:18:30 +0000 | [diff] [blame] | 1276 | break; |
| 1277 | case Type::SubstTemplateTypeParm: |
| 1278 | T = cast<SubstTemplateTypeParmType>(T)->getReplacementType(); |
| 1279 | break; |
Douglas Gregor | 840943d | 2009-12-21 20:18:30 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | assert(T != LastT && "Type unwrapping failed to unwrap!"); |
| 1283 | if (T == LastT) |
| 1284 | return T; |
| 1285 | } while (true); |
| 1286 | |
| 1287 | return T; |
Anders Carlsson | 5b6117a | 2009-11-14 21:08:12 +0000 | [diff] [blame] | 1288 | } |
| 1289 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1290 | /// getOrCreateType - Get the type from the cache or create a new |
| 1291 | /// one if necessary. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1292 | llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1293 | llvm::DIFile Unit) { |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1294 | if (Ty.isNull()) |
| 1295 | return llvm::DIType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1296 | |
Douglas Gregor | 840943d | 2009-12-21 20:18:30 +0000 | [diff] [blame] | 1297 | // Unwrap the type as needed for debug information. |
| 1298 | Ty = UnwrapTypeForDebugInfo(Ty); |
Anders Carlsson | 5b6117a | 2009-11-14 21:08:12 +0000 | [diff] [blame] | 1299 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 1300 | // Check for existing entry. |
Ted Kremenek | 590838b | 2010-03-29 18:29:57 +0000 | [diff] [blame] | 1301 | llvm::DenseMap<void *, llvm::WeakVH>::iterator it = |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 1302 | TypeCache.find(Ty.getAsOpaquePtr()); |
Daniel Dunbar | 65f13c3 | 2009-09-19 20:17:48 +0000 | [diff] [blame] | 1303 | if (it != TypeCache.end()) { |
| 1304 | // Verify that the debug info still exists. |
| 1305 | if (&*it->second) |
| 1306 | return llvm::DIType(cast<llvm::MDNode>(it->second)); |
| 1307 | } |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1308 | |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 1309 | // Otherwise create the type. |
| 1310 | llvm::DIType Res = CreateTypeNode(Ty, Unit); |
Anders Carlsson | 0dd57c6 | 2009-11-14 20:52:05 +0000 | [diff] [blame] | 1311 | |
| 1312 | // And update the type cache. |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 1313 | TypeCache[Ty.getAsOpaquePtr()] = Res; |
Daniel Dunbar | 23e81ba | 2009-09-19 19:27:24 +0000 | [diff] [blame] | 1314 | return Res; |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
Anders Carlsson | 0dd57c6 | 2009-11-14 20:52:05 +0000 | [diff] [blame] | 1317 | /// CreateTypeNode - Create a new debug type node. |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1318 | llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1319 | llvm::DIFile Unit) { |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 1320 | // Handle qualifiers, which recursively handles what they refer to. |
Douglas Gregor | a4923eb | 2009-11-16 21:35:15 +0000 | [diff] [blame] | 1321 | if (Ty.hasLocalQualifiers()) |
John McCall | a180529 | 2009-09-25 01:40:47 +0000 | [diff] [blame] | 1322 | return CreateQualifiedType(Ty, Unit); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1323 | |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1324 | const char *Diag = 0; |
| 1325 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1326 | // Work out details of type. |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1327 | switch (Ty->getTypeClass()) { |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1328 | #define TYPE(Class, Base) |
| 1329 | #define ABSTRACT_TYPE(Class, Base) |
| 1330 | #define NON_CANONICAL_TYPE(Class, Base) |
| 1331 | #define DEPENDENT_TYPE(Class, Base) case Type::Class: |
| 1332 | #include "clang/AST/TypeNodes.def" |
| 1333 | assert(false && "Dependent types cannot show up in debug information"); |
Argyrios Kyrtzidis | 1bb8a45 | 2009-08-19 01:28:17 +0000 | [diff] [blame] | 1334 | |
Anders Carlsson | bfe6995 | 2009-11-06 18:24:04 +0000 | [diff] [blame] | 1335 | // FIXME: Handle these. |
| 1336 | case Type::ExtVector: |
Anders Carlsson | bfe6995 | 2009-11-06 18:24:04 +0000 | [diff] [blame] | 1337 | return llvm::DIType(); |
Devang Patel | 70c23cd | 2010-02-23 22:59:39 +0000 | [diff] [blame] | 1338 | |
| 1339 | case Type::Vector: |
| 1340 | return CreateType(cast<VectorType>(Ty), Unit); |
Daniel Dunbar | 9df4bb3 | 2009-07-14 01:20:56 +0000 | [diff] [blame] | 1341 | case Type::ObjCObjectPointer: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1342 | return CreateType(cast<ObjCObjectPointerType>(Ty), Unit); |
John McCall | c12c5bb | 2010-05-15 11:32:37 +0000 | [diff] [blame] | 1343 | case Type::ObjCObject: |
| 1344 | return CreateType(cast<ObjCObjectType>(Ty), Unit); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1345 | case Type::ObjCInterface: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1346 | return CreateType(cast<ObjCInterfaceType>(Ty), Unit); |
| 1347 | case Type::Builtin: return CreateType(cast<BuiltinType>(Ty), Unit); |
| 1348 | case Type::Complex: return CreateType(cast<ComplexType>(Ty), Unit); |
| 1349 | case Type::Pointer: return CreateType(cast<PointerType>(Ty), Unit); |
Mike Stump | 9bc093c | 2009-05-14 02:03:51 +0000 | [diff] [blame] | 1350 | case Type::BlockPointer: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1351 | return CreateType(cast<BlockPointerType>(Ty), Unit); |
| 1352 | case Type::Typedef: return CreateType(cast<TypedefType>(Ty), Unit); |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1353 | case Type::Record: |
Douglas Gregor | 72564e7 | 2009-02-26 23:50:07 +0000 | [diff] [blame] | 1354 | case Type::Enum: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1355 | return CreateType(cast<TagType>(Ty), Unit); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1356 | case Type::FunctionProto: |
| 1357 | case Type::FunctionNoProto: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1358 | return CreateType(cast<FunctionType>(Ty), Unit); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1359 | case Type::ConstantArray: |
| 1360 | case Type::VariableArray: |
| 1361 | case Type::IncompleteArray: |
Daniel Dunbar | 03faac3 | 2009-09-19 19:27:14 +0000 | [diff] [blame] | 1362 | return CreateType(cast<ArrayType>(Ty), Unit); |
Anders Carlsson | a031b35 | 2009-11-06 19:19:55 +0000 | [diff] [blame] | 1363 | |
| 1364 | case Type::LValueReference: |
| 1365 | return CreateType(cast<LValueReferenceType>(Ty), Unit); |
| 1366 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1367 | case Type::MemberPointer: |
| 1368 | return CreateType(cast<MemberPointerType>(Ty), Unit); |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1369 | |
| 1370 | case Type::TemplateSpecialization: |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1371 | case Type::Elaborated: |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1372 | case Type::SubstTemplateTypeParm: |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1373 | case Type::TypeOfExpr: |
| 1374 | case Type::TypeOf: |
Douglas Gregor | 840943d | 2009-12-21 20:18:30 +0000 | [diff] [blame] | 1375 | case Type::Decltype: |
| 1376 | llvm_unreachable("type should have been unwrapped!"); |
| 1377 | return llvm::DIType(); |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1378 | |
| 1379 | case Type::RValueReference: |
| 1380 | // FIXME: Implement! |
| 1381 | Diag = "rvalue references"; |
| 1382 | break; |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1383 | } |
Douglas Gregor | 2101a82 | 2009-12-21 19:57:21 +0000 | [diff] [blame] | 1384 | |
| 1385 | assert(Diag && "Fall through without a diagnostic?"); |
| 1386 | unsigned DiagID = CGM.getDiags().getCustomDiagID(Diagnostic::Error, |
| 1387 | "debug information for %0 is not yet supported"); |
| 1388 | CGM.getDiags().Report(FullSourceLoc(), DiagID) |
| 1389 | << Diag; |
| 1390 | return llvm::DIType(); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1393 | /// CreateMemberType - Create new member and increase Offset by FType's size. |
| 1394 | llvm::DIType CGDebugInfo::CreateMemberType(llvm::DIFile Unit, QualType FType, |
| 1395 | llvm::StringRef Name, |
| 1396 | uint64_t *Offset) { |
| 1397 | llvm::DIType FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
| 1398 | uint64_t FieldSize = CGM.getContext().getTypeSize(FType); |
| 1399 | unsigned FieldAlign = CGM.getContext().getTypeAlign(FType); |
| 1400 | llvm::DIType Ty = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, |
| 1401 | Unit, Name, Unit, 0, |
| 1402 | FieldSize, FieldAlign, |
| 1403 | *Offset, 0, FieldTy); |
| 1404 | *Offset += FieldSize; |
| 1405 | return Ty; |
| 1406 | } |
| 1407 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1408 | /// EmitFunctionStart - Constructs the debug code for entering a function - |
| 1409 | /// "llvm.dbg.func.start.". |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1410 | void CGDebugInfo::EmitFunctionStart(GlobalDecl GD, QualType FnType, |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1411 | llvm::Function *Fn, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1412 | CGBuilderTy &Builder) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1413 | |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1414 | llvm::StringRef Name; |
Anders Carlsson | 9a20d55 | 2010-06-22 16:16:50 +0000 | [diff] [blame] | 1415 | llvm::StringRef LinkageName; |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1416 | |
Devang Patel | 5a6fbcf | 2010-07-22 22:29:16 +0000 | [diff] [blame] | 1417 | FnBeginRegionCount.push_back(RegionStack.size()); |
| 1418 | |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1419 | const Decl *D = GD.getDecl(); |
| 1420 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 1421 | // If there is a DISubprogram for this function available then use it. |
| 1422 | llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator |
| 1423 | FI = SPCache.find(FD); |
| 1424 | if (FI != SPCache.end()) { |
Devang Patel | 0804e6e | 2010-03-08 20:53:17 +0000 | [diff] [blame] | 1425 | llvm::DIDescriptor SP(dyn_cast_or_null<llvm::MDNode>(FI->second)); |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 1426 | if (SP.isSubprogram() && llvm::DISubprogram(SP).isDefinition()) { |
| 1427 | llvm::MDNode *SPN = SP; |
| 1428 | RegionStack.push_back(SPN); |
| 1429 | RegionMap[D] = llvm::WeakVH(SP); |
Devang Patel | 4125fd2 | 2010-01-19 01:54:44 +0000 | [diff] [blame] | 1430 | return; |
| 1431 | } |
| 1432 | } |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1433 | Name = getFunctionName(FD); |
| 1434 | // Use mangled name as linkage name for c/c++ functions. |
Anders Carlsson | 9a20d55 | 2010-06-22 16:16:50 +0000 | [diff] [blame] | 1435 | LinkageName = CGM.getMangledName(GD); |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1436 | } else { |
| 1437 | // Use llvm function name as linkage name. |
| 1438 | Name = Fn->getName(); |
Anders Carlsson | 9a20d55 | 2010-06-22 16:16:50 +0000 | [diff] [blame] | 1439 | LinkageName = Name; |
Devang Patel | 9c6c3a0 | 2010-01-14 00:36:21 +0000 | [diff] [blame] | 1440 | } |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1441 | if (!Name.empty() && Name[0] == '\01') |
| 1442 | Name = Name.substr(1); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1443 | |
Devang Patel | 970c618 | 2010-04-24 00:49:16 +0000 | [diff] [blame] | 1444 | // It is expected that CurLoc is set before using EmitFunctionStart. |
| 1445 | // Usually, CurLoc points to the left bracket location of compound |
| 1446 | // statement representing function body. |
| 1447 | llvm::DIFile Unit = getOrCreateFile(CurLoc); |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1448 | unsigned LineNo = getLineNumber(CurLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1449 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1450 | llvm::DISubprogram SP = |
Devang Patel | 970c618 | 2010-04-24 00:49:16 +0000 | [diff] [blame] | 1451 | DebugFactory.CreateSubprogram(Unit, Name, Name, LinkageName, Unit, LineNo, |
Mike Stump | 91cc815 | 2009-10-23 01:52:13 +0000 | [diff] [blame] | 1452 | getOrCreateType(FnType, Unit), |
Devang Patel | 15a3d7d | 2010-07-15 23:09:46 +0000 | [diff] [blame] | 1453 | Fn->hasInternalLinkage(), true/*definition*/, |
| 1454 | 0, 0, llvm::DIType(), |
| 1455 | D->isImplicit(), |
| 1456 | CGM.getLangOptions().Optimize, Fn); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1457 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1458 | // Push function on region stack. |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 1459 | llvm::MDNode *SPN = SP; |
| 1460 | RegionStack.push_back(SPN); |
| 1461 | RegionMap[D] = llvm::WeakVH(SP); |
Devang Patel | 5a6fbcf | 2010-07-22 22:29:16 +0000 | [diff] [blame] | 1462 | |
| 1463 | // Clear stack used to keep track of #line directives. |
| 1464 | LineDirectiveFiles.clear(); |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | |
Devang Patel | 4d939e6 | 2010-07-20 22:20:10 +0000 | [diff] [blame] | 1468 | void CGDebugInfo::EmitStopPoint(CGBuilderTy &Builder) { |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1469 | if (CurLoc.isInvalid() || CurLoc.isMacroID()) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1470 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1471 | // Don't bother if things are the same as last time. |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1472 | SourceManager &SM = CGM.getContext().getSourceManager(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1473 | if (CurLoc == PrevLoc |
Chris Lattner | 30fc933 | 2009-02-04 01:06:56 +0000 | [diff] [blame] | 1474 | || (SM.getInstantiationLineNumber(CurLoc) == |
| 1475 | SM.getInstantiationLineNumber(PrevLoc) |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1476 | && SM.isFromSameFile(CurLoc, PrevLoc))) |
Devang Patel | 4800ea6 | 2010-04-05 21:09:15 +0000 | [diff] [blame] | 1477 | // New Builder may not be in sync with CGDebugInfo. |
| 1478 | if (!Builder.getCurrentDebugLocation().isUnknown()) |
| 1479 | return; |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1480 | |
| 1481 | // Update last state. |
| 1482 | PrevLoc = CurLoc; |
| 1483 | |
Chris Lattner | c603463 | 2010-04-01 06:31:43 +0000 | [diff] [blame] | 1484 | llvm::MDNode *Scope = RegionStack.back(); |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1485 | Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(getLineNumber(CurLoc), |
| 1486 | getColumnNumber(CurLoc), |
Chris Lattner | e541d01 | 2010-04-02 20:21:43 +0000 | [diff] [blame] | 1487 | Scope)); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1488 | } |
| 1489 | |
Devang Patel | 5a6fbcf | 2010-07-22 22:29:16 +0000 | [diff] [blame] | 1490 | /// UpdateLineDirectiveRegion - Update region stack only if #line directive |
| 1491 | /// has introduced scope change. |
| 1492 | void CGDebugInfo::UpdateLineDirectiveRegion(CGBuilderTy &Builder) { |
| 1493 | if (CurLoc.isInvalid() || CurLoc.isMacroID() || |
| 1494 | PrevLoc.isInvalid() || PrevLoc.isMacroID()) |
| 1495 | return; |
| 1496 | SourceManager &SM = CGM.getContext().getSourceManager(); |
| 1497 | PresumedLoc PCLoc = SM.getPresumedLoc(CurLoc); |
| 1498 | PresumedLoc PPLoc = SM.getPresumedLoc(PrevLoc); |
| 1499 | |
| 1500 | if (!strcmp(PPLoc.getFilename(), PCLoc.getFilename())) |
| 1501 | return; |
| 1502 | |
| 1503 | // If #line directive stack is empty then we are entering a new scope. |
| 1504 | if (LineDirectiveFiles.empty()) { |
| 1505 | EmitRegionStart(Builder); |
| 1506 | LineDirectiveFiles.push_back(PCLoc.getFilename()); |
| 1507 | return; |
| 1508 | } |
| 1509 | |
| 1510 | assert (RegionStack.size() >= LineDirectiveFiles.size() |
| 1511 | && "error handling #line regions!"); |
| 1512 | |
| 1513 | bool SeenThisFile = false; |
| 1514 | for(std::vector<const char *>::iterator I = LineDirectiveFiles.begin(), |
| 1515 | E = LineDirectiveFiles.end(); I != E; ++I) |
| 1516 | if (!strcmp(PPLoc.getFilename(), *I)) { |
| 1517 | SeenThisFile = true; |
| 1518 | break; |
| 1519 | } |
| 1520 | |
| 1521 | // If #line for this file is seen earlier then pop out #line regions. |
| 1522 | if (SeenThisFile) { |
| 1523 | while (!LineDirectiveFiles.empty()) { |
| 1524 | const char *LastFile = LineDirectiveFiles.back(); |
| 1525 | RegionStack.pop_back(); |
| 1526 | LineDirectiveFiles.pop_back(); |
| 1527 | if (!strcmp(PPLoc.getFilename(), LastFile)) |
| 1528 | break; |
| 1529 | } |
| 1530 | return; |
| 1531 | } |
| 1532 | |
| 1533 | // .. otherwise insert new #line region. |
| 1534 | EmitRegionStart(Builder); |
| 1535 | LineDirectiveFiles.push_back(PCLoc.getFilename()); |
| 1536 | |
| 1537 | return; |
| 1538 | } |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1539 | /// EmitRegionStart- Constructs the debug code for entering a declarative |
| 1540 | /// region - "llvm.dbg.region.start.". |
Devang Patel | 4d939e6 | 2010-07-20 22:20:10 +0000 | [diff] [blame] | 1541 | void CGDebugInfo::EmitRegionStart(CGBuilderTy &Builder) { |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1542 | llvm::DIDescriptor D = |
| 1543 | DebugFactory.CreateLexicalBlock(RegionStack.empty() ? |
| 1544 | llvm::DIDescriptor() : |
Devang Patel | d19429f | 2010-02-16 21:41:20 +0000 | [diff] [blame] | 1545 | llvm::DIDescriptor(RegionStack.back()), |
Stuart Hastings | 257d1d3 | 2010-07-19 23:56:31 +0000 | [diff] [blame] | 1546 | getOrCreateFile(CurLoc), |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1547 | getLineNumber(CurLoc), |
| 1548 | getColumnNumber(CurLoc)); |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 1549 | llvm::MDNode *DN = D; |
| 1550 | RegionStack.push_back(DN); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | /// EmitRegionEnd - Constructs the debug code for exiting a declarative |
| 1554 | /// region - "llvm.dbg.region.end." |
Devang Patel | 4d939e6 | 2010-07-20 22:20:10 +0000 | [diff] [blame] | 1555 | void CGDebugInfo::EmitRegionEnd(CGBuilderTy &Builder) { |
Daniel Dunbar | 5273f51 | 2008-10-17 01:07:56 +0000 | [diff] [blame] | 1556 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1557 | |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1558 | // Provide an region stop point. |
Devang Patel | 4d939e6 | 2010-07-20 22:20:10 +0000 | [diff] [blame] | 1559 | EmitStopPoint(Builder); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1560 | |
Sanjiv Gupta | 1c6a38b | 2008-05-25 05:15:42 +0000 | [diff] [blame] | 1561 | RegionStack.pop_back(); |
Sanjiv Gupta | e8b9f5b | 2008-05-08 08:54:20 +0000 | [diff] [blame] | 1562 | } |
| 1563 | |
Devang Patel | 5a6fbcf | 2010-07-22 22:29:16 +0000 | [diff] [blame] | 1564 | /// EmitFunctionEnd - Constructs the debug code for exiting a function. |
| 1565 | void CGDebugInfo::EmitFunctionEnd(CGBuilderTy &Builder) { |
| 1566 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1567 | unsigned RCount = FnBeginRegionCount.back(); |
| 1568 | assert(RCount <= RegionStack.size() && "Region stack mismatch"); |
| 1569 | |
| 1570 | // Pop all regions for this function. |
| 1571 | while (RegionStack.size() != RCount) |
| 1572 | EmitRegionEnd(Builder); |
| 1573 | FnBeginRegionCount.pop_back(); |
| 1574 | } |
| 1575 | |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1576 | // EmitTypeForVarWithBlocksAttr - Build up structure info for the byref. |
| 1577 | // See BuildByRefType. |
| 1578 | llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, |
| 1579 | uint64_t *XOffset) { |
| 1580 | |
| 1581 | llvm::SmallVector<llvm::DIDescriptor, 5> EltTys; |
| 1582 | |
| 1583 | QualType FType; |
| 1584 | uint64_t FieldSize, FieldOffset; |
| 1585 | unsigned FieldAlign; |
| 1586 | |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1587 | llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1588 | QualType Type = VD->getType(); |
| 1589 | |
| 1590 | FieldOffset = 0; |
| 1591 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1592 | EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset)); |
| 1593 | EltTys.push_back(CreateMemberType(Unit, FType, "__forwarding", &FieldOffset)); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1594 | FType = CGM.getContext().IntTy; |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1595 | EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset)); |
| 1596 | EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset)); |
| 1597 | |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1598 | bool HasCopyAndDispose = CGM.BlockRequiresCopying(Type); |
| 1599 | if (HasCopyAndDispose) { |
| 1600 | FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy); |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1601 | EltTys.push_back(CreateMemberType(Unit, FType, "__copy_helper", |
| 1602 | &FieldOffset)); |
| 1603 | EltTys.push_back(CreateMemberType(Unit, FType, "__destroy_helper", |
| 1604 | &FieldOffset)); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | CharUnits Align = CGM.getContext().getDeclAlign(VD); |
| 1608 | if (Align > CharUnits::fromQuantity( |
| 1609 | CGM.getContext().Target.getPointerAlign(0) / 8)) { |
| 1610 | unsigned AlignedOffsetInBytes |
| 1611 | = llvm::RoundUpToAlignment(FieldOffset/8, Align.getQuantity()); |
| 1612 | unsigned NumPaddingBytes |
| 1613 | = AlignedOffsetInBytes - FieldOffset/8; |
| 1614 | |
| 1615 | if (NumPaddingBytes > 0) { |
| 1616 | llvm::APInt pad(32, NumPaddingBytes); |
| 1617 | FType = CGM.getContext().getConstantArrayType(CGM.getContext().CharTy, |
| 1618 | pad, ArrayType::Normal, 0); |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1619 | EltTys.push_back(CreateMemberType(Unit, FType, "", &FieldOffset)); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1620 | } |
| 1621 | } |
| 1622 | |
| 1623 | FType = Type; |
Benjamin Kramer | 48c70f6 | 2010-04-24 20:19:58 +0000 | [diff] [blame] | 1624 | llvm::DIType FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1625 | FieldSize = CGM.getContext().getTypeSize(FType); |
| 1626 | FieldAlign = Align.getQuantity()*8; |
| 1627 | |
| 1628 | *XOffset = FieldOffset; |
| 1629 | FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1630 | VD->getName(), Unit, |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1631 | 0, FieldSize, FieldAlign, |
| 1632 | FieldOffset, 0, FieldTy); |
| 1633 | EltTys.push_back(FieldTy); |
| 1634 | FieldOffset += FieldSize; |
| 1635 | |
| 1636 | llvm::DIArray Elements = |
| 1637 | DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size()); |
| 1638 | |
| 1639 | unsigned Flags = llvm::DIType::FlagBlockByrefStruct; |
| 1640 | |
| 1641 | return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_structure_type, |
Devang Patel | d58562e | 2010-03-09 22:49:11 +0000 | [diff] [blame] | 1642 | Unit, "", Unit, |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1643 | 0, FieldOffset, 0, 0, Flags, |
| 1644 | llvm::DIType(), Elements); |
| 1645 | |
| 1646 | } |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 1647 | /// EmitDeclare - Emit local variable declaration debug info. |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 1648 | void CGDebugInfo::EmitDeclare(const VarDecl *VD, unsigned Tag, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1649 | llvm::Value *Storage, CGBuilderTy &Builder) { |
Daniel Dunbar | 5273f51 | 2008-10-17 01:07:56 +0000 | [diff] [blame] | 1650 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1651 | |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1652 | llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1653 | llvm::DIType Ty; |
| 1654 | uint64_t XOffset = 0; |
| 1655 | if (VD->hasAttr<BlocksAttr>()) |
| 1656 | Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset); |
| 1657 | else |
| 1658 | Ty = getOrCreateType(VD->getType(), Unit); |
Chris Lattner | 650cea9 | 2009-05-05 04:57:08 +0000 | [diff] [blame] | 1659 | |
Devang Patel | f4e54a2 | 2010-05-07 23:05:55 +0000 | [diff] [blame] | 1660 | // If there is not any debug info for type then do not emit debug info |
| 1661 | // for this variable. |
| 1662 | if (!Ty) |
| 1663 | return; |
| 1664 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1665 | // Get location information. |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1666 | unsigned Line = getLineNumber(VD->getLocation()); |
| 1667 | unsigned Column = getColumnNumber(VD->getLocation()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1668 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1669 | // Create the descriptor for the variable. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1670 | llvm::DIVariable D = |
Devang Patel | 8fae060 | 2009-11-13 19:10:24 +0000 | [diff] [blame] | 1671 | DebugFactory.CreateVariable(Tag, llvm::DIDescriptor(RegionStack.back()), |
Devang Patel | 239cec6 | 2010-02-01 21:39:52 +0000 | [diff] [blame] | 1672 | VD->getName(), |
Devang Patel | 44eeeba | 2010-06-05 01:14:40 +0000 | [diff] [blame] | 1673 | Unit, Line, Ty, CGM.getLangOptions().Optimize); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1674 | // Insert an llvm.dbg.declare into the current block. |
Devang Patel | ebf16e8 | 2009-11-11 19:10:19 +0000 | [diff] [blame] | 1675 | llvm::Instruction *Call = |
Devang Patel | a020380 | 2009-11-10 23:07:24 +0000 | [diff] [blame] | 1676 | DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock()); |
Devang Patel | 23908b8 | 2009-11-12 18:21:39 +0000 | [diff] [blame] | 1677 | |
Chris Lattner | c603463 | 2010-04-01 06:31:43 +0000 | [diff] [blame] | 1678 | llvm::MDNode *Scope = RegionStack.back(); |
Chris Lattner | e541d01 | 2010-04-02 20:21:43 +0000 | [diff] [blame] | 1679 | Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope)); |
Sanjiv Gupta | cc9b163 | 2008-05-30 10:30:31 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1682 | /// EmitDeclare - Emit local variable declaration debug info. |
| 1683 | void CGDebugInfo::EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, |
| 1684 | llvm::Value *Storage, CGBuilderTy &Builder, |
| 1685 | CodeGenFunction *CGF) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1686 | const ValueDecl *VD = BDRE->getDecl(); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1687 | assert(!RegionStack.empty() && "Region stack mismatch, stack empty!"); |
| 1688 | |
Devang Patel | 2b594b9 | 2010-04-26 23:28:46 +0000 | [diff] [blame] | 1689 | if (Builder.GetInsertBlock() == 0) |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1690 | return; |
| 1691 | |
| 1692 | uint64_t XOffset = 0; |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1693 | llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); |
Devang Patel | 809b9bb | 2010-02-10 18:49:08 +0000 | [diff] [blame] | 1694 | llvm::DIType Ty; |
| 1695 | if (VD->hasAttr<BlocksAttr>()) |
| 1696 | Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset); |
| 1697 | else |
| 1698 | Ty = getOrCreateType(VD->getType(), Unit); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1699 | |
| 1700 | // Get location information. |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1701 | unsigned Line = getLineNumber(VD->getLocation()); |
| 1702 | unsigned Column = getColumnNumber(VD->getLocation()); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1703 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1704 | CharUnits offset = CGF->BlockDecls[VD]; |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1705 | llvm::SmallVector<llvm::Value *, 9> addr; |
Chris Lattner | 14b1a36 | 2010-01-25 03:29:35 +0000 | [diff] [blame] | 1706 | const llvm::Type *Int64Ty = llvm::Type::getInt64Ty(CGM.getLLVMContext()); |
| 1707 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpDeref)); |
| 1708 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpPlus)); |
| 1709 | addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity())); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1710 | if (BDRE->isByRef()) { |
Chris Lattner | 14b1a36 | 2010-01-25 03:29:35 +0000 | [diff] [blame] | 1711 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpDeref)); |
| 1712 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpPlus)); |
Ken Dyck | 199c3d6 | 2010-01-11 17:06:35 +0000 | [diff] [blame] | 1713 | // offset of __forwarding field |
| 1714 | offset = CharUnits::fromQuantity(CGF->LLVMPointerWidth/8); |
Chris Lattner | 14b1a36 | 2010-01-25 03:29:35 +0000 | [diff] [blame] | 1715 | addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity())); |
| 1716 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpDeref)); |
| 1717 | addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIFactory::OpPlus)); |
Ken Dyck | 199c3d6 | 2010-01-11 17:06:35 +0000 | [diff] [blame] | 1718 | // offset of x field |
| 1719 | offset = CharUnits::fromQuantity(XOffset/8); |
Chris Lattner | 14b1a36 | 2010-01-25 03:29:35 +0000 | [diff] [blame] | 1720 | addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity())); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | // Create the descriptor for the variable. |
| 1724 | llvm::DIVariable D = |
Chris Lattner | 165714e | 2010-01-25 03:34:56 +0000 | [diff] [blame] | 1725 | DebugFactory.CreateComplexVariable(Tag, |
| 1726 | llvm::DIDescriptor(RegionStack.back()), |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1727 | VD->getName(), Unit, Line, Ty, |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1728 | addr); |
| 1729 | // Insert an llvm.dbg.declare into the current block. |
Devang Patel | ebf16e8 | 2009-11-11 19:10:19 +0000 | [diff] [blame] | 1730 | llvm::Instruction *Call = |
Chris Lattner | 165714e | 2010-01-25 03:34:56 +0000 | [diff] [blame] | 1731 | DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock()); |
Chris Lattner | d5b8902 | 2009-12-28 21:44:41 +0000 | [diff] [blame] | 1732 | |
Chris Lattner | c603463 | 2010-04-01 06:31:43 +0000 | [diff] [blame] | 1733 | llvm::MDNode *Scope = RegionStack.back(); |
Devang Patel | f8e10a5 | 2010-05-10 23:48:38 +0000 | [diff] [blame] | 1734 | Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope)); |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1737 | void CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *VD, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1738 | llvm::Value *Storage, |
| 1739 | CGBuilderTy &Builder) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1740 | EmitDeclare(VD, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
Mike Stump | b1a6e68 | 2009-09-30 02:43:10 +0000 | [diff] [blame] | 1743 | void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable( |
| 1744 | const BlockDeclRefExpr *BDRE, llvm::Value *Storage, CGBuilderTy &Builder, |
| 1745 | CodeGenFunction *CGF) { |
| 1746 | EmitDeclare(BDRE, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder, CGF); |
| 1747 | } |
| 1748 | |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1749 | /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument |
| 1750 | /// variable declaration. |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1751 | void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *VD, llvm::Value *AI, |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1752 | CGBuilderTy &Builder) { |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1753 | EmitDeclare(VD, llvm::dwarf::DW_TAG_arg_variable, AI, Builder); |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | |
| 1757 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1758 | /// EmitGlobalVariable - Emit information about a global variable. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1759 | void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 1760 | const VarDecl *D) { |
| 1761 | |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1762 | // Create global variable debug descriptor. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1763 | llvm::DIFile Unit = getOrCreateFile(D->getLocation()); |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1764 | unsigned LineNo = getLineNumber(D->getLocation()); |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 1765 | |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 1766 | QualType T = D->getType(); |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1767 | if (T->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1768 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1769 | // CodeGen turns int[] into int[1] so we'll do the same here. |
| 1770 | llvm::APSInt ConstVal(32); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1771 | |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1772 | ConstVal = 1; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1773 | QualType ET = CGM.getContext().getAsArrayType(T)->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1774 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1775 | T = CGM.getContext().getConstantArrayType(ET, ConstVal, |
Anders Carlsson | 4d6e8dd | 2008-11-26 17:40:42 +0000 | [diff] [blame] | 1776 | ArrayType::Normal, 0); |
| 1777 | } |
Devang Patel | 5d822f0 | 2010-04-29 17:48:37 +0000 | [diff] [blame] | 1778 | llvm::StringRef DeclName = D->getName(); |
Devang Patel | 8b90a78 | 2010-05-13 23:52:37 +0000 | [diff] [blame] | 1779 | llvm::StringRef LinkageName; |
Devang Patel | 0fd3d1f | 2010-05-14 16:55:25 +0000 | [diff] [blame] | 1780 | if (D->getDeclContext() && !isa<FunctionDecl>(D->getDeclContext())) |
Devang Patel | 8b90a78 | 2010-05-13 23:52:37 +0000 | [diff] [blame] | 1781 | LinkageName = Var->getName(); |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 1782 | llvm::DIDescriptor DContext = |
| 1783 | getContextDescriptor(dyn_cast<Decl>(D->getDeclContext()), Unit); |
Devang Patel | 8b90a78 | 2010-05-13 23:52:37 +0000 | [diff] [blame] | 1784 | DebugFactory.CreateGlobalVariable(DContext, DeclName, DeclName, LinkageName, |
| 1785 | Unit, LineNo, getOrCreateType(T, Unit), |
Chris Lattner | 9c85ba3 | 2008-11-10 06:08:34 +0000 | [diff] [blame] | 1786 | Var->hasInternalLinkage(), |
| 1787 | true/*definition*/, Var); |
Sanjiv Gupta | 686226b | 2008-06-05 08:59:10 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1790 | /// EmitGlobalVariable - Emit information about an objective-c interface. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1791 | void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1792 | ObjCInterfaceDecl *ID) { |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1793 | // Create global variable debug descriptor. |
Devang Patel | 1780055 | 2010-03-09 00:44:50 +0000 | [diff] [blame] | 1794 | llvm::DIFile Unit = getOrCreateFile(ID->getLocation()); |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1795 | unsigned LineNo = getLineNumber(ID->getLocation()); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1796 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1797 | llvm::StringRef Name = ID->getName(); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1798 | |
Devang Patel | d6c5a26 | 2010-02-01 21:52:22 +0000 | [diff] [blame] | 1799 | QualType T = CGM.getContext().getObjCInterfaceType(ID); |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1800 | if (T->isIncompleteArrayType()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1801 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1802 | // CodeGen turns int[] into int[1] so we'll do the same here. |
| 1803 | llvm::APSInt ConstVal(32); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1804 | |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1805 | ConstVal = 1; |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1806 | QualType ET = CGM.getContext().getAsArrayType(T)->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1807 | |
Anders Carlsson | 20f12a2 | 2009-12-06 18:00:51 +0000 | [diff] [blame] | 1808 | T = CGM.getContext().getConstantArrayType(ET, ConstVal, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1809 | ArrayType::Normal, 0); |
| 1810 | } |
| 1811 | |
Devang Patel | f6a39b7 | 2009-10-20 18:26:30 +0000 | [diff] [blame] | 1812 | DebugFactory.CreateGlobalVariable(Unit, Name, Name, Name, Unit, LineNo, |
Devang Patel | 9ca36b6 | 2009-02-26 21:10:26 +0000 | [diff] [blame] | 1813 | getOrCreateType(T, Unit), |
| 1814 | Var->hasInternalLinkage(), |
| 1815 | true/*definition*/, Var); |
| 1816 | } |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame] | 1817 | |
Devang Patel | 25c2c8f | 2010-08-10 17:53:33 +0000 | [diff] [blame] | 1818 | /// EmitGlobalVariable - Emit global variable's debug info. |
| 1819 | void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, |
| 1820 | llvm::ConstantInt *Init, |
Devang Patel | 8d30838 | 2010-08-10 07:24:25 +0000 | [diff] [blame] | 1821 | CGBuilderTy &Builder) { |
| 1822 | // Create the descriptor for the variable. |
| 1823 | llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); |
| 1824 | llvm::StringRef Name = VD->getName(); |
Devang Patel | 0317ab0 | 2010-08-10 18:27:15 +0000 | [diff] [blame] | 1825 | llvm::DIType Ty = getOrCreateType(VD->getType(), Unit); |
| 1826 | // Do not use DIGlobalVariable for enums. |
| 1827 | if (Ty.getTag() == llvm::dwarf::DW_TAG_enumeration_type) |
| 1828 | return; |
Devang Patel | 8d30838 | 2010-08-10 07:24:25 +0000 | [diff] [blame] | 1829 | DebugFactory.CreateGlobalVariable(Unit, Name, Name, Name, Unit, |
| 1830 | getLineNumber(VD->getLocation()), |
Devang Patel | 4c4acc0 | 2010-08-10 20:16:57 +0000 | [diff] [blame] | 1831 | Ty, true, true, Init); |
Devang Patel | 8d30838 | 2010-08-10 07:24:25 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame] | 1834 | /// getOrCreateNamesSpace - Return namespace descriptor for the given |
| 1835 | /// namespace decl. |
| 1836 | llvm::DINameSpace |
| 1837 | CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl, |
| 1838 | llvm::DIDescriptor Unit) { |
| 1839 | llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH>::iterator I = |
| 1840 | NameSpaceCache.find(NSDecl); |
| 1841 | if (I != NameSpaceCache.end()) |
| 1842 | return llvm::DINameSpace(cast<llvm::MDNode>(I->second)); |
| 1843 | |
Devang Patel | 8ab870d | 2010-05-12 23:46:38 +0000 | [diff] [blame] | 1844 | unsigned LineNo = getLineNumber(NSDecl->getLocation()); |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame] | 1845 | |
| 1846 | llvm::DIDescriptor Context = |
Devang Patel | eb6d79b | 2010-02-01 21:34:11 +0000 | [diff] [blame] | 1847 | getContextDescriptor(dyn_cast<Decl>(NSDecl->getDeclContext()), Unit); |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame] | 1848 | llvm::DINameSpace NS = |
| 1849 | DebugFactory.CreateNameSpace(Context, NSDecl->getName(), |
Devang Patel | ab69979 | 2010-05-07 18:12:35 +0000 | [diff] [blame] | 1850 | llvm::DIFile(Unit), LineNo); |
| 1851 | NameSpaceCache[NSDecl] = llvm::WeakVH(NS); |
Devang Patel | abb485f | 2010-02-01 19:16:32 +0000 | [diff] [blame] | 1852 | return NS; |
| 1853 | } |