1f4a2713aSLionel Sambuc //===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc // 10*0a6a1f1dSLionel Sambuc // This is the source-level debug info generator for llvm translation. 11f4a2713aSLionel Sambuc // 12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 13f4a2713aSLionel Sambuc 14*0a6a1f1dSLionel Sambuc #ifndef LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H 15*0a6a1f1dSLionel Sambuc #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H 16f4a2713aSLionel Sambuc 17f4a2713aSLionel Sambuc #include "CGBuilder.h" 18f4a2713aSLionel Sambuc #include "clang/AST/Expr.h" 19f4a2713aSLionel Sambuc #include "clang/AST/Type.h" 20f4a2713aSLionel Sambuc #include "clang/Basic/SourceLocation.h" 21f4a2713aSLionel Sambuc #include "clang/Frontend/CodeGenOptions.h" 22f4a2713aSLionel Sambuc #include "llvm/ADT/DenseMap.h" 23*0a6a1f1dSLionel Sambuc #include "llvm/IR/DIBuilder.h" 24*0a6a1f1dSLionel Sambuc #include "llvm/IR/DebugInfo.h" 25*0a6a1f1dSLionel Sambuc #include "llvm/IR/ValueHandle.h" 26f4a2713aSLionel Sambuc #include "llvm/Support/Allocator.h" 27f4a2713aSLionel Sambuc 28f4a2713aSLionel Sambuc namespace llvm { 29f4a2713aSLionel Sambuc class MDNode; 30f4a2713aSLionel Sambuc } 31f4a2713aSLionel Sambuc 32f4a2713aSLionel Sambuc namespace clang { 33f4a2713aSLionel Sambuc class CXXMethodDecl; 34f4a2713aSLionel Sambuc class VarDecl; 35f4a2713aSLionel Sambuc class ObjCInterfaceDecl; 36f4a2713aSLionel Sambuc class ObjCIvarDecl; 37f4a2713aSLionel Sambuc class ClassTemplateSpecializationDecl; 38f4a2713aSLionel Sambuc class GlobalDecl; 39f4a2713aSLionel Sambuc class UsingDecl; 40f4a2713aSLionel Sambuc 41f4a2713aSLionel Sambuc namespace CodeGen { 42f4a2713aSLionel Sambuc class CodeGenModule; 43f4a2713aSLionel Sambuc class CodeGenFunction; 44f4a2713aSLionel Sambuc class CGBlockInfo; 45f4a2713aSLionel Sambuc 46f4a2713aSLionel Sambuc /// CGDebugInfo - This class gathers all debug information during compilation 47f4a2713aSLionel Sambuc /// and is responsible for emitting to llvm globals or pass directly to 48f4a2713aSLionel Sambuc /// the backend. 49f4a2713aSLionel Sambuc class CGDebugInfo { 50f4a2713aSLionel Sambuc friend class ArtificialLocation; 51*0a6a1f1dSLionel Sambuc friend class SaveAndRestoreLocation; 52f4a2713aSLionel Sambuc CodeGenModule &CGM; 53f4a2713aSLionel Sambuc const CodeGenOptions::DebugInfoKind DebugKind; 54f4a2713aSLionel Sambuc llvm::DIBuilder DBuilder; 55f4a2713aSLionel Sambuc llvm::DICompileUnit TheCU; 56*0a6a1f1dSLionel Sambuc SourceLocation CurLoc; 57f4a2713aSLionel Sambuc llvm::DIType VTablePtrType; 58f4a2713aSLionel Sambuc llvm::DIType ClassTy; 59f4a2713aSLionel Sambuc llvm::DICompositeType ObjTy; 60f4a2713aSLionel Sambuc llvm::DIType SelTy; 61f4a2713aSLionel Sambuc llvm::DIType OCLImage1dDITy, OCLImage1dArrayDITy, OCLImage1dBufferDITy; 62f4a2713aSLionel Sambuc llvm::DIType OCLImage2dDITy, OCLImage2dArrayDITy; 63f4a2713aSLionel Sambuc llvm::DIType OCLImage3dDITy; 64f4a2713aSLionel Sambuc llvm::DIType OCLEventDITy; 65f4a2713aSLionel Sambuc llvm::DIType BlockLiteralGeneric; 66f4a2713aSLionel Sambuc 67f4a2713aSLionel Sambuc /// TypeCache - Cache of previously constructed Types. 68*0a6a1f1dSLionel Sambuc llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache; 69*0a6a1f1dSLionel Sambuc 70*0a6a1f1dSLionel Sambuc struct ObjCInterfaceCacheEntry { 71*0a6a1f1dSLionel Sambuc const ObjCInterfaceType *Type; 72*0a6a1f1dSLionel Sambuc llvm::DIType Decl; 73*0a6a1f1dSLionel Sambuc llvm::DIFile Unit; ObjCInterfaceCacheEntryObjCInterfaceCacheEntry74*0a6a1f1dSLionel Sambuc ObjCInterfaceCacheEntry(const ObjCInterfaceType *Type, llvm::DIType Decl, 75*0a6a1f1dSLionel Sambuc llvm::DIFile Unit) 76*0a6a1f1dSLionel Sambuc : Type(Type), Decl(Decl), Unit(Unit) {} 77*0a6a1f1dSLionel Sambuc }; 78f4a2713aSLionel Sambuc 79f4a2713aSLionel Sambuc /// ObjCInterfaceCache - Cache of previously constructed interfaces 80*0a6a1f1dSLionel Sambuc /// which may change. 81*0a6a1f1dSLionel Sambuc llvm::SmallVector<ObjCInterfaceCacheEntry, 32> ObjCInterfaceCache; 82f4a2713aSLionel Sambuc 83f4a2713aSLionel Sambuc /// RetainedTypes - list of interfaces we want to keep even if orphaned. 84f4a2713aSLionel Sambuc std::vector<void *> RetainedTypes; 85f4a2713aSLionel Sambuc 86f4a2713aSLionel Sambuc /// ReplaceMap - Cache of forward declared types to RAUW at the end of 87f4a2713aSLionel Sambuc /// compilation. 88*0a6a1f1dSLionel Sambuc std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap; 89*0a6a1f1dSLionel Sambuc 90*0a6a1f1dSLionel Sambuc /// \brief Cache of replaceable forward declarartions (functions and 91*0a6a1f1dSLionel Sambuc /// variables) to RAUW at the end of compilation. 92*0a6a1f1dSLionel Sambuc std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>> 93*0a6a1f1dSLionel Sambuc FwdDeclReplaceMap; 94f4a2713aSLionel Sambuc 95f4a2713aSLionel Sambuc // LexicalBlockStack - Keep track of our current nested lexical block. 96*0a6a1f1dSLionel Sambuc std::vector<llvm::TrackingMDNodeRef> LexicalBlockStack; 97*0a6a1f1dSLionel Sambuc llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap; 98f4a2713aSLionel Sambuc // FnBeginRegionCount - Keep track of LexicalBlockStack counter at the 99f4a2713aSLionel Sambuc // beginning of a function. This is used to pop unbalanced regions at 100f4a2713aSLionel Sambuc // the end of a function. 101f4a2713aSLionel Sambuc std::vector<unsigned> FnBeginRegionCount; 102f4a2713aSLionel Sambuc 103f4a2713aSLionel Sambuc /// DebugInfoNames - This is a storage for names that are 104f4a2713aSLionel Sambuc /// constructed on demand. For example, C++ destructors, C++ operators etc.. 105f4a2713aSLionel Sambuc llvm::BumpPtrAllocator DebugInfoNames; 106f4a2713aSLionel Sambuc StringRef CWDName; 107f4a2713aSLionel Sambuc 108*0a6a1f1dSLionel Sambuc llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache; 109*0a6a1f1dSLionel Sambuc llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache; 110f4a2713aSLionel Sambuc /// \brief Cache declarations relevant to DW_TAG_imported_declarations (C++ 111f4a2713aSLionel Sambuc /// using declarations) that aren't covered by other more specific caches. 112*0a6a1f1dSLionel Sambuc llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache; 113*0a6a1f1dSLionel Sambuc llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NameSpaceCache; 114*0a6a1f1dSLionel Sambuc llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef> 115*0a6a1f1dSLionel Sambuc NamespaceAliasCache; 116*0a6a1f1dSLionel Sambuc llvm::DenseMap<const Decl *, llvm::TrackingMDRef> StaticDataMemberCache; 117f4a2713aSLionel Sambuc 118f4a2713aSLionel Sambuc /// Helper functions for getOrCreateType. 119f4a2713aSLionel Sambuc unsigned Checksum(const ObjCInterfaceDecl *InterfaceDecl); 120f4a2713aSLionel Sambuc llvm::DIType CreateType(const BuiltinType *Ty); 121f4a2713aSLionel Sambuc llvm::DIType CreateType(const ComplexType *Ty); 122f4a2713aSLionel Sambuc llvm::DIType CreateQualifiedType(QualType Ty, llvm::DIFile Fg); 123f4a2713aSLionel Sambuc llvm::DIType CreateType(const TypedefType *Ty, llvm::DIFile Fg); 124*0a6a1f1dSLionel Sambuc llvm::DIType CreateType(const TemplateSpecializationType *Ty, llvm::DIFile Fg); 125f4a2713aSLionel Sambuc llvm::DIType CreateType(const ObjCObjectPointerType *Ty, 126f4a2713aSLionel Sambuc llvm::DIFile F); 127f4a2713aSLionel Sambuc llvm::DIType CreateType(const PointerType *Ty, llvm::DIFile F); 128f4a2713aSLionel Sambuc llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DIFile F); 129f4a2713aSLionel Sambuc llvm::DIType CreateType(const FunctionType *Ty, llvm::DIFile F); 130f4a2713aSLionel Sambuc llvm::DIType CreateType(const RecordType *Tyg); 131f4a2713aSLionel Sambuc llvm::DIType CreateTypeDefinition(const RecordType *Ty); 132f4a2713aSLionel Sambuc llvm::DICompositeType CreateLimitedType(const RecordType *Ty); 133f4a2713aSLionel Sambuc void CollectContainingType(const CXXRecordDecl *RD, llvm::DICompositeType CT); 134f4a2713aSLionel Sambuc llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DIFile F); 135*0a6a1f1dSLionel Sambuc llvm::DIType CreateTypeDefinition(const ObjCInterfaceType *Ty, llvm::DIFile F); 136f4a2713aSLionel Sambuc llvm::DIType CreateType(const ObjCObjectType *Ty, llvm::DIFile F); 137f4a2713aSLionel Sambuc llvm::DIType CreateType(const VectorType *Ty, llvm::DIFile F); 138f4a2713aSLionel Sambuc llvm::DIType CreateType(const ArrayType *Ty, llvm::DIFile F); 139f4a2713aSLionel Sambuc llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DIFile F); 140f4a2713aSLionel Sambuc llvm::DIType CreateType(const RValueReferenceType *Ty, llvm::DIFile Unit); 141f4a2713aSLionel Sambuc llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DIFile F); 142f4a2713aSLionel Sambuc llvm::DIType CreateType(const AtomicType *Ty, llvm::DIFile F); 143f4a2713aSLionel Sambuc llvm::DIType CreateEnumType(const EnumType *Ty); 144*0a6a1f1dSLionel Sambuc llvm::DIType CreateTypeDefinition(const EnumType *Ty); 145f4a2713aSLionel Sambuc llvm::DIType CreateSelfType(const QualType &QualTy, llvm::DIType Ty); 146f4a2713aSLionel Sambuc llvm::DIType getTypeOrNull(const QualType); 147f4a2713aSLionel Sambuc llvm::DICompositeType getOrCreateMethodType(const CXXMethodDecl *Method, 148f4a2713aSLionel Sambuc llvm::DIFile F); 149f4a2713aSLionel Sambuc llvm::DICompositeType getOrCreateInstanceMethodType( 150f4a2713aSLionel Sambuc QualType ThisPtr, const FunctionProtoType *Func, llvm::DIFile Unit); 151f4a2713aSLionel Sambuc llvm::DICompositeType getOrCreateFunctionType(const Decl *D, QualType FnType, 152f4a2713aSLionel Sambuc llvm::DIFile F); 153f4a2713aSLionel Sambuc llvm::DIType getOrCreateVTablePtrType(llvm::DIFile F); 154f4a2713aSLionel Sambuc llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N); 155f4a2713aSLionel Sambuc llvm::DIType getOrCreateTypeDeclaration(QualType PointeeTy, llvm::DIFile F); 156*0a6a1f1dSLionel Sambuc llvm::DIType CreatePointerLikeType(llvm::dwarf::Tag Tag, 157f4a2713aSLionel Sambuc const Type *Ty, QualType PointeeTy, 158f4a2713aSLionel Sambuc llvm::DIFile F); 159f4a2713aSLionel Sambuc 160f4a2713aSLionel Sambuc llvm::Value *getCachedInterfaceTypeOrNull(const QualType Ty); 161f4a2713aSLionel Sambuc llvm::DIType getOrCreateStructPtrType(StringRef Name, llvm::DIType &Cache); 162f4a2713aSLionel Sambuc 163f4a2713aSLionel Sambuc llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method, 164f4a2713aSLionel Sambuc llvm::DIFile F, 165f4a2713aSLionel Sambuc llvm::DIType RecordTy); 166f4a2713aSLionel Sambuc 167*0a6a1f1dSLionel Sambuc void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, llvm::DIFile F, 168*0a6a1f1dSLionel Sambuc SmallVectorImpl<llvm::Metadata *> &E, 169f4a2713aSLionel Sambuc llvm::DIType T); 170f4a2713aSLionel Sambuc 171*0a6a1f1dSLionel Sambuc void CollectCXXBases(const CXXRecordDecl *Decl, llvm::DIFile F, 172*0a6a1f1dSLionel Sambuc SmallVectorImpl<llvm::Metadata *> &EltTys, 173f4a2713aSLionel Sambuc llvm::DIType RecordTy); 174f4a2713aSLionel Sambuc 175f4a2713aSLionel Sambuc llvm::DIArray 176f4a2713aSLionel Sambuc CollectTemplateParams(const TemplateParameterList *TPList, 177f4a2713aSLionel Sambuc ArrayRef<TemplateArgument> TAList, 178f4a2713aSLionel Sambuc llvm::DIFile Unit); 179f4a2713aSLionel Sambuc llvm::DIArray 180f4a2713aSLionel Sambuc CollectFunctionTemplateParams(const FunctionDecl *FD, llvm::DIFile Unit); 181f4a2713aSLionel Sambuc llvm::DIArray 182f4a2713aSLionel Sambuc CollectCXXTemplateParams(const ClassTemplateSpecializationDecl *TS, 183f4a2713aSLionel Sambuc llvm::DIFile F); 184f4a2713aSLionel Sambuc 185f4a2713aSLionel Sambuc llvm::DIType createFieldType(StringRef name, QualType type, 186f4a2713aSLionel Sambuc uint64_t sizeInBitsOverride, SourceLocation loc, 187*0a6a1f1dSLionel Sambuc AccessSpecifier AS, 188*0a6a1f1dSLionel Sambuc uint64_t offsetInBits, 189f4a2713aSLionel Sambuc llvm::DIFile tunit, 190*0a6a1f1dSLionel Sambuc llvm::DIScope scope, 191*0a6a1f1dSLionel Sambuc const RecordDecl* RD = nullptr); 192f4a2713aSLionel Sambuc 193f4a2713aSLionel Sambuc // Helpers for collecting fields of a record. 194f4a2713aSLionel Sambuc void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl, 195*0a6a1f1dSLionel Sambuc SmallVectorImpl<llvm::Metadata *> &E, 196f4a2713aSLionel Sambuc llvm::DIType RecordTy); 197f4a2713aSLionel Sambuc llvm::DIDerivedType CreateRecordStaticField(const VarDecl *Var, 198*0a6a1f1dSLionel Sambuc llvm::DIType RecordTy, 199*0a6a1f1dSLionel Sambuc const RecordDecl* RD); 200f4a2713aSLionel Sambuc void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits, 201f4a2713aSLionel Sambuc llvm::DIFile F, 202*0a6a1f1dSLionel Sambuc SmallVectorImpl<llvm::Metadata *> &E, 203*0a6a1f1dSLionel Sambuc llvm::DIType RecordTy, const RecordDecl *RD); 204f4a2713aSLionel Sambuc void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F, 205*0a6a1f1dSLionel Sambuc SmallVectorImpl<llvm::Metadata *> &E, 206f4a2713aSLionel Sambuc llvm::DICompositeType RecordTy); 207f4a2713aSLionel Sambuc 208*0a6a1f1dSLionel Sambuc void CollectVTableInfo(const CXXRecordDecl *Decl, llvm::DIFile F, 209*0a6a1f1dSLionel Sambuc SmallVectorImpl<llvm::Metadata *> &EltTys); 210f4a2713aSLionel Sambuc 211f4a2713aSLionel Sambuc // CreateLexicalBlock - Create a new lexical block node and push it on 212f4a2713aSLionel Sambuc // the stack. 213f4a2713aSLionel Sambuc void CreateLexicalBlock(SourceLocation Loc); 214f4a2713aSLionel Sambuc 215f4a2713aSLionel Sambuc public: 216f4a2713aSLionel Sambuc CGDebugInfo(CodeGenModule &CGM); 217f4a2713aSLionel Sambuc ~CGDebugInfo(); 218f4a2713aSLionel Sambuc 219f4a2713aSLionel Sambuc void finalize(); 220f4a2713aSLionel Sambuc 221f4a2713aSLionel Sambuc /// setLocation - Update the current source location. If \arg loc is 222f4a2713aSLionel Sambuc /// invalid it is ignored. 223f4a2713aSLionel Sambuc void setLocation(SourceLocation Loc); 224f4a2713aSLionel Sambuc 225f4a2713aSLionel Sambuc /// getLocation - Return the current source location. getLocation()226f4a2713aSLionel Sambuc SourceLocation getLocation() const { return CurLoc; } 227f4a2713aSLionel Sambuc 228f4a2713aSLionel Sambuc /// EmitLocation - Emit metadata to indicate a change in line/column 229f4a2713aSLionel Sambuc /// information in the source file. 230f4a2713aSLionel Sambuc /// \param ForceColumnInfo Assume DebugColumnInfo option is true. 231f4a2713aSLionel Sambuc void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc, 232f4a2713aSLionel Sambuc bool ForceColumnInfo = false); 233f4a2713aSLionel Sambuc 234f4a2713aSLionel Sambuc /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate 235f4a2713aSLionel Sambuc /// start of a new function. 236*0a6a1f1dSLionel Sambuc /// \param Loc The location of the function header. 237*0a6a1f1dSLionel Sambuc /// \param ScopeLoc The location of the function body. 238*0a6a1f1dSLionel Sambuc void EmitFunctionStart(GlobalDecl GD, 239*0a6a1f1dSLionel Sambuc SourceLocation Loc, SourceLocation ScopeLoc, 240*0a6a1f1dSLionel Sambuc QualType FnType, llvm::Function *Fn, 241*0a6a1f1dSLionel Sambuc CGBuilderTy &Builder); 242f4a2713aSLionel Sambuc 243f4a2713aSLionel Sambuc /// EmitFunctionEnd - Constructs the debug code for exiting a function. 244f4a2713aSLionel Sambuc void EmitFunctionEnd(CGBuilderTy &Builder); 245f4a2713aSLionel Sambuc 246f4a2713aSLionel Sambuc /// EmitLexicalBlockStart - Emit metadata to indicate the beginning of a 247f4a2713aSLionel Sambuc /// new lexical block and push the block onto the stack. 248f4a2713aSLionel Sambuc void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc); 249f4a2713aSLionel Sambuc 250f4a2713aSLionel Sambuc /// EmitLexicalBlockEnd - Emit metadata to indicate the end of a new lexical 251f4a2713aSLionel Sambuc /// block and pop the current block. 252f4a2713aSLionel Sambuc void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc); 253f4a2713aSLionel Sambuc 254f4a2713aSLionel Sambuc /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic 255f4a2713aSLionel Sambuc /// variable declaration. 256f4a2713aSLionel Sambuc void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, 257f4a2713aSLionel Sambuc CGBuilderTy &Builder); 258f4a2713aSLionel Sambuc 259f4a2713aSLionel Sambuc /// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an 260f4a2713aSLionel Sambuc /// imported variable declaration in a block. 261f4a2713aSLionel Sambuc void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable, 262f4a2713aSLionel Sambuc llvm::Value *storage, 263f4a2713aSLionel Sambuc CGBuilderTy &Builder, 264*0a6a1f1dSLionel Sambuc const CGBlockInfo &blockInfo, 265*0a6a1f1dSLionel Sambuc llvm::Instruction *InsertPoint = 0); 266f4a2713aSLionel Sambuc 267f4a2713aSLionel Sambuc /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument 268f4a2713aSLionel Sambuc /// variable declaration. 269f4a2713aSLionel Sambuc void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, 270f4a2713aSLionel Sambuc unsigned ArgNo, CGBuilderTy &Builder); 271f4a2713aSLionel Sambuc 272f4a2713aSLionel Sambuc /// EmitDeclareOfBlockLiteralArgVariable - Emit call to 273f4a2713aSLionel Sambuc /// llvm.dbg.declare for the block-literal argument to a block 274f4a2713aSLionel Sambuc /// invocation function. 275f4a2713aSLionel Sambuc void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block, 276*0a6a1f1dSLionel Sambuc llvm::Value *Arg, unsigned ArgNo, 277f4a2713aSLionel Sambuc llvm::Value *LocalAddr, 278f4a2713aSLionel Sambuc CGBuilderTy &Builder); 279f4a2713aSLionel Sambuc 280f4a2713aSLionel Sambuc /// EmitGlobalVariable - Emit information about a global variable. 281f4a2713aSLionel Sambuc void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); 282f4a2713aSLionel Sambuc 283f4a2713aSLionel Sambuc /// EmitGlobalVariable - Emit global variable's debug info. 284f4a2713aSLionel Sambuc void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init); 285f4a2713aSLionel Sambuc 286f4a2713aSLionel Sambuc /// \brief - Emit C++ using directive. 287f4a2713aSLionel Sambuc void EmitUsingDirective(const UsingDirectiveDecl &UD); 288f4a2713aSLionel Sambuc 289*0a6a1f1dSLionel Sambuc /// EmitExplicitCastType - Emit the type explicitly casted to. 290*0a6a1f1dSLionel Sambuc void EmitExplicitCastType(QualType Ty); 291*0a6a1f1dSLionel Sambuc 292f4a2713aSLionel Sambuc /// \brief - Emit C++ using declaration. 293f4a2713aSLionel Sambuc void EmitUsingDecl(const UsingDecl &UD); 294f4a2713aSLionel Sambuc 295f4a2713aSLionel Sambuc /// \brief - Emit C++ namespace alias. 296f4a2713aSLionel Sambuc llvm::DIImportedEntity EmitNamespaceAlias(const NamespaceAliasDecl &NA); 297f4a2713aSLionel Sambuc 298f4a2713aSLionel Sambuc /// getOrCreateRecordType - Emit record type's standalone debug info. 299f4a2713aSLionel Sambuc llvm::DIType getOrCreateRecordType(QualType Ty, SourceLocation L); 300f4a2713aSLionel Sambuc 301f4a2713aSLionel Sambuc /// getOrCreateInterfaceType - Emit an objective c interface type standalone 302f4a2713aSLionel Sambuc /// debug info. 303f4a2713aSLionel Sambuc llvm::DIType getOrCreateInterfaceType(QualType Ty, 304f4a2713aSLionel Sambuc SourceLocation Loc); 305f4a2713aSLionel Sambuc 306*0a6a1f1dSLionel Sambuc void completeType(const EnumDecl *ED); 307f4a2713aSLionel Sambuc void completeType(const RecordDecl *RD); 308f4a2713aSLionel Sambuc void completeRequiredType(const RecordDecl *RD); 309f4a2713aSLionel Sambuc void completeClassData(const RecordDecl *RD); 310f4a2713aSLionel Sambuc 311*0a6a1f1dSLionel Sambuc void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD); 312*0a6a1f1dSLionel Sambuc 313f4a2713aSLionel Sambuc private: 314f4a2713aSLionel Sambuc /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. 315*0a6a1f1dSLionel Sambuc /// Tag accepts custom types DW_TAG_arg_variable and DW_TAG_auto_variable, 316*0a6a1f1dSLionel Sambuc /// otherwise would be of type llvm::dwarf::Tag. 317*0a6a1f1dSLionel Sambuc void EmitDeclare(const VarDecl *decl, llvm::dwarf::LLVMConstants Tag, 318*0a6a1f1dSLionel Sambuc llvm::Value *AI, unsigned ArgNo, CGBuilderTy &Builder); 319f4a2713aSLionel Sambuc 320f4a2713aSLionel Sambuc // EmitTypeForVarWithBlocksAttr - Build up structure info for the byref. 321f4a2713aSLionel Sambuc // See BuildByRefType. 322f4a2713aSLionel Sambuc llvm::DIType EmitTypeForVarWithBlocksAttr(const VarDecl *VD, 323f4a2713aSLionel Sambuc uint64_t *OffSet); 324f4a2713aSLionel Sambuc 325f4a2713aSLionel Sambuc /// getContextDescriptor - Get context info for the decl. 326f4a2713aSLionel Sambuc llvm::DIScope getContextDescriptor(const Decl *Decl); 327f4a2713aSLionel Sambuc 328f4a2713aSLionel Sambuc llvm::DIScope getCurrentContextDescriptor(const Decl *Decl); 329f4a2713aSLionel Sambuc 330f4a2713aSLionel Sambuc /// \brief Create a forward decl for a RecordType in a given context. 331f4a2713aSLionel Sambuc llvm::DICompositeType getOrCreateRecordFwdDecl(const RecordType *, 332f4a2713aSLionel Sambuc llvm::DIDescriptor); 333f4a2713aSLionel Sambuc 334f4a2713aSLionel Sambuc /// createContextChain - Create a set of decls for the context chain. 335f4a2713aSLionel Sambuc llvm::DIDescriptor createContextChain(const Decl *Decl); 336f4a2713aSLionel Sambuc 337f4a2713aSLionel Sambuc /// getCurrentDirname - Return current directory name. 338f4a2713aSLionel Sambuc StringRef getCurrentDirname(); 339f4a2713aSLionel Sambuc 340f4a2713aSLionel Sambuc /// CreateCompileUnit - Create new compile unit. 341f4a2713aSLionel Sambuc void CreateCompileUnit(); 342f4a2713aSLionel Sambuc 343f4a2713aSLionel Sambuc /// getOrCreateFile - Get the file debug info descriptor for the input 344f4a2713aSLionel Sambuc /// location. 345f4a2713aSLionel Sambuc llvm::DIFile getOrCreateFile(SourceLocation Loc); 346f4a2713aSLionel Sambuc 347f4a2713aSLionel Sambuc /// getOrCreateMainFile - Get the file info for main compile unit. 348f4a2713aSLionel Sambuc llvm::DIFile getOrCreateMainFile(); 349f4a2713aSLionel Sambuc 350f4a2713aSLionel Sambuc /// getOrCreateType - Get the type from the cache or create a new type if 351f4a2713aSLionel Sambuc /// necessary. 352f4a2713aSLionel Sambuc llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile Fg); 353f4a2713aSLionel Sambuc 354f4a2713aSLionel Sambuc /// getOrCreateLimitedType - Get the type from the cache or create a new 355f4a2713aSLionel Sambuc /// partial type if necessary. 356f4a2713aSLionel Sambuc llvm::DIType getOrCreateLimitedType(const RecordType *Ty, llvm::DIFile F); 357f4a2713aSLionel Sambuc 358f4a2713aSLionel Sambuc /// CreateTypeNode - Create type metadata for a source language type. 359f4a2713aSLionel Sambuc llvm::DIType CreateTypeNode(QualType Ty, llvm::DIFile Fg); 360f4a2713aSLionel Sambuc 361f4a2713aSLionel Sambuc /// getObjCInterfaceDecl - return the underlying ObjCInterfaceDecl 362f4a2713aSLionel Sambuc /// if Ty is an ObjCInterface or a pointer to one. 363f4a2713aSLionel Sambuc ObjCInterfaceDecl* getObjCInterfaceDecl(QualType Ty); 364f4a2713aSLionel Sambuc 365f4a2713aSLionel Sambuc /// CreateMemberType - Create new member and increase Offset by FType's size. 366f4a2713aSLionel Sambuc llvm::DIType CreateMemberType(llvm::DIFile Unit, QualType FType, 367f4a2713aSLionel Sambuc StringRef Name, uint64_t *Offset); 368f4a2713aSLionel Sambuc 369f4a2713aSLionel Sambuc /// \brief Retrieve the DIDescriptor, if any, for the canonical form of this 370f4a2713aSLionel Sambuc /// declaration. 371f4a2713aSLionel Sambuc llvm::DIDescriptor getDeclarationOrDefinition(const Decl *D); 372f4a2713aSLionel Sambuc 373f4a2713aSLionel Sambuc /// getFunctionDeclaration - Return debug info descriptor to describe method 374f4a2713aSLionel Sambuc /// declaration for the given method definition. 375f4a2713aSLionel Sambuc llvm::DISubprogram getFunctionDeclaration(const Decl *D); 376f4a2713aSLionel Sambuc 377f4a2713aSLionel Sambuc /// Return debug info descriptor to describe in-class static data member 378f4a2713aSLionel Sambuc /// declaration for the given out-of-class definition. 379f4a2713aSLionel Sambuc llvm::DIDerivedType 380f4a2713aSLionel Sambuc getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D); 381f4a2713aSLionel Sambuc 382*0a6a1f1dSLionel Sambuc /// \brief Create a DISubprogram describing the forward 383*0a6a1f1dSLionel Sambuc /// decalration represented in the given FunctionDecl. 384*0a6a1f1dSLionel Sambuc llvm::DISubprogram getFunctionForwardDeclaration(const FunctionDecl *FD); 385*0a6a1f1dSLionel Sambuc 386*0a6a1f1dSLionel Sambuc /// \brief Create a DIGlobalVariable describing the forward 387*0a6a1f1dSLionel Sambuc /// decalration represented in the given VarDecl. 388*0a6a1f1dSLionel Sambuc llvm::DIGlobalVariable getGlobalVariableForwardDeclaration(const VarDecl *VD); 389*0a6a1f1dSLionel Sambuc 390*0a6a1f1dSLionel Sambuc /// Return a global variable that represents one of the collection of 391*0a6a1f1dSLionel Sambuc /// global variables created for an anonmyous union. 392*0a6a1f1dSLionel Sambuc llvm::DIGlobalVariable 393*0a6a1f1dSLionel Sambuc CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile Unit, unsigned LineNo, 394*0a6a1f1dSLionel Sambuc StringRef LinkageName, llvm::GlobalVariable *Var, 395*0a6a1f1dSLionel Sambuc llvm::DIDescriptor DContext); 396*0a6a1f1dSLionel Sambuc 397f4a2713aSLionel Sambuc /// getFunctionName - Get function name for the given FunctionDecl. If the 398f4a2713aSLionel Sambuc /// name is constructed on demand (e.g. C++ destructor) then the name 399f4a2713aSLionel Sambuc /// is stored on the side. 400f4a2713aSLionel Sambuc StringRef getFunctionName(const FunctionDecl *FD); 401f4a2713aSLionel Sambuc 402f4a2713aSLionel Sambuc /// getObjCMethodName - Returns the unmangled name of an Objective-C method. 403f4a2713aSLionel Sambuc /// This is the display name for the debugging info. 404f4a2713aSLionel Sambuc StringRef getObjCMethodName(const ObjCMethodDecl *FD); 405f4a2713aSLionel Sambuc 406f4a2713aSLionel Sambuc /// getSelectorName - Return selector name. This is used for debugging 407f4a2713aSLionel Sambuc /// info. 408f4a2713aSLionel Sambuc StringRef getSelectorName(Selector S); 409f4a2713aSLionel Sambuc 410f4a2713aSLionel Sambuc /// getClassName - Get class name including template argument list. 411f4a2713aSLionel Sambuc StringRef getClassName(const RecordDecl *RD); 412f4a2713aSLionel Sambuc 413f4a2713aSLionel Sambuc /// getVTableName - Get vtable name for the given Class. 414f4a2713aSLionel Sambuc StringRef getVTableName(const CXXRecordDecl *Decl); 415f4a2713aSLionel Sambuc 416f4a2713aSLionel Sambuc /// getLineNumber - Get line number for the location. If location is invalid 417f4a2713aSLionel Sambuc /// then use current location. 418f4a2713aSLionel Sambuc unsigned getLineNumber(SourceLocation Loc); 419f4a2713aSLionel Sambuc 420f4a2713aSLionel Sambuc /// getColumnNumber - Get column number for the location. If location is 421f4a2713aSLionel Sambuc /// invalid then use current location. 422f4a2713aSLionel Sambuc /// \param Force Assume DebugColumnInfo option is true. 423f4a2713aSLionel Sambuc unsigned getColumnNumber(SourceLocation Loc, bool Force=false); 424f4a2713aSLionel Sambuc 425*0a6a1f1dSLionel Sambuc /// \brief Collect various properties of a FunctionDecl. 426*0a6a1f1dSLionel Sambuc /// \param GD A GlobalDecl whose getDecl() must return a FunctionDecl. 427*0a6a1f1dSLionel Sambuc void collectFunctionDeclProps(GlobalDecl GD, 428*0a6a1f1dSLionel Sambuc llvm::DIFile Unit, 429*0a6a1f1dSLionel Sambuc StringRef &Name, StringRef &LinkageName, 430*0a6a1f1dSLionel Sambuc llvm::DIDescriptor &FDContext, 431*0a6a1f1dSLionel Sambuc llvm::DIArray &TParamsArray, 432*0a6a1f1dSLionel Sambuc unsigned &Flags); 433*0a6a1f1dSLionel Sambuc 434*0a6a1f1dSLionel Sambuc /// \brief Collect various properties of a VarDecl. 435*0a6a1f1dSLionel Sambuc void collectVarDeclProps(const VarDecl *VD, llvm::DIFile &Unit, 436*0a6a1f1dSLionel Sambuc unsigned &LineNo, QualType &T, 437*0a6a1f1dSLionel Sambuc StringRef &Name, StringRef &LinkageName, 438*0a6a1f1dSLionel Sambuc llvm::DIDescriptor &VDContext); 439*0a6a1f1dSLionel Sambuc 440f4a2713aSLionel Sambuc /// internString - Allocate a copy of \p A using the DebugInfoNames allocator 441f4a2713aSLionel Sambuc /// and return a reference to it. If multiple arguments are given the strings 442f4a2713aSLionel Sambuc /// are concatenated. 443f4a2713aSLionel Sambuc StringRef internString(StringRef A, StringRef B = StringRef()) { 444f4a2713aSLionel Sambuc char *Data = DebugInfoNames.Allocate<char>(A.size() + B.size()); 445f4a2713aSLionel Sambuc std::memcpy(Data, A.data(), A.size()); 446f4a2713aSLionel Sambuc std::memcpy(Data + A.size(), B.data(), B.size()); 447f4a2713aSLionel Sambuc return StringRef(Data, A.size() + B.size()); 448f4a2713aSLionel Sambuc } 449f4a2713aSLionel Sambuc }; 450f4a2713aSLionel Sambuc 451*0a6a1f1dSLionel Sambuc class ApplyDebugLocation { 452*0a6a1f1dSLionel Sambuc protected: 453*0a6a1f1dSLionel Sambuc llvm::DebugLoc OriginalLocation; 454*0a6a1f1dSLionel Sambuc CodeGenFunction &CGF; 455*0a6a1f1dSLionel Sambuc 456f4a2713aSLionel Sambuc public: 457*0a6a1f1dSLionel Sambuc ApplyDebugLocation(CodeGenFunction &CGF, 458*0a6a1f1dSLionel Sambuc SourceLocation TemporaryLocation = SourceLocation(), 459*0a6a1f1dSLionel Sambuc bool ForceColumnInfo = false); 460*0a6a1f1dSLionel Sambuc ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc); 461*0a6a1f1dSLionel Sambuc ~ApplyDebugLocation(); 462f4a2713aSLionel Sambuc }; 463f4a2713aSLionel Sambuc 464f4a2713aSLionel Sambuc /// ArtificialLocation - An RAII object that temporarily switches to 465f4a2713aSLionel Sambuc /// an artificial debug location that has a valid scope, but no line 466f4a2713aSLionel Sambuc /// information. This is useful when emitting compiler-generated 467f4a2713aSLionel Sambuc /// helper functions that have no source location associated with 468f4a2713aSLionel Sambuc /// them. The DWARF specification allows the compiler to use the 469f4a2713aSLionel Sambuc /// special line number 0 to indicate code that can not be attributed 470f4a2713aSLionel Sambuc /// to any source location. 471f4a2713aSLionel Sambuc /// 472f4a2713aSLionel Sambuc /// This is necessary because passing an empty SourceLocation to 473f4a2713aSLionel Sambuc /// CGDebugInfo::setLocation() will result in the last valid location 474f4a2713aSLionel Sambuc /// being reused. 475*0a6a1f1dSLionel Sambuc class ArtificialLocation : public ApplyDebugLocation { 476f4a2713aSLionel Sambuc public: 477*0a6a1f1dSLionel Sambuc ArtificialLocation(CodeGenFunction &CGF); 478f4a2713aSLionel Sambuc }; 479f4a2713aSLionel Sambuc 480f4a2713aSLionel Sambuc 481f4a2713aSLionel Sambuc } // namespace CodeGen 482f4a2713aSLionel Sambuc } // namespace clang 483f4a2713aSLionel Sambuc 484f4a2713aSLionel Sambuc 485f4a2713aSLionel Sambuc #endif 486