2008-10-31 11:54:29 +08:00
|
|
|
//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
|
2008-05-08 16:54:20 +08: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 23:08:12 +08:00
|
|
|
// This is the source level debug info generator for llvm translation.
|
2008-05-08 16:54:20 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef CLANG_CODEGEN_CGDEBUGINFO_H
|
|
|
|
#define CLANG_CODEGEN_CGDEBUGINFO_H
|
|
|
|
|
2008-05-25 13:15:42 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2009-09-30 10:43:10 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2008-05-08 16:54:20 +08:00
|
|
|
#include "clang/Basic/SourceLocation.h"
|
2008-11-10 14:08:34 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/Analysis/DebugInfo.h"
|
2009-09-20 03:27:24 +08:00
|
|
|
#include "llvm/Support/ValueHandle.h"
|
2010-01-14 08:36:21 +08:00
|
|
|
#include "llvm/Support/Allocator.h"
|
2008-05-08 16:54:20 +08:00
|
|
|
|
2008-11-01 09:53:16 +08:00
|
|
|
#include "CGBuilder.h"
|
2008-05-08 16:54:20 +08:00
|
|
|
|
2009-09-20 03:27:24 +08:00
|
|
|
namespace llvm {
|
|
|
|
class MDNode;
|
|
|
|
}
|
|
|
|
|
2008-05-08 16:54:20 +08:00
|
|
|
namespace clang {
|
2008-05-30 18:30:31 +08:00
|
|
|
class VarDecl;
|
2009-02-27 05:10:26 +08:00
|
|
|
class ObjCInterfaceDecl;
|
2008-11-01 09:53:16 +08:00
|
|
|
|
2008-05-08 16:54:20 +08:00
|
|
|
namespace CodeGen {
|
|
|
|
class CodeGenModule;
|
2009-09-30 10:43:10 +08:00
|
|
|
class CodeGenFunction;
|
2010-01-14 08:36:21 +08:00
|
|
|
class GlobalDecl;
|
2008-05-08 16:54:20 +08:00
|
|
|
|
2009-09-09 23:08:12 +08: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 13:15:42 +08:00
|
|
|
/// the backend.
|
2008-05-08 16:54:20 +08:00
|
|
|
class CGDebugInfo {
|
2009-12-07 02:00:51 +08:00
|
|
|
CodeGenModule &CGM;
|
2008-11-10 14:08:34 +08:00
|
|
|
llvm::DIFactory DebugFactory;
|
2010-03-09 08:44:50 +08:00
|
|
|
llvm::DICompileUnit TheCU;
|
2008-11-10 14:08:34 +08:00
|
|
|
SourceLocation CurLoc, PrevLoc;
|
2010-01-29 02:11:52 +08:00
|
|
|
llvm::DIType VTablePtrType;
|
2010-03-09 08:44:50 +08:00
|
|
|
|
2008-05-25 13:15:42 +08:00
|
|
|
/// TypeCache - Cache of previously constructed Types.
|
2010-03-30 02:29:57 +08:00
|
|
|
llvm::DenseMap<void *, llvm::WeakVH> TypeCache;
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-05-14 10:03:51 +08:00
|
|
|
bool BlockLiteralGenericSet;
|
|
|
|
llvm::DIType BlockLiteralGeneric;
|
|
|
|
|
2009-11-14 03:10:24 +08:00
|
|
|
std::vector<llvm::TrackingVH<llvm::MDNode> > RegionStack;
|
2010-01-30 02:11:03 +08:00
|
|
|
llvm::DenseMap<const Decl *, llvm::WeakVH> RegionMap;
|
2010-07-23 06:29:16 +08: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 09:40:10 +08:00
|
|
|
|
2010-01-29 02:21:00 +08:00
|
|
|
/// DebugInfoNames - This is a storage for names that are
|
2010-01-14 08:36:21 +08:00
|
|
|
/// constructed on demand. For example, C++ destructors, C++ operators etc..
|
2010-01-29 02:21:00 +08:00
|
|
|
llvm::BumpPtrAllocator DebugInfoNames;
|
2010-07-27 23:17:16 +08:00
|
|
|
llvm::StringRef CWDName;
|
2010-01-14 08:36:21 +08:00
|
|
|
|
2010-03-30 08:27:51 +08:00
|
|
|
llvm::DenseMap<const char *, llvm::WeakVH> DIFileCache;
|
2010-01-19 09:54:44 +08:00
|
|
|
llvm::DenseMap<const FunctionDecl *, llvm::WeakVH> SPCache;
|
2010-02-02 03:16:32 +08:00
|
|
|
llvm::DenseMap<const NamespaceDecl *, llvm::WeakVH> NameSpaceCache;
|
2010-01-19 09:54:44 +08:00
|
|
|
|
2008-05-25 13:15:42 +08:00
|
|
|
/// Helper functions for getOrCreateType.
|
2010-03-09 08:44:50 +08: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 23:08:12 +08:00
|
|
|
llvm::DIType CreateType(const ObjCObjectPointerType *Ty,
|
2010-03-09 08:44:50 +08: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 19:32:37 +08:00
|
|
|
llvm::DIType CreateType(const ObjCObjectType *Ty, llvm::DIFile F);
|
2010-03-09 08:44:50 +08: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 06:07:25 +08:00
|
|
|
llvm::DIType CreateEnumType(const EnumDecl *ED, llvm::DIFile Unit);
|
2010-01-28 08:28:01 +08:00
|
|
|
llvm::DIType getOrCreateMethodType(const CXXMethodDecl *Method,
|
2010-03-09 08:44:50 +08:00
|
|
|
llvm::DIFile F);
|
|
|
|
llvm::DIType getOrCreateVTablePtrType(llvm::DIFile F);
|
2010-02-02 03:16:32 +08:00
|
|
|
llvm::DINameSpace getOrCreateNameSpace(const NamespaceDecl *N,
|
|
|
|
llvm::DIDescriptor Unit);
|
2010-10-01 03:05:55 +08:00
|
|
|
llvm::DIType CreatePointeeType(QualType PointeeTy, llvm::DIFile F);
|
2009-11-07 03:19:55 +08:00
|
|
|
llvm::DIType CreatePointerLikeType(unsigned Tag,
|
|
|
|
const Type *Ty, QualType PointeeTy,
|
2010-03-09 08:44:50 +08:00
|
|
|
llvm::DIFile F);
|
2010-01-26 12:49:33 +08:00
|
|
|
|
2010-01-26 13:19:50 +08:00
|
|
|
llvm::DISubprogram CreateCXXMemberFunction(const CXXMethodDecl *Method,
|
2010-03-09 08:44:50 +08:00
|
|
|
llvm::DIFile F,
|
2010-08-21 06:02:57 +08:00
|
|
|
llvm::DIType RecordTy);
|
2010-01-26 12:49:33 +08:00
|
|
|
|
2010-01-19 09:54:44 +08:00
|
|
|
void CollectCXXMemberFunctions(const CXXRecordDecl *Decl,
|
2010-03-09 08:44:50 +08:00
|
|
|
llvm::DIFile F,
|
2010-01-19 09:54:44 +08:00
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &E,
|
2010-08-21 06:02:57 +08:00
|
|
|
llvm::DIType T);
|
2010-08-28 01:47:47 +08:00
|
|
|
|
|
|
|
void CollectCXXFriends(const CXXRecordDecl *Decl,
|
|
|
|
llvm::DIFile F,
|
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys,
|
|
|
|
llvm::DIType RecordTy);
|
|
|
|
|
2010-01-26 07:32:18 +08:00
|
|
|
void CollectCXXBases(const CXXRecordDecl *Decl,
|
2010-03-09 08:44:50 +08:00
|
|
|
llvm::DIFile F,
|
2010-01-26 07:32:18 +08:00
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys,
|
2010-08-21 06:02:57 +08:00
|
|
|
llvm::DIType RecordTy);
|
2010-01-26 07:32:18 +08:00
|
|
|
|
|
|
|
|
2010-03-09 08:44:50 +08:00
|
|
|
void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F,
|
2010-01-19 08:00:59 +08:00
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &E);
|
2010-01-29 02:11:52 +08:00
|
|
|
|
2010-04-18 04:15:18 +08:00
|
|
|
void CollectVTableInfo(const CXXRecordDecl *Decl,
|
2010-03-09 08:44:50 +08:00
|
|
|
llvm::DIFile F,
|
2010-01-29 02:11:52 +08:00
|
|
|
llvm::SmallVectorImpl<llvm::DIDescriptor> &EltTys);
|
|
|
|
|
2008-05-08 16:54:20 +08:00
|
|
|
public:
|
2009-12-07 02:00:51 +08:00
|
|
|
CGDebugInfo(CodeGenModule &CGM);
|
2008-05-08 16:54:20 +08:00
|
|
|
~CGDebugInfo();
|
|
|
|
|
2008-10-18 00:15:48 +08:00
|
|
|
/// setLocation - Update the current source location. If \arg loc is
|
|
|
|
/// invalid it is ignored.
|
2008-11-10 14:08:34 +08:00
|
|
|
void setLocation(SourceLocation Loc);
|
2008-05-08 16:54:20 +08:00
|
|
|
|
|
|
|
/// EmitStopPoint - Emit a call to llvm.dbg.stoppoint to indicate a change of
|
|
|
|
/// source line.
|
2010-07-21 06:20:10 +08:00
|
|
|
void EmitStopPoint(CGBuilderTy &Builder);
|
2008-05-25 13:15:42 +08:00
|
|
|
|
|
|
|
/// EmitFunctionStart - Emit a call to llvm.dbg.function.start to indicate
|
2008-10-19 02:22:23 +08:00
|
|
|
/// start of a new function.
|
2010-01-14 08:36:21 +08:00
|
|
|
void EmitFunctionStart(GlobalDecl GD, QualType FnType,
|
2008-11-01 09:53:16 +08:00
|
|
|
llvm::Function *Fn, CGBuilderTy &Builder);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-07-23 06:29:16 +08: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 13:15:42 +08:00
|
|
|
/// EmitRegionStart - Emit a call to llvm.dbg.region.start to indicate start
|
2009-09-09 23:08:12 +08:00
|
|
|
/// of a new block.
|
2010-07-21 06:20:10 +08:00
|
|
|
void EmitRegionStart(CGBuilderTy &Builder);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
|
|
|
/// EmitRegionEnd - Emit call to llvm.dbg.region.end to indicate end of a
|
2008-05-08 16:54:20 +08:00
|
|
|
/// block.
|
2010-07-21 06:20:10 +08:00
|
|
|
void EmitRegionEnd(CGBuilderTy &Builder);
|
2008-05-30 18:30:31 +08:00
|
|
|
|
2008-11-10 14:08:34 +08: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 16:59:10 +08:00
|
|
|
|
2009-09-30 10:43:10 +08: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 14:08:34 +08: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 23:08:12 +08:00
|
|
|
|
2008-06-05 16:59:10 +08:00
|
|
|
/// EmitGlobalVariable - Emit information about a global variable.
|
2008-11-10 14:08:34 +08:00
|
|
|
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
|
2009-02-27 05:10:26 +08:00
|
|
|
|
|
|
|
/// EmitGlobalVariable - Emit information about an objective-c interface.
|
|
|
|
void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl);
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2010-08-11 01:53:33 +08:00
|
|
|
/// EmitGlobalVariable - Emit global variable's debug info.
|
2010-10-09 09:34:31 +08:00
|
|
|
void EmitGlobalVariable(const ValueDecl *VD, llvm::Constant *Init);
|
2010-08-10 15:24:25 +08:00
|
|
|
|
2010-10-01 03:05:55 +08:00
|
|
|
/// getOrCreateRecordType - Emit record type's standalone debug info.
|
|
|
|
llvm::DIType getOrCreateRecordType(QualType Ty, SourceLocation L);
|
2008-11-03 17:11:11 +08:00
|
|
|
private:
|
2008-11-10 14:08:34 +08: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 23:08:12 +08:00
|
|
|
|
2009-09-30 10:43:10 +08: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 23:08:12 +08:00
|
|
|
|
2010-02-11 02:49:08 +08:00
|
|
|
// EmitTypeForVarWithBlocksAttr - Build up structure info for the byref.
|
|
|
|
// See BuildByRefType.
|
|
|
|
llvm::DIType EmitTypeForVarWithBlocksAttr(const ValueDecl *VD,
|
|
|
|
uint64_t *OffSet);
|
|
|
|
|
2010-01-29 07:15:27 +08:00
|
|
|
/// getContextDescriptor - Get context info for the decl.
|
2010-01-30 02:11:03 +08:00
|
|
|
llvm::DIDescriptor getContextDescriptor(const Decl *Decl,
|
2010-01-29 07:15:27 +08:00
|
|
|
llvm::DIDescriptor &CU);
|
2009-10-06 08:35:31 +08:00
|
|
|
|
2010-07-27 23:17:16 +08:00
|
|
|
/// getCurrentDirname - Return current directory name.
|
|
|
|
llvm::StringRef getCurrentDirname();
|
|
|
|
|
2010-03-09 08:44:50 +08: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 13:15:42 +08:00
|
|
|
|
|
|
|
/// getOrCreateType - Get the type from the cache or create a new type if
|
|
|
|
/// necessary.
|
2010-03-09 08:44:50 +08:00
|
|
|
llvm::DIType getOrCreateType(QualType Ty, llvm::DIFile F);
|
2009-09-20 03:27:14 +08:00
|
|
|
|
|
|
|
/// CreateTypeNode - Create type metadata for a source language type.
|
2010-03-09 08:44:50 +08:00
|
|
|
llvm::DIType CreateTypeNode(QualType Ty, llvm::DIFile F);
|
2010-01-14 08:36:21 +08:00
|
|
|
|
2010-04-25 04:26:20 +08:00
|
|
|
/// CreateMemberType - Create new member and increase Offset by FType's size.
|
2010-04-25 04:19:58 +08:00
|
|
|
llvm::DIType CreateMemberType(llvm::DIFile Unit, QualType FType,
|
|
|
|
llvm::StringRef Name, uint64_t *Offset);
|
|
|
|
|
2010-01-14 08:36:21 +08: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-09-03 02:01:51 +08: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-29 02:11:52 +08:00
|
|
|
|
2010-07-21 04:24:18 +08:00
|
|
|
/// getClassName - Get class name including template argument list.
|
|
|
|
llvm::StringRef getClassName(RecordDecl *RD);
|
|
|
|
|
2010-04-18 04:15:18 +08:00
|
|
|
/// getVTableName - Get vtable name for the given Class.
|
|
|
|
llvm::StringRef getVTableName(const CXXRecordDecl *Decl);
|
2010-01-29 02:11:52 +08:00
|
|
|
|
2010-05-13 07:46:38 +08: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 16:54:20 +08:00
|
|
|
};
|
|
|
|
} // namespace CodeGen
|
|
|
|
} // namespace clang
|
|
|
|
|
2009-10-07 02:36:08 +08:00
|
|
|
|
2008-05-08 16:54:20 +08:00
|
|
|
#endif
|