[cfe-commits] r94751 - in /cfe/trunk/lib/CodeGen: CGDebugInfo.cpp CGDebugInfo.h
Devang Patel
dpatel at apple.com
Thu Jan 28 10:11:52 PST 2010
Author: dpatel
Date: Thu Jan 28 12:11:52 2010
New Revision: 94751
URL: http://llvm.org/viewvc/llvm-project?rev=94751&view=rev
Log:
Emit vtable info.
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=94751&r1=94750&r2=94751&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Jan 28 12:11:52 2010
@@ -681,6 +681,72 @@
}
}
+/// getOrCreateVTablePtrType - Return debug info descriptor for vtable.
+llvm::DIType CGDebugInfo::getOrCreateVTablePtrType(llvm::DICompileUnit Unit) {
+ if (!VTablePtrType.isNull())
+ return VTablePtrType;
+
+ ASTContext &Context = CGM.getContext();
+
+ /* Function type */
+ llvm::SmallVector<llvm::DIDescriptor, 16> STys;
+ STys.push_back(getOrCreateType(Context.IntTy, Unit));
+ llvm::DIArray SElements =
+ DebugFactory.GetOrCreateArray(STys.data(), STys.size());
+ llvm::DIType SubTy =
+ DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type,
+ Unit, "", llvm::DICompileUnit(),
+ 0, 0, 0, 0, 0, llvm::DIType(), SElements);
+
+ unsigned Size = Context.getTypeSize(Context.VoidPtrTy);
+ llvm::DIType vtbl_ptr_type
+ = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
+ Unit, "__vtbl_ptr_type", llvm::DICompileUnit(),
+ 0, Size, 0, 0, 0, SubTy);
+
+ VTablePtrType = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
+ Unit, "", llvm::DICompileUnit(),
+ 0, Size, 0, 0, 0, vtbl_ptr_type);
+ return VTablePtrType;
+}
+
+/// getVtableName - Get vtable name for the given Class.
+llvm::StringRef CGDebugInfo::getVtableName(const CXXRecordDecl *Decl) {
+ // Otherwise construct gdb compatible name name.
+ std::string Name = "_vptr$" + Decl->getNameAsString();
+
+ // Copy this name on the side and use its reference.
+ char *StrPtr = FunctionNames.Allocate<char>(Name.length());
+ memcpy(StrPtr, Name.data(), Name.length());
+ return llvm::StringRef(StrPtr, Name.length());
+}
+
+
+/// CollectVtableInfo - If the C++ class has vtable info then insert appropriate
+/// debug info entry in EltTys vector.
+void CGDebugInfo::
+CollectVtableInfo(const CXXRecordDecl *Decl,
+ llvm::DICompileUnit Unit,
+ llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys) {
+ const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(Decl);
+
+ // 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 (!Decl->isDynamicClass())
+ return;
+
+ unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
+ llvm::DIType VPTR
+ = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
+ getVtableName(Decl), llvm::DICompileUnit(),
+ 0, Size, 0, 0, 0,
+ getOrCreateVTablePtrType(Unit));
+ EltTys.push_back(VPTR);
+}
+
/// CreateType - get structure or union type.
llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty,
llvm::DICompileUnit Unit) {
@@ -737,9 +803,12 @@
// Convert all the elements.
llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
+ const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(Decl);
+ if (CXXDecl)
+ CollectVtableInfo(CXXDecl, Unit, EltTys);
CollectRecordFields(Decl, Unit, EltTys);
llvm::MDNode *ContainingType = NULL;
- if (CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(Decl)) {
+ if (CXXDecl) {
CollectCXXMemberFunctions(CXXDecl, Unit, EltTys, FwdDecl);
CollectCXXBases(CXXDecl, Unit, EltTys, FwdDecl);
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=94751&r1=94750&r2=94751&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Thu Jan 28 12:11:52 2010
@@ -47,6 +47,8 @@
llvm::DIFactory DebugFactory;
SourceLocation CurLoc, PrevLoc;
+
+ llvm::DIType VTablePtrType;
/// CompileUnitCache - Cache of previously constructed CompileUnits.
llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache;
@@ -85,6 +87,7 @@
llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DICompileUnit U);
llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method,
llvm::DICompileUnit Unit);
+ llvm::DIType getOrCreateVTablePtrType(llvm::DICompileUnit Unit);
llvm::DIType CreatePointerLikeType(unsigned Tag,
const Type *Ty, QualType PointeeTy,
@@ -106,6 +109,11 @@
void CollectRecordFields(const RecordDecl *Decl, llvm::DICompileUnit U,
llvm::SmallVectorImpl<llvm::DIDescriptor> &E);
+
+ void CollectVtableInfo(const CXXRecordDecl *Decl,
+ llvm::DICompileUnit Unit,
+ llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys);
+
public:
CGDebugInfo(CodeGenModule &CGM);
~CGDebugInfo();
@@ -181,6 +189,10 @@
/// name is constructred on demand (e.g. C++ destructor) then the name
/// is stored on the side.
llvm::StringRef getFunctionName(const FunctionDecl *FD);
+
+ /// getVtableName - Get vtable name for the given Class.
+ llvm::StringRef getVtableName(const CXXRecordDecl *Decl);
+
};
} // namespace CodeGen
} // namespace clang
More information about the cfe-commits
mailing list