CGDebugInfo.h revision d3651cc24fbcffd8f187c82e6a91e6e3de7fe26e
1//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This is the source level debug info generator for llvm translation. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef CLANG_CODEGEN_CGDEBUGINFO_H 15#define CLANG_CODEGEN_CGDEBUGINFO_H 16 17#include "clang/AST/Type.h" 18#include "clang/AST/Expr.h" 19#include "clang/Basic/SourceLocation.h" 20#include "llvm/ADT/DenseMap.h" 21#include "llvm/Analysis/DebugInfo.h" 22#include "llvm/Support/ValueHandle.h" 23#include "llvm/Support/Allocator.h" 24 25#include "CGBuilder.h" 26 27namespace llvm { 28 class MDNode; 29} 30 31namespace clang { 32 class VarDecl; 33 class ObjCInterfaceDecl; 34 35namespace CodeGen { 36 class CodeGenModule; 37 class CodeGenFunction; 38 class GlobalDecl; 39 40/// CGDebugInfo - This class gathers all debug information during compilation 41/// and is responsible for emitting to llvm globals or pass directly to 42/// the backend. 43class CGDebugInfo { 44 CodeGenModule &CGM; 45 llvm::DIFactory DebugFactory; 46 llvm::DICompileUnit TheCU; 47 SourceLocation CurLoc, PrevLoc; 48 llvm::DIType VTablePtrType; 49 /// FwdDeclCount - This counter is used to ensure unique names for forward 50 /// record decls. 51 unsigned FwdDeclCount; 52 53 /// TypeCache - Cache of previously constructed Types. 54 llvm::DenseMap<void *, llvm::WeakVH> TypeCache; 55 56 bool BlockLiteralGenericSet; 57 llvm::DIType BlockLiteralGeneric; 58 59 std::vector<llvm::TrackingVH<llvm::MDNode> > RegionStack; 60 llvm::DenseMap<const Decl *, llvm::WeakVH> RegionMap; 61 62 /// DebugInfoNames - This is a storage for names that are 63 /// constructed on demand. For example, C++ destructors, C++ operators etc.. 64 llvm::BumpPtrAllocator DebugInfoNames; 65 66 llvm::DenseMap<const char *, llvm::WeakVH> DIFileCache; 67 llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache; 68 llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache; 69 70 /// Helper functions for getOrCreateType. 71 llvm::DIType CreateType(const BuiltinType *Ty, llvm::DIFile F); 72 llvm::DIType CreateType(const ComplexType *Ty, llvm::DIFile F); 73 llvm::DIType CreateQualifiedType(QualType Ty, llvm::DIFile F); 74 llvm::DIType CreateType(const TypedefType *Ty, llvm::DIFile F); 75 llvm::DIType CreateType(const ObjCObjectPointerType *Ty, 76 llvm::DIFile F); 77 llvm::DIType CreateType(const PointerType *Ty, llvm::DIFile F); 78 llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DIFile F); 79 llvm::DIType CreateType(const FunctionType *Ty, llvm::DIFile F); 80 llvm::DIType CreateType(const TagType *Ty, llvm::DIFile F); 81 llvm::DIType CreateType(const RecordType *Ty, llvm::DIFile F); 82 llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DIFile F); 83 llvm::DIType CreateType(const EnumType *Ty, llvm::DIFile F); 84 llvm::DIType CreateType(const VectorType *Ty, llvm::DIFile F); 85 llvm::DIType CreateType(const ArrayType *Ty, llvm::DIFile F); 86 llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DIFile F); 87 llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DIFile F); 88 llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method, 89 llvm::DIFile F); 90 llvm::DIType getOrCreateVTablePtrType(llvm::DIFile F); 91 llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N, 92 llvm::DIDescriptor Unit); 93 94 llvm::DIType CreatePointerLikeType(unsigned Tag, 95 const Type *Ty, QualType PointeeTy, 96 llvm::DIFile F); 97 98 llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method, 99 llvm::DIFile F, 100 llvm::DICompositeType &RecordTy); 101 102 void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, 103 llvm::DIFile F, 104 llvm::SmallVectorImpl<llvm::DIDescriptor> &E, 105 llvm::DICompositeType &T); 106 void CollectCXXBases(const CXXRecordDecl *Decl, 107 llvm::DIFile F, 108 llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys, 109 llvm::DICompositeType &RecordTy); 110 111 112 void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F, 113 llvm::SmallVectorImpl<llvm::DIDescriptor> &E); 114 115 void CollectVTableInfo(const CXXRecordDecl *Decl, 116 llvm::DIFile F, 117 llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys); 118 119public: 120 CGDebugInfo(CodeGenModule &CGM); 121 ~CGDebugInfo(); 122 123 /// setLocation - Update the current source location. If \arg loc is 124 /// invalid it is ignored. 125 void setLocation(SourceLocation Loc); 126 127 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of 128 /// source line. 129 void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder); 130 131 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate 132 /// start of a new function. 133 void EmitFunctionStart(GlobalDecl GD, QualType FnType, 134 llvm::Function *Fn, CGBuilderTy &Builder); 135 136 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start 137 /// of a new block. 138 void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder); 139 140 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a 141 /// block. 142 void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder); 143 144 /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic 145 /// variable declaration. 146 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, 147 CGBuilderTy &Builder); 148 149 /// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an 150 /// imported variable declaration in a block. 151 void EmitDeclareOfBlockDeclRefVariable(const BlockDeclRefExpr *BDRE, 152 llvm::Value *AI, 153 CGBuilderTy &Builder, 154 CodeGenFunction *CGF); 155 156 /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument 157 /// variable declaration. 158 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, 159 CGBuilderTy &Builder); 160 161 /// EmitGlobalVariable - Emit information about a global variable. 162 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); 163 164 /// EmitGlobalVariable - Emit information about an objective-c interface. 165 void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl); 166 167private: 168 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. 169 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, 170 CGBuilderTy &Builder); 171 172 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. 173 void EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, llvm::Value *AI, 174 CGBuilderTy &Builder, CodeGenFunction *CGF); 175 176 // EmitTypeForVarWithBlocksAttr - Build up structure info for the byref. 177 // See BuildByRefType. 178 llvm::DIType EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, 179 uint64_t *OffSet); 180 181 /// getContextDescriptor - Get context info for the decl. 182 llvm::DIDescriptor getContextDescriptor(const Decl *Decl, 183 llvm::DIDescriptor &CU); 184 185 /// CreateCompileUnit - Create new compile unit. 186 void CreateCompileUnit(); 187 188 /// getOrCreateFile - Get the file debug info descriptor for the input 189 /// location. 190 llvm::DIFile getOrCreateFile(SourceLocation Loc); 191 192 /// getOrCreateType - Get the type from the cache or create a new type if 193 /// necessary. 194 llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile F); 195 196 /// CreateTypeNode - Create type metadata for a source language type. 197 llvm::DIType CreateTypeNode(QualType Ty, llvm::DIFile F); 198 199 /// CreateMemberType - Create new member and increase Offset by FType's size. 200 llvm::DIType CreateMemberType(llvm::DIFile Unit, QualType FType, 201 llvm::StringRef Name, uint64_t *Offset); 202 203 /// getFunctionName - Get function name for the given FunctionDecl. If the 204 /// name is constructred on demand (e.g. C++ destructor) then the name 205 /// is stored on the side. 206 llvm::StringRef getFunctionName(const FunctionDecl *FD); 207 208 /// getVTableName - Get vtable name for the given Class. 209 llvm::StringRef getVTableName(const CXXRecordDecl *Decl); 210 211}; 212} // namespace CodeGen 213} // namespace clang 214 215 216#endif 217