CGDebugInfo.h revision 809b9bb733d6b65883a89eae0cf20c1635cff141
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#include <map> 25 26#include "CGBuilder.h" 27 28namespace llvm { 29 class MDNode; 30} 31 32namespace clang { 33 class VarDecl; 34 class ObjCInterfaceDecl; 35 36namespace CodeGen { 37 class CodeGenModule; 38 class CodeGenFunction; 39 class GlobalDecl; 40 41/// CGDebugInfo - This class gathers all debug information during compilation 42/// and is responsible for emitting to llvm globals or pass directly to 43/// the backend. 44class CGDebugInfo { 45 CodeGenModule &CGM; 46 bool isMainCompileUnitCreated; 47 llvm::DIFactory DebugFactory; 48 49 SourceLocation CurLoc, PrevLoc; 50 51 llvm::DIType VTablePtrType; 52 53 /// CompileUnitCache - Cache of previously constructed CompileUnits. 54 llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache; 55 56 /// TypeCache - Cache of previously constructed Types. 57 // FIXME: Eliminate this map. Be careful of iterator invalidation. 58 std::map<void *, llvm::WeakVH> TypeCache; 59 60 bool BlockLiteralGenericSet; 61 llvm::DIType BlockLiteralGeneric; 62 63 std::vector<llvm::TrackingVH<llvm::MDNode> > RegionStack; 64 llvm::DenseMap<const Decl *, llvm::WeakVH> RegionMap; 65 66 /// DebugInfoNames - This is a storage for names that are 67 /// constructed on demand. For example, C++ destructors, C++ operators etc.. 68 llvm::BumpPtrAllocator DebugInfoNames; 69 70 llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache; 71 llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache; 72 73 /// Helper functions for getOrCreateType. 74 llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U); 75 llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U); 76 llvm::DIType CreateQualifiedType(QualType Ty, llvm::DICompileUnit U); 77 llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U); 78 llvm::DIType CreateType(const ObjCObjectPointerType *Ty, 79 llvm::DICompileUnit Unit); 80 llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U); 81 llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DICompileUnit U); 82 llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U); 83 llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U); 84 llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U); 85 llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U); 86 llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U); 87 llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U); 88 llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DICompileUnit U); 89 llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DICompileUnit U); 90 llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method, 91 llvm::DICompileUnit Unit); 92 llvm::DIType getOrCreateVTablePtrType(llvm::DICompileUnit Unit); 93 llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N, 94 llvm::DIDescriptor Unit); 95 96 llvm::DIType CreatePointerLikeType(unsigned Tag, 97 const Type *Ty, QualType PointeeTy, 98 llvm::DICompileUnit U); 99 100 llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method, 101 llvm::DICompileUnit Unit, 102 llvm::DICompositeType &RecordTy); 103 104 void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, 105 llvm::DICompileUnit U, 106 llvm::SmallVectorImpl<llvm::DIDescriptor> &E, 107 llvm::DICompositeType &T); 108 void CollectCXXBases(const CXXRecordDecl *Decl, 109 llvm::DICompileUnit Unit, 110 llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys, 111 llvm::DICompositeType &RecordTy); 112 113 114 void CollectRecordFields(const RecordDecl *Decl, llvm::DICompileUnit U, 115 llvm::SmallVectorImpl<llvm::DIDescriptor> &E); 116 117 void CollectVtableInfo(const CXXRecordDecl *Decl, 118 llvm::DICompileUnit Unit, 119 llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys); 120 121public: 122 CGDebugInfo(CodeGenModule &CGM); 123 ~CGDebugInfo(); 124 125 /// setLocation - Update the current source location. If \arg loc is 126 /// invalid it is ignored. 127 void setLocation(SourceLocation Loc); 128 129 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of 130 /// source line. 131 void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder); 132 133 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate 134 /// start of a new function. 135 void EmitFunctionStart(GlobalDecl GD, QualType FnType, 136 llvm::Function *Fn, CGBuilderTy &Builder); 137 138 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start 139 /// of a new block. 140 void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder); 141 142 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a 143 /// block. 144 void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder); 145 146 /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic 147 /// variable declaration. 148 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, 149 CGBuilderTy &Builder); 150 151 /// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an 152 /// imported variable declaration in a block. 153 void EmitDeclareOfBlockDeclRefVariable(const BlockDeclRefExpr *BDRE, 154 llvm::Value *AI, 155 CGBuilderTy &Builder, 156 CodeGenFunction *CGF); 157 158 /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument 159 /// variable declaration. 160 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, 161 CGBuilderTy &Builder); 162 163 /// EmitGlobalVariable - Emit information about a global variable. 164 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); 165 166 /// EmitGlobalVariable - Emit information about an objective-c interface. 167 void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl); 168 169private: 170 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. 171 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, 172 CGBuilderTy &Builder); 173 174 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. 175 void EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, llvm::Value *AI, 176 CGBuilderTy &Builder, CodeGenFunction *CGF); 177 178 // EmitTypeForVarWithBlocksAttr - Build up structure info for the byref. 179 // See BuildByRefType. 180 llvm::DIType EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, 181 uint64_t *OffSet); 182 183 /// getContextDescriptor - Get context info for the decl. 184 llvm::DIDescriptor getContextDescriptor(const Decl *Decl, 185 llvm::DIDescriptor &CU); 186 187 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a 188 /// new one if necessary. 189 llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc); 190 191 /// getOrCreateType - Get the type from the cache or create a new type if 192 /// necessary. 193 llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit); 194 195 /// CreateTypeNode - Create type metadata for a source language type. 196 llvm::DIType CreateTypeNode(QualType Ty, llvm::DICompileUnit Unit); 197 198 /// getFunctionName - Get function name for the given FunctionDecl. If the 199 /// name is constructred on demand (e.g. C++ destructor) then the name 200 /// is stored on the side. 201 llvm::StringRef getFunctionName(const FunctionDecl *FD); 202 203 /// getVtableName - Get vtable name for the given Class. 204 llvm::StringRef getVtableName(const CXXRecordDecl *Decl); 205 206}; 207} // namespace CodeGen 208} // namespace clang 209 210 211#endif 212