CGDebugInfo.h revision c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44e
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 ObjCObjectType *Ty, llvm::DIFile F); 84 llvm::DIType CreateType(const EnumType *Ty, llvm::DIFile F); 85 llvm::DIType CreateType(const VectorType *Ty, llvm::DIFile F); 86 llvm::DIType CreateType(const ArrayType *Ty, llvm::DIFile F); 87 llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DIFile F); 88 llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DIFile F); 89 llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method, 90 llvm::DIFile F); 91 llvm::DIType getOrCreateVTablePtrType(llvm::DIFile F); 92 llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N, 93 llvm::DIDescriptor Unit); 94 95 llvm::DIType CreatePointerLikeType(unsigned Tag, 96 const Type *Ty, QualType PointeeTy, 97 llvm::DIFile F); 98 99 llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method, 100 llvm::DIFile F, 101 llvm::DICompositeType &RecordTy); 102 103 void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, 104 llvm::DIFile F, 105 llvm::SmallVectorImpl<llvm::DIDescriptor> &E, 106 llvm::DICompositeType &T); 107 void CollectCXXBases(const CXXRecordDecl *Decl, 108 llvm::DIFile F, 109 llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys, 110 llvm::DICompositeType &RecordTy); 111 112 113 void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F, 114 llvm::SmallVectorImpl<llvm::DIDescriptor> &E); 115 116 void CollectVTableInfo(const CXXRecordDecl *Decl, 117 llvm::DIFile F, 118 llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys); 119 120public: 121 CGDebugInfo(CodeGenModule &CGM); 122 ~CGDebugInfo(); 123 124 /// setLocation - Update the current source location. If \arg loc is 125 /// invalid it is ignored. 126 void setLocation(SourceLocation Loc); 127 128 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of 129 /// source line. 130 void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder); 131 132 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate 133 /// start of a new function. 134 void EmitFunctionStart(GlobalDecl GD, QualType FnType, 135 llvm::Function *Fn, CGBuilderTy &Builder); 136 137 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start 138 /// of a new block. 139 void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder); 140 141 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a 142 /// block. 143 void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder); 144 145 /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic 146 /// variable declaration. 147 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, 148 CGBuilderTy &Builder); 149 150 /// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an 151 /// imported variable declaration in a block. 152 void EmitDeclareOfBlockDeclRefVariable(const BlockDeclRefExpr *BDRE, 153 llvm::Value *AI, 154 CGBuilderTy &Builder, 155 CodeGenFunction *CGF); 156 157 /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument 158 /// variable declaration. 159 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, 160 CGBuilderTy &Builder); 161 162 /// EmitGlobalVariable - Emit information about a global variable. 163 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); 164 165 /// EmitGlobalVariable - Emit information about an objective-c interface. 166 void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl); 167 168private: 169 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. 170 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, 171 CGBuilderTy &Builder); 172 173 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. 174 void EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, llvm::Value *AI, 175 CGBuilderTy &Builder, CodeGenFunction *CGF); 176 177 // EmitTypeForVarWithBlocksAttr - Build up structure info for the byref. 178 // See BuildByRefType. 179 llvm::DIType EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, 180 uint64_t *OffSet); 181 182 /// getContextDescriptor - Get context info for the decl. 183 llvm::DIDescriptor getContextDescriptor(const Decl *Decl, 184 llvm::DIDescriptor &CU); 185 186 /// CreateCompileUnit - Create new compile unit. 187 void CreateCompileUnit(); 188 189 /// getOrCreateFile - Get the file debug info descriptor for the input 190 /// location. 191 llvm::DIFile getOrCreateFile(SourceLocation Loc); 192 193 /// getOrCreateType - Get the type from the cache or create a new type if 194 /// necessary. 195 llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile F); 196 197 /// CreateTypeNode - Create type metadata for a source language type. 198 llvm::DIType CreateTypeNode(QualType Ty, llvm::DIFile F); 199 200 /// CreateMemberType - Create new member and increase Offset by FType's size. 201 llvm::DIType CreateMemberType(llvm::DIFile Unit, QualType FType, 202 llvm::StringRef Name, uint64_t *Offset); 203 204 /// getFunctionName - Get function name for the given FunctionDecl. If the 205 /// name is constructred on demand (e.g. C++ destructor) then the name 206 /// is stored on the side. 207 llvm::StringRef getFunctionName(const FunctionDecl *FD); 208 209 /// getVTableName - Get vtable name for the given Class. 210 llvm::StringRef getVTableName(const CXXRecordDecl *Decl); 211 212 /// getLineNumber - Get line number for the location. If location is invalid 213 /// then use current location. 214 unsigned getLineNumber(SourceLocation Loc); 215 216 /// getColumnNumber - Get column number for the location. If location is 217 /// invalid then use current location. 218 unsigned getColumnNumber(SourceLocation Loc); 219}; 220} // namespace CodeGen 221} // namespace clang 222 223 224#endif 225