2008-10-31 06:54:29 +03:00
|
|
|
//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
|
2008-05-08 12:54:20 +04:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-09-09 19:08:12 +04:00
|
|
|
// This is the source level debug info generator for llvm translation.
|
2008-05-08 12:54:20 +04:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef CLANG_CODEGEN_CGDEBUGINFO_H
|
|
|
|
#define CLANG_CODEGEN_CGDEBUGINFO_H
|
|
|
|
|
2008-05-25 09:15:42 +04:00
|
|
|
#include "clang/AST/Type.h"
|
2009-09-30 06:43:10 +04:00
|
|
|
#include "clang/AST/Expr.h"
|
2008-05-08 12:54:20 +04:00
|
|
|
#include "clang/Basic/SourceLocation.h"
|
2008-11-10 09:08:34 +03:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/Analysis/DebugInfo.h"
|
2009-09-19 23:27:24 +04:00
|
|
|
#include "llvm/Support/ValueHandle.h"
|
2010-01-14 03:36:21 +03:00
|
|
|
#include "llvm/Support/Allocator.h"
|
2008-05-08 12:54:20 +04:00
|
|
|
|
2008-11-01 04:53:16 +03:00
|
|
|
#include "CGBuilder.h"
|
2008-05-08 12:54:20 +04:00
|
|
|
|
2009-09-19 23:27:24 +04:00
|
|
|
namespace llvm {
|
|
|
|
class MDNode;
|
|
|
|
}
|
|
|
|
|
2008-05-08 12:54:20 +04:00
|
|
|
namespace clang {
|
2008-05-30 14:30:31 +04:00
|
|
|
class VarDecl;
|
2009-02-27 00:10:26 +03:00
|
|
|
class ObjCInterfaceDecl;
|
2008-11-01 04:53:16 +03:00
|
|
|
|
2008-05-08 12:54:20 +04:00
|
|
|
namespace CodeGen {
|
|
|
|
class CodeGenModule;
|
2009-09-30 06:43:10 +04:00
|
|
|
class CodeGenFunction;
|
2010-01-14 03:36:21 +03:00
|
|
|
class GlobalDecl;
|
2008-05-08 12:54:20 +04:00
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
/// CGDebugInfo - This class gathers all debug information during compilation
|
|
|
|
/// and is responsible for emitting to llvm globals or pass directly to
|
2008-05-25 09:15:42 +04:00
|
|
|
/// the backend.
|
2008-05-08 12:54:20 +04:00
|
|
|
class CGDebugInfo {
|
2009-12-06 21:00:51 +03:00
|
|
|
CodeGenModule &CGM;
|
2008-11-10 09:08:34 +03:00
|
|
|
llvm::DIFactory DebugFactory;
|
2010-03-09 03:44:50 +03:00
|
|
|
llvm::DICompileUnit TheCU;
|
2008-11-10 09:08:34 +03:00
|
|
|
SourceLocation CurLoc, PrevLoc;
|
2010-01-28 21:11:52 +03:00
|
|
|
llvm::DIType VTablePtrType;
|
2010-03-09 03:44:50 +03:00
|
|
|
|
2008-05-25 09:15:42 +04:00
|
|
|
/// TypeCache - Cache of previously constructed Types.
|
2010-03-29 22:29:57 +04:00
|
|
|
llvm::DenseMap<void *, llvm::WeakVH> TypeCache;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-05-14 06:03:51 +04:00
|
|
|
bool BlockLiteralGenericSet;
|
|
|
|
llvm::DIType BlockLiteralGeneric;
|
|
|
|
|
2009-11-13 22:10:24 +03:00
|
|
|
std::vector<llvm::TrackingVH<llvm::MDNode> > RegionStack;
|
2010-01-29 21:11:03 +03:00
|
|
|
llvm::DenseMap<const Decl *, llvm::WeakVH> RegionMap;
|
2010-07-23 02:29:16 +04:00
|
|
|
// FnBeginRegionCount - Keep track of RegionStack counter at the beginning
|
|
|
|
// of a function. This is used to pop unbalanced regions at the end of a
|
|
|
|
// function.
|
|
|
|
std::vector<unsigned> FnBeginRegionCount;
|
|
|
|
|
|
|
|
/// LineDirectiveFiles - This stack is used to keep track of
|
|
|
|
/// scopes introduced by #line directives.
|
|
|
|
std::vector<const char *> LineDirectiveFiles;
|
2008-05-22 05:40:10 +04:00
|
|
|
|
2010-01-28 21:21:00 +03:00
|
|
|
/// DebugInfoNames - This is a storage for names that are
|
2010-01-14 03:36:21 +03:00
|
|
|
/// constructed on demand. For example, C++ destructors, C++ operators etc..
|
2010-01-28 21:21:00 +03:00
|
|
|
llvm::BumpPtrAllocator DebugInfoNames;
|
2010-07-27 19:17:16 +04:00
|
|
|
llvm::StringRef CWDName;
|
2010-01-14 03:36:21 +03:00
|
|
|
|
2010-03-30 04:27:51 +04:00
|
|
|
llvm::DenseMap<const char *, llvm::WeakVH> DIFileCache;
|
2010-01-19 04:54:44 +03:00
|
|
|
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache;
|
2010-02-01 22:16:32 +03:00
|
|
|
llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache;
|
2010-01-19 04:54:44 +03:00
|
|
|
|
2008-05-25 09:15:42 +04:00
|
|
|
/// Helper functions for getOrCreateType.
|
2010-03-09 03:44:50 +03:00
|
|
|
llvm::DIType CreateType(const BuiltinType *Ty, llvm::DIFile F);
|
|
|
|
llvm::DIType CreateType(const ComplexType *Ty, llvm::DIFile F);
|
|
|
|
llvm::DIType CreateQualifiedType(QualType Ty, llvm::DIFile F);
|
|
|
|
llvm::DIType CreateType(const TypedefType *Ty, llvm::DIFile F);
|
2009-09-09 19:08:12 +04:00
|
|
|
llvm::DIType CreateType(const ObjCObjectPointerType *Ty,
|
2010-03-09 03:44:50 +03:00
|
|
|
llvm::DIFile F);
|
|
|
|
llvm::DIType CreateType(const PointerType *Ty, llvm::DIFile F);
|
|
|
|
llvm::DIType CreateType(const BlockPointerType *Ty, llvm::DIFile F);
|
|
|
|
llvm::DIType CreateType(const FunctionType *Ty, llvm::DIFile F);
|
|
|
|
llvm::DIType CreateType(const TagType *Ty, llvm::DIFile F);
|
|
|
|
llvm::DIType CreateType(const RecordType *Ty, llvm::DIFile F);
|
|
|
|
llvm::DIType CreateType(const ObjCInterfaceType *Ty, llvm::DIFile F);
|
2010-05-15 15:32:37 +04:00
|
|
|
llvm::DIType CreateType(const ObjCObjectType *Ty, llvm::DIFile F);
|
2010-03-09 03:44:50 +03:00
|
|
|
llvm::DIType CreateType(const EnumType *Ty, llvm::DIFile F);
|
|
|
|
llvm::DIType CreateType(const VectorType *Ty, llvm::DIFile F);
|
|
|
|
llvm::DIType CreateType(const ArrayType *Ty, llvm::DIFile F);
|
|
|
|
llvm::DIType CreateType(const LValueReferenceType *Ty, llvm::DIFile F);
|
|
|
|
llvm::DIType CreateType(const MemberPointerType *Ty, llvm::DIFile F);
|
2010-08-24 02:07:25 +04:00
|
|
|
llvm::DIType CreateEnumType(const EnumDecl *ED, llvm::DIFile Unit);
|
2010-01-28 03:28:01 +03:00
|
|
|
llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method,
|
2010-03-09 03:44:50 +03:00
|
|
|
llvm::DIFile F);
|
|
|
|
llvm::DIType getOrCreateVTablePtrType(llvm::DIFile F);
|
2010-02-01 22:16:32 +03:00
|
|
|
llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N,
|
|
|
|
llvm::DIDescriptor Unit);
|
2010-09-30 23:05:55 +04:00
|
|
|
llvm::DIType CreatePointeeType(QualType PointeeTy, llvm::DIFile F);
|
2009-11-06 22:19:55 +03:00
|
|
|
llvm::DIType CreatePointerLikeType(unsigned Tag,
|
|
|
|
const Type *Ty, QualType PointeeTy,
|
2010-03-09 03:44:50 +03:00
|
|
|
llvm::DIFile F);
|
2010-01-26 07:49:33 +03:00
|
|
|
|
2010-01-26 08:19:50 +03:00
|
|
|
llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method,
|
2010-03-09 03:44:50 +03:00
|
|
|
llvm::DIFile F,
|
2010-08-21 02:02:57 +04:00
|
|
|
llvm::DIType RecordTy);
|
2010-01-26 07:49:33 +03:00
|
|
|
|
2010-01-19 04:54:44 +03:00
|
|
|
void CollectCXXMemberFunctions(const CXXRecordDecl *Decl,
|
2010-03-09 03:44:50 +03:00
|
|
|
llvm::DIFile F,
|
2010-01-19 04:54:44 +03:00
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &E,
|
2010-08-21 02:02:57 +04:00
|
|
|
llvm::DIType T);
|
2010-08-27 21:47:47 +04:00
|
|
|
|
|
|
|
void CollectCXXFriends(const CXXRecordDecl *Decl,
|
|
|
|
llvm::DIFile F,
|
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys,
|
|
|
|
llvm::DIType RecordTy);
|
|
|
|
|
2010-01-26 02:32:18 +03:00
|
|
|
void CollectCXXBases(const CXXRecordDecl *Decl,
|
2010-03-09 03:44:50 +03:00
|
|
|
llvm::DIFile F,
|
2010-01-26 02:32:18 +03:00
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys,
|
2010-08-21 02:02:57 +04:00
|
|
|
llvm::DIType RecordTy);
|
2010-01-26 02:32:18 +03:00
|
|
|
|
|
|
|
|
2010-03-09 03:44:50 +03:00
|
|
|
void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F,
|
2010-01-19 03:00:59 +03:00
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &E);
|
2010-01-28 21:11:52 +03:00
|
|
|
|
2010-04-18 00:15:18 +04:00
|
|
|
void CollectVTableInfo(const CXXRecordDecl *Decl,
|
2010-03-09 03:44:50 +03:00
|
|
|
llvm::DIFile F,
|
2010-01-28 21:11:52 +03:00
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys);
|
|
|
|
|
2008-05-08 12:54:20 +04:00
|
|
|
public:
|
2009-12-06 21:00:51 +03:00
|
|
|
CGDebugInfo(CodeGenModule &CGM);
|
2008-05-08 12:54:20 +04:00
|
|
|
~CGDebugInfo();
|
|
|
|
|
2008-10-17 20:15:48 +04:00
|
|
|
/// setLocation - Update the current source location. If \arg loc is
|
|
|
|
/// invalid it is ignored.
|
2008-11-10 09:08:34 +03:00
|
|
|
void setLocation(SourceLocation Loc);
|
2008-05-08 12:54:20 +04:00
|
|
|
|
|
|
|
/// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
|
|
|
|
/// source line.
|
2010-07-21 02:20:10 +04:00
|
|
|
void EmitStopPoint(CGBuilderTy &Builder);
|
2008-05-25 09:15:42 +04:00
|
|
|
|
|
|
|
/// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
|
2008-10-18 22:22:23 +04:00
|
|
|
/// start of a new function.
|
2010-01-14 03:36:21 +03:00
|
|
|
void EmitFunctionStart(GlobalDecl GD, QualType FnType,
|
2008-11-01 04:53:16 +03:00
|
|
|
llvm::Function *Fn, CGBuilderTy &Builder);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-07-23 02:29:16 +04:00
|
|
|
/// EmitFunctionEnd - Constructs the debug code for exiting a function.
|
|
|
|
void EmitFunctionEnd(CGBuilderTy &Builder);
|
|
|
|
|
|
|
|
/// UpdateLineDirectiveRegion - Update region stack only if #line directive
|
|
|
|
/// has introduced scope change.
|
|
|
|
void UpdateLineDirectiveRegion(CGBuilderTy &Builder);
|
|
|
|
|
2008-05-25 09:15:42 +04:00
|
|
|
/// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
|
2009-09-09 19:08:12 +04:00
|
|
|
/// of a new block.
|
2010-07-21 02:20:10 +04:00
|
|
|
void EmitRegionStart(CGBuilderTy &Builder);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
/// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
|
2008-05-08 12:54:20 +04:00
|
|
|
/// block.
|
2010-07-21 02:20:10 +04:00
|
|
|
void EmitRegionEnd(CGBuilderTy &Builder);
|
2008-05-30 14:30:31 +04:00
|
|
|
|
2008-11-10 09:08:34 +03:00
|
|
|
/// EmitDeclareOfAutoVariable - Emit call to llvm.dbg.declare for an automatic
|
|
|
|
/// variable declaration.
|
|
|
|
void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
|
|
|
|
CGBuilderTy &Builder);
|
2008-06-05 12:59:10 +04:00
|
|
|
|
2009-09-30 06:43:10 +04:00
|
|
|
/// EmitDeclareOfBlockDeclRefVariable - Emit call to llvm.dbg.declare for an
|
|
|
|
/// imported variable declaration in a block.
|
|
|
|
void EmitDeclareOfBlockDeclRefVariable(const BlockDeclRefExpr *BDRE,
|
|
|
|
llvm::Value *AI,
|
|
|
|
CGBuilderTy &Builder,
|
|
|
|
CodeGenFunction *CGF);
|
|
|
|
|
2008-11-10 09:08:34 +03:00
|
|
|
/// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
|
|
|
|
/// variable declaration.
|
|
|
|
void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
|
|
|
|
CGBuilderTy &Builder);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-06-05 12:59:10 +04:00
|
|
|
/// EmitGlobalVariable - Emit information about a global variable.
|
2008-11-10 09:08:34 +03:00
|
|
|
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
|
2009-02-27 00:10:26 +03:00
|
|
|
|
|
|
|
/// EmitGlobalVariable - Emit information about an objective-c interface.
|
|
|
|
void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-08-10 21:53:33 +04:00
|
|
|
/// EmitGlobalVariable - Emit global variable's debug info.
|
2010-10-09 05:34:31 +04:00
|
|
|
void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init);
|
2010-08-10 11:24:25 +04:00
|
|
|
|
2010-09-30 23:05:55 +04:00
|
|
|
/// getOrCreateRecordType - Emit record type's standalone debug info.
|
|
|
|
llvm::DIType getOrCreateRecordType(QualType Ty, SourceLocation L);
|
2008-11-03 12:11:11 +03:00
|
|
|
private:
|
2008-11-10 09:08:34 +03:00
|
|
|
/// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
|
|
|
|
void EmitDeclare(const VarDecl *decl, unsigned Tag, llvm::Value *AI,
|
|
|
|
CGBuilderTy &Builder);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-09-30 06:43:10 +04:00
|
|
|
/// EmitDeclare - Emit call to llvm.dbg.declare for a variable declaration.
|
|
|
|
void EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag, llvm::Value *AI,
|
|
|
|
CGBuilderTy &Builder, CodeGenFunction *CGF);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-02-10 21:49:08 +03:00
|
|
|
// EmitTypeForVarWithBlocksAttr - Build up structure info for the byref.
|
|
|
|
// See BuildByRefType.
|
|
|
|
llvm::DIType EmitTypeForVarWithBlocksAttr(const ValueDecl *VD,
|
|
|
|
uint64_t *OffSet);
|
|
|
|
|
2010-01-29 02:15:27 +03:00
|
|
|
/// getContextDescriptor - Get context info for the decl.
|
2010-01-29 21:11:03 +03:00
|
|
|
llvm::DIDescriptor getContextDescriptor(const Decl *Decl,
|
2010-01-29 02:15:27 +03:00
|
|
|
llvm::DIDescriptor &CU);
|
2009-10-06 04:35:31 +04:00
|
|
|
|
2010-07-27 19:17:16 +04:00
|
|
|
/// getCurrentDirname - Return current directory name.
|
|
|
|
llvm::StringRef getCurrentDirname();
|
|
|
|
|
2010-03-09 03:44:50 +03:00
|
|
|
/// CreateCompileUnit - Create new compile unit.
|
|
|
|
void CreateCompileUnit();
|
|
|
|
|
|
|
|
/// getOrCreateFile - Get the file debug info descriptor for the input
|
|
|
|
/// location.
|
|
|
|
llvm::DIFile getOrCreateFile(SourceLocation Loc);
|
2008-05-25 09:15:42 +04:00
|
|
|
|
|
|
|
/// getOrCreateType - Get the type from the cache or create a new type if
|
|
|
|
/// necessary.
|
2010-03-09 03:44:50 +03:00
|
|
|
llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile F);
|
2009-09-19 23:27:14 +04:00
|
|
|
|
|
|
|
/// CreateTypeNode - Create type metadata for a source language type.
|
2010-03-09 03:44:50 +03:00
|
|
|
llvm::DIType CreateTypeNode(QualType Ty, llvm::DIFile F);
|
2010-01-14 03:36:21 +03:00
|
|
|
|
2010-04-25 00:26:20 +04:00
|
|
|
/// CreateMemberType - Create new member and increase Offset by FType's size.
|
2010-04-25 00:19:58 +04:00
|
|
|
llvm::DIType CreateMemberType(llvm::DIFile Unit, QualType FType,
|
|
|
|
llvm::StringRef Name, uint64_t *Offset);
|
|
|
|
|
2010-01-14 03:36:21 +03:00
|
|
|
/// getFunctionName - Get function name for the given FunctionDecl. If the
|
|
|
|
/// name is constructred on demand (e.g. C++ destructor) then the name
|
|
|
|
/// is stored on the side.
|
|
|
|
llvm::StringRef getFunctionName(const FunctionDecl *FD);
|
2010-10-13 03:24:54 +04:00
|
|
|
|
2010-09-02 22:01:51 +04:00
|
|
|
/// getObjCMethodName - Returns the unmangled name of an Objective-C method.
|
|
|
|
/// This is the display name for the debugging info.
|
|
|
|
llvm::StringRef getObjCMethodName(const ObjCMethodDecl *FD);
|
2010-01-28 21:11:52 +03:00
|
|
|
|
2010-07-21 00:24:18 +04:00
|
|
|
/// getClassName - Get class name including template argument list.
|
|
|
|
llvm::StringRef getClassName(RecordDecl *RD);
|
|
|
|
|
2010-04-18 00:15:18 +04:00
|
|
|
/// getVTableName - Get vtable name for the given Class.
|
|
|
|
llvm::StringRef getVTableName(const CXXRecordDecl *Decl);
|
2010-01-28 21:11:52 +03:00
|
|
|
|
2010-05-13 03:46:38 +04:00
|
|
|
/// getLineNumber - Get line number for the location. If location is invalid
|
|
|
|
/// then use current location.
|
|
|
|
unsigned getLineNumber(SourceLocation Loc);
|
|
|
|
|
|
|
|
/// getColumnNumber - Get column number for the location. If location is
|
|
|
|
/// invalid then use current location.
|
|
|
|
unsigned getColumnNumber(SourceLocation Loc);
|
2008-05-08 12:54:20 +04:00
|
|
|
};
|
|
|
|
} // namespace CodeGen
|
|
|
|
} // namespace clang
|
|
|
|
|
2009-10-06 22:36:08 +04:00
|
|
|
|
2008-05-08 12:54:20 +04:00
|
|
|
#endif
|