From d6f9a0d14b47e7ea9739623544d967682f41b86d Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Tue, 26 Jan 2010 04:49:33 +0000 Subject: [PATCH] Factor creating the DISubprogram for a member function out into a separate function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94513 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 114 ++++++++++++++++++++---------------- lib/CodeGen/CGDebugInfo.h | 5 ++ 2 files changed, 68 insertions(+), 51 deletions(-) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 5d3c2cd84d..14f34a7c72 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -518,6 +518,67 @@ CollectRecordFields(const RecordDecl *Decl, } } +/// CreateCXXMemberFunction - A helper function to create a DISubprogram for +/// a single member function GlobalDecl. +llvm::DISubprogram +CGDebugInfo::CreateCXXMemberFunction(GlobalDecl GD, + llvm::DICompileUnit Unit, + llvm::DICompositeType &RecordTy) { + const CXXMethodDecl *Method = cast(GD.getDecl()); + + llvm::StringRef MethodName; + llvm::StringRef MethodLinkageName; + llvm::DIType MethodTy = getOrCreateType(Method->getType(), Unit); + if (const CXXConstructorDecl *CDecl = dyn_cast(Method)) { + (void)CDecl; + MethodName = Method->getName(); + // FIXME : Find linkage name. + } else if (const CXXDestructorDecl *DDecl = dyn_cast(Method)) { + (void)DDecl; + MethodName = getFunctionName(Method); + // FIXME : Find linkage name. + } else { + // regular method + MethodName = getFunctionName(Method); + MethodLinkageName = CGM.getMangledName(Method); + } + SourceManager &SM = CGM.getContext().getSourceManager(); + + // Get the location for the method. + SourceLocation MethodDefLoc = Method->getLocation(); + PresumedLoc PLoc = SM.getPresumedLoc(MethodDefLoc); + llvm::DICompileUnit MethodDefUnit; + unsigned MethodLine = 0; + + if (!PLoc.isInvalid()) { + MethodDefUnit = getOrCreateCompileUnit(MethodDefLoc); + MethodLine = PLoc.getLine(); + } + + // Collect virtual method info. + llvm::DIType ContainingType; + unsigned Virtuality = 0; + unsigned VIndex = 0; + if (Method->isVirtual()) { + // FIXME: Identify pure virtual functions. + Virtuality = llvm::dwarf::DW_VIRTUALITY_virtual; + VIndex = CGM.getVtableInfo().getMethodVtableIndex(Method); + ContainingType = RecordTy; + } + + llvm::DISubprogram SP = + DebugFactory.CreateSubprogram(RecordTy , MethodName, MethodName, + MethodLinkageName, + MethodDefUnit, MethodLine, + MethodTy, /*isLocalToUnit=*/false, + Method->isThisDeclarationADefinition(), + Virtuality, VIndex, ContainingType); + if (Method->isThisDeclarationADefinition()) + SPCache[cast(Method)] = llvm::WeakVH(SP.getNode()); + + return SP; +} + /// CollectCXXMemberFunctions - A helper function to collect debug info for /// C++ member functions.This is used while creating debug info entry for /// a Record. @@ -526,63 +587,14 @@ CollectCXXMemberFunctions(const CXXRecordDecl *Decl, llvm::DICompileUnit Unit, llvm::SmallVectorImpl &EltTys, llvm::DICompositeType &RecordTy) { - SourceManager &SM = CGM.getContext().getSourceManager(); for(CXXRecordDecl::method_iterator I = Decl->method_begin(), E = Decl->method_end(); I != E; ++I) { - CXXMethodDecl *Method = *I; + const CXXMethodDecl *Method = *I; if (Method->isImplicit()) continue; - - llvm::StringRef MethodName; - llvm::StringRef MethodLinkageName; - llvm::DIType MethodTy = getOrCreateType(Method->getType(), Unit); - if (CXXConstructorDecl *CDecl = dyn_cast(Method)) { - (void)CDecl; - MethodName = Decl->getName(); - // FIXME : Find linkage name. - } else if (CXXDestructorDecl *DDecl = dyn_cast(Method)) { - (void)DDecl; - MethodName = getFunctionName(Method); - // FIXME : Find linkage name. - } else { - // regular method - MethodName = getFunctionName(Method); - MethodLinkageName = CGM.getMangledName(Method); - } - - // Get the location for the method. - SourceLocation MethodDefLoc = Method->getLocation(); - PresumedLoc PLoc = SM.getPresumedLoc(MethodDefLoc); - llvm::DICompileUnit MethodDefUnit; - unsigned MethodLine = 0; - - if (!PLoc.isInvalid()) { - MethodDefUnit = getOrCreateCompileUnit(MethodDefLoc); - MethodLine = PLoc.getLine(); - } - - // Collect virtual method info. - llvm::DIType ContainingType; - unsigned Virtuality = 0; - unsigned VIndex = 0; - if (Method->isVirtual()) { - // FIXME: Identify pure virtual functions. - Virtuality = llvm::dwarf::DW_VIRTUALITY_virtual; - VIndex = CGM.getVtableInfo().getMethodVtableIndex(Method); - ContainingType = RecordTy; - } - llvm::DISubprogram SP = - DebugFactory.CreateSubprogram(RecordTy , MethodName, MethodName, - MethodLinkageName, - MethodDefUnit, MethodLine, - MethodTy, false, - Method->isThisDeclarationADefinition(), - Virtuality, VIndex, ContainingType); - if (Method->isThisDeclarationADefinition()) - SPCache[cast(Method)] = llvm::WeakVH(SP.getNode()); - EltTys.push_back(SP); + EltTys.push_back(CreateCXXMemberFunction(Method, Unit, RecordTy)); } } diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index 2af1d77b09..e785bef101 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -87,6 +87,11 @@ class CGDebugInfo { llvm::DIType CreatePointerLikeType(unsigned Tag, const Type *Ty, QualType PointeeTy, llvm::DICompileUnit U); + + llvm::DISubprogram CreateCXXMemberFunction(GlobalDecl GD, + llvm::DICompileUnit Unit, + llvm::DICompositeType &RecordTy); + void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, llvm::DICompileUnit U, llvm::SmallVectorImpl &E, -- 2.40.0