2012-12-18 22:30:41 +08:00
|
|
|
//===--- CGDebugInfo.cpp - Emit Debug Information for a Module ------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This coordinates the debug information generation while generating code.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CGDebugInfo.h"
|
|
|
|
#include "CGBlocks.h"
|
2013-05-11 05:53:14 +08:00
|
|
|
#include "CGCXXABI.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "CGObjCRuntime.h"
|
|
|
|
#include "CodeGenFunction.h"
|
|
|
|
#include "CodeGenModule.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/DeclFriend.h"
|
|
|
|
#include "clang/AST/DeclObjC.h"
|
|
|
|
#include "clang/AST/DeclTemplate.h"
|
|
|
|
#include "clang/AST/Expr.h"
|
|
|
|
#include "clang/AST/RecordLayout.h"
|
|
|
|
#include "clang/Basic/FileManager.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
|
|
|
#include "clang/Basic/Version.h"
|
|
|
|
#include "clang/Frontend/CodeGenOptions.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2013-01-02 19:45:17 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/Intrinsics.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
|
|
|
#include "llvm/Support/FileSystem.h"
|
2013-12-19 05:48:18 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
using namespace clang;
|
|
|
|
using namespace clang::CodeGen;
|
|
|
|
|
|
|
|
CGDebugInfo::CGDebugInfo(CodeGenModule &CGM)
|
2013-07-15 05:12:44 +08:00
|
|
|
: CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
|
|
|
|
DBuilder(CGM.getModule()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
CreateCompileUnit();
|
|
|
|
}
|
|
|
|
|
|
|
|
CGDebugInfo::~CGDebugInfo() {
|
|
|
|
assert(LexicalBlockStack.empty() &&
|
|
|
|
"Region stack mismatch, stack not empty!");
|
|
|
|
}
|
|
|
|
|
2014-02-26 10:49:36 +08:00
|
|
|
SaveAndRestoreLocation::SaveAndRestoreLocation(CodeGenFunction &CGF,
|
|
|
|
CGBuilderTy &B)
|
|
|
|
: DI(CGF.getDebugInfo()), Builder(B) {
|
2013-07-18 08:28:02 +08:00
|
|
|
if (DI) {
|
|
|
|
SavedLoc = DI->getLocation();
|
|
|
|
DI->CurLoc = SourceLocation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-17 08:15:10 +08:00
|
|
|
SaveAndRestoreLocation::~SaveAndRestoreLocation() {
|
|
|
|
if (DI)
|
|
|
|
DI->EmitLocation(Builder, SavedLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
NoLocation::NoLocation(CodeGenFunction &CGF, CGBuilderTy &B)
|
|
|
|
: SaveAndRestoreLocation(CGF, B) {
|
|
|
|
if (DI)
|
|
|
|
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
|
|
|
|
}
|
|
|
|
|
2013-07-18 08:28:02 +08:00
|
|
|
NoLocation::~NoLocation() {
|
2014-01-17 08:15:10 +08:00
|
|
|
if (DI)
|
2013-07-18 08:28:02 +08:00
|
|
|
assert(Builder.getCurrentDebugLocation().isUnknown());
|
|
|
|
}
|
|
|
|
|
2013-07-18 09:36:04 +08:00
|
|
|
ArtificialLocation::ArtificialLocation(CodeGenFunction &CGF, CGBuilderTy &B)
|
2014-01-17 08:15:10 +08:00
|
|
|
: SaveAndRestoreLocation(CGF, B) {
|
|
|
|
if (DI)
|
2013-07-25 04:34:39 +08:00
|
|
|
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ArtificialLocation::Emit() {
|
|
|
|
if (DI) {
|
2013-07-18 08:28:02 +08:00
|
|
|
// Sync the Builder.
|
|
|
|
DI->EmitLocation(Builder, SavedLoc);
|
|
|
|
DI->CurLoc = SourceLocation();
|
|
|
|
// Construct a location that has a valid scope, but no line info.
|
2013-07-25 04:34:39 +08:00
|
|
|
assert(!DI->LexicalBlockStack.empty());
|
|
|
|
llvm::DIDescriptor Scope(DI->LexicalBlockStack.back());
|
2013-07-18 08:28:02 +08:00
|
|
|
Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(0, 0, Scope));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 09:36:04 +08:00
|
|
|
ArtificialLocation::~ArtificialLocation() {
|
2014-01-17 08:15:10 +08:00
|
|
|
if (DI)
|
2013-07-18 08:28:02 +08:00
|
|
|
assert(Builder.getCurrentDebugLocation().getLine() == 0);
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void CGDebugInfo::setLocation(SourceLocation Loc) {
|
|
|
|
// If the new location isn't valid return.
|
2013-07-18 08:27:56 +08:00
|
|
|
if (Loc.isInvalid()) return;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
CurLoc = CGM.getContext().getSourceManager().getExpansionLoc(Loc);
|
|
|
|
|
|
|
|
// If we've changed files in the middle of a lexical scope go ahead
|
|
|
|
// and create a new lexical scope with file node if it's different
|
|
|
|
// from the one in the scope.
|
|
|
|
if (LexicalBlockStack.empty()) return;
|
|
|
|
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
2014-05-14 08:29:00 +08:00
|
|
|
llvm::DIScope Scope(LexicalBlockStack.back());
|
2012-12-18 22:30:41 +08:00
|
|
|
PresumedLoc PCLoc = SM.getPresumedLoc(CurLoc);
|
|
|
|
|
2014-05-14 08:29:00 +08:00
|
|
|
if (PCLoc.isInvalid() || Scope.getFilename() == PCLoc.getFilename())
|
2012-12-18 22:30:41 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (Scope.isLexicalBlockFile()) {
|
2014-05-14 08:29:00 +08:00
|
|
|
llvm::DILexicalBlockFile LBF = llvm::DILexicalBlockFile(Scope);
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIDescriptor D
|
|
|
|
= DBuilder.createLexicalBlockFile(LBF.getScope(),
|
|
|
|
getOrCreateFile(CurLoc));
|
|
|
|
llvm::MDNode *N = D;
|
|
|
|
LexicalBlockStack.pop_back();
|
|
|
|
LexicalBlockStack.push_back(N);
|
2013-01-27 06:16:26 +08:00
|
|
|
} else if (Scope.isLexicalBlock() || Scope.isSubprogram()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIDescriptor D
|
|
|
|
= DBuilder.createLexicalBlockFile(Scope, getOrCreateFile(CurLoc));
|
|
|
|
llvm::MDNode *N = D;
|
|
|
|
LexicalBlockStack.pop_back();
|
|
|
|
LexicalBlockStack.push_back(N);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getContextDescriptor - Get context info for the decl.
|
2013-04-19 14:56:38 +08:00
|
|
|
llvm::DIScope CGDebugInfo::getContextDescriptor(const Decl *Context) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!Context)
|
|
|
|
return TheCU;
|
|
|
|
|
|
|
|
llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator
|
|
|
|
I = RegionMap.find(Context);
|
|
|
|
if (I != RegionMap.end()) {
|
|
|
|
llvm::Value *V = I->second;
|
2013-04-19 14:56:38 +08:00
|
|
|
return llvm::DIScope(dyn_cast_or_null<llvm::MDNode>(V));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check namespace.
|
|
|
|
if (const NamespaceDecl *NSDecl = dyn_cast<NamespaceDecl>(Context))
|
2013-04-19 14:56:38 +08:00
|
|
|
return getOrCreateNameSpace(NSDecl);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-04-19 14:56:38 +08:00
|
|
|
if (const RecordDecl *RDecl = dyn_cast<RecordDecl>(Context))
|
|
|
|
if (!RDecl->isDependentType())
|
|
|
|
return getOrCreateType(CGM.getContext().getTypeDeclType(RDecl),
|
2012-12-18 22:30:41 +08:00
|
|
|
getOrCreateMainFile());
|
|
|
|
return TheCU;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getFunctionName - Get function name for the given FunctionDecl. If the
|
2013-09-09 22:48:42 +08:00
|
|
|
/// name is constructed on demand (e.g. C++ destructor) then the name
|
2012-12-18 22:30:41 +08:00
|
|
|
/// is stored on the side.
|
|
|
|
StringRef CGDebugInfo::getFunctionName(const FunctionDecl *FD) {
|
|
|
|
assert (FD && "Invalid FunctionDecl!");
|
|
|
|
IdentifierInfo *FII = FD->getIdentifier();
|
|
|
|
FunctionTemplateSpecializationInfo *Info
|
|
|
|
= FD->getTemplateSpecializationInfo();
|
|
|
|
if (!Info && FII)
|
|
|
|
return FII->getName();
|
|
|
|
|
|
|
|
// Otherwise construct human readable name for debug info.
|
2013-02-22 23:46:01 +08:00
|
|
|
SmallString<128> NS;
|
|
|
|
llvm::raw_svector_ostream OS(NS);
|
|
|
|
FD->printName(OS);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Add any template specialization args.
|
|
|
|
if (Info) {
|
|
|
|
const TemplateArgumentList *TArgs = Info->TemplateArguments;
|
|
|
|
const TemplateArgument *Args = TArgs->data();
|
|
|
|
unsigned NumArgs = TArgs->size();
|
|
|
|
PrintingPolicy Policy(CGM.getLangOpts());
|
2013-02-22 23:46:01 +08:00
|
|
|
TemplateSpecializationType::PrintTemplateArgumentList(OS, Args, NumArgs,
|
|
|
|
Policy);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy this name on the side and use its reference.
|
2013-09-10 00:39:06 +08:00
|
|
|
return internString(OS.str());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StringRef CGDebugInfo::getObjCMethodName(const ObjCMethodDecl *OMD) {
|
|
|
|
SmallString<256> MethodName;
|
|
|
|
llvm::raw_svector_ostream OS(MethodName);
|
|
|
|
OS << (OMD->isInstanceMethod() ? '-' : '+') << '[';
|
|
|
|
const DeclContext *DC = OMD->getDeclContext();
|
2013-05-16 08:45:12 +08:00
|
|
|
if (const ObjCImplementationDecl *OID =
|
2012-12-18 22:30:41 +08:00
|
|
|
dyn_cast<const ObjCImplementationDecl>(DC)) {
|
|
|
|
OS << OID->getName();
|
2013-05-16 08:45:12 +08:00
|
|
|
} else if (const ObjCInterfaceDecl *OID =
|
2012-12-18 22:30:41 +08:00
|
|
|
dyn_cast<const ObjCInterfaceDecl>(DC)) {
|
|
|
|
OS << OID->getName();
|
2013-05-16 08:45:12 +08:00
|
|
|
} else if (const ObjCCategoryImplDecl *OCD =
|
2012-12-18 22:30:41 +08:00
|
|
|
dyn_cast<const ObjCCategoryImplDecl>(DC)){
|
|
|
|
OS << ((const NamedDecl *)OCD)->getIdentifier()->getNameStart() << '(' <<
|
|
|
|
OCD->getIdentifier()->getNameStart() << ')';
|
2013-05-18 07:58:45 +08:00
|
|
|
} else if (isa<ObjCProtocolDecl>(DC)) {
|
2013-05-18 07:49:10 +08:00
|
|
|
// We can extract the type of the class from the self pointer.
|
|
|
|
if (ImplicitParamDecl* SelfDecl = OMD->getSelfDecl()) {
|
|
|
|
QualType ClassTy =
|
|
|
|
cast<ObjCObjectPointerType>(SelfDecl->getType())->getPointeeType();
|
|
|
|
ClassTy.print(OS, PrintingPolicy(LangOptions()));
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
OS << ' ' << OMD->getSelector().getAsString() << ']';
|
|
|
|
|
2013-09-10 00:39:06 +08:00
|
|
|
return internString(OS.str());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getSelectorName - Return selector name. This is used for debugging
|
|
|
|
/// info.
|
|
|
|
StringRef CGDebugInfo::getSelectorName(Selector S) {
|
2013-09-10 00:39:06 +08:00
|
|
|
return internString(S.getAsString());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getClassName - Get class name including template argument list.
|
2013-05-16 08:45:12 +08:00
|
|
|
StringRef
|
2012-12-18 22:30:41 +08:00
|
|
|
CGDebugInfo::getClassName(const RecordDecl *RD) {
|
2014-04-03 02:21:09 +08:00
|
|
|
// quick optimization to avoid having to intern strings that are already
|
|
|
|
// stored reliably elsewhere
|
|
|
|
if (!isa<ClassTemplateSpecializationDecl>(RD))
|
2012-12-18 22:30:41 +08:00
|
|
|
return RD->getName();
|
|
|
|
|
2014-04-03 02:21:09 +08:00
|
|
|
SmallString<128> Name;
|
2013-02-22 23:46:01 +08:00
|
|
|
{
|
2014-04-03 02:21:09 +08:00
|
|
|
llvm::raw_svector_ostream OS(Name);
|
|
|
|
RD->getNameForDiagnostic(OS, CGM.getContext().getPrintingPolicy(),
|
|
|
|
/*Qualified*/ false);
|
2013-02-22 23:46:01 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Copy this name on the side and use its reference.
|
2014-04-03 02:21:09 +08:00
|
|
|
return internString(Name);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getOrCreateFile - Get the file debug info descriptor for the input location.
|
|
|
|
llvm::DIFile CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
|
|
|
|
if (!Loc.isValid())
|
|
|
|
// If Location is not valid then use main input file.
|
|
|
|
return DBuilder.createFile(TheCU.getFilename(), TheCU.getDirectory());
|
|
|
|
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
|
|
|
PresumedLoc PLoc = SM.getPresumedLoc(Loc);
|
|
|
|
|
|
|
|
if (PLoc.isInvalid() || StringRef(PLoc.getFilename()).empty())
|
|
|
|
// If the location is not valid then use main input file.
|
|
|
|
return DBuilder.createFile(TheCU.getFilename(), TheCU.getDirectory());
|
|
|
|
|
|
|
|
// Cache the results.
|
|
|
|
const char *fname = PLoc.getFilename();
|
|
|
|
llvm::DenseMap<const char *, llvm::WeakVH>::iterator it =
|
|
|
|
DIFileCache.find(fname);
|
|
|
|
|
|
|
|
if (it != DIFileCache.end()) {
|
|
|
|
// Verify that the information still exists.
|
|
|
|
if (llvm::Value *V = it->second)
|
|
|
|
return llvm::DIFile(cast<llvm::MDNode>(V));
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIFile F = DBuilder.createFile(PLoc.getFilename(), getCurrentDirname());
|
|
|
|
|
|
|
|
DIFileCache[fname] = F;
|
|
|
|
return F;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getOrCreateMainFile - Get the file info for main compile unit.
|
|
|
|
llvm::DIFile CGDebugInfo::getOrCreateMainFile() {
|
|
|
|
return DBuilder.createFile(TheCU.getFilename(), TheCU.getDirectory());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getLineNumber - Get line number for the location. If location is invalid
|
|
|
|
/// then use current location.
|
|
|
|
unsigned CGDebugInfo::getLineNumber(SourceLocation Loc) {
|
|
|
|
if (Loc.isInvalid() && CurLoc.isInvalid())
|
|
|
|
return 0;
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
|
|
|
PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc);
|
|
|
|
return PLoc.isValid()? PLoc.getLine() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getColumnNumber - Get column number for the location.
|
2013-03-13 04:43:25 +08:00
|
|
|
unsigned CGDebugInfo::getColumnNumber(SourceLocation Loc, bool Force) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// We may not want column information at all.
|
2013-03-13 04:43:25 +08:00
|
|
|
if (!Force && !CGM.getCodeGenOpts().DebugColumnInfo)
|
2012-12-18 22:30:41 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// If the location is invalid then use the current column.
|
|
|
|
if (Loc.isInvalid() && CurLoc.isInvalid())
|
|
|
|
return 0;
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
|
|
|
PresumedLoc PLoc = SM.getPresumedLoc(Loc.isValid() ? Loc : CurLoc);
|
|
|
|
return PLoc.isValid()? PLoc.getColumn() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef CGDebugInfo::getCurrentDirname() {
|
|
|
|
if (!CGM.getCodeGenOpts().DebugCompilationDir.empty())
|
|
|
|
return CGM.getCodeGenOpts().DebugCompilationDir;
|
|
|
|
|
|
|
|
if (!CWDName.empty())
|
|
|
|
return CWDName;
|
|
|
|
SmallString<256> CWD;
|
|
|
|
llvm::sys::fs::current_path(CWD);
|
2013-09-10 00:39:06 +08:00
|
|
|
return CWDName = internString(CWD);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// CreateCompileUnit - Create new compile unit.
|
|
|
|
void CGDebugInfo::CreateCompileUnit() {
|
|
|
|
|
2014-05-14 08:29:00 +08:00
|
|
|
// Should we be asking the SourceManager for the main file name, instead of
|
|
|
|
// accepting it as an argument? This just causes the main file name to
|
|
|
|
// mismatch with source locations and create extra lexical scopes or
|
|
|
|
// mismatched debug info (a CU with a DW_AT_file of "-", because that's what
|
|
|
|
// the driver passed, but functions/other things have DW_AT_file of "<stdin>"
|
|
|
|
// because that's what the SourceManager says)
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Get absolute path name.
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
|
|
|
std::string MainFileName = CGM.getCodeGenOpts().MainFileName;
|
|
|
|
if (MainFileName.empty())
|
2014-05-14 08:29:00 +08:00
|
|
|
MainFileName = "<stdin>";
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// The main file name provided via the "-main-file-name" option contains just
|
|
|
|
// the file name itself with no path information. This file name may have had
|
|
|
|
// a relative path, so we look into the actual file entry for the main
|
|
|
|
// file to determine the real absolute path for the file.
|
|
|
|
std::string MainFileDir;
|
|
|
|
if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
|
|
|
|
MainFileDir = MainFile->getDir()->getName();
|
2013-10-22 04:07:37 +08:00
|
|
|
if (MainFileDir != ".") {
|
2014-02-26 10:49:36 +08:00
|
|
|
llvm::SmallString<1024> MainFileDirSS(MainFileDir);
|
|
|
|
llvm::sys::path::append(MainFileDirSS, MainFileName);
|
|
|
|
MainFileName = MainFileDirSS.str();
|
2013-10-22 04:07:37 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save filename string.
|
2013-09-10 00:39:06 +08:00
|
|
|
StringRef Filename = internString(MainFileName);
|
2013-02-23 07:50:16 +08:00
|
|
|
|
|
|
|
// Save split dwarf file string.
|
|
|
|
std::string SplitDwarfFile = CGM.getCodeGenOpts().SplitDwarfFile;
|
2013-09-10 00:39:06 +08:00
|
|
|
StringRef SplitDwarfFilename = internString(SplitDwarfFile);
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2014-05-07 20:49:30 +08:00
|
|
|
llvm::dwarf::SourceLanguage LangTag;
|
2012-12-18 22:30:41 +08:00
|
|
|
const LangOptions &LO = CGM.getLangOpts();
|
|
|
|
if (LO.CPlusPlus) {
|
|
|
|
if (LO.ObjC1)
|
|
|
|
LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
|
|
|
|
else
|
|
|
|
LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
|
|
|
|
} else if (LO.ObjC1) {
|
|
|
|
LangTag = llvm::dwarf::DW_LANG_ObjC;
|
|
|
|
} else if (LO.C99) {
|
|
|
|
LangTag = llvm::dwarf::DW_LANG_C99;
|
|
|
|
} else {
|
|
|
|
LangTag = llvm::dwarf::DW_LANG_C89;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Producer = getClangFullVersion();
|
|
|
|
|
|
|
|
// Figure out which version of the ObjC runtime we have.
|
|
|
|
unsigned RuntimeVers = 0;
|
|
|
|
if (LO.ObjC1)
|
|
|
|
RuntimeVers = LO.ObjCRuntime.isNonFragile() ? 2 : 1;
|
|
|
|
|
|
|
|
// Create new compile unit.
|
|
|
|
// FIXME - Eliminate TheCU.
|
2014-02-27 09:25:08 +08:00
|
|
|
TheCU = DBuilder.createCompileUnit(
|
|
|
|
LangTag, Filename, getCurrentDirname(), Producer, LO.Optimize,
|
|
|
|
CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers, SplitDwarfFilename,
|
2014-06-25 01:02:17 +08:00
|
|
|
DebugKind <= CodeGenOptions::DebugLineTablesOnly
|
2014-02-27 09:25:08 +08:00
|
|
|
? llvm::DIBuilder::LineTablesOnly
|
2014-06-25 01:02:17 +08:00
|
|
|
: llvm::DIBuilder::FullDebug,
|
|
|
|
DebugKind != CodeGenOptions::LocTrackingOnly);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// CreateType - Get the Basic type from the cache or create a new
|
|
|
|
/// one if necessary.
|
|
|
|
llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT) {
|
2014-05-07 20:49:30 +08:00
|
|
|
llvm::dwarf::TypeKind Encoding;
|
2012-12-18 22:30:41 +08:00
|
|
|
StringRef BTName;
|
|
|
|
switch (BT->getKind()) {
|
|
|
|
#define BUILTIN_TYPE(Id, SingletonId)
|
|
|
|
#define PLACEHOLDER_TYPE(Id, SingletonId) \
|
|
|
|
case BuiltinType::Id:
|
|
|
|
#include "clang/AST/BuiltinTypes.def"
|
|
|
|
case BuiltinType::Dependent:
|
|
|
|
llvm_unreachable("Unexpected builtin type");
|
|
|
|
case BuiltinType::NullPtr:
|
2013-06-28 06:51:01 +08:00
|
|
|
return DBuilder.createNullPtrType();
|
2012-12-18 22:30:41 +08:00
|
|
|
case BuiltinType::Void:
|
|
|
|
return llvm::DIType();
|
|
|
|
case BuiltinType::ObjCClass:
|
2014-05-06 11:42:01 +08:00
|
|
|
if (!ClassTy)
|
|
|
|
ClassTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
|
|
|
|
"objc_class", TheCU,
|
|
|
|
getOrCreateMainFile(), 0);
|
2012-12-18 22:30:41 +08:00
|
|
|
return ClassTy;
|
|
|
|
case BuiltinType::ObjCId: {
|
|
|
|
// typedef struct objc_class *Class;
|
|
|
|
// typedef struct objc_object {
|
|
|
|
// Class isa;
|
|
|
|
// } *id;
|
|
|
|
|
2013-07-18 08:52:50 +08:00
|
|
|
if (ObjTy)
|
2012-12-18 22:30:41 +08:00
|
|
|
return ObjTy;
|
|
|
|
|
2013-07-18 08:52:50 +08:00
|
|
|
if (!ClassTy)
|
2012-12-18 22:30:41 +08:00
|
|
|
ClassTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
|
|
|
|
"objc_class", TheCU,
|
|
|
|
getOrCreateMainFile(), 0);
|
|
|
|
|
|
|
|
unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIType ISATy = DBuilder.createPointerType(ClassTy, Size);
|
|
|
|
|
2013-04-03 06:59:11 +08:00
|
|
|
ObjTy =
|
2013-02-25 09:07:08 +08:00
|
|
|
DBuilder.createStructType(TheCU, "objc_object", getOrCreateMainFile(),
|
|
|
|
0, 0, 0, 0, llvm::DIType(), llvm::DIArray());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-07-29 03:14:41 +08:00
|
|
|
ObjTy.setArrays(DBuilder.getOrCreateArray(&*DBuilder.createMemberType(
|
2013-04-03 06:59:11 +08:00
|
|
|
ObjTy, "isa", getOrCreateMainFile(), 0, Size, 0, 0, 0, ISATy)));
|
2012-12-18 22:30:41 +08:00
|
|
|
return ObjTy;
|
|
|
|
}
|
|
|
|
case BuiltinType::ObjCSel: {
|
2014-05-06 11:42:01 +08:00
|
|
|
if (!SelTy)
|
|
|
|
SelTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
|
|
|
|
"objc_selector", TheCU,
|
|
|
|
getOrCreateMainFile(), 0);
|
2012-12-18 22:30:41 +08:00
|
|
|
return SelTy;
|
|
|
|
}
|
2012-12-18 22:38:23 +08:00
|
|
|
|
|
|
|
case BuiltinType::OCLImage1d:
|
|
|
|
return getOrCreateStructPtrType("opencl_image1d_t",
|
|
|
|
OCLImage1dDITy);
|
|
|
|
case BuiltinType::OCLImage1dArray:
|
2013-05-16 08:45:12 +08:00
|
|
|
return getOrCreateStructPtrType("opencl_image1d_array_t",
|
2012-12-18 22:38:23 +08:00
|
|
|
OCLImage1dArrayDITy);
|
|
|
|
case BuiltinType::OCLImage1dBuffer:
|
|
|
|
return getOrCreateStructPtrType("opencl_image1d_buffer_t",
|
|
|
|
OCLImage1dBufferDITy);
|
|
|
|
case BuiltinType::OCLImage2d:
|
|
|
|
return getOrCreateStructPtrType("opencl_image2d_t",
|
|
|
|
OCLImage2dDITy);
|
|
|
|
case BuiltinType::OCLImage2dArray:
|
|
|
|
return getOrCreateStructPtrType("opencl_image2d_array_t",
|
|
|
|
OCLImage2dArrayDITy);
|
|
|
|
case BuiltinType::OCLImage3d:
|
|
|
|
return getOrCreateStructPtrType("opencl_image3d_t",
|
|
|
|
OCLImage3dDITy);
|
2013-02-07 18:55:47 +08:00
|
|
|
case BuiltinType::OCLSampler:
|
|
|
|
return DBuilder.createBasicType("opencl_sampler_t",
|
|
|
|
CGM.getContext().getTypeSize(BT),
|
|
|
|
CGM.getContext().getTypeAlign(BT),
|
|
|
|
llvm::dwarf::DW_ATE_unsigned);
|
2013-01-20 20:31:11 +08:00
|
|
|
case BuiltinType::OCLEvent:
|
|
|
|
return getOrCreateStructPtrType("opencl_event_t",
|
|
|
|
OCLEventDITy);
|
2012-12-18 22:38:23 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case BuiltinType::UChar:
|
|
|
|
case BuiltinType::Char_U: Encoding = llvm::dwarf::DW_ATE_unsigned_char; break;
|
|
|
|
case BuiltinType::Char_S:
|
|
|
|
case BuiltinType::SChar: Encoding = llvm::dwarf::DW_ATE_signed_char; break;
|
|
|
|
case BuiltinType::Char16:
|
|
|
|
case BuiltinType::Char32: Encoding = llvm::dwarf::DW_ATE_UTF; break;
|
|
|
|
case BuiltinType::UShort:
|
|
|
|
case BuiltinType::UInt:
|
|
|
|
case BuiltinType::UInt128:
|
|
|
|
case BuiltinType::ULong:
|
|
|
|
case BuiltinType::WChar_U:
|
|
|
|
case BuiltinType::ULongLong: Encoding = llvm::dwarf::DW_ATE_unsigned; break;
|
|
|
|
case BuiltinType::Short:
|
|
|
|
case BuiltinType::Int:
|
|
|
|
case BuiltinType::Int128:
|
|
|
|
case BuiltinType::Long:
|
|
|
|
case BuiltinType::WChar_S:
|
|
|
|
case BuiltinType::LongLong: Encoding = llvm::dwarf::DW_ATE_signed; break;
|
|
|
|
case BuiltinType::Bool: Encoding = llvm::dwarf::DW_ATE_boolean; break;
|
|
|
|
case BuiltinType::Half:
|
|
|
|
case BuiltinType::Float:
|
|
|
|
case BuiltinType::LongDouble:
|
|
|
|
case BuiltinType::Double: Encoding = llvm::dwarf::DW_ATE_float; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (BT->getKind()) {
|
|
|
|
case BuiltinType::Long: BTName = "long int"; break;
|
|
|
|
case BuiltinType::LongLong: BTName = "long long int"; break;
|
|
|
|
case BuiltinType::ULong: BTName = "long unsigned int"; break;
|
|
|
|
case BuiltinType::ULongLong: BTName = "long long unsigned int"; break;
|
|
|
|
default:
|
|
|
|
BTName = BT->getName(CGM.getLangOpts());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Bit size, align and offset of the type.
|
|
|
|
uint64_t Size = CGM.getContext().getTypeSize(BT);
|
|
|
|
uint64_t Align = CGM.getContext().getTypeAlign(BT);
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DIType DbgTy =
|
2012-12-18 22:30:41 +08:00
|
|
|
DBuilder.createBasicType(BTName, Size, Align, Encoding);
|
|
|
|
return DbgTy;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIType CGDebugInfo::CreateType(const ComplexType *Ty) {
|
|
|
|
// Bit size, align and offset of the type.
|
2014-05-07 20:49:30 +08:00
|
|
|
llvm::dwarf::TypeKind Encoding = llvm::dwarf::DW_ATE_complex_float;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Ty->isComplexIntegerType())
|
|
|
|
Encoding = llvm::dwarf::DW_ATE_lo_user;
|
|
|
|
|
|
|
|
uint64_t Size = CGM.getContext().getTypeSize(Ty);
|
|
|
|
uint64_t Align = CGM.getContext().getTypeAlign(Ty);
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DIType DbgTy =
|
2012-12-18 22:30:41 +08:00
|
|
|
DBuilder.createBasicType("complex", Size, Align, Encoding);
|
|
|
|
|
|
|
|
return DbgTy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CreateCVRType - Get the qualified type from the cache or create
|
|
|
|
/// a new one if necessary.
|
2013-09-05 06:03:57 +08:00
|
|
|
llvm::DIType CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DIFile Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
QualifierCollector Qc;
|
|
|
|
const Type *T = Qc.strip(Ty);
|
|
|
|
|
|
|
|
// Ignore these qualifiers for now.
|
|
|
|
Qc.removeObjCGCAttr();
|
|
|
|
Qc.removeAddressSpace();
|
|
|
|
Qc.removeObjCLifetime();
|
|
|
|
|
|
|
|
// We will create one Derived type for one qualifier and recurse to handle any
|
|
|
|
// additional ones.
|
2014-05-07 20:49:30 +08:00
|
|
|
llvm::dwarf::Tag Tag;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Qc.hasConst()) {
|
|
|
|
Tag = llvm::dwarf::DW_TAG_const_type;
|
|
|
|
Qc.removeConst();
|
|
|
|
} else if (Qc.hasVolatile()) {
|
|
|
|
Tag = llvm::dwarf::DW_TAG_volatile_type;
|
|
|
|
Qc.removeVolatile();
|
|
|
|
} else if (Qc.hasRestrict()) {
|
|
|
|
Tag = llvm::dwarf::DW_TAG_restrict_type;
|
|
|
|
Qc.removeRestrict();
|
|
|
|
} else {
|
|
|
|
assert(Qc.empty() && "Unknown type qualifier for debug info");
|
|
|
|
return getOrCreateType(QualType(T, 0), Unit);
|
|
|
|
}
|
|
|
|
|
2013-09-05 06:03:57 +08:00
|
|
|
llvm::DIType FromTy = getOrCreateType(Qc.apply(CGM.getContext(), T), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// No need to fill in the Name, Line, Size, Alignment, Offset in case of
|
|
|
|
// CVR derived types.
|
|
|
|
llvm::DIType DbgTy = DBuilder.createQualifiedType(Tag, FromTy);
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
return DbgTy;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIType CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty,
|
|
|
|
llvm::DIFile Unit) {
|
2013-02-22 04:42:11 +08:00
|
|
|
|
|
|
|
// The frontend treats 'id' as a typedef to an ObjCObjectType,
|
|
|
|
// whereas 'id<protocol>' is treated as an ObjCPointerType. For the
|
|
|
|
// debug info, we want to emit 'id' in both cases.
|
|
|
|
if (Ty->isObjCQualifiedIdType())
|
|
|
|
return getOrCreateType(CGM.getContext().getObjCIdType(), Unit);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIType DbgTy =
|
2013-05-16 08:45:12 +08:00
|
|
|
CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
|
2012-12-18 22:30:41 +08:00
|
|
|
Ty->getPointeeType(), Unit);
|
|
|
|
return DbgTy;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty,
|
|
|
|
llvm::DIFile Unit) {
|
2013-05-16 08:45:12 +08:00
|
|
|
return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
|
2012-12-18 22:30:41 +08:00
|
|
|
Ty->getPointeeType(), Unit);
|
|
|
|
}
|
|
|
|
|
2013-08-30 07:19:58 +08:00
|
|
|
/// In C++ mode, types have linkage, so we can rely on the ODR and
|
|
|
|
/// on their mangled names, if they're external.
|
|
|
|
static SmallString<256>
|
|
|
|
getUniqueTagTypeName(const TagType *Ty, CodeGenModule &CGM,
|
|
|
|
llvm::DICompileUnit TheCU) {
|
|
|
|
SmallString<256> FullName;
|
|
|
|
// FIXME: ODR should apply to ObjC++ exactly the same wasy it does to C++.
|
|
|
|
// For now, only apply ODR with C++.
|
|
|
|
const TagDecl *TD = Ty->getDecl();
|
|
|
|
if (TheCU.getLanguage() != llvm::dwarf::DW_LANG_C_plus_plus ||
|
|
|
|
!TD->isExternallyVisible())
|
|
|
|
return FullName;
|
|
|
|
// Microsoft Mangler does not have support for mangleCXXRTTIName yet.
|
|
|
|
if (CGM.getTarget().getCXXABI().isMicrosoft())
|
|
|
|
return FullName;
|
|
|
|
|
|
|
|
// TODO: This is using the RTTI name. Is there a better way to get
|
|
|
|
// a unique string for a type?
|
|
|
|
llvm::raw_svector_ostream Out(FullName);
|
|
|
|
CGM.getCXXABI().getMangleContext().mangleCXXRTTIName(QualType(Ty, 0), Out);
|
|
|
|
Out.flush();
|
|
|
|
return FullName;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Creates a forward declaration for a RecordDecl in the given context.
|
2013-08-21 05:03:29 +08:00
|
|
|
llvm::DICompositeType
|
2013-08-29 05:20:28 +08:00
|
|
|
CGDebugInfo::getOrCreateRecordFwdDecl(const RecordType *Ty,
|
2013-08-21 05:03:29 +08:00
|
|
|
llvm::DIDescriptor Ctx) {
|
2013-08-29 05:20:28 +08:00
|
|
|
const RecordDecl *RD = Ty->getDecl();
|
2013-08-16 04:17:25 +08:00
|
|
|
if (llvm::DIType T = getTypeOrNull(CGM.getContext().getRecordType(RD)))
|
2013-08-21 05:03:29 +08:00
|
|
|
return llvm::DICompositeType(T);
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation());
|
|
|
|
unsigned Line = getLineNumber(RD->getLocation());
|
|
|
|
StringRef RDName = getClassName(RD);
|
|
|
|
|
2014-05-07 20:49:30 +08:00
|
|
|
llvm::dwarf::Tag Tag;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (RD->isStruct() || RD->isInterface())
|
|
|
|
Tag = llvm::dwarf::DW_TAG_structure_type;
|
|
|
|
else if (RD->isUnion())
|
|
|
|
Tag = llvm::dwarf::DW_TAG_union_type;
|
|
|
|
else {
|
|
|
|
assert(RD->isClass());
|
|
|
|
Tag = llvm::dwarf::DW_TAG_class_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the type.
|
2013-08-30 07:19:58 +08:00
|
|
|
SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU);
|
2014-05-06 11:42:01 +08:00
|
|
|
llvm::DICompositeType RetTy = DBuilder.createReplaceableForwardDecl(
|
|
|
|
Tag, RDName, Ctx, DefUnit, Line, 0, 0, 0, FullName);
|
|
|
|
ReplaceMap.push_back(std::make_pair(Ty, static_cast<llvm::Value *>(RetTy)));
|
|
|
|
return RetTy;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-05-07 20:49:30 +08:00
|
|
|
llvm::DIType CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
|
2013-05-16 08:45:12 +08:00
|
|
|
const Type *Ty,
|
2012-12-18 22:30:41 +08:00
|
|
|
QualType PointeeTy,
|
|
|
|
llvm::DIFile Unit) {
|
|
|
|
if (Tag == llvm::dwarf::DW_TAG_reference_type ||
|
|
|
|
Tag == llvm::dwarf::DW_TAG_rvalue_reference_type)
|
2013-09-05 06:03:57 +08:00
|
|
|
return DBuilder.createReferenceType(Tag, getOrCreateType(PointeeTy, Unit));
|
2013-02-22 04:42:11 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Bit size, align and offset of the type.
|
|
|
|
// Size is always the size of a pointer. We can't use getTypeSize here
|
|
|
|
// because that does not return the correct value for references.
|
|
|
|
unsigned AS = CGM.getContext().getTargetAddressSpace(PointeeTy);
|
2013-04-17 06:48:15 +08:00
|
|
|
uint64_t Size = CGM.getTarget().getPointerWidth(AS);
|
2012-12-18 22:30:41 +08:00
|
|
|
uint64_t Align = CGM.getContext().getTypeAlign(Ty);
|
|
|
|
|
2013-09-05 06:03:57 +08:00
|
|
|
return DBuilder.createPointerType(getOrCreateType(PointeeTy, Unit), Size,
|
|
|
|
Align);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-05-16 08:52:20 +08:00
|
|
|
llvm::DIType CGDebugInfo::getOrCreateStructPtrType(StringRef Name,
|
|
|
|
llvm::DIType &Cache) {
|
2013-07-18 08:52:50 +08:00
|
|
|
if (Cache)
|
2012-12-18 22:38:23 +08:00
|
|
|
return Cache;
|
2013-05-22 01:58:54 +08:00
|
|
|
Cache = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name,
|
|
|
|
TheCU, getOrCreateMainFile(), 0);
|
|
|
|
unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
|
|
|
|
Cache = DBuilder.createPointerType(Cache, Size);
|
|
|
|
return Cache;
|
2012-12-18 22:38:23 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty,
|
|
|
|
llvm::DIFile Unit) {
|
2013-07-18 08:52:50 +08:00
|
|
|
if (BlockLiteralGeneric)
|
2012-12-18 22:30:41 +08:00
|
|
|
return BlockLiteralGeneric;
|
|
|
|
|
|
|
|
SmallVector<llvm::Value *, 8> EltTys;
|
|
|
|
llvm::DIType FieldTy;
|
|
|
|
QualType FType;
|
|
|
|
uint64_t FieldSize, FieldOffset;
|
|
|
|
unsigned FieldAlign;
|
|
|
|
llvm::DIArray Elements;
|
|
|
|
llvm::DIType EltTy, DescTy;
|
|
|
|
|
|
|
|
FieldOffset = 0;
|
|
|
|
FType = CGM.getContext().UnsignedLongTy;
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "reserved", &FieldOffset));
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "Size", &FieldOffset));
|
|
|
|
|
|
|
|
Elements = DBuilder.getOrCreateArray(EltTys);
|
|
|
|
EltTys.clear();
|
|
|
|
|
|
|
|
unsigned Flags = llvm::DIDescriptor::FlagAppleBlock;
|
|
|
|
unsigned LineNo = getLineNumber(CurLoc);
|
|
|
|
|
|
|
|
EltTy = DBuilder.createStructType(Unit, "__block_descriptor",
|
|
|
|
Unit, LineNo, FieldOffset, 0,
|
2013-02-25 09:07:08 +08:00
|
|
|
Flags, llvm::DIType(), Elements);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Bit size, align and offset of the type.
|
|
|
|
uint64_t Size = CGM.getContext().getTypeSize(Ty);
|
|
|
|
|
|
|
|
DescTy = DBuilder.createPointerType(EltTy, Size);
|
|
|
|
|
|
|
|
FieldOffset = 0;
|
|
|
|
FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
|
|
|
|
FType = CGM.getContext().IntTy;
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset));
|
|
|
|
FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
|
|
|
|
|
|
|
|
FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
|
|
|
|
FieldTy = DescTy;
|
|
|
|
FieldSize = CGM.getContext().getTypeSize(Ty);
|
|
|
|
FieldAlign = CGM.getContext().getTypeAlign(Ty);
|
|
|
|
FieldTy = DBuilder.createMemberType(Unit, "__descriptor", Unit,
|
|
|
|
LineNo, FieldSize, FieldAlign,
|
|
|
|
FieldOffset, 0, FieldTy);
|
|
|
|
EltTys.push_back(FieldTy);
|
|
|
|
|
|
|
|
FieldOffset += FieldSize;
|
|
|
|
Elements = DBuilder.getOrCreateArray(EltTys);
|
|
|
|
|
|
|
|
EltTy = DBuilder.createStructType(Unit, "__block_literal_generic",
|
|
|
|
Unit, LineNo, FieldOffset, 0,
|
2013-02-25 09:07:08 +08:00
|
|
|
Flags, llvm::DIType(), Elements);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
BlockLiteralGeneric = DBuilder.createPointerType(EltTy, Size);
|
|
|
|
return BlockLiteralGeneric;
|
|
|
|
}
|
|
|
|
|
2014-04-07 01:14:06 +08:00
|
|
|
llvm::DIType CGDebugInfo::CreateType(const TemplateSpecializationType *Ty, llvm::DIFile Unit) {
|
|
|
|
assert(Ty->isTypeAlias());
|
|
|
|
llvm::DIType Src = getOrCreateType(Ty->getAliasedType(), Unit);
|
|
|
|
|
|
|
|
SmallString<128> NS;
|
|
|
|
llvm::raw_svector_ostream OS(NS);
|
|
|
|
Ty->getTemplateName().print(OS, CGM.getContext().getPrintingPolicy(), /*qualified*/ false);
|
|
|
|
|
|
|
|
TemplateSpecializationType::PrintTemplateArgumentList(
|
|
|
|
OS, Ty->getArgs(), Ty->getNumArgs(),
|
|
|
|
CGM.getContext().getPrintingPolicy());
|
|
|
|
|
|
|
|
TypeAliasDecl *AliasDecl =
|
|
|
|
cast<TypeAliasTemplateDecl>(Ty->getTemplateName().getAsTemplateDecl())
|
|
|
|
->getTemplatedDecl();
|
|
|
|
|
|
|
|
SourceLocation Loc = AliasDecl->getLocation();
|
|
|
|
llvm::DIFile File = getOrCreateFile(Loc);
|
|
|
|
unsigned Line = getLineNumber(Loc);
|
|
|
|
|
|
|
|
llvm::DIDescriptor Ctxt = getContextDescriptor(cast<Decl>(AliasDecl->getDeclContext()));
|
|
|
|
|
|
|
|
return DBuilder.createTypedef(Src, internString(OS.str()), File, Line, Ctxt);
|
|
|
|
}
|
|
|
|
|
2013-09-05 06:03:57 +08:00
|
|
|
llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty, llvm::DIFile Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Typedefs are derived from some other type. If we have a typedef of a
|
|
|
|
// typedef, make sure to emit the whole chain.
|
2013-09-05 06:03:57 +08:00
|
|
|
llvm::DIType Src = getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
// We don't set size information, but do specify where the typedef was
|
|
|
|
// declared.
|
2014-01-22 02:42:27 +08:00
|
|
|
SourceLocation Loc = Ty->getDecl()->getLocation();
|
|
|
|
llvm::DIFile File = getOrCreateFile(Loc);
|
|
|
|
unsigned Line = getLineNumber(Loc);
|
2012-12-18 22:30:41 +08:00
|
|
|
const TypedefNameDecl *TyDecl = Ty->getDecl();
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIDescriptor TypedefContext =
|
|
|
|
getContextDescriptor(cast<Decl>(Ty->getDecl()->getDeclContext()));
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
return
|
2014-01-22 02:42:27 +08:00
|
|
|
DBuilder.createTypedef(Src, TyDecl->getName(), File, Line, TypedefContext);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty,
|
|
|
|
llvm::DIFile Unit) {
|
|
|
|
SmallVector<llvm::Value *, 16> EltTys;
|
|
|
|
|
|
|
|
// Add the result type at least.
|
2014-01-26 00:55:45 +08:00
|
|
|
EltTys.push_back(getOrCreateType(Ty->getReturnType(), Unit));
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Set up remainder of arguments if there is a prototype.
|
2014-02-26 07:42:18 +08:00
|
|
|
// otherwise emit it as a variadic function.
|
2012-12-18 22:30:41 +08:00
|
|
|
if (isa<FunctionNoProtoType>(Ty))
|
|
|
|
EltTys.push_back(DBuilder.createUnspecifiedParameter());
|
|
|
|
else if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(Ty)) {
|
2014-01-21 04:26:09 +08:00
|
|
|
for (unsigned i = 0, e = FPT->getNumParams(); i != e; ++i)
|
|
|
|
EltTys.push_back(getOrCreateType(FPT->getParamType(i), Unit));
|
2014-02-26 03:38:11 +08:00
|
|
|
if (FPT->isVariadic())
|
|
|
|
EltTys.push_back(DBuilder.createUnspecifiedParameter());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-07-29 06:24:34 +08:00
|
|
|
llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
|
2012-12-18 22:30:41 +08:00
|
|
|
return DBuilder.createSubroutineType(Unit, EltTypeArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
llvm::DIType CGDebugInfo::createFieldType(StringRef name,
|
|
|
|
QualType type,
|
|
|
|
uint64_t sizeInBitsOverride,
|
|
|
|
SourceLocation loc,
|
|
|
|
AccessSpecifier AS,
|
|
|
|
uint64_t offsetInBits,
|
|
|
|
llvm::DIFile tunit,
|
2013-09-08 11:45:05 +08:00
|
|
|
llvm::DIScope scope) {
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIType debugType = getOrCreateType(type, tunit);
|
|
|
|
|
|
|
|
// Get the location for the field.
|
|
|
|
llvm::DIFile file = getOrCreateFile(loc);
|
|
|
|
unsigned line = getLineNumber(loc);
|
|
|
|
|
2014-07-30 09:30:47 +08:00
|
|
|
uint64_t SizeInBits = 0;
|
|
|
|
unsigned AlignInBits = 0;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!type->isIncompleteArrayType()) {
|
2014-07-30 09:30:47 +08:00
|
|
|
TypeInfo TI = CGM.getContext().getTypeInfo(type);
|
|
|
|
SizeInBits = TI.Width;
|
|
|
|
AlignInBits = TI.Align;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
if (sizeInBitsOverride)
|
2014-07-30 09:30:47 +08:00
|
|
|
SizeInBits = sizeInBitsOverride;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned flags = 0;
|
|
|
|
if (AS == clang::AS_private)
|
|
|
|
flags |= llvm::DIDescriptor::FlagPrivate;
|
|
|
|
else if (AS == clang::AS_protected)
|
|
|
|
flags |= llvm::DIDescriptor::FlagProtected;
|
|
|
|
|
2014-07-30 09:30:47 +08:00
|
|
|
return DBuilder.createMemberType(scope, name, file, line, SizeInBits,
|
|
|
|
AlignInBits, offsetInBits, flags, debugType);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-01-16 09:22:32 +08:00
|
|
|
/// CollectRecordLambdaFields - Helper for CollectRecordFields.
|
|
|
|
void CGDebugInfo::
|
|
|
|
CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl,
|
|
|
|
SmallVectorImpl<llvm::Value *> &elements,
|
|
|
|
llvm::DIType RecordTy) {
|
|
|
|
// For C++11 Lambdas a Field will be the same as a Capture, but the Capture
|
|
|
|
// has the name and the location of the variable so we should iterate over
|
|
|
|
// both concurrently.
|
|
|
|
const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(CXXDecl);
|
|
|
|
RecordDecl::field_iterator Field = CXXDecl->field_begin();
|
|
|
|
unsigned fieldno = 0;
|
|
|
|
for (CXXRecordDecl::capture_const_iterator I = CXXDecl->captures_begin(),
|
|
|
|
E = CXXDecl->captures_end(); I != E; ++I, ++Field, ++fieldno) {
|
2014-05-11 00:31:55 +08:00
|
|
|
const LambdaCapture &C = *I;
|
2013-01-16 09:22:32 +08:00
|
|
|
if (C.capturesVariable()) {
|
|
|
|
VarDecl *V = C.getCapturedVar();
|
|
|
|
llvm::DIFile VUnit = getOrCreateFile(C.getLocation());
|
|
|
|
StringRef VName = V->getName();
|
|
|
|
uint64_t SizeInBitsOverride = 0;
|
|
|
|
if (Field->isBitField()) {
|
|
|
|
SizeInBitsOverride = Field->getBitWidthValue(CGM.getContext());
|
|
|
|
assert(SizeInBitsOverride && "found named 0-width bitfield");
|
|
|
|
}
|
|
|
|
llvm::DIType fieldType
|
|
|
|
= createFieldType(VName, Field->getType(), SizeInBitsOverride,
|
|
|
|
C.getLocation(), Field->getAccess(),
|
|
|
|
layout.getFieldOffset(fieldno), VUnit, RecordTy);
|
|
|
|
elements.push_back(fieldType);
|
|
|
|
} else {
|
|
|
|
// TODO: Need to handle 'this' in some way by probably renaming the
|
|
|
|
// this of the lambda class and having a field member of 'this' or
|
|
|
|
// by using AT_object_pointer for the function and having that be
|
|
|
|
// used as 'this' for semantic references.
|
|
|
|
assert(C.capturesThis() && "Field that isn't captured and isn't this?");
|
|
|
|
FieldDecl *f = *Field;
|
|
|
|
llvm::DIFile VUnit = getOrCreateFile(f->getLocation());
|
|
|
|
QualType type = f->getType();
|
|
|
|
llvm::DIType fieldType
|
|
|
|
= createFieldType("this", type, 0, f->getLocation(), f->getAccess(),
|
|
|
|
layout.getFieldOffset(fieldno), VUnit, RecordTy);
|
|
|
|
|
|
|
|
elements.push_back(fieldType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-20 09:28:15 +08:00
|
|
|
/// Helper for CollectRecordFields.
|
2013-08-16 06:50:29 +08:00
|
|
|
llvm::DIDerivedType
|
|
|
|
CGDebugInfo::CreateRecordStaticField(const VarDecl *Var,
|
|
|
|
llvm::DIType RecordTy) {
|
2013-01-16 09:22:32 +08:00
|
|
|
// Create the descriptor for the static variable, with or without
|
|
|
|
// constant initializers.
|
|
|
|
llvm::DIFile VUnit = getOrCreateFile(Var->getLocation());
|
|
|
|
llvm::DIType VTy = getOrCreateType(Var->getType(), VUnit);
|
|
|
|
|
|
|
|
unsigned LineNumber = getLineNumber(Var->getLocation());
|
|
|
|
StringRef VName = Var->getName();
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Constant *C = nullptr;
|
2013-01-16 09:22:32 +08:00
|
|
|
if (Var->getInit()) {
|
|
|
|
const APValue *Value = Var->evaluateValue();
|
2013-01-20 09:19:17 +08:00
|
|
|
if (Value) {
|
|
|
|
if (Value->isInt())
|
|
|
|
C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->getInt());
|
|
|
|
if (Value->isFloat())
|
|
|
|
C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->getFloat());
|
|
|
|
}
|
2013-01-16 09:22:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned Flags = 0;
|
|
|
|
AccessSpecifier Access = Var->getAccess();
|
|
|
|
if (Access == clang::AS_private)
|
|
|
|
Flags |= llvm::DIDescriptor::FlagPrivate;
|
|
|
|
else if (Access == clang::AS_protected)
|
|
|
|
Flags |= llvm::DIDescriptor::FlagProtected;
|
|
|
|
|
2013-08-16 06:50:29 +08:00
|
|
|
llvm::DIDerivedType GV = DBuilder.createStaticMemberType(
|
|
|
|
RecordTy, VName, VUnit, LineNumber, VTy, Flags, C);
|
2013-01-16 09:22:32 +08:00
|
|
|
StaticDataMemberCache[Var->getCanonicalDecl()] = llvm::WeakVH(GV);
|
2013-08-16 06:50:29 +08:00
|
|
|
return GV;
|
2013-01-16 09:22:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// CollectRecordNormalField - Helper for CollectRecordFields.
|
|
|
|
void CGDebugInfo::
|
|
|
|
CollectRecordNormalField(const FieldDecl *field, uint64_t OffsetInBits,
|
|
|
|
llvm::DIFile tunit,
|
|
|
|
SmallVectorImpl<llvm::Value *> &elements,
|
|
|
|
llvm::DIType RecordTy) {
|
|
|
|
StringRef name = field->getName();
|
|
|
|
QualType type = field->getType();
|
|
|
|
|
|
|
|
// Ignore unnamed fields unless they're anonymous structs/unions.
|
|
|
|
if (name.empty() && !type->isRecordType())
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint64_t SizeInBitsOverride = 0;
|
|
|
|
if (field->isBitField()) {
|
|
|
|
SizeInBitsOverride = field->getBitWidthValue(CGM.getContext());
|
|
|
|
assert(SizeInBitsOverride && "found named 0-width bitfield");
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIType fieldType
|
|
|
|
= createFieldType(name, type, SizeInBitsOverride,
|
|
|
|
field->getLocation(), field->getAccess(),
|
|
|
|
OffsetInBits, tunit, RecordTy);
|
|
|
|
|
|
|
|
elements.push_back(fieldType);
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
/// CollectRecordFields - A helper function to collect debug info for
|
|
|
|
/// record fields. This is used while creating debug info entry for a Record.
|
2013-08-17 04:40:25 +08:00
|
|
|
void CGDebugInfo::CollectRecordFields(const RecordDecl *record,
|
|
|
|
llvm::DIFile tunit,
|
|
|
|
SmallVectorImpl<llvm::Value *> &elements,
|
|
|
|
llvm::DICompositeType RecordTy) {
|
2012-12-18 22:30:41 +08:00
|
|
|
const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(record);
|
|
|
|
|
2013-01-16 09:22:32 +08:00
|
|
|
if (CXXDecl && CXXDecl->isLambda())
|
|
|
|
CollectRecordLambdaFields(CXXDecl, elements, RecordTy);
|
|
|
|
else {
|
|
|
|
const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(record);
|
|
|
|
|
|
|
|
// Field number for non-static fields.
|
2013-01-05 01:59:07 +08:00
|
|
|
unsigned fieldNo = 0;
|
2013-01-16 09:22:32 +08:00
|
|
|
|
|
|
|
// Static and non-static members should appear in the same order as
|
|
|
|
// the corresponding declarations in the source program.
|
2014-03-08 03:56:05 +08:00
|
|
|
for (const auto *I : record->decls())
|
|
|
|
if (const auto *V = dyn_cast<VarDecl>(I)) {
|
2013-08-21 05:49:21 +08:00
|
|
|
// Reuse the existing static member declaration if one exists
|
|
|
|
llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator MI =
|
|
|
|
StaticDataMemberCache.find(V->getCanonicalDecl());
|
|
|
|
if (MI != StaticDataMemberCache.end()) {
|
|
|
|
assert(MI->second &&
|
|
|
|
"Static data member declaration should still exist");
|
|
|
|
elements.push_back(
|
|
|
|
llvm::DIDerivedType(cast<llvm::MDNode>(MI->second)));
|
|
|
|
} else
|
|
|
|
elements.push_back(CreateRecordStaticField(V, RecordTy));
|
2014-03-08 03:56:05 +08:00
|
|
|
} else if (const auto *field = dyn_cast<FieldDecl>(I)) {
|
2013-01-16 09:22:32 +08:00
|
|
|
CollectRecordNormalField(field, layout.getFieldOffset(fieldNo),
|
|
|
|
tunit, elements, RecordTy);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-01-16 09:22:32 +08:00
|
|
|
// Bump field number for next field.
|
|
|
|
++fieldNo;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getOrCreateMethodType - CXXMethodDecl's type is a FunctionType. This
|
|
|
|
/// function type is not updated to include implicit "this" pointer. Use this
|
|
|
|
/// routine to get a method type which includes "this" pointer.
|
2013-05-23 07:22:42 +08:00
|
|
|
llvm::DICompositeType
|
2012-12-18 22:30:41 +08:00
|
|
|
CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method,
|
|
|
|
llvm::DIFile Unit) {
|
2013-01-08 07:06:35 +08:00
|
|
|
const FunctionProtoType *Func = Method->getType()->getAs<FunctionProtoType>();
|
2013-01-08 06:24:59 +08:00
|
|
|
if (Method->isStatic())
|
2013-05-23 07:22:42 +08:00
|
|
|
return llvm::DICompositeType(getOrCreateType(QualType(Func, 0), Unit));
|
2013-01-08 07:06:35 +08:00
|
|
|
return getOrCreateInstanceMethodType(Method->getThisType(CGM.getContext()),
|
|
|
|
Func, Unit);
|
|
|
|
}
|
2013-01-08 06:24:59 +08:00
|
|
|
|
2013-05-23 07:22:42 +08:00
|
|
|
llvm::DICompositeType CGDebugInfo::getOrCreateInstanceMethodType(
|
2013-01-08 07:06:35 +08:00
|
|
|
QualType ThisPtr, const FunctionProtoType *Func, llvm::DIFile Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Add "this" pointer.
|
2014-07-29 06:24:34 +08:00
|
|
|
llvm::DITypeArray Args = llvm::DISubroutineType(
|
|
|
|
getOrCreateType(QualType(Func, 0), Unit)).getTypeArray();
|
2012-12-18 22:30:41 +08:00
|
|
|
assert (Args.getNumElements() && "Invalid number of arguments!");
|
|
|
|
|
|
|
|
SmallVector<llvm::Value *, 16> Elts;
|
|
|
|
|
|
|
|
// First element is always return type. For 'void' functions it is NULL.
|
|
|
|
Elts.push_back(Args.getElement(0));
|
|
|
|
|
2013-01-08 06:24:59 +08:00
|
|
|
// "this" pointer is always first argument.
|
2013-01-08 07:06:35 +08:00
|
|
|
const CXXRecordDecl *RD = ThisPtr->getPointeeCXXRecordDecl();
|
2013-01-08 06:24:59 +08:00
|
|
|
if (isa<ClassTemplateSpecializationDecl>(RD)) {
|
|
|
|
// Create pointer type directly in this case.
|
|
|
|
const PointerType *ThisPtrTy = cast<PointerType>(ThisPtr);
|
|
|
|
QualType PointeeTy = ThisPtrTy->getPointeeType();
|
|
|
|
unsigned AS = CGM.getContext().getTargetAddressSpace(PointeeTy);
|
2013-04-17 06:48:15 +08:00
|
|
|
uint64_t Size = CGM.getTarget().getPointerWidth(AS);
|
2013-01-08 06:24:59 +08:00
|
|
|
uint64_t Align = CGM.getContext().getTypeAlign(ThisPtrTy);
|
|
|
|
llvm::DIType PointeeType = getOrCreateType(PointeeTy, Unit);
|
2013-05-16 08:52:20 +08:00
|
|
|
llvm::DIType ThisPtrType =
|
|
|
|
DBuilder.createPointerType(PointeeType, Size, Align);
|
2013-01-08 06:24:59 +08:00
|
|
|
TypeCache[ThisPtr.getAsOpaquePtr()] = ThisPtrType;
|
|
|
|
// TODO: This and the artificial type below are misleading, the
|
|
|
|
// types aren't artificial the argument is, but the current
|
|
|
|
// metadata doesn't represent that.
|
|
|
|
ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
|
|
|
|
Elts.push_back(ThisPtrType);
|
|
|
|
} else {
|
|
|
|
llvm::DIType ThisPtrType = getOrCreateType(ThisPtr, Unit);
|
|
|
|
TypeCache[ThisPtr.getAsOpaquePtr()] = ThisPtrType;
|
|
|
|
ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
|
|
|
|
Elts.push_back(ThisPtrType);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy rest of the arguments.
|
|
|
|
for (unsigned i = 1, e = Args.getNumElements(); i != e; ++i)
|
|
|
|
Elts.push_back(Args.getElement(i));
|
|
|
|
|
2014-07-29 06:24:34 +08:00
|
|
|
llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-12-19 05:48:18 +08:00
|
|
|
unsigned Flags = 0;
|
|
|
|
if (Func->getExtProtoInfo().RefQualifier == RQ_LValue)
|
|
|
|
Flags |= llvm::DIDescriptor::FlagLValueReference;
|
|
|
|
if (Func->getExtProtoInfo().RefQualifier == RQ_RValue)
|
|
|
|
Flags |= llvm::DIDescriptor::FlagRValueReference;
|
|
|
|
|
|
|
|
return DBuilder.createSubroutineType(Unit, EltTypeArray, Flags);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-05-16 08:45:12 +08:00
|
|
|
/// isFunctionLocalClass - Return true if CXXRecordDecl is defined
|
2012-12-18 22:30:41 +08:00
|
|
|
/// inside a function.
|
|
|
|
static bool isFunctionLocalClass(const CXXRecordDecl *RD) {
|
|
|
|
if (const CXXRecordDecl *NRD = dyn_cast<CXXRecordDecl>(RD->getDeclContext()))
|
|
|
|
return isFunctionLocalClass(NRD);
|
|
|
|
if (isa<FunctionDecl>(RD->getDeclContext()))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CreateCXXMemberFunction - A helper function to create a DISubprogram for
|
|
|
|
/// a single member function GlobalDecl.
|
|
|
|
llvm::DISubprogram
|
|
|
|
CGDebugInfo::CreateCXXMemberFunction(const CXXMethodDecl *Method,
|
|
|
|
llvm::DIFile Unit,
|
|
|
|
llvm::DIType RecordTy) {
|
2013-05-16 08:45:12 +08:00
|
|
|
bool IsCtorOrDtor =
|
2012-12-18 22:30:41 +08:00
|
|
|
isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method);
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
StringRef MethodName = getFunctionName(Method);
|
2013-05-23 07:22:42 +08:00
|
|
|
llvm::DICompositeType MethodTy = getOrCreateMethodType(Method, Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Since a single ctor/dtor corresponds to multiple functions, it doesn't
|
|
|
|
// make sense to give a single ctor/dtor a linkage name.
|
|
|
|
StringRef MethodLinkageName;
|
|
|
|
if (!IsCtorOrDtor && !isFunctionLocalClass(Method->getParent()))
|
|
|
|
MethodLinkageName = CGM.getMangledName(Method);
|
|
|
|
|
|
|
|
// Get the location for the method.
|
2013-08-19 11:37:48 +08:00
|
|
|
llvm::DIFile MethodDefUnit;
|
|
|
|
unsigned MethodLine = 0;
|
|
|
|
if (!Method->isImplicit()) {
|
|
|
|
MethodDefUnit = getOrCreateFile(Method->getLocation());
|
|
|
|
MethodLine = getLineNumber(Method->getLocation());
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Collect virtual method info.
|
|
|
|
llvm::DIType ContainingType;
|
2013-05-16 08:45:12 +08:00
|
|
|
unsigned Virtuality = 0;
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned VIndex = 0;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Method->isVirtual()) {
|
|
|
|
if (Method->isPure())
|
|
|
|
Virtuality = llvm::dwarf::DW_VIRTUALITY_pure_virtual;
|
|
|
|
else
|
|
|
|
Virtuality = llvm::dwarf::DW_VIRTUALITY_virtual;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// It doesn't make sense to give a virtual destructor a vtable index,
|
|
|
|
// since a single destructor has two entries in the vtable.
|
2013-09-27 22:48:01 +08:00
|
|
|
// FIXME: Add proper support for debug info for virtual calls in
|
|
|
|
// the Microsoft ABI, where we may use multiple vptrs to make a vftable
|
|
|
|
// lookup if we have multiple or virtual inheritance.
|
|
|
|
if (!isa<CXXDestructorDecl>(Method) &&
|
|
|
|
!CGM.getTarget().getCXXABI().isMicrosoft())
|
2013-11-05 23:54:58 +08:00
|
|
|
VIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(Method);
|
2012-12-18 22:30:41 +08:00
|
|
|
ContainingType = RecordTy;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned Flags = 0;
|
|
|
|
if (Method->isImplicit())
|
|
|
|
Flags |= llvm::DIDescriptor::FlagArtificial;
|
|
|
|
AccessSpecifier Access = Method->getAccess();
|
|
|
|
if (Access == clang::AS_private)
|
|
|
|
Flags |= llvm::DIDescriptor::FlagPrivate;
|
|
|
|
else if (Access == clang::AS_protected)
|
|
|
|
Flags |= llvm::DIDescriptor::FlagProtected;
|
|
|
|
if (const CXXConstructorDecl *CXXC = dyn_cast<CXXConstructorDecl>(Method)) {
|
|
|
|
if (CXXC->isExplicit())
|
|
|
|
Flags |= llvm::DIDescriptor::FlagExplicit;
|
2013-05-16 08:45:12 +08:00
|
|
|
} else if (const CXXConversionDecl *CXXC =
|
2012-12-18 22:30:41 +08:00
|
|
|
dyn_cast<CXXConversionDecl>(Method)) {
|
|
|
|
if (CXXC->isExplicit())
|
|
|
|
Flags |= llvm::DIDescriptor::FlagExplicit;
|
|
|
|
}
|
|
|
|
if (Method->hasPrototype())
|
|
|
|
Flags |= llvm::DIDescriptor::FlagPrototyped;
|
2013-12-19 05:48:18 +08:00
|
|
|
if (Method->getRefQualifier() == RQ_LValue)
|
|
|
|
Flags |= llvm::DIDescriptor::FlagLValueReference;
|
|
|
|
if (Method->getRefQualifier() == RQ_RValue)
|
|
|
|
Flags |= llvm::DIDescriptor::FlagRValueReference;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
llvm::DIArray TParamsArray = CollectFunctionTemplateParams(Method, Unit);
|
|
|
|
llvm::DISubprogram SP =
|
2013-05-16 08:45:12 +08:00
|
|
|
DBuilder.createMethod(RecordTy, MethodName, MethodLinkageName,
|
2012-12-18 22:30:41 +08:00
|
|
|
MethodDefUnit, MethodLine,
|
2013-05-16 08:45:12 +08:00
|
|
|
MethodTy, /*isLocalToUnit=*/false,
|
2012-12-18 22:30:41 +08:00
|
|
|
/* isDefinition=*/ false,
|
|
|
|
Virtuality, VIndex, ContainingType,
|
2014-05-21 13:09:00 +08:00
|
|
|
Flags, CGM.getLangOpts().Optimize, nullptr,
|
2012-12-18 22:30:41 +08:00
|
|
|
TParamsArray);
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
SPCache[Method->getCanonicalDecl()] = llvm::WeakVH(SP);
|
|
|
|
|
|
|
|
return SP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CollectCXXMemberFunctions - A helper function to collect debug info for
|
2013-05-16 08:45:12 +08:00
|
|
|
/// C++ member functions. This is used while creating debug info entry for
|
2012-12-18 22:30:41 +08:00
|
|
|
/// a Record.
|
|
|
|
void CGDebugInfo::
|
|
|
|
CollectCXXMemberFunctions(const CXXRecordDecl *RD, llvm::DIFile Unit,
|
|
|
|
SmallVectorImpl<llvm::Value *> &EltTys,
|
|
|
|
llvm::DIType RecordTy) {
|
|
|
|
|
|
|
|
// Since we want more than just the individual member decls if we
|
|
|
|
// have templated functions iterate over every declaration to gather
|
|
|
|
// the functions.
|
2014-03-08 03:56:05 +08:00
|
|
|
for(const auto *I : RD->decls()) {
|
|
|
|
if (const auto *Method = dyn_cast<CXXMethodDecl>(I)) {
|
2013-08-29 04:58:00 +08:00
|
|
|
// Reuse the existing member function declaration if it exists.
|
2013-08-29 04:24:55 +08:00
|
|
|
// It may be associated with the declaration of the type & should be
|
|
|
|
// reused as we're building the definition.
|
2013-08-29 04:58:00 +08:00
|
|
|
//
|
|
|
|
// This situation can arise in the vtable-based debug info reduction where
|
|
|
|
// implicit members are emitted in a non-vtable TU.
|
2013-08-20 09:28:15 +08:00
|
|
|
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator MI =
|
|
|
|
SPCache.find(Method->getCanonicalDecl());
|
2013-08-29 01:27:13 +08:00
|
|
|
if (MI == SPCache.end()) {
|
2013-08-29 04:24:55 +08:00
|
|
|
// If the member is implicit, lazily create it when we see the
|
|
|
|
// definition, not before. (an ODR-used implicit default ctor that's
|
|
|
|
// never actually code generated should not produce debug info)
|
2013-08-29 01:27:13 +08:00
|
|
|
if (!Method->isImplicit())
|
|
|
|
EltTys.push_back(CreateCXXMemberFunction(Method, Unit, RecordTy));
|
|
|
|
} else
|
2013-08-20 09:28:15 +08:00
|
|
|
EltTys.push_back(MI->second);
|
2014-03-08 03:56:05 +08:00
|
|
|
} else if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(I)) {
|
2013-08-29 07:06:52 +08:00
|
|
|
// Add any template specializations that have already been seen. Like
|
|
|
|
// implicit member functions, these may have been added to a declaration
|
|
|
|
// in the case of vtable-based debug info reduction.
|
2014-03-15 00:05:56 +08:00
|
|
|
for (const auto *SI : FTD->specializations()) {
|
2013-08-29 07:06:52 +08:00
|
|
|
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator MI =
|
2014-03-15 00:05:56 +08:00
|
|
|
SPCache.find(cast<CXXMethodDecl>(SI)->getCanonicalDecl());
|
2013-08-29 07:06:52 +08:00
|
|
|
if (MI != SPCache.end())
|
|
|
|
EltTys.push_back(MI->second);
|
|
|
|
}
|
2013-08-20 09:28:15 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-05-16 08:45:12 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
/// CollectCXXBases - A helper function to collect debug info for
|
2013-05-16 08:45:12 +08:00
|
|
|
/// C++ base classes. This is used while creating debug info entry for
|
2012-12-18 22:30:41 +08:00
|
|
|
/// a Record.
|
|
|
|
void CGDebugInfo::
|
|
|
|
CollectCXXBases(const CXXRecordDecl *RD, llvm::DIFile Unit,
|
|
|
|
SmallVectorImpl<llvm::Value *> &EltTys,
|
|
|
|
llvm::DIType RecordTy) {
|
|
|
|
|
|
|
|
const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
|
2014-03-13 23:41:46 +08:00
|
|
|
for (const auto &BI : RD->bases()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned BFlags = 0;
|
|
|
|
uint64_t BaseOffset;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
const CXXRecordDecl *Base =
|
2014-03-13 23:41:46 +08:00
|
|
|
cast<CXXRecordDecl>(BI.getType()->getAs<RecordType>()->getDecl());
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2014-03-13 23:41:46 +08:00
|
|
|
if (BI.isVirtual()) {
|
2014-08-08 05:29:25 +08:00
|
|
|
if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
|
|
|
|
// virtual base offset offset is -ve. The code generator emits dwarf
|
|
|
|
// expression where it expects +ve number.
|
|
|
|
BaseOffset =
|
|
|
|
0 - CGM.getItaniumVTableContext()
|
|
|
|
.getVirtualBaseOffsetOffset(RD, Base).getQuantity();
|
|
|
|
} else {
|
|
|
|
// In the MS ABI, store the vbtable offset, which is analogous to the
|
|
|
|
// vbase offset offset in Itanium.
|
|
|
|
BaseOffset =
|
|
|
|
4 * CGM.getMicrosoftVTableContext().getVBTableIndex(RD, Base);
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
BFlags = llvm::DIDescriptor::FlagVirtual;
|
|
|
|
} else
|
|
|
|
BaseOffset = CGM.getContext().toBits(RL.getBaseClassOffset(Base));
|
|
|
|
// FIXME: Inconsistent units for BaseOffset. It is in bytes when
|
|
|
|
// BI->isVirtual() and bits when not.
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2014-03-13 23:41:46 +08:00
|
|
|
AccessSpecifier Access = BI.getAccessSpecifier();
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Access == clang::AS_private)
|
|
|
|
BFlags |= llvm::DIDescriptor::FlagPrivate;
|
|
|
|
else if (Access == clang::AS_protected)
|
|
|
|
BFlags |= llvm::DIDescriptor::FlagProtected;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
|
|
|
llvm::DIType DTy =
|
|
|
|
DBuilder.createInheritance(RecordTy,
|
2014-03-13 23:41:46 +08:00
|
|
|
getOrCreateType(BI.getType(), Unit),
|
2012-12-18 22:30:41 +08:00
|
|
|
BaseOffset, BFlags);
|
|
|
|
EltTys.push_back(DTy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CollectTemplateParams - A helper function to collect template parameters.
|
|
|
|
llvm::DIArray CGDebugInfo::
|
|
|
|
CollectTemplateParams(const TemplateParameterList *TPList,
|
2013-06-23 02:59:18 +08:00
|
|
|
ArrayRef<TemplateArgument> TAList,
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIFile Unit) {
|
2013-05-16 08:45:12 +08:00
|
|
|
SmallVector<llvm::Value *, 16> TemplateParams;
|
2012-12-18 22:30:41 +08:00
|
|
|
for (unsigned i = 0, e = TAList.size(); i != e; ++i) {
|
|
|
|
const TemplateArgument &TA = TAList[i];
|
2013-06-23 02:59:18 +08:00
|
|
|
StringRef Name;
|
|
|
|
if (TPList)
|
|
|
|
Name = TPList->getParam(i)->getName();
|
2013-05-11 05:53:14 +08:00
|
|
|
switch (TA.getKind()) {
|
|
|
|
case TemplateArgument::Type: {
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIType TTy = getOrCreateType(TA.getAsType(), Unit);
|
|
|
|
llvm::DITemplateTypeParameter TTP =
|
2013-06-23 02:59:18 +08:00
|
|
|
DBuilder.createTemplateTypeParameter(TheCU, Name, TTy);
|
2012-12-18 22:30:41 +08:00
|
|
|
TemplateParams.push_back(TTP);
|
2013-05-11 05:53:14 +08:00
|
|
|
} break;
|
|
|
|
case TemplateArgument::Integral: {
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIType TTy = getOrCreateType(TA.getIntegralType(), Unit);
|
|
|
|
llvm::DITemplateValueParameter TVP =
|
2013-05-11 05:53:14 +08:00
|
|
|
DBuilder.createTemplateValueParameter(
|
2013-06-23 02:59:18 +08:00
|
|
|
TheCU, Name, TTy,
|
2013-05-11 05:53:14 +08:00
|
|
|
llvm::ConstantInt::get(CGM.getLLVMContext(), TA.getAsIntegral()));
|
|
|
|
TemplateParams.push_back(TVP);
|
|
|
|
} break;
|
|
|
|
case TemplateArgument::Declaration: {
|
|
|
|
const ValueDecl *D = TA.getAsDecl();
|
|
|
|
bool InstanceMember = D->isCXXInstanceMember();
|
|
|
|
QualType T = InstanceMember
|
|
|
|
? CGM.getContext().getMemberPointerType(
|
|
|
|
D->getType(), cast<RecordDecl>(D->getDeclContext())
|
|
|
|
->getTypeForDecl())
|
|
|
|
: CGM.getContext().getPointerType(D->getType());
|
|
|
|
llvm::DIType TTy = getOrCreateType(T, Unit);
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Value *V = nullptr;
|
2013-05-11 05:53:14 +08:00
|
|
|
// Variable pointer template parameters have a value that is the address
|
|
|
|
// of the variable.
|
|
|
|
if (const VarDecl *VD = dyn_cast<VarDecl>(D))
|
|
|
|
V = CGM.GetAddrOfGlobalVar(VD);
|
|
|
|
// Member function pointers have special support for building them, though
|
|
|
|
// this is currently unsupported in LLVM CodeGen.
|
2013-05-13 14:57:50 +08:00
|
|
|
if (InstanceMember) {
|
2013-05-11 05:53:14 +08:00
|
|
|
if (const CXXMethodDecl *method = dyn_cast<CXXMethodDecl>(D))
|
|
|
|
V = CGM.getCXXABI().EmitMemberPointer(method);
|
2013-05-13 14:57:50 +08:00
|
|
|
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
|
|
|
|
V = CGM.GetAddrOfFunction(FD);
|
2013-05-11 05:53:14 +08:00
|
|
|
// Member data pointers have special handling too to compute the fixed
|
|
|
|
// offset within the object.
|
2014-04-02 01:52:06 +08:00
|
|
|
if (isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D)) {
|
2013-05-11 05:53:14 +08:00
|
|
|
// These five lines (& possibly the above member function pointer
|
|
|
|
// handling) might be able to be refactored to use similar code in
|
|
|
|
// CodeGenModule::getMemberPointerConstant
|
|
|
|
uint64_t fieldOffset = CGM.getContext().getFieldOffset(D);
|
|
|
|
CharUnits chars =
|
|
|
|
CGM.getContext().toCharUnitsFromBits((int64_t) fieldOffset);
|
|
|
|
V = CGM.getCXXABI().EmitMemberDataPointer(
|
|
|
|
cast<MemberPointerType>(T.getTypePtr()), chars);
|
|
|
|
}
|
|
|
|
llvm::DITemplateValueParameter TVP =
|
2013-08-26 06:13:27 +08:00
|
|
|
DBuilder.createTemplateValueParameter(TheCU, Name, TTy,
|
|
|
|
V->stripPointerCasts());
|
2013-05-11 05:53:14 +08:00
|
|
|
TemplateParams.push_back(TVP);
|
|
|
|
} break;
|
|
|
|
case TemplateArgument::NullPtr: {
|
|
|
|
QualType T = TA.getNullPtrType();
|
|
|
|
llvm::DIType TTy = getOrCreateType(T, Unit);
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::Value *V = nullptr;
|
2013-05-11 05:53:14 +08:00
|
|
|
// Special case member data pointer null values since they're actually -1
|
|
|
|
// instead of zero.
|
|
|
|
if (const MemberPointerType *MPT =
|
|
|
|
dyn_cast<MemberPointerType>(T.getTypePtr()))
|
|
|
|
// But treat member function pointers as simple zero integers because
|
|
|
|
// it's easier than having a special case in LLVM's CodeGen. If LLVM
|
|
|
|
// CodeGen grows handling for values of non-null member function
|
|
|
|
// pointers then perhaps we could remove this special case and rely on
|
|
|
|
// EmitNullMemberPointer for member function pointers.
|
|
|
|
if (MPT->isMemberDataPointer())
|
|
|
|
V = CGM.getCXXABI().EmitNullMemberPointer(MPT);
|
|
|
|
if (!V)
|
|
|
|
V = llvm::ConstantInt::get(CGM.Int8Ty, 0);
|
|
|
|
llvm::DITemplateValueParameter TVP =
|
2013-06-23 02:59:18 +08:00
|
|
|
DBuilder.createTemplateValueParameter(TheCU, Name, TTy, V);
|
|
|
|
TemplateParams.push_back(TVP);
|
|
|
|
} break;
|
|
|
|
case TemplateArgument::Template: {
|
|
|
|
llvm::DITemplateValueParameter TVP =
|
|
|
|
DBuilder.createTemplateTemplateParameter(
|
|
|
|
TheCU, Name, llvm::DIType(),
|
|
|
|
TA.getAsTemplate().getAsTemplateDecl()
|
|
|
|
->getQualifiedNameAsString());
|
|
|
|
TemplateParams.push_back(TVP);
|
|
|
|
} break;
|
|
|
|
case TemplateArgument::Pack: {
|
|
|
|
llvm::DITemplateValueParameter TVP =
|
|
|
|
DBuilder.createTemplateParameterPack(
|
|
|
|
TheCU, Name, llvm::DIType(),
|
2014-05-21 13:09:00 +08:00
|
|
|
CollectTemplateParams(nullptr, TA.getPackAsArray(), Unit));
|
2013-05-11 05:53:14 +08:00
|
|
|
TemplateParams.push_back(TVP);
|
|
|
|
} break;
|
2013-08-24 16:21:10 +08:00
|
|
|
case TemplateArgument::Expression: {
|
|
|
|
const Expr *E = TA.getAsExpr();
|
|
|
|
QualType T = E->getType();
|
|
|
|
llvm::Value *V = CGM.EmitConstantExpr(E, T);
|
|
|
|
assert(V && "Expression in template argument isn't constant");
|
|
|
|
llvm::DIType TTy = getOrCreateType(T, Unit);
|
|
|
|
llvm::DITemplateValueParameter TVP =
|
|
|
|
DBuilder.createTemplateValueParameter(TheCU, Name, TTy,
|
|
|
|
V->stripPointerCasts());
|
|
|
|
TemplateParams.push_back(TVP);
|
|
|
|
} break;
|
2013-05-11 07:36:06 +08:00
|
|
|
// And the following should never occur:
|
2013-05-11 05:53:14 +08:00
|
|
|
case TemplateArgument::TemplateExpansion:
|
|
|
|
case TemplateArgument::Null:
|
|
|
|
llvm_unreachable(
|
|
|
|
"These argument types shouldn't exist in concrete types");
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return DBuilder.getOrCreateArray(TemplateParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CollectFunctionTemplateParams - A helper function to collect debug
|
|
|
|
/// info for function template parameters.
|
|
|
|
llvm::DIArray CGDebugInfo::
|
|
|
|
CollectFunctionTemplateParams(const FunctionDecl *FD, llvm::DIFile Unit) {
|
|
|
|
if (FD->getTemplatedKind() ==
|
|
|
|
FunctionDecl::TK_FunctionTemplateSpecialization) {
|
|
|
|
const TemplateParameterList *TList =
|
|
|
|
FD->getTemplateSpecializationInfo()->getTemplate()
|
|
|
|
->getTemplateParameters();
|
2013-06-23 02:59:18 +08:00
|
|
|
return CollectTemplateParams(
|
|
|
|
TList, FD->getTemplateSpecializationArgs()->asArray(), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
return llvm::DIArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CollectCXXTemplateParams - A helper function to collect debug info for
|
|
|
|
/// template parameters.
|
|
|
|
llvm::DIArray CGDebugInfo::
|
|
|
|
CollectCXXTemplateParams(const ClassTemplateSpecializationDecl *TSpecial,
|
|
|
|
llvm::DIFile Unit) {
|
2014-04-17 09:04:01 +08:00
|
|
|
// Always get the full list of parameters, not just the ones from
|
|
|
|
// the specialization.
|
|
|
|
TemplateParameterList *TPList =
|
|
|
|
TSpecial->getSpecializedTemplate()->getTemplateParameters();
|
2014-04-17 08:30:48 +08:00
|
|
|
const TemplateArgumentList &TAList = TSpecial->getTemplateArgs();
|
2013-06-23 02:59:18 +08:00
|
|
|
return CollectTemplateParams(TPList, TAList.asArray(), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getOrCreateVTablePtrType - Return debug info descriptor for vtable.
|
|
|
|
llvm::DIType CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile Unit) {
|
|
|
|
if (VTablePtrType.isValid())
|
|
|
|
return VTablePtrType;
|
|
|
|
|
|
|
|
ASTContext &Context = CGM.getContext();
|
|
|
|
|
|
|
|
/* Function type */
|
|
|
|
llvm::Value *STy = getOrCreateType(Context.IntTy, Unit);
|
2014-07-29 06:24:34 +08:00
|
|
|
llvm::DITypeArray SElements = DBuilder.getOrCreateTypeArray(STy);
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIType SubTy = DBuilder.createSubroutineType(Unit, SElements);
|
|
|
|
unsigned Size = Context.getTypeSize(Context.VoidPtrTy);
|
|
|
|
llvm::DIType vtbl_ptr_type = DBuilder.createPointerType(SubTy, Size, 0,
|
|
|
|
"__vtbl_ptr_type");
|
|
|
|
VTablePtrType = DBuilder.createPointerType(vtbl_ptr_type, Size);
|
|
|
|
return VTablePtrType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getVTableName - Get vtable name for the given Class.
|
|
|
|
StringRef CGDebugInfo::getVTableName(const CXXRecordDecl *RD) {
|
2013-09-10 00:39:06 +08:00
|
|
|
// Copy the gdb compatible name on the side and use its reference.
|
|
|
|
return internString("_vptr$", RD->getNameAsString());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// CollectVTableInfo - If the C++ class has vtable info then insert appropriate
|
|
|
|
/// debug info entry in EltTys vector.
|
|
|
|
void CGDebugInfo::
|
|
|
|
CollectVTableInfo(const CXXRecordDecl *RD, llvm::DIFile Unit,
|
|
|
|
SmallVectorImpl<llvm::Value *> &EltTys) {
|
|
|
|
const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
|
|
|
|
|
|
|
|
// If there is a primary base then it will hold vtable info.
|
|
|
|
if (RL.getPrimaryBase())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If this class is not dynamic then there is not any vtable info to collect.
|
|
|
|
if (!RD->isDynamicClass())
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
|
|
|
|
llvm::DIType VPTR
|
|
|
|
= DBuilder.createMemberType(Unit, getVTableName(RD), Unit,
|
2013-05-16 08:52:20 +08:00
|
|
|
0, Size, 0, 0,
|
|
|
|
llvm::DIDescriptor::FlagArtificial,
|
2012-12-18 22:30:41 +08:00
|
|
|
getOrCreateVTablePtrType(Unit));
|
|
|
|
EltTys.push_back(VPTR);
|
|
|
|
}
|
|
|
|
|
2013-05-16 08:45:12 +08:00
|
|
|
/// getOrCreateRecordType - Emit record type's standalone debug info.
|
|
|
|
llvm::DIType CGDebugInfo::getOrCreateRecordType(QualType RTy,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceLocation Loc) {
|
2013-05-16 08:45:23 +08:00
|
|
|
assert(DebugKind >= CodeGenOptions::LimitedDebugInfo);
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIType T = getOrCreateType(RTy, getOrCreateFile(Loc));
|
|
|
|
return T;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getOrCreateInterfaceType - Emit an objective c interface type standalone
|
|
|
|
/// debug info.
|
|
|
|
llvm::DIType CGDebugInfo::getOrCreateInterfaceType(QualType D,
|
2013-02-22 06:35:08 +08:00
|
|
|
SourceLocation Loc) {
|
2013-05-16 08:45:23 +08:00
|
|
|
assert(DebugKind >= CodeGenOptions::LimitedDebugInfo);
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIType T = getOrCreateType(D, getOrCreateFile(Loc));
|
2013-03-12 02:33:46 +08:00
|
|
|
RetainedTypes.push_back(D.getAsOpaquePtr());
|
2012-12-18 22:30:41 +08:00
|
|
|
return T;
|
|
|
|
}
|
|
|
|
|
2014-05-07 02:35:21 +08:00
|
|
|
void CGDebugInfo::completeType(const EnumDecl *ED) {
|
|
|
|
if (DebugKind <= CodeGenOptions::DebugLineTablesOnly)
|
|
|
|
return;
|
|
|
|
QualType Ty = CGM.getContext().getEnumType(ED);
|
|
|
|
void* TyPtr = Ty.getAsOpaquePtr();
|
|
|
|
auto I = TypeCache.find(TyPtr);
|
|
|
|
if (I == TypeCache.end() ||
|
|
|
|
!llvm::DIType(cast<llvm::MDNode>(static_cast<llvm::Value *>(I->second)))
|
|
|
|
.isForwardDecl())
|
|
|
|
return;
|
|
|
|
llvm::DIType Res = CreateTypeDefinition(Ty->castAs<EnumType>());
|
|
|
|
assert(!Res.isForwardDecl());
|
|
|
|
TypeCache[TyPtr] = Res;
|
|
|
|
}
|
|
|
|
|
2013-08-16 04:49:17 +08:00
|
|
|
void CGDebugInfo::completeType(const RecordDecl *RD) {
|
|
|
|
if (DebugKind > CodeGenOptions::LimitedDebugInfo ||
|
|
|
|
!CGM.getLangOpts().CPlusPlus)
|
|
|
|
completeRequiredType(RD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGDebugInfo::completeRequiredType(const RecordDecl *RD) {
|
2014-03-05 06:01:08 +08:00
|
|
|
if (DebugKind <= CodeGenOptions::DebugLineTablesOnly)
|
|
|
|
return;
|
|
|
|
|
2013-08-20 09:28:15 +08:00
|
|
|
if (const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
|
|
|
|
if (CXXDecl->isDynamicClass())
|
|
|
|
return;
|
|
|
|
|
2013-08-16 04:49:17 +08:00
|
|
|
QualType Ty = CGM.getContext().getRecordType(RD);
|
|
|
|
llvm::DIType T = getTypeOrNull(Ty);
|
2013-08-20 09:28:15 +08:00
|
|
|
if (T && T.isForwardDecl())
|
|
|
|
completeClassData(RD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGDebugInfo::completeClassData(const RecordDecl *RD) {
|
|
|
|
if (DebugKind <= CodeGenOptions::DebugLineTablesOnly)
|
2013-08-20 02:46:16 +08:00
|
|
|
return;
|
2013-08-20 09:28:15 +08:00
|
|
|
QualType Ty = CGM.getContext().getRecordType(RD);
|
2013-08-16 04:49:17 +08:00
|
|
|
void* TyPtr = Ty.getAsOpaquePtr();
|
2014-05-06 07:23:53 +08:00
|
|
|
auto I = TypeCache.find(TyPtr);
|
|
|
|
if (I != TypeCache.end() &&
|
|
|
|
!llvm::DIType(cast<llvm::MDNode>(static_cast<llvm::Value *>(I->second)))
|
|
|
|
.isForwardDecl())
|
2013-08-16 04:49:17 +08:00
|
|
|
return;
|
|
|
|
llvm::DIType Res = CreateTypeDefinition(Ty->castAs<RecordType>());
|
|
|
|
assert(!Res.isForwardDecl());
|
|
|
|
TypeCache[TyPtr] = Res;
|
|
|
|
}
|
|
|
|
|
2014-03-04 07:48:23 +08:00
|
|
|
static bool hasExplicitMemberDefinition(CXXRecordDecl::method_iterator I,
|
|
|
|
CXXRecordDecl::method_iterator End) {
|
|
|
|
for (; I != End; ++I)
|
|
|
|
if (FunctionDecl *Tmpl = I->getInstantiatedFromMemberFunction())
|
2014-03-04 11:08:14 +08:00
|
|
|
if (!Tmpl->isImplicit() && Tmpl->isThisDeclarationADefinition() &&
|
|
|
|
!I->getMemberSpecializationInfo()->isExplicitSpecialization())
|
2014-03-04 07:48:23 +08:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool shouldOmitDefinition(CodeGenOptions::DebugInfoKind DebugKind,
|
|
|
|
const RecordDecl *RD,
|
|
|
|
const LangOptions &LangOpts) {
|
|
|
|
if (DebugKind > CodeGenOptions::LimitedDebugInfo)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!LangOpts.CPlusPlus)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!RD->isCompleteDefinitionRequired())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
|
|
|
|
|
|
|
|
if (!CXXDecl)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (CXXDecl->hasDefinition() && CXXDecl->isDynamicClass())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
TemplateSpecializationKind Spec = TSK_Undeclared;
|
|
|
|
if (const ClassTemplateSpecializationDecl *SD =
|
|
|
|
dyn_cast<ClassTemplateSpecializationDecl>(RD))
|
|
|
|
Spec = SD->getSpecializationKind();
|
|
|
|
|
|
|
|
if (Spec == TSK_ExplicitInstantiationDeclaration &&
|
|
|
|
hasExplicitMemberDefinition(CXXDecl->method_begin(),
|
|
|
|
CXXDecl->method_end()))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
/// CreateType - get structure or union type.
|
2013-09-05 06:03:57 +08:00
|
|
|
llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty) {
|
2012-12-18 22:30:41 +08:00
|
|
|
RecordDecl *RD = Ty->getDecl();
|
PR17046, PR17092: Debug Info assert-on-valid due to member loss when context creation recreates the item the context is created for
By removing the possibility of strange partial definitions with no
members that older GCC's produced for the otherwise unreferenced outer
types of referenced inner types, we can simplify debug info generation
and correct this bug. Newer (4.8.1 and ToT) GCC's don't produce this
quirky debug info, and instead produce the full definition for the outer
type (except in the case where that type is dynamic and its vtable is
not emitted in this TU).
During the creation of the context for a type, we may revisit that type
(due to the need to visit template parameters, among other things) and
used to end up visiting it first there. Then when we would reach the
original code attempting to define that type, we would lose debug info
by overwriting its members.
By avoiding the possibility of latent "defined with no members" types,
we can be sure than whenever we already have a type in a cache (either a
definition or declaration), we can just return that. In the case of a
full definition, our work is done. In the case of a partial definition,
we must already be in the process of completing it. And in the case of a
declaration, the completed/vtable/etc callbacks can handle converting it
to a definition.
llvm-svn: 190122
2013-09-06 14:45:04 +08:00
|
|
|
llvm::DICompositeType T(getTypeOrNull(QualType(Ty, 0)));
|
2014-03-04 07:48:23 +08:00
|
|
|
if (T || shouldOmitDefinition(DebugKind, RD, CGM.getLangOpts())) {
|
PR17046, PR17092: Debug Info assert-on-valid due to member loss when context creation recreates the item the context is created for
By removing the possibility of strange partial definitions with no
members that older GCC's produced for the otherwise unreferenced outer
types of referenced inner types, we can simplify debug info generation
and correct this bug. Newer (4.8.1 and ToT) GCC's don't produce this
quirky debug info, and instead produce the full definition for the outer
type (except in the case where that type is dynamic and its vtable is
not emitted in this TU).
During the creation of the context for a type, we may revisit that type
(due to the need to visit template parameters, among other things) and
used to end up visiting it first there. Then when we would reach the
original code attempting to define that type, we would lose debug info
by overwriting its members.
By avoiding the possibility of latent "defined with no members" types,
we can be sure than whenever we already have a type in a cache (either a
definition or declaration), we can just return that. In the case of a
full definition, our work is done. In the case of a partial definition,
we must already be in the process of completing it. And in the case of a
declaration, the completed/vtable/etc callbacks can handle converting it
to a definition.
llvm-svn: 190122
2013-09-06 14:45:04 +08:00
|
|
|
if (!T)
|
2014-02-19 04:52:05 +08:00
|
|
|
T = getOrCreateRecordFwdDecl(
|
|
|
|
Ty, getContextDescriptor(cast<Decl>(RD->getDeclContext())));
|
PR17046, PR17092: Debug Info assert-on-valid due to member loss when context creation recreates the item the context is created for
By removing the possibility of strange partial definitions with no
members that older GCC's produced for the otherwise unreferenced outer
types of referenced inner types, we can simplify debug info generation
and correct this bug. Newer (4.8.1 and ToT) GCC's don't produce this
quirky debug info, and instead produce the full definition for the outer
type (except in the case where that type is dynamic and its vtable is
not emitted in this TU).
During the creation of the context for a type, we may revisit that type
(due to the need to visit template parameters, among other things) and
used to end up visiting it first there. Then when we would reach the
original code attempting to define that type, we would lose debug info
by overwriting its members.
By avoiding the possibility of latent "defined with no members" types,
we can be sure than whenever we already have a type in a cache (either a
definition or declaration), we can just return that. In the case of a
full definition, our work is done. In the case of a partial definition,
we must already be in the process of completing it. And in the case of a
declaration, the completed/vtable/etc callbacks can handle converting it
to a definition.
llvm-svn: 190122
2013-09-06 14:45:04 +08:00
|
|
|
return T;
|
2013-06-05 13:32:23 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-08-16 04:49:17 +08:00
|
|
|
return CreateTypeDefinition(Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIType CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
|
|
|
|
RecordDecl *RD = Ty->getDecl();
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Get overall information about the record type for the debug info.
|
|
|
|
llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation());
|
|
|
|
|
|
|
|
// Records and classes and unions can all be recursive. To handle them, we
|
|
|
|
// first generate a debug descriptor for the struct as a forward declaration.
|
|
|
|
// Then (if it is a definition) we go through and get debug info for all of
|
|
|
|
// its members. Finally, we create a descriptor for the complete type (which
|
|
|
|
// may refer to the forward decl if the struct is recursive) and replace all
|
|
|
|
// uses of the forward declaration with the final definition.
|
|
|
|
|
2013-08-13 06:24:20 +08:00
|
|
|
llvm::DICompositeType FwdDecl(getOrCreateLimitedType(Ty, DefUnit));
|
2013-07-03 03:01:53 +08:00
|
|
|
assert(FwdDecl.isCompositeType() &&
|
2013-05-23 07:22:42 +08:00
|
|
|
"The debug type of a RecordType should be a llvm::DICompositeType");
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
if (FwdDecl.isForwardDecl())
|
|
|
|
return FwdDecl;
|
|
|
|
|
2013-08-19 00:55:33 +08:00
|
|
|
if (const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
|
|
|
|
CollectContainingType(CXXDecl, FwdDecl);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Push the struct on region stack.
|
2013-04-03 06:59:11 +08:00
|
|
|
LexicalBlockStack.push_back(&*FwdDecl);
|
2012-12-18 22:30:41 +08:00
|
|
|
RegionMap[Ty->getDecl()] = llvm::WeakVH(FwdDecl);
|
|
|
|
|
|
|
|
// Convert all the elements.
|
|
|
|
SmallVector<llvm::Value *, 16> EltTys;
|
2013-08-20 09:28:15 +08:00
|
|
|
// what about nested types?
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Note: The split of CXXDecl information here is intentional, the
|
|
|
|
// gdb tests will depend on a certain ordering at printout. The debug
|
|
|
|
// information offsets are still correct if we merge them all together
|
|
|
|
// though.
|
|
|
|
const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
|
|
|
|
if (CXXDecl) {
|
|
|
|
CollectCXXBases(CXXDecl, DefUnit, EltTys, FwdDecl);
|
|
|
|
CollectVTableInfo(CXXDecl, DefUnit, EltTys);
|
|
|
|
}
|
|
|
|
|
2013-01-16 09:22:32 +08:00
|
|
|
// Collect data fields (including static variables and any initializers).
|
2012-12-18 22:30:41 +08:00
|
|
|
CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
|
2013-10-12 02:16:51 +08:00
|
|
|
if (CXXDecl)
|
2012-12-18 22:30:41 +08:00
|
|
|
CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
|
|
|
|
|
|
|
|
LexicalBlockStack.pop_back();
|
|
|
|
RegionMap.erase(Ty->getDecl());
|
|
|
|
|
|
|
|
llvm::DIArray Elements = DBuilder.getOrCreateArray(EltTys);
|
2014-07-29 03:14:41 +08:00
|
|
|
FwdDecl.setArrays(Elements);
|
2013-04-02 04:33:18 +08:00
|
|
|
|
2013-04-03 06:59:11 +08:00
|
|
|
RegionMap[Ty->getDecl()] = llvm::WeakVH(FwdDecl);
|
|
|
|
return FwdDecl;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// CreateType - get objective-c object type.
|
|
|
|
llvm::DIType CGDebugInfo::CreateType(const ObjCObjectType *Ty,
|
|
|
|
llvm::DIFile Unit) {
|
|
|
|
// Ignore protocols.
|
|
|
|
return getOrCreateType(Ty->getBaseType(), Unit);
|
|
|
|
}
|
|
|
|
|
2013-06-07 09:10:45 +08:00
|
|
|
|
|
|
|
/// \return true if Getter has the default name for the property PD.
|
|
|
|
static bool hasDefaultGetterName(const ObjCPropertyDecl *PD,
|
|
|
|
const ObjCMethodDecl *Getter) {
|
|
|
|
assert(PD);
|
|
|
|
if (!Getter)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
assert(Getter->getDeclName().isObjCZeroArgSelector());
|
|
|
|
return PD->getName() ==
|
|
|
|
Getter->getDeclName().getObjCSelector().getNameForSlot(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \return true if Setter has the default name for the property PD.
|
|
|
|
static bool hasDefaultSetterName(const ObjCPropertyDecl *PD,
|
|
|
|
const ObjCMethodDecl *Setter) {
|
|
|
|
assert(PD);
|
|
|
|
if (!Setter)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
assert(Setter->getDeclName().isObjCOneArgSelector());
|
2013-06-08 06:29:12 +08:00
|
|
|
return SelectorTable::constructSetterName(PD->getName()) ==
|
2013-06-07 09:10:45 +08:00
|
|
|
Setter->getDeclName().getObjCSelector().getNameForSlot(0);
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
/// CreateType - get objective-c interface type.
|
|
|
|
llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
|
|
|
|
llvm::DIFile Unit) {
|
|
|
|
ObjCInterfaceDecl *ID = Ty->getDecl();
|
|
|
|
if (!ID)
|
|
|
|
return llvm::DIType();
|
|
|
|
|
|
|
|
// Get overall information about the record type for the debug info.
|
|
|
|
llvm::DIFile DefUnit = getOrCreateFile(ID->getLocation());
|
|
|
|
unsigned Line = getLineNumber(ID->getLocation());
|
2014-05-07 20:49:30 +08:00
|
|
|
llvm::dwarf::SourceLanguage RuntimeLang = TheCU.getLanguage();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// If this is just a forward declaration return a special forward-declaration
|
|
|
|
// debug type since we won't be able to lay out the entire type.
|
|
|
|
ObjCInterfaceDecl *Def = ID->getDefinition();
|
2014-05-06 07:23:53 +08:00
|
|
|
if (!Def || !Def->getImplementation()) {
|
2014-05-06 11:42:01 +08:00
|
|
|
llvm::DIType FwdDecl = DBuilder.createReplaceableForwardDecl(
|
|
|
|
llvm::dwarf::DW_TAG_structure_type, ID->getName(), TheCU, DefUnit, Line,
|
|
|
|
RuntimeLang);
|
2014-05-06 07:23:53 +08:00
|
|
|
ObjCInterfaceCache.push_back(ObjCInterfaceCacheEntry(Ty, FwdDecl, Unit));
|
2012-12-18 22:30:41 +08:00
|
|
|
return FwdDecl;
|
|
|
|
}
|
|
|
|
|
2014-05-06 07:23:53 +08:00
|
|
|
|
|
|
|
return CreateTypeDefinition(Ty, Unit);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIType CGDebugInfo::CreateTypeDefinition(const ObjCInterfaceType *Ty, llvm::DIFile Unit) {
|
|
|
|
ObjCInterfaceDecl *ID = Ty->getDecl();
|
|
|
|
llvm::DIFile DefUnit = getOrCreateFile(ID->getLocation());
|
|
|
|
unsigned Line = getLineNumber(ID->getLocation());
|
|
|
|
unsigned RuntimeLang = TheCU.getLanguage();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Bit size, align and offset of the type.
|
|
|
|
uint64_t Size = CGM.getContext().getTypeSize(Ty);
|
|
|
|
uint64_t Align = CGM.getContext().getTypeAlign(Ty);
|
|
|
|
|
|
|
|
unsigned Flags = 0;
|
|
|
|
if (ID->getImplementation())
|
|
|
|
Flags |= llvm::DIDescriptor::FlagObjcClassComplete;
|
|
|
|
|
2013-04-03 06:59:11 +08:00
|
|
|
llvm::DICompositeType RealDecl =
|
2012-12-18 22:30:41 +08:00
|
|
|
DBuilder.createStructType(Unit, ID->getName(), DefUnit,
|
|
|
|
Line, Size, Align, Flags,
|
2013-02-25 09:07:08 +08:00
|
|
|
llvm::DIType(), llvm::DIArray(), RuntimeLang);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-05-06 07:23:53 +08:00
|
|
|
QualType QTy(Ty, 0);
|
|
|
|
TypeCache[QTy.getAsOpaquePtr()] = RealDecl;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-07-15 05:00:07 +08:00
|
|
|
// Push the struct on region stack.
|
2013-04-03 06:59:11 +08:00
|
|
|
LexicalBlockStack.push_back(static_cast<llvm::MDNode*>(RealDecl));
|
2012-12-18 22:30:41 +08:00
|
|
|
RegionMap[Ty->getDecl()] = llvm::WeakVH(RealDecl);
|
|
|
|
|
|
|
|
// Convert all the elements.
|
|
|
|
SmallVector<llvm::Value *, 16> EltTys;
|
|
|
|
|
|
|
|
ObjCInterfaceDecl *SClass = ID->getSuperClass();
|
|
|
|
if (SClass) {
|
|
|
|
llvm::DIType SClassTy =
|
|
|
|
getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit);
|
|
|
|
if (!SClassTy.isValid())
|
|
|
|
return llvm::DIType();
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIType InhTag =
|
|
|
|
DBuilder.createInheritance(RealDecl, SClassTy, 0, 0);
|
|
|
|
EltTys.push_back(InhTag);
|
|
|
|
}
|
|
|
|
|
2013-07-15 05:00:07 +08:00
|
|
|
// Create entries for all of the properties.
|
2014-03-14 03:11:50 +08:00
|
|
|
for (const auto *PD : ID->properties()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceLocation Loc = PD->getLocation();
|
|
|
|
llvm::DIFile PUnit = getOrCreateFile(Loc);
|
|
|
|
unsigned PLine = getLineNumber(Loc);
|
|
|
|
ObjCMethodDecl *Getter = PD->getGetterMethodDecl();
|
|
|
|
ObjCMethodDecl *Setter = PD->getSetterMethodDecl();
|
|
|
|
llvm::MDNode *PropertyNode =
|
|
|
|
DBuilder.createObjCProperty(PD->getName(),
|
2013-02-22 06:35:08 +08:00
|
|
|
PUnit, PLine,
|
2013-06-07 09:10:45 +08:00
|
|
|
hasDefaultGetterName(PD, Getter) ? "" :
|
2012-12-18 22:30:41 +08:00
|
|
|
getSelectorName(PD->getGetterName()),
|
2013-06-07 09:10:45 +08:00
|
|
|
hasDefaultSetterName(PD, Setter) ? "" :
|
2012-12-18 22:30:41 +08:00
|
|
|
getSelectorName(PD->getSetterName()),
|
|
|
|
PD->getPropertyAttributes(),
|
2013-02-22 06:35:08 +08:00
|
|
|
getOrCreateType(PD->getType(), PUnit));
|
2012-12-18 22:30:41 +08:00
|
|
|
EltTys.push_back(PropertyNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ASTRecordLayout &RL = CGM.getContext().getASTObjCInterfaceLayout(ID);
|
|
|
|
unsigned FieldNo = 0;
|
|
|
|
for (ObjCIvarDecl *Field = ID->all_declared_ivar_begin(); Field;
|
|
|
|
Field = Field->getNextIvar(), ++FieldNo) {
|
|
|
|
llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit);
|
|
|
|
if (!FieldTy.isValid())
|
|
|
|
return llvm::DIType();
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
StringRef FieldName = Field->getName();
|
|
|
|
|
|
|
|
// Ignore unnamed fields.
|
|
|
|
if (FieldName.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Get the location for the field.
|
|
|
|
llvm::DIFile FieldDefUnit = getOrCreateFile(Field->getLocation());
|
|
|
|
unsigned FieldLine = getLineNumber(Field->getLocation());
|
|
|
|
QualType FType = Field->getType();
|
|
|
|
uint64_t FieldSize = 0;
|
|
|
|
unsigned FieldAlign = 0;
|
|
|
|
|
|
|
|
if (!FType->isIncompleteArrayType()) {
|
|
|
|
|
|
|
|
// Bit size, align and offset of the type.
|
|
|
|
FieldSize = Field->isBitField()
|
2013-07-15 05:00:07 +08:00
|
|
|
? Field->getBitWidthValue(CGM.getContext())
|
|
|
|
: CGM.getContext().getTypeSize(FType);
|
2012-12-18 22:30:41 +08:00
|
|
|
FieldAlign = CGM.getContext().getTypeAlign(FType);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t FieldOffset;
|
|
|
|
if (CGM.getLangOpts().ObjCRuntime.isNonFragile()) {
|
|
|
|
// We don't know the runtime offset of an ivar if we're using the
|
|
|
|
// non-fragile ABI. For bitfields, use the bit offset into the first
|
|
|
|
// byte of storage of the bitfield. For other fields, use zero.
|
|
|
|
if (Field->isBitField()) {
|
|
|
|
FieldOffset = CGM.getObjCRuntime().ComputeBitfieldBitOffset(
|
|
|
|
CGM, ID, Field);
|
|
|
|
FieldOffset %= CGM.getContext().getCharWidth();
|
|
|
|
} else {
|
|
|
|
FieldOffset = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
FieldOffset = RL.getFieldOffset(FieldNo);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned Flags = 0;
|
|
|
|
if (Field->getAccessControl() == ObjCIvarDecl::Protected)
|
|
|
|
Flags = llvm::DIDescriptor::FlagProtected;
|
|
|
|
else if (Field->getAccessControl() == ObjCIvarDecl::Private)
|
|
|
|
Flags = llvm::DIDescriptor::FlagPrivate;
|
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::MDNode *PropertyNode = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (ObjCImplementationDecl *ImpD = ID->getImplementation()) {
|
2013-05-16 08:45:12 +08:00
|
|
|
if (ObjCPropertyImplDecl *PImpD =
|
2012-12-18 22:30:41 +08:00
|
|
|
ImpD->FindPropertyImplIvarDecl(Field->getIdentifier())) {
|
|
|
|
if (ObjCPropertyDecl *PD = PImpD->getPropertyDecl()) {
|
2013-02-22 06:35:08 +08:00
|
|
|
SourceLocation Loc = PD->getLocation();
|
|
|
|
llvm::DIFile PUnit = getOrCreateFile(Loc);
|
|
|
|
unsigned PLine = getLineNumber(Loc);
|
2012-12-18 22:30:41 +08:00
|
|
|
ObjCMethodDecl *Getter = PD->getGetterMethodDecl();
|
|
|
|
ObjCMethodDecl *Setter = PD->getSetterMethodDecl();
|
|
|
|
PropertyNode =
|
|
|
|
DBuilder.createObjCProperty(PD->getName(),
|
|
|
|
PUnit, PLine,
|
2013-06-07 09:10:45 +08:00
|
|
|
hasDefaultGetterName(PD, Getter) ? "" :
|
2012-12-18 22:30:41 +08:00
|
|
|
getSelectorName(PD->getGetterName()),
|
2013-06-07 09:10:45 +08:00
|
|
|
hasDefaultSetterName(PD, Setter) ? "" :
|
2012-12-18 22:30:41 +08:00
|
|
|
getSelectorName(PD->getSetterName()),
|
|
|
|
PD->getPropertyAttributes(),
|
|
|
|
getOrCreateType(PD->getType(), PUnit));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FieldTy = DBuilder.createObjCIVar(FieldName, FieldDefUnit,
|
|
|
|
FieldLine, FieldSize, FieldAlign,
|
|
|
|
FieldOffset, Flags, FieldTy,
|
|
|
|
PropertyNode);
|
|
|
|
EltTys.push_back(FieldTy);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIArray Elements = DBuilder.getOrCreateArray(EltTys);
|
2014-07-29 03:14:41 +08:00
|
|
|
RealDecl.setArrays(Elements);
|
2013-03-07 06:03:30 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
LexicalBlockStack.pop_back();
|
2013-04-03 06:59:11 +08:00
|
|
|
return RealDecl;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIType CGDebugInfo::CreateType(const VectorType *Ty, llvm::DIFile Unit) {
|
|
|
|
llvm::DIType ElementTy = getOrCreateType(Ty->getElementType(), Unit);
|
|
|
|
int64_t Count = Ty->getNumElements();
|
|
|
|
if (Count == 0)
|
|
|
|
// If number of elements are not known then this is an unbounded array.
|
|
|
|
// Use Count == -1 to express such arrays.
|
|
|
|
Count = -1;
|
|
|
|
|
|
|
|
llvm::Value *Subscript = DBuilder.getOrCreateSubrange(0, Count);
|
|
|
|
llvm::DIArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
|
|
|
|
|
|
|
|
uint64_t Size = CGM.getContext().getTypeSize(Ty);
|
|
|
|
uint64_t Align = CGM.getContext().getTypeAlign(Ty);
|
|
|
|
|
|
|
|
return DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty,
|
|
|
|
llvm::DIFile Unit) {
|
|
|
|
uint64_t Size;
|
|
|
|
uint64_t Align;
|
|
|
|
|
|
|
|
// FIXME: make getTypeAlign() aware of VLAs and incomplete array types
|
|
|
|
if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(Ty)) {
|
|
|
|
Size = 0;
|
|
|
|
Align =
|
|
|
|
CGM.getContext().getTypeAlign(CGM.getContext().getBaseElementType(VAT));
|
|
|
|
} else if (Ty->isIncompleteArrayType()) {
|
|
|
|
Size = 0;
|
|
|
|
if (Ty->getElementType()->isIncompleteType())
|
|
|
|
Align = 0;
|
|
|
|
else
|
|
|
|
Align = CGM.getContext().getTypeAlign(Ty->getElementType());
|
2013-05-10 04:48:12 +08:00
|
|
|
} else if (Ty->isIncompleteType()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
Size = 0;
|
|
|
|
Align = 0;
|
|
|
|
} else {
|
|
|
|
// Size and align of the whole array, not the element type.
|
|
|
|
Size = CGM.getContext().getTypeSize(Ty);
|
|
|
|
Align = CGM.getContext().getTypeAlign(Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the dimensions of the array. FIXME: This loses CV qualifiers from
|
|
|
|
// interior arrays, do we care? Why aren't nested arrays represented the
|
|
|
|
// obvious/recursive way?
|
|
|
|
SmallVector<llvm::Value *, 8> Subscripts;
|
|
|
|
QualType EltTy(Ty, 0);
|
|
|
|
while ((Ty = dyn_cast<ArrayType>(EltTy))) {
|
|
|
|
// If the number of elements is known, then count is that number. Otherwise,
|
|
|
|
// it's -1. This allows us to represent a subrange with an array of 0
|
|
|
|
// elements, like this:
|
|
|
|
//
|
|
|
|
// struct foo {
|
|
|
|
// int x[0];
|
|
|
|
// };
|
|
|
|
int64_t Count = -1; // Count == -1 is an unbounded array.
|
|
|
|
if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty))
|
|
|
|
Count = CAT->getSize().getZExtValue();
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// FIXME: Verify this is right for VLAs.
|
|
|
|
Subscripts.push_back(DBuilder.getOrCreateSubrange(0, Count));
|
|
|
|
EltTy = Ty->getElementType();
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
|
|
|
|
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DIType DbgTy =
|
2012-12-18 22:30:41 +08:00
|
|
|
DBuilder.createArrayType(Size, Align, getOrCreateType(EltTy, Unit),
|
|
|
|
SubscriptArray);
|
|
|
|
return DbgTy;
|
|
|
|
}
|
|
|
|
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DIType CGDebugInfo::CreateType(const LValueReferenceType *Ty,
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIFile Unit) {
|
2013-05-16 08:45:12 +08:00
|
|
|
return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type,
|
2012-12-18 22:30:41 +08:00
|
|
|
Ty, Ty->getPointeeType(), Unit);
|
|
|
|
}
|
|
|
|
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DIType CGDebugInfo::CreateType(const RValueReferenceType *Ty,
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIFile Unit) {
|
2013-05-16 08:45:12 +08:00
|
|
|
return CreatePointerLikeType(llvm::dwarf::DW_TAG_rvalue_reference_type,
|
2012-12-18 22:30:41 +08:00
|
|
|
Ty, Ty->getPointeeType(), Unit);
|
|
|
|
}
|
|
|
|
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DIType CGDebugInfo::CreateType(const MemberPointerType *Ty,
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIFile U) {
|
2013-01-20 03:20:56 +08:00
|
|
|
llvm::DIType ClassType = getOrCreateType(QualType(Ty->getClass(), 0), U);
|
|
|
|
if (!Ty->getPointeeType()->isFunctionType())
|
|
|
|
return DBuilder.createMemberPointerType(
|
2013-09-05 06:03:57 +08:00
|
|
|
getOrCreateType(Ty->getPointeeType(), U), ClassType);
|
2013-12-19 09:38:47 +08:00
|
|
|
|
|
|
|
const FunctionProtoType *FPT =
|
|
|
|
Ty->getPointeeType()->getAs<FunctionProtoType>();
|
2013-01-20 03:20:56 +08:00
|
|
|
return DBuilder.createMemberPointerType(getOrCreateInstanceMethodType(
|
2013-12-19 09:38:47 +08:00
|
|
|
CGM.getContext().getPointerType(QualType(Ty->getClass(),
|
|
|
|
FPT->getTypeQuals())),
|
|
|
|
FPT, U), ClassType);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DIType CGDebugInfo::CreateType(const AtomicType *Ty,
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIFile U) {
|
|
|
|
// Ignore the atomic wrapping
|
|
|
|
// FIXME: What is the correct representation?
|
|
|
|
return getOrCreateType(Ty->getValueType(), U);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CreateEnumType - get enumeration type.
|
2013-08-29 05:46:36 +08:00
|
|
|
llvm::DIType CGDebugInfo::CreateEnumType(const EnumType *Ty) {
|
2013-08-29 05:20:28 +08:00
|
|
|
const EnumDecl *ED = Ty->getDecl();
|
2012-12-18 22:30:41 +08:00
|
|
|
uint64_t Size = 0;
|
|
|
|
uint64_t Align = 0;
|
|
|
|
if (!ED->getTypeForDecl()->isIncompleteType()) {
|
|
|
|
Size = CGM.getContext().getTypeSize(ED->getTypeForDecl());
|
|
|
|
Align = CGM.getContext().getTypeAlign(ED->getTypeForDecl());
|
|
|
|
}
|
|
|
|
|
2013-08-30 07:19:58 +08:00
|
|
|
SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// If this is just a forward declaration, construct an appropriately
|
|
|
|
// marked node and just return it.
|
|
|
|
if (!ED->getDefinition()) {
|
|
|
|
llvm::DIDescriptor EDContext;
|
|
|
|
EDContext = getContextDescriptor(cast<Decl>(ED->getDeclContext()));
|
|
|
|
llvm::DIFile DefUnit = getOrCreateFile(ED->getLocation());
|
|
|
|
unsigned Line = getLineNumber(ED->getLocation());
|
|
|
|
StringRef EDName = ED->getName();
|
2014-05-06 11:42:01 +08:00
|
|
|
llvm::DIType RetTy = DBuilder.createReplaceableForwardDecl(
|
|
|
|
llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit, Line,
|
|
|
|
0, Size, Align, FullName);
|
|
|
|
ReplaceMap.push_back(std::make_pair(Ty, static_cast<llvm::Value *>(RetTy)));
|
|
|
|
return RetTy;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-05-07 02:35:21 +08:00
|
|
|
return CreateTypeDefinition(Ty);
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIType CGDebugInfo::CreateTypeDefinition(const EnumType *Ty) {
|
|
|
|
const EnumDecl *ED = Ty->getDecl();
|
|
|
|
uint64_t Size = 0;
|
|
|
|
uint64_t Align = 0;
|
|
|
|
if (!ED->getTypeForDecl()->isIncompleteType()) {
|
|
|
|
Size = CGM.getContext().getTypeSize(ED->getTypeForDecl());
|
|
|
|
Align = CGM.getContext().getTypeAlign(ED->getTypeForDecl());
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Create DIEnumerator elements for each enumerator.
|
|
|
|
SmallVector<llvm::Value *, 16> Enumerators;
|
|
|
|
ED = ED->getDefinition();
|
2014-03-09 02:45:14 +08:00
|
|
|
for (const auto *Enum : ED->enumerators()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
Enumerators.push_back(
|
|
|
|
DBuilder.createEnumerator(Enum->getName(),
|
2013-06-24 15:13:13 +08:00
|
|
|
Enum->getInitVal().getSExtValue()));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return a CompositeType for the enum itself.
|
|
|
|
llvm::DIArray EltArray = DBuilder.getOrCreateArray(Enumerators);
|
|
|
|
|
|
|
|
llvm::DIFile DefUnit = getOrCreateFile(ED->getLocation());
|
|
|
|
unsigned Line = getLineNumber(ED->getLocation());
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DIDescriptor EnumContext =
|
2012-12-18 22:30:41 +08:00
|
|
|
getContextDescriptor(cast<Decl>(ED->getDeclContext()));
|
2013-04-20 03:56:39 +08:00
|
|
|
llvm::DIType ClassTy = ED->isFixed() ?
|
2012-12-18 22:30:41 +08:00
|
|
|
getOrCreateType(ED->getIntegerType(), DefUnit) : llvm::DIType();
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DIType DbgTy =
|
2012-12-18 22:30:41 +08:00
|
|
|
DBuilder.createEnumerationType(EnumContext, ED->getName(), DefUnit, Line,
|
|
|
|
Size, Align, EltArray,
|
2013-08-30 07:19:58 +08:00
|
|
|
ClassTy, FullName);
|
2012-12-18 22:30:41 +08:00
|
|
|
return DbgTy;
|
|
|
|
}
|
|
|
|
|
2013-01-21 12:37:12 +08:00
|
|
|
static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C) {
|
|
|
|
Qualifiers Quals;
|
2012-12-18 22:30:41 +08:00
|
|
|
do {
|
2013-09-27 05:35:50 +08:00
|
|
|
Qualifiers InnerQuals = T.getLocalQualifiers();
|
|
|
|
// Qualifiers::operator+() doesn't like it if you add a Qualifier
|
|
|
|
// that is already there.
|
|
|
|
Quals += Qualifiers::removeCommonQualifiers(Quals, InnerQuals);
|
|
|
|
Quals += InnerQuals;
|
2012-12-18 22:30:41 +08:00
|
|
|
QualType LastT = T;
|
|
|
|
switch (T->getTypeClass()) {
|
|
|
|
default:
|
2013-01-21 12:37:12 +08:00
|
|
|
return C.getQualifiedType(T.getTypePtr(), Quals);
|
2014-04-07 01:14:06 +08:00
|
|
|
case Type::TemplateSpecialization: {
|
|
|
|
const auto *Spec = cast<TemplateSpecializationType>(T);
|
|
|
|
if (Spec->isTypeAlias())
|
|
|
|
return C.getQualifiedType(T.getTypePtr(), Quals);
|
|
|
|
T = Spec->desugar();
|
|
|
|
break; }
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::TypeOfExpr:
|
|
|
|
T = cast<TypeOfExprType>(T)->getUnderlyingExpr()->getType();
|
|
|
|
break;
|
|
|
|
case Type::TypeOf:
|
|
|
|
T = cast<TypeOfType>(T)->getUnderlyingType();
|
|
|
|
break;
|
|
|
|
case Type::Decltype:
|
|
|
|
T = cast<DecltypeType>(T)->getUnderlyingType();
|
|
|
|
break;
|
|
|
|
case Type::UnaryTransform:
|
|
|
|
T = cast<UnaryTransformType>(T)->getUnderlyingType();
|
|
|
|
break;
|
|
|
|
case Type::Attributed:
|
|
|
|
T = cast<AttributedType>(T)->getEquivalentType();
|
|
|
|
break;
|
|
|
|
case Type::Elaborated:
|
|
|
|
T = cast<ElaboratedType>(T)->getNamedType();
|
|
|
|
break;
|
|
|
|
case Type::Paren:
|
|
|
|
T = cast<ParenType>(T)->getInnerType();
|
|
|
|
break;
|
2013-01-21 12:37:12 +08:00
|
|
|
case Type::SubstTemplateTypeParm:
|
2012-12-18 22:30:41 +08:00
|
|
|
T = cast<SubstTemplateTypeParmType>(T)->getReplacementType();
|
|
|
|
break;
|
|
|
|
case Type::Auto:
|
2013-05-25 05:24:35 +08:00
|
|
|
QualType DT = cast<AutoType>(T)->getDeducedType();
|
|
|
|
if (DT.isNull())
|
|
|
|
return T;
|
|
|
|
T = DT;
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(T != LastT && "Type unwrapping failed to unwrap!");
|
2013-01-21 18:51:28 +08:00
|
|
|
(void)LastT;
|
2012-12-18 22:30:41 +08:00
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
2013-05-16 08:52:20 +08:00
|
|
|
/// getType - Get the type from the cache or return null type if it doesn't
|
|
|
|
/// exist.
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIType CGDebugInfo::getTypeOrNull(QualType Ty) {
|
|
|
|
|
|
|
|
// Unwrap the type as needed for debug information.
|
2013-01-21 12:37:12 +08:00
|
|
|
Ty = UnwrapTypeForDebugInfo(Ty, CGM.getContext());
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2014-05-06 11:42:01 +08:00
|
|
|
auto it = TypeCache.find(Ty.getAsOpaquePtr());
|
2012-12-18 22:30:41 +08:00
|
|
|
if (it != TypeCache.end()) {
|
|
|
|
// Verify that the debug info still exists.
|
|
|
|
if (llvm::Value *V = it->second)
|
|
|
|
return llvm::DIType(cast<llvm::MDNode>(V));
|
|
|
|
}
|
|
|
|
|
|
|
|
return llvm::DIType();
|
|
|
|
}
|
|
|
|
|
2014-03-04 07:48:23 +08:00
|
|
|
void CGDebugInfo::completeTemplateDefinition(
|
|
|
|
const ClassTemplateSpecializationDecl &SD) {
|
2014-03-05 06:01:08 +08:00
|
|
|
if (DebugKind <= CodeGenOptions::DebugLineTablesOnly)
|
|
|
|
return;
|
|
|
|
|
2014-03-04 07:48:23 +08:00
|
|
|
completeClassData(&SD);
|
|
|
|
// In case this type has no member function definitions being emitted, ensure
|
|
|
|
// it is retained
|
|
|
|
RetainedTypes.push_back(CGM.getContext().getRecordType(&SD).getAsOpaquePtr());
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
/// getOrCreateType - Get the type from the cache or create a new
|
|
|
|
/// one if necessary.
|
2013-09-05 06:03:57 +08:00
|
|
|
llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty, llvm::DIFile Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (Ty.isNull())
|
|
|
|
return llvm::DIType();
|
|
|
|
|
|
|
|
// Unwrap the type as needed for debug information.
|
2013-01-21 12:37:12 +08:00
|
|
|
Ty = UnwrapTypeForDebugInfo(Ty, CGM.getContext());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-05-06 07:23:53 +08:00
|
|
|
if (llvm::DIType T = getTypeOrNull(Ty))
|
2012-12-18 22:30:41 +08:00
|
|
|
return T;
|
|
|
|
|
|
|
|
// Otherwise create the type.
|
2013-09-05 06:03:57 +08:00
|
|
|
llvm::DIType Res = CreateTypeNode(Ty, Unit);
|
2013-03-12 02:33:46 +08:00
|
|
|
void* TyPtr = Ty.getAsOpaquePtr();
|
|
|
|
|
|
|
|
// And update the type cache.
|
|
|
|
TypeCache[TyPtr] = Res;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
2013-06-07 09:10:41 +08:00
|
|
|
/// Currently the checksum of an interface includes the number of
|
|
|
|
/// ivars and property accessors.
|
2013-06-08 06:54:39 +08:00
|
|
|
unsigned CGDebugInfo::Checksum(const ObjCInterfaceDecl *ID) {
|
2013-06-07 09:10:48 +08:00
|
|
|
// The assumption is that the number of ivars can only increase
|
|
|
|
// monotonically, so it is safe to just use their current number as
|
|
|
|
// a checksum.
|
2013-06-07 09:10:41 +08:00
|
|
|
unsigned Sum = 0;
|
|
|
|
for (const ObjCIvarDecl *Ivar = ID->all_declared_ivar_begin();
|
2014-05-21 13:09:00 +08:00
|
|
|
Ivar != nullptr; Ivar = Ivar->getNextIvar())
|
2013-06-07 09:10:41 +08:00
|
|
|
++Sum;
|
|
|
|
|
|
|
|
return Sum;
|
2013-03-07 06:03:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjCInterfaceDecl *CGDebugInfo::getObjCInterfaceDecl(QualType Ty) {
|
|
|
|
switch (Ty->getTypeClass()) {
|
|
|
|
case Type::ObjCObjectPointer:
|
2013-05-16 08:52:20 +08:00
|
|
|
return getObjCInterfaceDecl(cast<ObjCObjectPointerType>(Ty)
|
|
|
|
->getPointeeType());
|
2013-03-07 06:03:30 +08:00
|
|
|
case Type::ObjCInterface:
|
|
|
|
return cast<ObjCInterfaceType>(Ty)->getDecl();
|
|
|
|
default:
|
2014-05-21 13:09:00 +08:00
|
|
|
return nullptr;
|
2013-03-07 06:03:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
/// CreateTypeNode - Create a new debug type node.
|
2013-09-05 06:03:57 +08:00
|
|
|
llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile Unit) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Handle qualifiers, which recursively handles what they refer to.
|
|
|
|
if (Ty.hasLocalQualifiers())
|
2013-09-05 06:03:57 +08:00
|
|
|
return CreateQualifiedType(Ty, Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
const char *Diag = nullptr;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Work out details of type.
|
|
|
|
switch (Ty->getTypeClass()) {
|
|
|
|
#define TYPE(Class, Base)
|
|
|
|
#define ABSTRACT_TYPE(Class, Base)
|
|
|
|
#define NON_CANONICAL_TYPE(Class, Base)
|
|
|
|
#define DEPENDENT_TYPE(Class, Base) case Type::Class:
|
|
|
|
#include "clang/AST/TypeNodes.def"
|
|
|
|
llvm_unreachable("Dependent types cannot show up in debug information");
|
|
|
|
|
|
|
|
case Type::ExtVector:
|
|
|
|
case Type::Vector:
|
|
|
|
return CreateType(cast<VectorType>(Ty), Unit);
|
|
|
|
case Type::ObjCObjectPointer:
|
|
|
|
return CreateType(cast<ObjCObjectPointerType>(Ty), Unit);
|
|
|
|
case Type::ObjCObject:
|
|
|
|
return CreateType(cast<ObjCObjectType>(Ty), Unit);
|
|
|
|
case Type::ObjCInterface:
|
|
|
|
return CreateType(cast<ObjCInterfaceType>(Ty), Unit);
|
|
|
|
case Type::Builtin:
|
|
|
|
return CreateType(cast<BuiltinType>(Ty));
|
|
|
|
case Type::Complex:
|
|
|
|
return CreateType(cast<ComplexType>(Ty));
|
|
|
|
case Type::Pointer:
|
|
|
|
return CreateType(cast<PointerType>(Ty), Unit);
|
2013-12-05 09:23:43 +08:00
|
|
|
case Type::Adjusted:
|
2013-06-25 01:51:48 +08:00
|
|
|
case Type::Decayed:
|
2013-12-05 09:23:43 +08:00
|
|
|
// Decayed and adjusted types use the adjusted type in LLVM and DWARF.
|
2013-06-25 01:51:48 +08:00
|
|
|
return CreateType(
|
2013-12-05 09:23:43 +08:00
|
|
|
cast<PointerType>(cast<AdjustedType>(Ty)->getAdjustedType()), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::BlockPointer:
|
|
|
|
return CreateType(cast<BlockPointerType>(Ty), Unit);
|
|
|
|
case Type::Typedef:
|
2013-09-05 06:03:57 +08:00
|
|
|
return CreateType(cast<TypedefType>(Ty), Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::Record:
|
2013-09-05 06:03:57 +08:00
|
|
|
return CreateType(cast<RecordType>(Ty));
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::Enum:
|
2013-08-29 05:20:28 +08:00
|
|
|
return CreateEnumType(cast<EnumType>(Ty));
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::FunctionProto:
|
|
|
|
case Type::FunctionNoProto:
|
|
|
|
return CreateType(cast<FunctionType>(Ty), Unit);
|
|
|
|
case Type::ConstantArray:
|
|
|
|
case Type::VariableArray:
|
|
|
|
case Type::IncompleteArray:
|
|
|
|
return CreateType(cast<ArrayType>(Ty), Unit);
|
|
|
|
|
|
|
|
case Type::LValueReference:
|
|
|
|
return CreateType(cast<LValueReferenceType>(Ty), Unit);
|
|
|
|
case Type::RValueReference:
|
|
|
|
return CreateType(cast<RValueReferenceType>(Ty), Unit);
|
|
|
|
|
|
|
|
case Type::MemberPointer:
|
|
|
|
return CreateType(cast<MemberPointerType>(Ty), Unit);
|
|
|
|
|
|
|
|
case Type::Atomic:
|
|
|
|
return CreateType(cast<AtomicType>(Ty), Unit);
|
|
|
|
|
|
|
|
case Type::TemplateSpecialization:
|
2014-04-07 01:14:06 +08:00
|
|
|
return CreateType(cast<TemplateSpecializationType>(Ty), Unit);
|
|
|
|
|
|
|
|
case Type::Attributed:
|
2012-12-18 22:30:41 +08:00
|
|
|
case Type::Elaborated:
|
|
|
|
case Type::Paren:
|
|
|
|
case Type::SubstTemplateTypeParm:
|
|
|
|
case Type::TypeOfExpr:
|
|
|
|
case Type::TypeOf:
|
|
|
|
case Type::Decltype:
|
|
|
|
case Type::UnaryTransform:
|
2013-07-14 05:08:08 +08:00
|
|
|
case Type::PackExpansion:
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm_unreachable("type should have been unwrapped!");
|
2013-05-25 05:24:35 +08:00
|
|
|
case Type::Auto:
|
|
|
|
Diag = "auto";
|
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(Diag && "Fall through without a diagnostic?");
|
|
|
|
unsigned DiagID = CGM.getDiags().getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"debug information for %0 is not yet supported");
|
|
|
|
CGM.getDiags().Report(DiagID)
|
|
|
|
<< Diag;
|
|
|
|
return llvm::DIType();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getOrCreateLimitedType - Get the type from the cache or create a new
|
|
|
|
/// limited type if necessary.
|
2013-08-13 06:24:20 +08:00
|
|
|
llvm::DIType CGDebugInfo::getOrCreateLimitedType(const RecordType *Ty,
|
2013-02-22 06:35:08 +08:00
|
|
|
llvm::DIFile Unit) {
|
2013-08-13 06:24:20 +08:00
|
|
|
QualType QTy(Ty, 0);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-08-21 05:03:29 +08:00
|
|
|
llvm::DICompositeType T(getTypeOrNull(QTy));
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// We may have cached a forward decl when we could have created
|
|
|
|
// a non-forward decl. Go ahead and create a non-forward decl
|
|
|
|
// now.
|
2013-07-18 08:52:50 +08:00
|
|
|
if (T && !T.isForwardDecl()) return T;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Otherwise create the type.
|
2013-08-21 05:03:29 +08:00
|
|
|
llvm::DICompositeType Res = CreateLimitedType(Ty);
|
|
|
|
|
|
|
|
// Propagate members from the declaration to the definition
|
|
|
|
// CreateType(const RecordType*) will overwrite this with the members in the
|
|
|
|
// correct order if the full type is needed.
|
2014-07-29 03:14:41 +08:00
|
|
|
Res.setArrays(T.getElements());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// And update the type cache.
|
2013-08-13 06:24:20 +08:00
|
|
|
TypeCache[QTy.getAsOpaquePtr()] = Res;
|
2012-12-18 22:30:41 +08:00
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Currently used for context chains when limiting debug info.
|
2013-08-21 05:03:29 +08:00
|
|
|
llvm::DICompositeType CGDebugInfo::CreateLimitedType(const RecordType *Ty) {
|
2012-12-18 22:30:41 +08:00
|
|
|
RecordDecl *RD = Ty->getDecl();
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Get overall information about the record type for the debug info.
|
|
|
|
llvm::DIFile DefUnit = getOrCreateFile(RD->getLocation());
|
|
|
|
unsigned Line = getLineNumber(RD->getLocation());
|
|
|
|
StringRef RDName = getClassName(RD);
|
|
|
|
|
2013-10-16 05:22:34 +08:00
|
|
|
llvm::DIDescriptor RDContext =
|
|
|
|
getContextDescriptor(cast<Decl>(RD->getDeclContext()));
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-08-19 01:36:19 +08:00
|
|
|
// If we ended up creating the type during the context chain construction,
|
|
|
|
// just return that.
|
2013-08-21 05:03:29 +08:00
|
|
|
llvm::DICompositeType T(getTypeOrNull(CGM.getContext().getRecordType(RD)));
|
|
|
|
if (T && (!T.isForwardDecl() || !RD->getDefinition()))
|
2013-08-19 01:36:19 +08:00
|
|
|
return T;
|
|
|
|
|
2014-02-05 05:29:50 +08:00
|
|
|
// If this is just a forward or incomplete declaration, construct an
|
|
|
|
// appropriately marked node and just return it.
|
|
|
|
const RecordDecl *D = RD->getDefinition();
|
|
|
|
if (!D || !D->isCompleteDefinition())
|
2013-08-29 05:20:28 +08:00
|
|
|
return getOrCreateRecordFwdDecl(Ty, RDContext);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
uint64_t Size = CGM.getContext().getTypeSize(Ty);
|
|
|
|
uint64_t Align = CGM.getContext().getTypeAlign(Ty);
|
2013-03-27 07:47:35 +08:00
|
|
|
llvm::DICompositeType RealDecl;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2013-08-30 07:19:58 +08:00
|
|
|
SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (RD->isUnion())
|
|
|
|
RealDecl = DBuilder.createUnionType(RDContext, RDName, DefUnit, Line,
|
2013-08-30 07:19:58 +08:00
|
|
|
Size, Align, 0, llvm::DIArray(), 0,
|
|
|
|
FullName);
|
2012-12-18 22:30:41 +08:00
|
|
|
else if (RD->isClass()) {
|
|
|
|
// FIXME: This could be a struct type giving a default visibility different
|
|
|
|
// than C++ class type, but needs llvm metadata changes first.
|
|
|
|
RealDecl = DBuilder.createClassType(RDContext, RDName, DefUnit, Line,
|
2013-02-22 06:35:08 +08:00
|
|
|
Size, Align, 0, 0, llvm::DIType(),
|
|
|
|
llvm::DIArray(), llvm::DIType(),
|
2013-08-30 07:19:58 +08:00
|
|
|
llvm::DIArray(), FullName);
|
2012-12-18 22:30:41 +08:00
|
|
|
} else
|
|
|
|
RealDecl = DBuilder.createStructType(RDContext, RDName, DefUnit, Line,
|
2013-05-16 08:52:20 +08:00
|
|
|
Size, Align, 0, llvm::DIType(),
|
2013-11-19 07:38:26 +08:00
|
|
|
llvm::DIArray(), 0, llvm::DIType(),
|
|
|
|
FullName);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
RegionMap[Ty->getDecl()] = llvm::WeakVH(RealDecl);
|
2013-03-27 07:47:35 +08:00
|
|
|
TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-08-19 00:55:33 +08:00
|
|
|
if (const ClassTemplateSpecializationDecl *TSpecial =
|
|
|
|
dyn_cast<ClassTemplateSpecializationDecl>(RD))
|
2014-07-29 03:14:41 +08:00
|
|
|
RealDecl.setArrays(llvm::DIArray(),
|
2013-08-19 00:55:33 +08:00
|
|
|
CollectCXXTemplateParams(TSpecial, DefUnit));
|
2013-08-16 06:42:12 +08:00
|
|
|
return RealDecl;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-08-19 00:55:33 +08:00
|
|
|
void CGDebugInfo::CollectContainingType(const CXXRecordDecl *RD,
|
|
|
|
llvm::DICompositeType RealDecl) {
|
|
|
|
// A class's primary base or the class itself contains the vtable.
|
|
|
|
llvm::DICompositeType ContainingType;
|
|
|
|
const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
|
|
|
|
if (const CXXRecordDecl *PBase = RL.getPrimaryBase()) {
|
2013-12-05 12:47:09 +08:00
|
|
|
// Seek non-virtual primary base root.
|
2013-08-19 00:55:33 +08:00
|
|
|
while (1) {
|
|
|
|
const ASTRecordLayout &BRL = CGM.getContext().getASTRecordLayout(PBase);
|
|
|
|
const CXXRecordDecl *PBT = BRL.getPrimaryBase();
|
|
|
|
if (PBT && !BRL.isPrimaryBaseVirtual())
|
|
|
|
PBase = PBT;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ContainingType = llvm::DICompositeType(
|
|
|
|
getOrCreateType(QualType(PBase->getTypeForDecl(), 0),
|
|
|
|
getOrCreateFile(RD->getLocation())));
|
|
|
|
} else if (RD->isDynamicClass())
|
|
|
|
ContainingType = RealDecl;
|
|
|
|
|
|
|
|
RealDecl.setContainingType(ContainingType);
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
/// CreateMemberType - Create new member and increase Offset by FType's size.
|
|
|
|
llvm::DIType CGDebugInfo::CreateMemberType(llvm::DIFile Unit, QualType FType,
|
|
|
|
StringRef Name,
|
|
|
|
uint64_t *Offset) {
|
|
|
|
llvm::DIType FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
|
|
|
|
uint64_t FieldSize = CGM.getContext().getTypeSize(FType);
|
|
|
|
unsigned FieldAlign = CGM.getContext().getTypeAlign(FType);
|
|
|
|
llvm::DIType Ty = DBuilder.createMemberType(Unit, Name, Unit, 0,
|
|
|
|
FieldSize, FieldAlign,
|
|
|
|
*Offset, 0, FieldTy);
|
|
|
|
*Offset += FieldSize;
|
|
|
|
return Ty;
|
|
|
|
}
|
|
|
|
|
2014-04-01 11:41:01 +08:00
|
|
|
llvm::DIScope CGDebugInfo::getDeclarationOrDefinition(const Decl *D) {
|
2013-05-20 12:58:53 +08:00
|
|
|
// We only need a declaration (not a definition) of the type - so use whatever
|
|
|
|
// we would otherwise do to get a type for a pointee. (forward declarations in
|
|
|
|
// limited debug info, full definitions (if the type definition is available)
|
|
|
|
// in unlimited debug info)
|
2013-08-13 07:14:36 +08:00
|
|
|
if (const TypeDecl *TD = dyn_cast<TypeDecl>(D))
|
|
|
|
return getOrCreateType(CGM.getContext().getTypeDeclType(TD),
|
2013-09-05 06:03:57 +08:00
|
|
|
getOrCreateFile(TD->getLocation()));
|
2013-05-20 12:58:53 +08:00
|
|
|
// Otherwise fall back to a fairly rudimentary cache of existing declarations.
|
|
|
|
// This doesn't handle providing declarations (for functions or variables) for
|
|
|
|
// entities without definitions in this TU, nor when the definition proceeds
|
|
|
|
// the call to this function.
|
|
|
|
// FIXME: This should be split out into more specific maps with support for
|
|
|
|
// emitting forward declarations and merging definitions with declarations,
|
|
|
|
// the same way as we do for types.
|
|
|
|
llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator I =
|
|
|
|
DeclCache.find(D->getCanonicalDecl());
|
|
|
|
if (I == DeclCache.end())
|
2014-04-01 11:41:01 +08:00
|
|
|
return llvm::DIScope();
|
2013-05-20 12:58:53 +08:00
|
|
|
llvm::Value *V = I->second;
|
2014-04-01 11:41:01 +08:00
|
|
|
return llvm::DIScope(dyn_cast_or_null<llvm::MDNode>(V));
|
2013-05-20 12:58:53 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
/// getFunctionDeclaration - Return debug info descriptor to describe method
|
|
|
|
/// declaration for the given method definition.
|
|
|
|
llvm::DISubprogram CGDebugInfo::getFunctionDeclaration(const Decl *D) {
|
2014-06-25 01:02:17 +08:00
|
|
|
if (!D || DebugKind <= CodeGenOptions::DebugLineTablesOnly)
|
2013-06-22 08:09:36 +08:00
|
|
|
return llvm::DISubprogram();
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
|
|
|
|
if (!FD) return llvm::DISubprogram();
|
|
|
|
|
|
|
|
// Setup context.
|
2013-08-10 01:20:05 +08:00
|
|
|
llvm::DIScope S = getContextDescriptor(cast<Decl>(D->getDeclContext()));
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator
|
|
|
|
MI = SPCache.find(FD->getCanonicalDecl());
|
2013-08-10 01:20:05 +08:00
|
|
|
if (MI == SPCache.end()) {
|
2013-08-29 07:12:10 +08:00
|
|
|
if (const CXXMethodDecl *MD =
|
|
|
|
dyn_cast<CXXMethodDecl>(FD->getCanonicalDecl())) {
|
2013-08-10 01:20:05 +08:00
|
|
|
llvm::DICompositeType T(S);
|
2013-08-29 07:12:10 +08:00
|
|
|
llvm::DISubprogram SP =
|
|
|
|
CreateCXXMemberFunction(MD, getOrCreateFile(MD->getLocation()), T);
|
2013-08-10 01:20:05 +08:00
|
|
|
return SP;
|
|
|
|
}
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
if (MI != SPCache.end()) {
|
|
|
|
llvm::Value *V = MI->second;
|
|
|
|
llvm::DISubprogram SP(dyn_cast_or_null<llvm::MDNode>(V));
|
2013-06-22 08:09:36 +08:00
|
|
|
if (SP.isSubprogram() && !SP.isDefinition())
|
2012-12-18 22:30:41 +08:00
|
|
|
return SP;
|
|
|
|
}
|
|
|
|
|
2014-03-07 07:45:36 +08:00
|
|
|
for (auto NextFD : FD->redecls()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator
|
|
|
|
MI = SPCache.find(NextFD->getCanonicalDecl());
|
|
|
|
if (MI != SPCache.end()) {
|
|
|
|
llvm::Value *V = MI->second;
|
|
|
|
llvm::DISubprogram SP(dyn_cast_or_null<llvm::MDNode>(V));
|
2013-06-22 08:09:36 +08:00
|
|
|
if (SP.isSubprogram() && !SP.isDefinition())
|
2012-12-18 22:30:41 +08:00
|
|
|
return SP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return llvm::DISubprogram();
|
|
|
|
}
|
|
|
|
|
|
|
|
// getOrCreateFunctionType - Construct DIType. If it is a c++ method, include
|
|
|
|
// implicit parameter "this".
|
2013-05-23 07:22:42 +08:00
|
|
|
llvm::DICompositeType CGDebugInfo::getOrCreateFunctionType(const Decl *D,
|
|
|
|
QualType FnType,
|
|
|
|
llvm::DIFile F) {
|
2014-06-25 01:02:17 +08:00
|
|
|
if (!D || DebugKind <= CodeGenOptions::DebugLineTablesOnly)
|
2013-06-22 08:09:36 +08:00
|
|
|
// Create fake but valid subroutine type. Otherwise
|
|
|
|
// llvm::DISubprogram::Verify() would return false, and
|
|
|
|
// subprogram DIE will miss DW_AT_decl_file and
|
|
|
|
// DW_AT_decl_line fields.
|
2014-07-29 06:24:34 +08:00
|
|
|
return DBuilder.createSubroutineType(F,
|
|
|
|
DBuilder.getOrCreateTypeArray(None));
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D))
|
|
|
|
return getOrCreateMethodType(Method, F);
|
|
|
|
if (const ObjCMethodDecl *OMethod = dyn_cast<ObjCMethodDecl>(D)) {
|
|
|
|
// Add "self" and "_cmd"
|
|
|
|
SmallVector<llvm::Value *, 16> Elts;
|
|
|
|
|
|
|
|
// First element is always return type. For 'void' functions it is NULL.
|
2014-01-26 00:55:45 +08:00
|
|
|
QualType ResultTy = OMethod->getReturnType();
|
2013-05-23 05:37:49 +08:00
|
|
|
|
|
|
|
// Replace the instancetype keyword with the actual type.
|
|
|
|
if (ResultTy == CGM.getContext().getObjCInstanceType())
|
|
|
|
ResultTy = CGM.getContext().getPointerType(
|
|
|
|
QualType(OMethod->getClassInterface()->getTypeForDecl(), 0));
|
|
|
|
|
2013-05-11 05:08:31 +08:00
|
|
|
Elts.push_back(getOrCreateType(ResultTy, F));
|
2012-12-18 22:30:41 +08:00
|
|
|
// "self" pointer is always first argument.
|
2013-03-30 03:20:29 +08:00
|
|
|
QualType SelfDeclTy = OMethod->getSelfDecl()->getType();
|
|
|
|
llvm::DIType SelfTy = getOrCreateType(SelfDeclTy, F);
|
|
|
|
Elts.push_back(CreateSelfType(SelfDeclTy, SelfTy));
|
2012-12-18 22:30:41 +08:00
|
|
|
// "_cmd" pointer is always second argument.
|
|
|
|
llvm::DIType CmdTy = getOrCreateType(OMethod->getCmdDecl()->getType(), F);
|
|
|
|
Elts.push_back(DBuilder.createArtificialType(CmdTy));
|
|
|
|
// Get rest of the arguments.
|
2014-03-08 01:50:17 +08:00
|
|
|
for (const auto *PI : OMethod->params())
|
|
|
|
Elts.push_back(getOrCreateType(PI->getType(), F));
|
2014-08-12 12:42:23 +08:00
|
|
|
// Variadic methods need a special marker at the end of the type list.
|
|
|
|
if (OMethod->isVariadic())
|
|
|
|
Elts.push_back(DBuilder.createUnspecifiedParameter());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-07-29 06:24:34 +08:00
|
|
|
llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
|
2012-12-18 22:30:41 +08:00
|
|
|
return DBuilder.createSubroutineType(F, EltTypeArray);
|
|
|
|
}
|
2014-02-26 03:38:11 +08:00
|
|
|
|
2014-02-26 07:42:18 +08:00
|
|
|
// Handle variadic function types; they need an additional
|
|
|
|
// unspecified parameter.
|
2014-02-26 03:38:11 +08:00
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
|
|
|
|
if (FD->isVariadic()) {
|
|
|
|
SmallVector<llvm::Value *, 16> EltTys;
|
|
|
|
EltTys.push_back(getOrCreateType(FD->getReturnType(), F));
|
|
|
|
if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(FnType))
|
|
|
|
for (unsigned i = 0, e = FPT->getNumParams(); i != e; ++i)
|
|
|
|
EltTys.push_back(getOrCreateType(FPT->getParamType(i), F));
|
|
|
|
EltTys.push_back(DBuilder.createUnspecifiedParameter());
|
2014-07-29 06:24:34 +08:00
|
|
|
llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
|
2014-02-26 03:38:11 +08:00
|
|
|
return DBuilder.createSubroutineType(F, EltTypeArray);
|
|
|
|
}
|
|
|
|
|
2013-05-23 07:22:42 +08:00
|
|
|
return llvm::DICompositeType(getOrCreateType(FnType, F));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitFunctionStart - Constructs the debug code for entering a function.
|
2014-04-11 07:21:53 +08:00
|
|
|
void CGDebugInfo::EmitFunctionStart(GlobalDecl GD,
|
|
|
|
SourceLocation Loc,
|
|
|
|
SourceLocation ScopeLoc,
|
|
|
|
QualType FnType,
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::Function *Fn,
|
|
|
|
CGBuilderTy &Builder) {
|
|
|
|
|
|
|
|
StringRef Name;
|
|
|
|
StringRef LinkageName;
|
|
|
|
|
|
|
|
FnBeginRegionCount.push_back(LexicalBlockStack.size());
|
|
|
|
|
|
|
|
const Decl *D = GD.getDecl();
|
2014-05-21 13:09:00 +08:00
|
|
|
bool HasDecl = (D != nullptr);
|
2014-04-02 06:25:28 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned Flags = 0;
|
|
|
|
llvm::DIFile Unit = getOrCreateFile(Loc);
|
|
|
|
llvm::DIDescriptor FDContext(Unit);
|
|
|
|
llvm::DIArray TParamsArray;
|
|
|
|
if (!HasDecl) {
|
|
|
|
// Use llvm function name.
|
2013-08-28 07:57:18 +08:00
|
|
|
LinkageName = Fn->getName();
|
2012-12-18 22:30:41 +08:00
|
|
|
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
// If there is a DISubprogram for this function available then use it.
|
|
|
|
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH>::iterator
|
|
|
|
FI = SPCache.find(FD->getCanonicalDecl());
|
|
|
|
if (FI != SPCache.end()) {
|
|
|
|
llvm::Value *V = FI->second;
|
|
|
|
llvm::DIDescriptor SP(dyn_cast_or_null<llvm::MDNode>(V));
|
|
|
|
if (SP.isSubprogram() && llvm::DISubprogram(SP).isDefinition()) {
|
|
|
|
llvm::MDNode *SPN = SP;
|
|
|
|
LexicalBlockStack.push_back(SPN);
|
|
|
|
RegionMap[D] = llvm::WeakVH(SP);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Name = getFunctionName(FD);
|
2013-03-20 09:38:16 +08:00
|
|
|
// Use mangled name as linkage name for C/C++ functions.
|
2012-12-18 22:30:41 +08:00
|
|
|
if (FD->hasPrototype()) {
|
|
|
|
LinkageName = CGM.getMangledName(GD);
|
|
|
|
Flags |= llvm::DIDescriptor::FlagPrototyped;
|
|
|
|
}
|
2013-03-20 09:38:16 +08:00
|
|
|
// No need to replicate the linkage name if it isn't different from the
|
|
|
|
// subprogram name, no need to have it at all unless coverage is enabled or
|
|
|
|
// debug is set to more than just line tables.
|
2012-12-18 22:30:41 +08:00
|
|
|
if (LinkageName == Name ||
|
2013-03-20 09:38:16 +08:00
|
|
|
(!CGM.getCodeGenOpts().EmitGcovArcs &&
|
|
|
|
!CGM.getCodeGenOpts().EmitGcovNotes &&
|
2013-05-16 08:45:23 +08:00
|
|
|
DebugKind <= CodeGenOptions::DebugLineTablesOnly))
|
2012-12-18 22:30:41 +08:00
|
|
|
LinkageName = StringRef();
|
|
|
|
|
2013-05-16 08:45:23 +08:00
|
|
|
if (DebugKind >= CodeGenOptions::LimitedDebugInfo) {
|
2014-03-27 13:29:34 +08:00
|
|
|
if (const NamespaceDecl *NSDecl =
|
|
|
|
dyn_cast_or_null<NamespaceDecl>(FD->getDeclContext()))
|
|
|
|
FDContext = getOrCreateNameSpace(NSDecl);
|
|
|
|
else if (const RecordDecl *RDecl =
|
|
|
|
dyn_cast_or_null<RecordDecl>(FD->getDeclContext()))
|
|
|
|
FDContext = getContextDescriptor(cast<Decl>(RDecl));
|
|
|
|
|
|
|
|
// Collect template parameters.
|
2012-12-18 22:30:41 +08:00
|
|
|
TParamsArray = CollectFunctionTemplateParams(FD, Unit);
|
|
|
|
}
|
|
|
|
} else if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) {
|
|
|
|
Name = getObjCMethodName(OMD);
|
|
|
|
Flags |= llvm::DIDescriptor::FlagPrototyped;
|
|
|
|
} else {
|
|
|
|
// Use llvm function name.
|
|
|
|
Name = Fn->getName();
|
|
|
|
Flags |= llvm::DIDescriptor::FlagPrototyped;
|
|
|
|
}
|
|
|
|
if (!Name.empty() && Name[0] == '\01')
|
|
|
|
Name = Name.substr(1);
|
|
|
|
|
2014-04-11 07:21:53 +08:00
|
|
|
if (!HasDecl || D->isImplicit()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
Flags |= llvm::DIDescriptor::FlagArtificial;
|
2014-04-11 07:21:53 +08:00
|
|
|
// Artificial functions without a location should not silently reuse CurLoc.
|
|
|
|
if (Loc.isInvalid())
|
|
|
|
CurLoc = SourceLocation();
|
|
|
|
}
|
|
|
|
unsigned LineNo = getLineNumber(Loc);
|
|
|
|
unsigned ScopeLine = getLineNumber(ScopeLoc);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-03-28 02:50:35 +08:00
|
|
|
// FIXME: The function declaration we're constructing here is mostly reusing
|
|
|
|
// declarations from CXXMethodDecl and not constructing new ones for arbitrary
|
|
|
|
// FunctionDecls. When/if we fix this we can have FDContext be TheCU/null for
|
|
|
|
// all subprograms instead of the actual context since subprogram definitions
|
|
|
|
// are emitted as CU level entities by the backend.
|
2013-10-17 09:31:21 +08:00
|
|
|
llvm::DISubprogram SP =
|
|
|
|
DBuilder.createFunction(FDContext, Name, LinkageName, Unit, LineNo,
|
|
|
|
getOrCreateFunctionType(D, FnType, Unit),
|
|
|
|
Fn->hasInternalLinkage(), true /*definition*/,
|
2014-04-11 07:21:53 +08:00
|
|
|
ScopeLine, Flags,
|
2013-10-17 09:31:21 +08:00
|
|
|
CGM.getLangOpts().Optimize, Fn, TParamsArray,
|
|
|
|
getFunctionDeclaration(D));
|
2013-05-20 12:58:53 +08:00
|
|
|
if (HasDecl)
|
|
|
|
DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(SP)));
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-03-22 05:01:58 +08:00
|
|
|
// Push the function onto the lexical block stack.
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::MDNode *SPN = SP;
|
|
|
|
LexicalBlockStack.push_back(SPN);
|
2014-03-22 05:01:58 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (HasDecl)
|
|
|
|
RegionMap[D] = llvm::WeakVH(SP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitLocation - Emit metadata to indicate a change in line/column
|
2013-07-18 08:27:59 +08:00
|
|
|
/// information in the source file. If the location is invalid, the
|
|
|
|
/// previous location will be reused.
|
2013-03-13 04:43:25 +08:00
|
|
|
void CGDebugInfo::EmitLocation(CGBuilderTy &Builder, SourceLocation Loc,
|
2014-01-08 06:05:52 +08:00
|
|
|
bool ForceColumnInfo) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Update our current location
|
|
|
|
setLocation(Loc);
|
|
|
|
|
|
|
|
if (CurLoc.isInvalid() || CurLoc.isMacroID()) return;
|
|
|
|
|
|
|
|
// Don't bother if things are the same as last time.
|
|
|
|
SourceManager &SM = CGM.getContext().getSourceManager();
|
|
|
|
if (CurLoc == PrevLoc ||
|
|
|
|
SM.getExpansionLoc(CurLoc) == SM.getExpansionLoc(PrevLoc))
|
|
|
|
// New Builder may not be in sync with CGDebugInfo.
|
2013-02-02 03:09:49 +08:00
|
|
|
if (!Builder.getCurrentDebugLocation().isUnknown() &&
|
|
|
|
Builder.getCurrentDebugLocation().getScope(CGM.getLLVMContext()) ==
|
|
|
|
LexicalBlockStack.back())
|
2012-12-18 22:30:41 +08:00
|
|
|
return;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Update last state.
|
|
|
|
PrevLoc = CurLoc;
|
|
|
|
|
2014-01-08 06:05:52 +08:00
|
|
|
llvm::MDNode *Scope = LexicalBlockStack.back();
|
2013-03-13 04:43:25 +08:00
|
|
|
Builder.SetCurrentDebugLocation(llvm::DebugLoc::get
|
|
|
|
(getLineNumber(CurLoc),
|
|
|
|
getColumnNumber(CurLoc, ForceColumnInfo),
|
|
|
|
Scope));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// CreateLexicalBlock - Creates a new lexical block node and pushes it on
|
|
|
|
/// the stack.
|
|
|
|
void CGDebugInfo::CreateLexicalBlock(SourceLocation Loc) {
|
2014-06-03 00:32:05 +08:00
|
|
|
llvm::DIDescriptor D = DBuilder.createLexicalBlock(
|
|
|
|
llvm::DIDescriptor(LexicalBlockStack.empty() ? nullptr
|
|
|
|
: LexicalBlockStack.back()),
|
|
|
|
getOrCreateFile(CurLoc), getLineNumber(CurLoc), getColumnNumber(CurLoc),
|
|
|
|
0);
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::MDNode *DN = D;
|
|
|
|
LexicalBlockStack.push_back(DN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitLexicalBlockStart - Constructs the debug code for entering a declarative
|
|
|
|
/// region - beginning of a DW_TAG_lexical_block.
|
2013-05-16 08:52:20 +08:00
|
|
|
void CGDebugInfo::EmitLexicalBlockStart(CGBuilderTy &Builder,
|
|
|
|
SourceLocation Loc) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Set our current location.
|
|
|
|
setLocation(Loc);
|
|
|
|
|
|
|
|
// Create a new lexical block and push it on the stack.
|
|
|
|
CreateLexicalBlock(Loc);
|
|
|
|
|
|
|
|
// Emit a line table change for the current location inside the new scope.
|
|
|
|
Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(getLineNumber(Loc),
|
|
|
|
getColumnNumber(Loc),
|
|
|
|
LexicalBlockStack.back()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitLexicalBlockEnd - Constructs the debug code for exiting a declarative
|
|
|
|
/// region - end of a DW_TAG_lexical_block.
|
2013-05-16 08:52:20 +08:00
|
|
|
void CGDebugInfo::EmitLexicalBlockEnd(CGBuilderTy &Builder,
|
|
|
|
SourceLocation Loc) {
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
|
|
|
|
|
|
|
|
// Provide an entry in the line table for the end of the block.
|
|
|
|
EmitLocation(Builder, Loc);
|
|
|
|
|
|
|
|
LexicalBlockStack.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitFunctionEnd - Constructs the debug code for exiting a function.
|
|
|
|
void CGDebugInfo::EmitFunctionEnd(CGBuilderTy &Builder) {
|
|
|
|
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
|
|
|
|
unsigned RCount = FnBeginRegionCount.back();
|
|
|
|
assert(RCount <= LexicalBlockStack.size() && "Region stack mismatch");
|
|
|
|
|
|
|
|
// Pop all regions for this function.
|
|
|
|
while (LexicalBlockStack.size() != RCount)
|
|
|
|
EmitLexicalBlockEnd(Builder, CurLoc);
|
|
|
|
FnBeginRegionCount.pop_back();
|
|
|
|
}
|
|
|
|
|
2013-05-16 08:45:12 +08:00
|
|
|
// EmitTypeForVarWithBlocksAttr - Build up structure info for the byref.
|
2012-12-18 22:30:41 +08:00
|
|
|
// See BuildByRefType.
|
|
|
|
llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
|
|
|
|
uint64_t *XOffset) {
|
|
|
|
|
|
|
|
SmallVector<llvm::Value *, 5> EltTys;
|
|
|
|
QualType FType;
|
|
|
|
uint64_t FieldSize, FieldOffset;
|
|
|
|
unsigned FieldAlign;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIFile Unit = getOrCreateFile(VD->getLocation());
|
2013-05-16 08:45:12 +08:00
|
|
|
QualType Type = VD->getType();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
FieldOffset = 0;
|
|
|
|
FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__isa", &FieldOffset));
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__forwarding", &FieldOffset));
|
|
|
|
FType = CGM.getContext().IntTy;
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__size", &FieldOffset));
|
|
|
|
|
|
|
|
bool HasCopyAndDispose = CGM.getContext().BlockRequiresCopying(Type, VD);
|
|
|
|
if (HasCopyAndDispose) {
|
|
|
|
FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__copy_helper",
|
|
|
|
&FieldOffset));
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "__destroy_helper",
|
|
|
|
&FieldOffset));
|
|
|
|
}
|
|
|
|
bool HasByrefExtendedLayout;
|
|
|
|
Qualifiers::ObjCLifetime Lifetime;
|
|
|
|
if (CGM.getContext().getByrefLifetime(Type,
|
|
|
|
Lifetime, HasByrefExtendedLayout)
|
2013-07-23 08:12:14 +08:00
|
|
|
&& HasByrefExtendedLayout) {
|
|
|
|
FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
|
2012-12-18 22:30:41 +08:00
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType,
|
|
|
|
"__byref_variable_layout",
|
|
|
|
&FieldOffset));
|
2013-07-23 08:12:14 +08:00
|
|
|
}
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
CharUnits Align = CGM.getContext().getDeclAlign(VD);
|
|
|
|
if (Align > CGM.getContext().toCharUnitsFromBits(
|
2013-04-17 06:48:15 +08:00
|
|
|
CGM.getTarget().getPointerAlign(0))) {
|
2013-05-16 08:45:12 +08:00
|
|
|
CharUnits FieldOffsetInBytes
|
2012-12-18 22:30:41 +08:00
|
|
|
= CGM.getContext().toCharUnitsFromBits(FieldOffset);
|
|
|
|
CharUnits AlignedOffsetInBytes
|
|
|
|
= FieldOffsetInBytes.RoundUpToAlignment(Align);
|
|
|
|
CharUnits NumPaddingBytes
|
|
|
|
= AlignedOffsetInBytes - FieldOffsetInBytes;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (NumPaddingBytes.isPositive()) {
|
|
|
|
llvm::APInt pad(32, NumPaddingBytes.getQuantity());
|
|
|
|
FType = CGM.getContext().getConstantArrayType(CGM.getContext().CharTy,
|
|
|
|
pad, ArrayType::Normal, 0);
|
|
|
|
EltTys.push_back(CreateMemberType(Unit, FType, "", &FieldOffset));
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
FType = Type;
|
2014-05-06 11:42:01 +08:00
|
|
|
llvm::DIType FieldTy = getOrCreateType(FType, Unit);
|
2012-12-18 22:30:41 +08:00
|
|
|
FieldSize = CGM.getContext().getTypeSize(FType);
|
|
|
|
FieldAlign = CGM.getContext().toBits(Align);
|
|
|
|
|
2013-05-16 08:45:12 +08:00
|
|
|
*XOffset = FieldOffset;
|
2012-12-18 22:30:41 +08:00
|
|
|
FieldTy = DBuilder.createMemberType(Unit, VD->getName(), Unit,
|
|
|
|
0, FieldSize, FieldAlign,
|
|
|
|
FieldOffset, 0, FieldTy);
|
|
|
|
EltTys.push_back(FieldTy);
|
|
|
|
FieldOffset += FieldSize;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIArray Elements = DBuilder.getOrCreateArray(EltTys);
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned Flags = llvm::DIDescriptor::FlagBlockByrefStruct;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
return DBuilder.createStructType(Unit, "", Unit, 0, FieldOffset, 0, Flags,
|
2013-02-25 09:07:08 +08:00
|
|
|
llvm::DIType(), Elements);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitDeclare - Emit local variable declaration debug info.
|
2014-05-07 20:49:30 +08:00
|
|
|
void CGDebugInfo::EmitDeclare(const VarDecl *VD, llvm::dwarf::LLVMConstants Tag,
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::Value *Storage,
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned ArgNo, CGBuilderTy &Builder) {
|
2013-05-16 08:45:23 +08:00
|
|
|
assert(DebugKind >= CodeGenOptions::LimitedDebugInfo);
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
|
|
|
|
|
2013-08-19 11:37:48 +08:00
|
|
|
bool Unwritten =
|
|
|
|
VD->isImplicit() || (isa<Decl>(VD->getDeclContext()) &&
|
|
|
|
cast<Decl>(VD->getDeclContext())->isImplicit());
|
|
|
|
llvm::DIFile Unit;
|
|
|
|
if (!Unwritten)
|
|
|
|
Unit = getOrCreateFile(VD->getLocation());
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIType Ty;
|
|
|
|
uint64_t XOffset = 0;
|
|
|
|
if (VD->hasAttr<BlocksAttr>())
|
|
|
|
Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset);
|
2013-05-16 08:45:12 +08:00
|
|
|
else
|
2012-12-18 22:30:41 +08:00
|
|
|
Ty = getOrCreateType(VD->getType(), Unit);
|
|
|
|
|
|
|
|
// If there is no debug info for this type then do not emit debug info
|
|
|
|
// for this variable.
|
|
|
|
if (!Ty)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Get location information.
|
2013-08-19 11:37:48 +08:00
|
|
|
unsigned Line = 0;
|
|
|
|
unsigned Column = 0;
|
|
|
|
if (!Unwritten) {
|
|
|
|
Line = getLineNumber(VD->getLocation());
|
|
|
|
Column = getColumnNumber(VD->getLocation());
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned Flags = 0;
|
|
|
|
if (VD->isImplicit())
|
|
|
|
Flags |= llvm::DIDescriptor::FlagArtificial;
|
|
|
|
// If this is the first argument and it is implicit then
|
|
|
|
// give it an object pointer flag.
|
|
|
|
// FIXME: There has to be a better way to do this, but for static
|
|
|
|
// functions there won't be an implicit param at arg1 and
|
|
|
|
// otherwise it is 'self' or 'this'.
|
|
|
|
if (isa<ImplicitParamDecl>(VD) && ArgNo == 1)
|
|
|
|
Flags |= llvm::DIDescriptor::FlagObjectPointer;
|
2013-06-20 05:53:53 +08:00
|
|
|
if (llvm::Argument *Arg = dyn_cast<llvm::Argument>(Storage))
|
2013-07-18 06:52:53 +08:00
|
|
|
if (Arg->getType()->isPointerTy() && !Arg->hasByValAttr() &&
|
|
|
|
!VD->getType()->isPointerType())
|
2013-06-20 05:53:53 +08:00
|
|
|
Flags |= llvm::DIDescriptor::FlagIndirectVariable;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
llvm::MDNode *Scope = LexicalBlockStack.back();
|
|
|
|
|
|
|
|
StringRef Name = VD->getName();
|
|
|
|
if (!Name.empty()) {
|
|
|
|
if (VD->hasAttr<BlocksAttr>()) {
|
|
|
|
CharUnits offset = CharUnits::fromQuantity(32);
|
|
|
|
SmallVector<llvm::Value *, 9> addr;
|
|
|
|
llvm::Type *Int64Ty = CGM.Int64Ty;
|
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIBuilder::OpPlus));
|
|
|
|
// offset of __forwarding field
|
|
|
|
offset = CGM.getContext().toCharUnitsFromBits(
|
2013-04-17 06:48:15 +08:00
|
|
|
CGM.getTarget().getPointerWidth(0));
|
2012-12-18 22:30:41 +08:00
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity()));
|
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIBuilder::OpDeref));
|
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIBuilder::OpPlus));
|
|
|
|
// offset of x field
|
|
|
|
offset = CGM.getContext().toCharUnitsFromBits(XOffset);
|
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity()));
|
|
|
|
|
|
|
|
// Create the descriptor for the variable.
|
|
|
|
llvm::DIVariable D =
|
2013-05-16 08:45:12 +08:00
|
|
|
DBuilder.createComplexVariable(Tag,
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIDescriptor(Scope),
|
|
|
|
VD->getName(), Unit, Line, Ty,
|
|
|
|
addr, ArgNo);
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Insert an llvm.dbg.declare into the current block.
|
|
|
|
llvm::Instruction *Call =
|
|
|
|
DBuilder.insertDeclare(Storage, D, Builder.GetInsertBlock());
|
|
|
|
Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope));
|
|
|
|
return;
|
2013-09-19 06:18:17 +08:00
|
|
|
} else if (isa<VariableArrayType>(VD->getType()))
|
2013-09-19 06:08:57 +08:00
|
|
|
Flags |= llvm::DIDescriptor::FlagIndirectVariable;
|
2013-01-05 13:58:35 +08:00
|
|
|
} else if (const RecordType *RT = dyn_cast<RecordType>(VD->getType())) {
|
|
|
|
// If VD is an anonymous union then Storage represents value for
|
|
|
|
// all union fields.
|
2012-12-18 22:30:41 +08:00
|
|
|
const RecordDecl *RD = cast<RecordDecl>(RT->getDecl());
|
2013-01-06 04:03:07 +08:00
|
|
|
if (RD->isUnion() && RD->isAnonymousStructOrUnion()) {
|
2014-03-09 04:12:42 +08:00
|
|
|
for (const auto *Field : RD->fields()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit);
|
|
|
|
StringRef FieldName = Field->getName();
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Ignore unnamed fields. Do not ignore unnamed records.
|
|
|
|
if (FieldName.empty() && !isa<RecordType>(Field->getType()))
|
|
|
|
continue;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Use VarDecl's Tag, Scope and Line number.
|
|
|
|
llvm::DIVariable D =
|
|
|
|
DBuilder.createLocalVariable(Tag, llvm::DIDescriptor(Scope),
|
2013-05-16 08:45:12 +08:00
|
|
|
FieldName, Unit, Line, FieldTy,
|
2012-12-18 22:30:41 +08:00
|
|
|
CGM.getLangOpts().Optimize, Flags,
|
|
|
|
ArgNo);
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Insert an llvm.dbg.declare into the current block.
|
|
|
|
llvm::Instruction *Call =
|
|
|
|
DBuilder.insertDeclare(Storage, D, Builder.GetInsertBlock());
|
|
|
|
Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope));
|
|
|
|
}
|
2013-01-06 04:03:07 +08:00
|
|
|
return;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
2013-01-05 13:58:35 +08:00
|
|
|
|
|
|
|
// Create the descriptor for the variable.
|
|
|
|
llvm::DIVariable D =
|
|
|
|
DBuilder.createLocalVariable(Tag, llvm::DIDescriptor(Scope),
|
|
|
|
Name, Unit, Line, Ty,
|
|
|
|
CGM.getLangOpts().Optimize, Flags, ArgNo);
|
|
|
|
|
|
|
|
// Insert an llvm.dbg.declare into the current block.
|
|
|
|
llvm::Instruction *Call =
|
|
|
|
DBuilder.insertDeclare(Storage, D, Builder.GetInsertBlock());
|
|
|
|
Call->setDebugLoc(llvm::DebugLoc::get(Line, Column, Scope));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *VD,
|
|
|
|
llvm::Value *Storage,
|
|
|
|
CGBuilderTy &Builder) {
|
2013-05-16 08:45:23 +08:00
|
|
|
assert(DebugKind >= CodeGenOptions::LimitedDebugInfo);
|
2012-12-18 22:30:41 +08:00
|
|
|
EmitDeclare(VD, llvm::dwarf::DW_TAG_auto_variable, Storage, 0, Builder);
|
|
|
|
}
|
|
|
|
|
2013-03-30 03:20:29 +08:00
|
|
|
/// Look up the completed type for a self pointer in the TypeCache and
|
|
|
|
/// create a copy of it with the ObjectPointer and Artificial flags
|
|
|
|
/// set. If the type is not cached, a new one is created. This should
|
|
|
|
/// never happen though, since creating a type for the implicit self
|
|
|
|
/// argument implies that we already parsed the interface definition
|
|
|
|
/// and the ivar declarations in the implementation.
|
2013-05-16 08:52:20 +08:00
|
|
|
llvm::DIType CGDebugInfo::CreateSelfType(const QualType &QualTy,
|
|
|
|
llvm::DIType Ty) {
|
2013-03-30 03:20:29 +08:00
|
|
|
llvm::DIType CachedTy = getTypeOrNull(QualTy);
|
2013-07-18 08:52:50 +08:00
|
|
|
if (CachedTy) Ty = CachedTy;
|
2013-03-30 03:20:29 +08:00
|
|
|
return DBuilder.createObjectPointerType(Ty);
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(const VarDecl *VD,
|
|
|
|
llvm::Value *Storage,
|
|
|
|
CGBuilderTy &Builder,
|
|
|
|
const CGBlockInfo &blockInfo) {
|
2013-05-16 08:45:23 +08:00
|
|
|
assert(DebugKind >= CodeGenOptions::LimitedDebugInfo);
|
2012-12-18 22:30:41 +08:00
|
|
|
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2014-05-21 13:09:00 +08:00
|
|
|
if (Builder.GetInsertBlock() == nullptr)
|
2012-12-18 22:30:41 +08:00
|
|
|
return;
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
bool isByRef = VD->hasAttr<BlocksAttr>();
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
uint64_t XOffset = 0;
|
|
|
|
llvm::DIFile Unit = getOrCreateFile(VD->getLocation());
|
|
|
|
llvm::DIType Ty;
|
|
|
|
if (isByRef)
|
|
|
|
Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset);
|
2013-05-16 08:45:12 +08:00
|
|
|
else
|
2012-12-18 22:30:41 +08:00
|
|
|
Ty = getOrCreateType(VD->getType(), Unit);
|
|
|
|
|
|
|
|
// Self is passed along as an implicit non-arg variable in a
|
|
|
|
// block. Mark it as the object pointer.
|
|
|
|
if (isa<ImplicitParamDecl>(VD) && VD->getName() == "self")
|
2013-03-30 03:20:29 +08:00
|
|
|
Ty = CreateSelfType(VD->getType(), Ty);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Get location information.
|
|
|
|
unsigned Line = getLineNumber(VD->getLocation());
|
|
|
|
unsigned Column = getColumnNumber(VD->getLocation());
|
|
|
|
|
|
|
|
const llvm::DataLayout &target = CGM.getDataLayout();
|
|
|
|
|
|
|
|
CharUnits offset = CharUnits::fromQuantity(
|
|
|
|
target.getStructLayout(blockInfo.StructureType)
|
|
|
|
->getElementOffset(blockInfo.getCapture(VD).getIndex()));
|
|
|
|
|
|
|
|
SmallVector<llvm::Value *, 9> addr;
|
|
|
|
llvm::Type *Int64Ty = CGM.Int64Ty;
|
2013-03-30 03:20:35 +08:00
|
|
|
if (isa<llvm::AllocaInst>(Storage))
|
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIBuilder::OpDeref));
|
2012-12-18 22:30:41 +08:00
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIBuilder::OpPlus));
|
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity()));
|
|
|
|
if (isByRef) {
|
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIBuilder::OpDeref));
|
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIBuilder::OpPlus));
|
|
|
|
// offset of __forwarding field
|
|
|
|
offset = CGM.getContext()
|
|
|
|
.toCharUnitsFromBits(target.getPointerSizeInBits(0));
|
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity()));
|
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIBuilder::OpDeref));
|
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, llvm::DIBuilder::OpPlus));
|
|
|
|
// offset of x field
|
|
|
|
offset = CGM.getContext().toCharUnitsFromBits(XOffset);
|
|
|
|
addr.push_back(llvm::ConstantInt::get(Int64Ty, offset.getQuantity()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the descriptor for the variable.
|
|
|
|
llvm::DIVariable D =
|
2013-05-16 08:45:12 +08:00
|
|
|
DBuilder.createComplexVariable(llvm::dwarf::DW_TAG_auto_variable,
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIDescriptor(LexicalBlockStack.back()),
|
|
|
|
VD->getName(), Unit, Line, Ty, addr);
|
2013-03-30 03:20:35 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Insert an llvm.dbg.declare into the current block.
|
|
|
|
llvm::Instruction *Call =
|
|
|
|
DBuilder.insertDeclare(Storage, D, Builder.GetInsertPoint());
|
|
|
|
Call->setDebugLoc(llvm::DebugLoc::get(Line, Column,
|
|
|
|
LexicalBlockStack.back()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
|
|
|
|
/// variable declaration.
|
|
|
|
void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *VD, llvm::Value *AI,
|
|
|
|
unsigned ArgNo,
|
|
|
|
CGBuilderTy &Builder) {
|
2013-05-16 08:45:23 +08:00
|
|
|
assert(DebugKind >= CodeGenOptions::LimitedDebugInfo);
|
2012-12-18 22:30:41 +08:00
|
|
|
EmitDeclare(VD, llvm::dwarf::DW_TAG_arg_variable, AI, ArgNo, Builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct BlockLayoutChunk {
|
|
|
|
uint64_t OffsetInBits;
|
|
|
|
const BlockDecl::Capture *Capture;
|
|
|
|
};
|
|
|
|
bool operator<(const BlockLayoutChunk &l, const BlockLayoutChunk &r) {
|
|
|
|
return l.OffsetInBits < r.OffsetInBits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
|
2013-03-15 01:53:33 +08:00
|
|
|
llvm::Value *Arg,
|
2014-08-09 01:10:14 +08:00
|
|
|
unsigned ArgNo,
|
2013-03-15 01:53:33 +08:00
|
|
|
llvm::Value *LocalAddr,
|
2012-12-18 22:30:41 +08:00
|
|
|
CGBuilderTy &Builder) {
|
2013-05-16 08:45:23 +08:00
|
|
|
assert(DebugKind >= CodeGenOptions::LimitedDebugInfo);
|
2012-12-18 22:30:41 +08:00
|
|
|
ASTContext &C = CGM.getContext();
|
|
|
|
const BlockDecl *blockDecl = block.getBlockDecl();
|
|
|
|
|
|
|
|
// Collect some general information about the block's location.
|
|
|
|
SourceLocation loc = blockDecl->getCaretLocation();
|
|
|
|
llvm::DIFile tunit = getOrCreateFile(loc);
|
|
|
|
unsigned line = getLineNumber(loc);
|
|
|
|
unsigned column = getColumnNumber(loc);
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Build the debug-info type for the block literal.
|
|
|
|
getContextDescriptor(cast<Decl>(blockDecl->getDeclContext()));
|
|
|
|
|
|
|
|
const llvm::StructLayout *blockLayout =
|
|
|
|
CGM.getDataLayout().getStructLayout(block.StructureType);
|
|
|
|
|
|
|
|
SmallVector<llvm::Value*, 16> fields;
|
|
|
|
fields.push_back(createFieldType("__isa", C.VoidPtrTy, 0, loc, AS_public,
|
|
|
|
blockLayout->getElementOffsetInBits(0),
|
|
|
|
tunit, tunit));
|
|
|
|
fields.push_back(createFieldType("__flags", C.IntTy, 0, loc, AS_public,
|
|
|
|
blockLayout->getElementOffsetInBits(1),
|
|
|
|
tunit, tunit));
|
|
|
|
fields.push_back(createFieldType("__reserved", C.IntTy, 0, loc, AS_public,
|
|
|
|
blockLayout->getElementOffsetInBits(2),
|
|
|
|
tunit, tunit));
|
|
|
|
fields.push_back(createFieldType("__FuncPtr", C.VoidPtrTy, 0, loc, AS_public,
|
|
|
|
blockLayout->getElementOffsetInBits(3),
|
|
|
|
tunit, tunit));
|
|
|
|
fields.push_back(createFieldType("__descriptor",
|
|
|
|
C.getPointerType(block.NeedsCopyDispose ?
|
|
|
|
C.getBlockDescriptorExtendedType() :
|
|
|
|
C.getBlockDescriptorType()),
|
|
|
|
0, loc, AS_public,
|
|
|
|
blockLayout->getElementOffsetInBits(4),
|
|
|
|
tunit, tunit));
|
|
|
|
|
|
|
|
// We want to sort the captures by offset, not because DWARF
|
|
|
|
// requires this, but because we're paranoid about debuggers.
|
|
|
|
SmallVector<BlockLayoutChunk, 8> chunks;
|
|
|
|
|
|
|
|
// 'this' capture.
|
|
|
|
if (blockDecl->capturesCXXThis()) {
|
|
|
|
BlockLayoutChunk chunk;
|
|
|
|
chunk.OffsetInBits =
|
|
|
|
blockLayout->getElementOffsetInBits(block.CXXThisIndex);
|
2014-05-21 13:09:00 +08:00
|
|
|
chunk.Capture = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
chunks.push_back(chunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Variable captures.
|
2014-03-15 02:34:04 +08:00
|
|
|
for (const auto &capture : blockDecl->captures()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
const VarDecl *variable = capture.getVariable();
|
|
|
|
const CGBlockInfo::Capture &captureInfo = block.getCapture(variable);
|
|
|
|
|
|
|
|
// Ignore constant captures.
|
|
|
|
if (captureInfo.isConstant())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
BlockLayoutChunk chunk;
|
|
|
|
chunk.OffsetInBits =
|
|
|
|
blockLayout->getElementOffsetInBits(captureInfo.getIndex());
|
|
|
|
chunk.Capture = &capture;
|
|
|
|
chunks.push_back(chunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort by offset.
|
|
|
|
llvm::array_pod_sort(chunks.begin(), chunks.end());
|
|
|
|
|
|
|
|
for (SmallVectorImpl<BlockLayoutChunk>::iterator
|
|
|
|
i = chunks.begin(), e = chunks.end(); i != e; ++i) {
|
|
|
|
uint64_t offsetInBits = i->OffsetInBits;
|
|
|
|
const BlockDecl::Capture *capture = i->Capture;
|
|
|
|
|
|
|
|
// If we have a null capture, this must be the C++ 'this' capture.
|
|
|
|
if (!capture) {
|
|
|
|
const CXXMethodDecl *method =
|
|
|
|
cast<CXXMethodDecl>(blockDecl->getNonClosureContext());
|
|
|
|
QualType type = method->getThisType(C);
|
|
|
|
|
|
|
|
fields.push_back(createFieldType("this", type, 0, loc, AS_public,
|
|
|
|
offsetInBits, tunit, tunit));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const VarDecl *variable = capture->getVariable();
|
|
|
|
StringRef name = variable->getName();
|
|
|
|
|
|
|
|
llvm::DIType fieldType;
|
|
|
|
if (capture->isByRef()) {
|
2014-07-30 09:30:47 +08:00
|
|
|
TypeInfo PtrInfo = C.getTypeInfo(C.VoidPtrTy);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// FIXME: this creates a second copy of this type!
|
|
|
|
uint64_t xoffset;
|
|
|
|
fieldType = EmitTypeForVarWithBlocksAttr(variable, &xoffset);
|
2014-07-30 09:30:47 +08:00
|
|
|
fieldType = DBuilder.createPointerType(fieldType, PtrInfo.Width);
|
|
|
|
fieldType =
|
|
|
|
DBuilder.createMemberType(tunit, name, tunit, line, PtrInfo.Width,
|
|
|
|
PtrInfo.Align, offsetInBits, 0, fieldType);
|
2012-12-18 22:30:41 +08:00
|
|
|
} else {
|
|
|
|
fieldType = createFieldType(name, variable->getType(), 0,
|
|
|
|
loc, AS_public, offsetInBits, tunit, tunit);
|
|
|
|
}
|
|
|
|
fields.push_back(fieldType);
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallString<36> typeName;
|
|
|
|
llvm::raw_svector_ostream(typeName)
|
|
|
|
<< "__block_literal_" << CGM.getUniqueBlockCount();
|
|
|
|
|
|
|
|
llvm::DIArray fieldsArray = DBuilder.getOrCreateArray(fields);
|
|
|
|
|
|
|
|
llvm::DIType type =
|
|
|
|
DBuilder.createStructType(tunit, typeName.str(), tunit, line,
|
|
|
|
CGM.getContext().toBits(block.BlockSize),
|
|
|
|
CGM.getContext().toBits(block.BlockAlign),
|
2013-02-25 09:07:08 +08:00
|
|
|
0, llvm::DIType(), fieldsArray);
|
2012-12-18 22:30:41 +08:00
|
|
|
type = DBuilder.createPointerType(type, CGM.PointerWidthInBits);
|
|
|
|
|
|
|
|
// Get overall information about the block.
|
|
|
|
unsigned flags = llvm::DIDescriptor::FlagArtificial;
|
|
|
|
llvm::MDNode *scope = LexicalBlockStack.back();
|
|
|
|
|
|
|
|
// Create the descriptor for the parameter.
|
|
|
|
llvm::DIVariable debugVar =
|
|
|
|
DBuilder.createLocalVariable(llvm::dwarf::DW_TAG_arg_variable,
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DIDescriptor(scope),
|
2013-03-15 01:53:33 +08:00
|
|
|
Arg->getName(), tunit, line, type,
|
2012-12-18 22:30:41 +08:00
|
|
|
CGM.getLangOpts().Optimize, flags,
|
2014-08-09 01:10:14 +08:00
|
|
|
ArgNo);
|
2013-03-15 01:53:33 +08:00
|
|
|
|
2013-03-15 05:52:59 +08:00
|
|
|
if (LocalAddr) {
|
2013-03-15 01:53:33 +08:00
|
|
|
// Insert an llvm.dbg.value into the current block.
|
2013-03-15 05:52:59 +08:00
|
|
|
llvm::Instruction *DbgVal =
|
|
|
|
DBuilder.insertDbgValueIntrinsic(LocalAddr, 0, debugVar,
|
2013-04-03 06:59:11 +08:00
|
|
|
Builder.GetInsertBlock());
|
2013-03-15 05:52:59 +08:00
|
|
|
DbgVal->setDebugLoc(llvm::DebugLoc::get(line, column, scope));
|
|
|
|
}
|
2013-03-15 01:53:33 +08:00
|
|
|
|
2013-03-15 05:52:59 +08:00
|
|
|
// Insert an llvm.dbg.declare into the current block.
|
|
|
|
llvm::Instruction *DbgDecl =
|
|
|
|
DBuilder.insertDeclare(Arg, debugVar, Builder.GetInsertBlock());
|
|
|
|
DbgDecl->setDebugLoc(llvm::DebugLoc::get(line, column, scope));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-08-20 09:28:15 +08:00
|
|
|
/// If D is an out-of-class definition of a static data member of a class, find
|
|
|
|
/// its corresponding in-class declaration.
|
|
|
|
llvm::DIDerivedType
|
|
|
|
CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D) {
|
|
|
|
if (!D->isStaticDataMember())
|
|
|
|
return llvm::DIDerivedType();
|
|
|
|
llvm::DenseMap<const Decl *, llvm::WeakVH>::iterator MI =
|
|
|
|
StaticDataMemberCache.find(D->getCanonicalDecl());
|
|
|
|
if (MI != StaticDataMemberCache.end()) {
|
|
|
|
assert(MI->second && "Static data member declaration should still exist");
|
|
|
|
return llvm::DIDerivedType(cast<llvm::MDNode>(MI->second));
|
|
|
|
}
|
2013-08-21 05:49:21 +08:00
|
|
|
|
|
|
|
// If the member wasn't found in the cache, lazily construct and add it to the
|
|
|
|
// type (used when a limited form of the type is emitted).
|
2013-08-20 09:28:15 +08:00
|
|
|
llvm::DICompositeType Ctxt(
|
|
|
|
getContextDescriptor(cast<Decl>(D->getDeclContext())));
|
|
|
|
llvm::DIDerivedType T = CreateRecordStaticField(D, Ctxt);
|
|
|
|
return T;
|
|
|
|
}
|
|
|
|
|
2014-04-10 13:20:00 +08:00
|
|
|
/// Recursively collect all of the member fields of a global anonymous decl and
|
|
|
|
/// create static variables for them. The first time this is called it needs
|
|
|
|
/// to be on a union and then from there we can have additional unnamed fields.
|
|
|
|
llvm::DIGlobalVariable
|
|
|
|
CGDebugInfo::CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile Unit,
|
|
|
|
unsigned LineNo, StringRef LinkageName,
|
|
|
|
llvm::GlobalVariable *Var,
|
|
|
|
llvm::DIDescriptor DContext) {
|
|
|
|
llvm::DIGlobalVariable GV;
|
|
|
|
|
|
|
|
for (const auto *Field : RD->fields()) {
|
|
|
|
llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit);
|
|
|
|
StringRef FieldName = Field->getName();
|
|
|
|
|
|
|
|
// Ignore unnamed fields, but recurse into anonymous records.
|
|
|
|
if (FieldName.empty()) {
|
|
|
|
const RecordType *RT = dyn_cast<RecordType>(Field->getType());
|
|
|
|
if (RT)
|
|
|
|
GV = CollectAnonRecordDecls(RT->getDecl(), Unit, LineNo, LinkageName,
|
|
|
|
Var, DContext);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Use VarDecl's Tag, Scope and Line number.
|
|
|
|
GV = DBuilder.createStaticVariable(DContext, FieldName, LinkageName, Unit,
|
|
|
|
LineNo, FieldTy,
|
|
|
|
Var->hasInternalLinkage(), Var,
|
|
|
|
llvm::DIDerivedType());
|
|
|
|
}
|
|
|
|
return GV;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
/// EmitGlobalVariable - Emit information about a global variable.
|
2013-08-30 16:53:09 +08:00
|
|
|
void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
|
2012-12-18 22:30:41 +08:00
|
|
|
const VarDecl *D) {
|
2013-05-16 08:45:23 +08:00
|
|
|
assert(DebugKind >= CodeGenOptions::LimitedDebugInfo);
|
2012-12-18 22:30:41 +08:00
|
|
|
// Create global variable debug descriptor.
|
|
|
|
llvm::DIFile Unit = getOrCreateFile(D->getLocation());
|
|
|
|
unsigned LineNo = getLineNumber(D->getLocation());
|
2013-08-30 16:53:09 +08:00
|
|
|
|
|
|
|
setLocation(D->getLocation());
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
QualType T = D->getType();
|
|
|
|
if (T->isIncompleteArrayType()) {
|
|
|
|
|
|
|
|
// CodeGen turns int[] into int[1] so we'll do the same here.
|
|
|
|
llvm::APInt ConstVal(32, 1);
|
|
|
|
QualType ET = CGM.getContext().getAsArrayType(T)->getElementType();
|
|
|
|
|
|
|
|
T = CGM.getContext().getConstantArrayType(ET, ConstVal,
|
|
|
|
ArrayType::Normal, 0);
|
|
|
|
}
|
2014-04-10 13:20:00 +08:00
|
|
|
|
2013-08-30 16:53:09 +08:00
|
|
|
StringRef DeclName = D->getName();
|
|
|
|
StringRef LinkageName;
|
2014-04-10 13:20:00 +08:00
|
|
|
if (D->getDeclContext() && !isa<FunctionDecl>(D->getDeclContext()) &&
|
|
|
|
!isa<ObjCMethodDecl>(D->getDeclContext()))
|
2013-08-30 16:53:09 +08:00
|
|
|
LinkageName = Var->getName();
|
|
|
|
if (LinkageName == DeclName)
|
|
|
|
LinkageName = StringRef();
|
2014-04-10 13:20:00 +08:00
|
|
|
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DIDescriptor DContext =
|
2012-12-18 22:30:41 +08:00
|
|
|
getContextDescriptor(dyn_cast<Decl>(D->getDeclContext()));
|
2014-04-10 13:20:00 +08:00
|
|
|
|
|
|
|
// Attempt to store one global variable for the declaration - even if we
|
|
|
|
// emit a lot of fields.
|
|
|
|
llvm::DIGlobalVariable GV;
|
|
|
|
|
|
|
|
// If this is an anonymous union then we'll want to emit a global
|
|
|
|
// variable for each member of the anonymous union so that it's possible
|
|
|
|
// to find the name of any field in the union.
|
|
|
|
if (T->isUnionType() && DeclName.empty()) {
|
|
|
|
const RecordDecl *RD = cast<RecordType>(T)->getDecl();
|
|
|
|
assert(RD->isAnonymousStructOrUnion() && "unnamed non-anonymous struct or union?");
|
|
|
|
GV = CollectAnonRecordDecls(RD, Unit, LineNo, LinkageName, Var, DContext);
|
|
|
|
} else {
|
|
|
|
GV = DBuilder.createStaticVariable(
|
|
|
|
DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
|
|
|
|
Var->hasInternalLinkage(), Var,
|
|
|
|
getOrCreateStaticDataMemberDeclarationOrNull(D));
|
|
|
|
}
|
2013-05-20 12:58:53 +08:00
|
|
|
DeclCache.insert(std::make_pair(D->getCanonicalDecl(), llvm::WeakVH(GV)));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-08-30 16:53:09 +08:00
|
|
|
/// EmitGlobalVariable - Emit global variable's debug info.
|
|
|
|
void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD,
|
|
|
|
llvm::Constant *Init) {
|
2013-05-16 08:45:23 +08:00
|
|
|
assert(DebugKind >= CodeGenOptions::LimitedDebugInfo);
|
2013-08-30 16:53:09 +08:00
|
|
|
// Create the descriptor for the variable.
|
|
|
|
llvm::DIFile Unit = getOrCreateFile(VD->getLocation());
|
|
|
|
StringRef Name = VD->getName();
|
|
|
|
llvm::DIType Ty = getOrCreateType(VD->getType(), Unit);
|
|
|
|
if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(VD)) {
|
|
|
|
const EnumDecl *ED = cast<EnumDecl>(ECD->getDeclContext());
|
|
|
|
assert(isa<EnumType>(ED->getTypeForDecl()) && "Enum without EnumType?");
|
|
|
|
Ty = getOrCreateType(QualType(ED->getTypeForDecl(), 0), Unit);
|
|
|
|
}
|
|
|
|
// Do not use DIGlobalVariable for enums.
|
|
|
|
if (Ty.getTag() == llvm::dwarf::DW_TAG_enumeration_type)
|
|
|
|
return;
|
2014-04-05 04:56:17 +08:00
|
|
|
// Do not emit separate definitions for function local const/statics.
|
|
|
|
if (isa<FunctionDecl>(VD->getDeclContext()))
|
|
|
|
return;
|
2014-04-05 15:23:17 +08:00
|
|
|
VD = cast<ValueDecl>(VD->getCanonicalDecl());
|
|
|
|
auto pair = DeclCache.insert(std::make_pair(VD, llvm::WeakVH()));
|
|
|
|
if (!pair.second)
|
|
|
|
return;
|
2014-04-05 15:46:57 +08:00
|
|
|
llvm::DIDescriptor DContext =
|
|
|
|
getContextDescriptor(dyn_cast<Decl>(VD->getDeclContext()));
|
2013-08-30 16:53:09 +08:00
|
|
|
llvm::DIGlobalVariable GV = DBuilder.createStaticVariable(
|
2014-04-05 15:46:57 +08:00
|
|
|
DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty,
|
|
|
|
true, Init,
|
2013-08-30 16:53:09 +08:00
|
|
|
getOrCreateStaticDataMemberDeclarationOrNull(cast<VarDecl>(VD)));
|
2014-04-05 15:23:17 +08:00
|
|
|
pair.first->second = llvm::WeakVH(GV);
|
2013-05-20 12:58:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
llvm::DIScope CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
|
|
|
|
if (!LexicalBlockStack.empty())
|
|
|
|
return llvm::DIScope(LexicalBlockStack.back());
|
|
|
|
return getContextDescriptor(D);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-04-22 14:13:21 +08:00
|
|
|
void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) {
|
2013-05-20 12:58:53 +08:00
|
|
|
if (CGM.getCodeGenOpts().getDebugInfo() < CodeGenOptions::LimitedDebugInfo)
|
|
|
|
return;
|
2013-04-22 14:13:21 +08:00
|
|
|
DBuilder.createImportedModule(
|
2013-05-20 12:58:53 +08:00
|
|
|
getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())),
|
|
|
|
getOrCreateNameSpace(UD.getNominatedNamespace()),
|
2013-04-22 14:13:21 +08:00
|
|
|
getLineNumber(UD.getLocation()));
|
|
|
|
}
|
|
|
|
|
2013-05-20 12:58:53 +08:00
|
|
|
void CGDebugInfo::EmitUsingDecl(const UsingDecl &UD) {
|
|
|
|
if (CGM.getCodeGenOpts().getDebugInfo() < CodeGenOptions::LimitedDebugInfo)
|
|
|
|
return;
|
|
|
|
assert(UD.shadow_size() &&
|
|
|
|
"We shouldn't be codegening an invalid UsingDecl containing no decls");
|
|
|
|
// Emitting one decl is sufficient - debuggers can detect that this is an
|
|
|
|
// overloaded name & provide lookup for all the overloads.
|
|
|
|
const UsingShadowDecl &USD = **UD.shadow_begin();
|
2014-04-01 11:41:01 +08:00
|
|
|
if (llvm::DIScope Target =
|
2013-06-08 06:54:39 +08:00
|
|
|
getDeclarationOrDefinition(USD.getUnderlyingDecl()))
|
2013-05-20 12:58:53 +08:00
|
|
|
DBuilder.createImportedDeclaration(
|
|
|
|
getCurrentContextDescriptor(cast<Decl>(USD.getDeclContext())), Target,
|
|
|
|
getLineNumber(USD.getLocation()));
|
|
|
|
}
|
|
|
|
|
2013-05-21 06:50:41 +08:00
|
|
|
llvm::DIImportedEntity
|
|
|
|
CGDebugInfo::EmitNamespaceAlias(const NamespaceAliasDecl &NA) {
|
|
|
|
if (CGM.getCodeGenOpts().getDebugInfo() < CodeGenOptions::LimitedDebugInfo)
|
2014-05-21 13:09:00 +08:00
|
|
|
return llvm::DIImportedEntity(nullptr);
|
2013-05-21 06:50:41 +08:00
|
|
|
llvm::WeakVH &VH = NamespaceAliasCache[&NA];
|
|
|
|
if (VH)
|
|
|
|
return llvm::DIImportedEntity(cast<llvm::MDNode>(VH));
|
2014-05-21 13:09:00 +08:00
|
|
|
llvm::DIImportedEntity R(nullptr);
|
2013-05-21 06:50:41 +08:00
|
|
|
if (const NamespaceAliasDecl *Underlying =
|
|
|
|
dyn_cast<NamespaceAliasDecl>(NA.getAliasedNamespace()))
|
|
|
|
// This could cache & dedup here rather than relying on metadata deduping.
|
2014-04-06 14:30:03 +08:00
|
|
|
R = DBuilder.createImportedDeclaration(
|
2013-05-21 06:50:41 +08:00
|
|
|
getCurrentContextDescriptor(cast<Decl>(NA.getDeclContext())),
|
|
|
|
EmitNamespaceAlias(*Underlying), getLineNumber(NA.getLocation()),
|
|
|
|
NA.getName());
|
|
|
|
else
|
2014-04-06 14:30:03 +08:00
|
|
|
R = DBuilder.createImportedDeclaration(
|
2013-05-21 06:50:41 +08:00
|
|
|
getCurrentContextDescriptor(cast<Decl>(NA.getDeclContext())),
|
|
|
|
getOrCreateNameSpace(cast<NamespaceDecl>(NA.getAliasedNamespace())),
|
|
|
|
getLineNumber(NA.getLocation()), NA.getName());
|
|
|
|
VH = R;
|
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
/// getOrCreateNamesSpace - Return namespace descriptor for the given
|
|
|
|
/// namespace decl.
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DINameSpace
|
2012-12-18 22:30:41 +08:00
|
|
|
CGDebugInfo::getOrCreateNameSpace(const NamespaceDecl *NSDecl) {
|
2013-08-17 06:52:07 +08:00
|
|
|
NSDecl = NSDecl->getCanonicalDecl();
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH>::iterator I =
|
2012-12-18 22:30:41 +08:00
|
|
|
NameSpaceCache.find(NSDecl);
|
|
|
|
if (I != NameSpaceCache.end())
|
|
|
|
return llvm::DINameSpace(cast<llvm::MDNode>(I->second));
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
unsigned LineNo = getLineNumber(NSDecl->getLocation());
|
|
|
|
llvm::DIFile FileD = getOrCreateFile(NSDecl->getLocation());
|
2013-05-16 08:45:12 +08:00
|
|
|
llvm::DIDescriptor Context =
|
2012-12-18 22:30:41 +08:00
|
|
|
getContextDescriptor(dyn_cast<Decl>(NSDecl->getDeclContext()));
|
|
|
|
llvm::DINameSpace NS =
|
|
|
|
DBuilder.createNameSpace(Context, NSDecl->getName(), FileD, LineNo);
|
|
|
|
NameSpaceCache[NSDecl] = llvm::WeakVH(NS);
|
|
|
|
return NS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGDebugInfo::finalize() {
|
2014-05-08 00:56:58 +08:00
|
|
|
// Creating types might create further types - invalidating the current
|
|
|
|
// element and the size(), so don't cache/reference them.
|
|
|
|
for (size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
|
|
|
|
ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i];
|
|
|
|
E.Decl.replaceAllUsesWith(CGM.getLLVMContext(),
|
|
|
|
E.Type->getDecl()->getDefinition()
|
|
|
|
? CreateTypeDefinition(E.Type, E.Unit)
|
|
|
|
: E.Decl);
|
|
|
|
}
|
|
|
|
|
2014-05-06 11:42:01 +08:00
|
|
|
for (auto p : ReplaceMap) {
|
|
|
|
assert(p.second);
|
|
|
|
llvm::DIType Ty(cast<llvm::MDNode>(p.second));
|
2014-05-06 05:21:39 +08:00
|
|
|
assert(Ty.isForwardDecl());
|
2013-05-16 08:45:12 +08:00
|
|
|
|
2014-05-06 11:42:01 +08:00
|
|
|
auto it = TypeCache.find(p.first);
|
2014-05-06 05:21:39 +08:00
|
|
|
assert(it != TypeCache.end());
|
|
|
|
assert(it->second);
|
2013-03-12 02:33:46 +08:00
|
|
|
|
2014-05-06 11:42:01 +08:00
|
|
|
llvm::DIType RepTy(cast<llvm::MDNode>(it->second));
|
|
|
|
Ty.replaceAllUsesWith(CGM.getLLVMContext(), RepTy);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-03-12 02:33:46 +08:00
|
|
|
|
|
|
|
// We keep our own list of retained types, because we need to look
|
|
|
|
// up the final type in the type cache.
|
|
|
|
for (std::vector<void *>::const_iterator RI = RetainedTypes.begin(),
|
|
|
|
RE = RetainedTypes.end(); RI != RE; ++RI)
|
2014-03-05 06:01:08 +08:00
|
|
|
DBuilder.retainType(llvm::DIType(cast<llvm::MDNode>(TypeCache[*RI])));
|
2013-03-12 02:33:46 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
DBuilder.finalize();
|
|
|
|
}
|