CGDebugInfo.h revision 218893
1193326Sed//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed// 10198092Srdivacky// This is the source level debug info generator for llvm translation. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef CLANG_CODEGEN_CGDEBUGINFO_H 15193326Sed#define CLANG_CODEGEN_CGDEBUGINFO_H 16193326Sed 17193326Sed#include "clang/AST/Type.h" 18198092Srdivacky#include "clang/AST/Expr.h" 19193326Sed#include "clang/Basic/SourceLocation.h" 20193326Sed#include "llvm/ADT/DenseMap.h" 21193326Sed#include "llvm/Analysis/DebugInfo.h" 22218893Sdim#include "llvm/Analysis/DIBuilder.h" 23198092Srdivacky#include "llvm/Support/ValueHandle.h" 24202379Srdivacky#include "llvm/Support/Allocator.h" 25193326Sed 26193326Sed#include "CGBuilder.h" 27193326Sed 28198092Srdivackynamespace llvm { 29198092Srdivacky class MDNode; 30198092Srdivacky} 31198092Srdivacky 32193326Sednamespace clang { 33193326Sed class VarDecl; 34193326Sed class ObjCInterfaceDecl; 35193326Sed 36193326Sednamespace CodeGen { 37193326Sed class CodeGenModule; 38198092Srdivacky class CodeGenFunction; 39202379Srdivacky class GlobalDecl; 40218893Sdim class CGBlockInfo; 41193326Sed 42198092Srdivacky/// CGDebugInfo - This class gathers all debug information during compilation 43198092Srdivacky/// and is responsible for emitting to llvm globals or pass directly to 44193326Sed/// the backend. 45193326Sedclass CGDebugInfo { 46200583Srdivacky CodeGenModule &CGM; 47218893Sdim llvm::DIBuilder DBuilder; 48204962Srdivacky llvm::DICompileUnit TheCU; 49193326Sed SourceLocation CurLoc, PrevLoc; 50204962Srdivacky llvm::DIType VTablePtrType; 51203955Srdivacky 52193326Sed /// TypeCache - Cache of previously constructed Types. 53206084Srdivacky llvm::DenseMap<void *, llvm::WeakVH> TypeCache; 54198092Srdivacky 55193326Sed bool BlockLiteralGenericSet; 56193326Sed llvm::DIType BlockLiteralGeneric; 57193326Sed 58199482Srdivacky std::vector<llvm::TrackingVH<llvm::MDNode> > RegionStack; 59203955Srdivacky llvm::DenseMap<const Decl *, llvm::WeakVH> RegionMap; 60212904Sdim // FnBeginRegionCount - Keep track of RegionStack counter at the beginning 61212904Sdim // of a function. This is used to pop unbalanced regions at the end of a 62212904Sdim // function. 63212904Sdim std::vector<unsigned> FnBeginRegionCount; 64193326Sed 65212904Sdim /// LineDirectiveFiles - This stack is used to keep track of 66212904Sdim /// scopes introduced by #line directives. 67212904Sdim std::vector<const char *> LineDirectiveFiles; 68212904Sdim 69203955Srdivacky /// DebugInfoNames - This is a storage for names that are 70202379Srdivacky /// constructed on demand. For example, C++ destructors, C++ operators etc.. 71203955Srdivacky llvm::BumpPtrAllocator DebugInfoNames; 72212904Sdim llvm::StringRef CWDName; 73202379Srdivacky 74206084Srdivacky llvm::DenseMap<const char *, llvm::WeakVH> DIFileCache; 75202879Srdivacky llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache; 76203955Srdivacky llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache; 77202879Srdivacky 78193326Sed /// Helper functions for getOrCreateType. 79218893Sdim llvm::DIType CreateType(const BuiltinType *Ty); 80218893Sdim llvm::DIType CreateType(const ComplexType *Ty); 81204962Srdivacky llvm::DIType CreateQualifiedType(QualType Ty, llvm::DIFile F); 82204962Srdivacky llvm::DIType CreateType(const TypedefType *Ty, llvm::DIFile F); 83198092Srdivacky llvm::DIType CreateType(const ObjCObjectPointerType *Ty, 84204962Srdivacky llvm::DIFile F); 85204962Srdivacky llvm::DIType CreateType(const PointerType *Ty, llvm::DIFile F); 86204962Srdivacky llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DIFile F); 87204962Srdivacky llvm::DIType CreateType(const FunctionType *Ty, llvm::DIFile F); 88218893Sdim llvm::DIType CreateType(const TagType *Ty); 89218893Sdim llvm::DIType CreateType(const RecordType *Ty); 90204962Srdivacky llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DIFile F); 91208600Srdivacky llvm::DIType CreateType(const ObjCObjectType *Ty, llvm::DIFile F); 92204962Srdivacky llvm::DIType CreateType(const VectorType *Ty, llvm::DIFile F); 93204962Srdivacky llvm::DIType CreateType(const ArrayType *Ty, llvm::DIFile F); 94204962Srdivacky llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DIFile F); 95218893Sdim llvm::DIType CreateType(const RValueReferenceType *Ty, llvm::DIFile Unit); 96204962Srdivacky llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DIFile F); 97218893Sdim llvm::DIType CreateEnumType(const EnumDecl *ED); 98203955Srdivacky llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method, 99204962Srdivacky llvm::DIFile F); 100204962Srdivacky llvm::DIType getOrCreateVTablePtrType(llvm::DIFile F); 101218893Sdim llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N); 102218893Sdim llvm::DIType CreatePointeeType(QualType PointeeTy, llvm::DIFile F); 103199482Srdivacky llvm::DIType CreatePointerLikeType(unsigned Tag, 104199482Srdivacky const Type *Ty, QualType PointeeTy, 105204962Srdivacky llvm::DIFile F); 106203955Srdivacky 107203955Srdivacky llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method, 108204962Srdivacky llvm::DIFile F, 109212904Sdim llvm::DIType RecordTy); 110203955Srdivacky 111202879Srdivacky void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, 112204962Srdivacky llvm::DIFile F, 113218893Sdim llvm::SmallVectorImpl<llvm::Value *> &E, 114212904Sdim llvm::DIType T); 115212904Sdim 116212904Sdim void CollectCXXFriends(const CXXRecordDecl *Decl, 117212904Sdim llvm::DIFile F, 118218893Sdim llvm::SmallVectorImpl<llvm::Value *> &EltTys, 119212904Sdim llvm::DIType RecordTy); 120212904Sdim 121203955Srdivacky void CollectCXXBases(const CXXRecordDecl *Decl, 122204962Srdivacky llvm::DIFile F, 123218893Sdim llvm::SmallVectorImpl<llvm::Value *> &EltTys, 124212904Sdim llvm::DIType RecordTy); 125203955Srdivacky 126203955Srdivacky 127204962Srdivacky void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F, 128218893Sdim llvm::SmallVectorImpl<llvm::Value *> &E); 129203955Srdivacky 130207619Srdivacky void CollectVTableInfo(const CXXRecordDecl *Decl, 131204962Srdivacky llvm::DIFile F, 132218893Sdim llvm::SmallVectorImpl<llvm::Value *> &EltTys); 133203955Srdivacky 134193326Sedpublic: 135200583Srdivacky CGDebugInfo(CodeGenModule &CGM); 136193326Sed ~CGDebugInfo(); 137193326Sed 138193326Sed /// setLocation - Update the current source location. If \arg loc is 139193326Sed /// invalid it is ignored. 140193326Sed void setLocation(SourceLocation Loc); 141193326Sed 142193326Sed /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of 143193326Sed /// source line. 144212904Sdim void EmitStopPoint(CGBuilderTy &Builder); 145193326Sed 146193326Sed /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate 147193326Sed /// start of a new function. 148202379Srdivacky void EmitFunctionStart(GlobalDecl GD, QualType FnType, 149193326Sed llvm::Function *Fn, CGBuilderTy &Builder); 150198092Srdivacky 151212904Sdim /// EmitFunctionEnd - Constructs the debug code for exiting a function. 152212904Sdim void EmitFunctionEnd(CGBuilderTy &Builder); 153212904Sdim 154212904Sdim /// UpdateLineDirectiveRegion - Update region stack only if #line directive 155212904Sdim /// has introduced scope change. 156212904Sdim void UpdateLineDirectiveRegion(CGBuilderTy &Builder); 157212904Sdim 158193326Sed /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start 159198092Srdivacky /// of a new block. 160212904Sdim void EmitRegionStart(CGBuilderTy &Builder); 161198092Srdivacky 162198092Srdivacky /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a 163193326Sed /// block. 164212904Sdim void EmitRegionEnd(CGBuilderTy &Builder); 165193326Sed 166193326Sed /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic 167193326Sed /// variable declaration. 168193326Sed void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, 169193326Sed CGBuilderTy &Builder); 170193326Sed 171198092Srdivacky /// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an 172198092Srdivacky /// imported variable declaration in a block. 173218893Sdim void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable, 174218893Sdim llvm::Value *storage, 175198092Srdivacky CGBuilderTy &Builder, 176218893Sdim const CGBlockInfo &blockInfo); 177198092Srdivacky 178193326Sed /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument 179193326Sed /// variable declaration. 180193326Sed void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, 181193326Sed CGBuilderTy &Builder); 182198092Srdivacky 183193326Sed /// EmitGlobalVariable - Emit information about a global variable. 184193326Sed void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); 185193326Sed 186193326Sed /// EmitGlobalVariable - Emit information about an objective-c interface. 187193326Sed void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl); 188198092Srdivacky 189212904Sdim /// EmitGlobalVariable - Emit global variable's debug info. 190218893Sdim void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init); 191212904Sdim 192218893Sdim /// getOrCreateRecordType - Emit record type's standalone debug info. 193218893Sdim llvm::DIType getOrCreateRecordType(QualType Ty, SourceLocation L); 194193326Sedprivate: 195193326Sed /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. 196193326Sed void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, 197193326Sed CGBuilderTy &Builder); 198198092Srdivacky 199218893Sdim /// EmitDeclare - Emit call to llvm.dbg.declare for a variable 200218893Sdim /// declaration from an enclosing block. 201218893Sdim void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, 202218893Sdim CGBuilderTy &Builder, const CGBlockInfo &blockInfo); 203198092Srdivacky 204203955Srdivacky // EmitTypeForVarWithBlocksAttr - Build up structure info for the byref. 205203955Srdivacky // See BuildByRefType. 206203955Srdivacky llvm::DIType EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, 207203955Srdivacky uint64_t *OffSet); 208198092Srdivacky 209203955Srdivacky /// getContextDescriptor - Get context info for the decl. 210218893Sdim llvm::DIDescriptor getContextDescriptor(const Decl *Decl); 211203955Srdivacky 212212904Sdim /// getCurrentDirname - Return current directory name. 213212904Sdim llvm::StringRef getCurrentDirname(); 214212904Sdim 215204962Srdivacky /// CreateCompileUnit - Create new compile unit. 216204962Srdivacky void CreateCompileUnit(); 217193326Sed 218204962Srdivacky /// getOrCreateFile - Get the file debug info descriptor for the input 219204962Srdivacky /// location. 220204962Srdivacky llvm::DIFile getOrCreateFile(SourceLocation Loc); 221204962Srdivacky 222218893Sdim /// getOrCreateMainFile - Get the file info for main compile unit. 223218893Sdim llvm::DIFile getOrCreateMainFile(); 224218893Sdim 225193326Sed /// getOrCreateType - Get the type from the cache or create a new type if 226193326Sed /// necessary. 227204962Srdivacky llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile F); 228198092Srdivacky 229198092Srdivacky /// CreateTypeNode - Create type metadata for a source language type. 230204962Srdivacky llvm::DIType CreateTypeNode(QualType Ty, llvm::DIFile F); 231202379Srdivacky 232207619Srdivacky /// CreateMemberType - Create new member and increase Offset by FType's size. 233207619Srdivacky llvm::DIType CreateMemberType(llvm::DIFile Unit, QualType FType, 234207619Srdivacky llvm::StringRef Name, uint64_t *Offset); 235207619Srdivacky 236202379Srdivacky /// getFunctionName - Get function name for the given FunctionDecl. If the 237202379Srdivacky /// name is constructred on demand (e.g. C++ destructor) then the name 238202379Srdivacky /// is stored on the side. 239202379Srdivacky llvm::StringRef getFunctionName(const FunctionDecl *FD); 240218893Sdim 241212904Sdim /// getObjCMethodName - Returns the unmangled name of an Objective-C method. 242212904Sdim /// This is the display name for the debugging info. 243212904Sdim llvm::StringRef getObjCMethodName(const ObjCMethodDecl *FD); 244203955Srdivacky 245212904Sdim /// getClassName - Get class name including template argument list. 246212904Sdim llvm::StringRef getClassName(RecordDecl *RD); 247212904Sdim 248207619Srdivacky /// getVTableName - Get vtable name for the given Class. 249207619Srdivacky llvm::StringRef getVTableName(const CXXRecordDecl *Decl); 250203955Srdivacky 251208600Srdivacky /// getLineNumber - Get line number for the location. If location is invalid 252208600Srdivacky /// then use current location. 253208600Srdivacky unsigned getLineNumber(SourceLocation Loc); 254208600Srdivacky 255208600Srdivacky /// getColumnNumber - Get column number for the location. If location is 256208600Srdivacky /// invalid then use current location. 257208600Srdivacky unsigned getColumnNumber(SourceLocation Loc); 258193326Sed}; 259193326Sed} // namespace CodeGen 260193326Sed} // namespace clang 261193326Sed 262198092Srdivacky 263193326Sed#endif 264