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/Basic/SourceLocation.h" 19 #include "llvm/ADT/DenseMap.h" 20 #include "llvm/Analysis/DebugInfo.h" 21 #include <map> 22 23 #include "CGBuilder.h" 24 25 namespace clang { 26 class VarDecl; 27 class ObjCInterfaceDecl; 28 29 namespace CodeGen { 30 class CodeGenModule; 31 32 /// CGDebugInfo - This class gathers all debug information during compilation 33 /// and is responsible for emitting to llvm globals or pass directly to 34 /// the backend. 35 class CGDebugInfo { 36 CodeGenModule *M; 37 bool isMainCompileUnitCreated; 38 llvm::DIFactory DebugFactory; 39 40 SourceLocation CurLoc, PrevLoc; 41 42 /// CompileUnitCache - Cache of previously constructed CompileUnits. 43 llvm::DenseMap<unsigned, llvm::DICompileUnit> CompileUnitCache; 44 45 /// TypeCache - Cache of previously constructed Types. 46 // FIXME: Eliminate this map. Be careful of iterator invalidation. 47 std::map<void *, llvm::DIType> TypeCache; 48 49 bool BlockLiteralGenericSet; 50 llvm::DIType BlockLiteralGeneric; 51 52 std::vector<llvm::DIDescriptor> RegionStack; 53 54 /// Helper functions for getOrCreateType. 55 llvm::DIType CreateType(const BuiltinType *Ty, llvm::DICompileUnit U); 56 llvm::DIType CreateType(const ComplexType *Ty, llvm::DICompileUnit U); 57 llvm::DIType CreateCVRType(QualType Ty, llvm::DICompileUnit U); 58 llvm::DIType CreateType(const TypedefType *Ty, llvm::DICompileUnit U); 59 llvm::DIType CreateType(const ObjCObjectPointerType *Ty, 60 llvm::DICompileUnit Unit); 61 llvm::DIType CreateType(const PointerType *Ty, llvm::DICompileUnit U); 62 llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DICompileUnit U); 63 llvm::DIType CreateType(const FunctionType *Ty, llvm::DICompileUnit U); 64 llvm::DIType CreateType(const TagType *Ty, llvm::DICompileUnit U); 65 llvm::DIType CreateType(const RecordType *Ty, llvm::DICompileUnit U); 66 llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DICompileUnit U); 67 llvm::DIType CreateType(const EnumType *Ty, llvm::DICompileUnit U); 68 llvm::DIType CreateType(const ArrayType *Ty, llvm::DICompileUnit U); 69 70 public: 71 CGDebugInfo(CodeGenModule *m); 72 ~CGDebugInfo(); 73 74 /// setLocation - Update the current source location. If \arg loc is 75 /// invalid it is ignored. 76 void setLocation(SourceLocation Loc); 77 78 /// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of 79 /// source line. 80 void EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder); 81 82 /// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate 83 /// start of a new function. 84 void EmitFunctionStart(const char *Name, QualType ReturnType, 85 llvm::Function *Fn, CGBuilderTy &Builder); 86 87 /// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start 88 /// of a new block. 89 void EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder); 90 91 /// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a 92 /// block. 93 void EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder); 94 95 /// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic 96 /// variable declaration. 97 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, 98 CGBuilderTy &Builder); 99 100 /// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument 101 /// variable declaration. 102 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, 103 CGBuilderTy &Builder); 104 105 /// EmitGlobalVariable - Emit information about a global variable. 106 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl); 107 108 /// EmitGlobalVariable - Emit information about an objective-c interface. 109 void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl); 110 111 private: 112 /// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration. 113 void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI, 114 CGBuilderTy &Builder); 115 116 117 /// getOrCreateCompileUnit - Get the compile unit from the cache or create a 118 /// new one if necessary. 119 llvm::DICompileUnit getOrCreateCompileUnit(SourceLocation Loc); 120 121 /// getOrCreateType - Get the type from the cache or create a new type if 122 /// necessary. 123 llvm::DIType getOrCreateType(QualType Ty, llvm::DICompileUnit Unit); 124 }; 125 } // namespace CodeGen 126 } // namespace clang 127 128 #endif 129