2012-12-18 22:30:41 +08:00
|
|
|
//===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2014-07-09 22:06:35 +08:00
|
|
|
// This is the source-level debug info generator for llvm translation.
|
2012-12-18 22:30:41 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:25:19 +08:00
|
|
|
#ifndef LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
|
|
|
|
#define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
#include "CGBuilder.h"
|
2016-10-26 06:19:32 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2016-01-23 05:14:41 +08:00
|
|
|
#include "clang/AST/ExternalASTSource.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "clang/AST/Type.h"
|
|
|
|
#include "clang/Basic/SourceLocation.h"
|
2016-04-09 00:52:00 +08:00
|
|
|
#include "clang/Frontend/CodeGenOptions.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2016-10-26 06:19:32 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2015-08-01 01:56:14 +08:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2014-03-06 08:22:29 +08:00
|
|
|
#include "llvm/IR/DIBuilder.h"
|
2014-03-06 08:46:56 +08:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
2014-03-04 19:18:19 +08:00
|
|
|
#include "llvm/IR/ValueHandle.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "llvm/Support/Allocator.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
2015-07-09 04:53:55 +08:00
|
|
|
class MDNode;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace clang {
|
2015-07-09 04:53:55 +08:00
|
|
|
class ClassTemplateSpecializationDecl;
|
|
|
|
class GlobalDecl;
|
2015-09-21 00:51:35 +08:00
|
|
|
class ModuleMap;
|
|
|
|
class ObjCInterfaceDecl;
|
|
|
|
class ObjCIvarDecl;
|
2015-07-09 04:53:55 +08:00
|
|
|
class UsingDecl;
|
2015-09-21 00:51:35 +08:00
|
|
|
class VarDecl;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
namespace CodeGen {
|
2015-07-09 04:53:55 +08:00
|
|
|
class CodeGenModule;
|
|
|
|
class CodeGenFunction;
|
|
|
|
class CGBlockInfo;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// This class gathers all debug information during compilation and is
|
|
|
|
/// responsible for emitting to llvm globals or pass directly to the
|
|
|
|
/// backend.
|
2012-12-18 22:30:41 +08:00
|
|
|
class CGDebugInfo {
|
2015-02-04 02:40:42 +08:00
|
|
|
friend class ApplyDebugLocation;
|
2014-01-17 08:15:10 +08:00
|
|
|
friend class SaveAndRestoreLocation;
|
2012-12-18 22:30:41 +08:00
|
|
|
CodeGenModule &CGM;
|
2016-02-02 19:06:51 +08:00
|
|
|
const codegenoptions::DebugInfoKind DebugKind;
|
2015-08-28 03:46:20 +08:00
|
|
|
bool DebugTypeExtRefs;
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::DIBuilder DBuilder;
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DICompileUnit *TheCU = nullptr;
|
2015-09-21 00:51:35 +08:00
|
|
|
ModuleMap *ClangModuleMap = nullptr;
|
2016-01-23 05:14:41 +08:00
|
|
|
ExternalASTSource::ASTSourceDescriptor PCHDescriptor;
|
2015-01-14 15:38:27 +08:00
|
|
|
SourceLocation CurLoc;
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *VTablePtrType = nullptr;
|
|
|
|
llvm::DIType *ClassTy = nullptr;
|
|
|
|
llvm::DICompositeType *ObjTy = nullptr;
|
|
|
|
llvm::DIType *SelTy = nullptr;
|
2016-04-08 21:40:33 +08:00
|
|
|
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
|
|
|
|
llvm::DIType *SingletonId = nullptr;
|
2016-04-13 16:33:41 +08:00
|
|
|
#include "clang/Basic/OpenCLImageTypes.def"
|
2016-07-29 03:26:30 +08:00
|
|
|
llvm::DIType *OCLSamplerDITy = nullptr;
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *OCLEventDITy = nullptr;
|
2015-09-15 19:18:52 +08:00
|
|
|
llvm::DIType *OCLClkEventDITy = nullptr;
|
|
|
|
llvm::DIType *OCLQueueDITy = nullptr;
|
|
|
|
llvm::DIType *OCLNDRangeDITy = nullptr;
|
|
|
|
llvm::DIType *OCLReserveIDDITy = nullptr;
|
2013-05-16 08:52:23 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Cache of previously constructed Types.
|
2014-12-10 02:39:32 +08:00
|
|
|
llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-10-13 04:21:08 +08:00
|
|
|
llvm::SmallDenseMap<llvm::StringRef, llvm::StringRef> DebugPrefixMap;
|
|
|
|
|
2014-05-06 07:23:53 +08:00
|
|
|
struct ObjCInterfaceCacheEntry {
|
|
|
|
const ObjCInterfaceType *Type;
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *Decl;
|
|
|
|
llvm::DIFile *Unit;
|
|
|
|
ObjCInterfaceCacheEntry(const ObjCInterfaceType *Type, llvm::DIType *Decl,
|
|
|
|
llvm::DIFile *Unit)
|
2014-05-06 07:23:53 +08:00
|
|
|
: Type(Type), Decl(Decl), Unit(Unit) {}
|
|
|
|
};
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Cache of previously constructed interfaces which may change.
|
2014-05-06 07:23:53 +08:00
|
|
|
llvm::SmallVector<ObjCInterfaceCacheEntry, 32> ObjCInterfaceCache;
|
2013-03-07 06:03:30 +08:00
|
|
|
|
2015-09-19 05:06:14 +08:00
|
|
|
/// Cache of references to clang modules and precompiled headers.
|
2015-09-25 00:10:04 +08:00
|
|
|
llvm::DenseMap<const Module *, llvm::TrackingMDRef> ModuleCache;
|
2015-07-01 01:39:51 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// List of interfaces we want to keep even if orphaned.
|
2013-03-12 02:33:46 +08:00
|
|
|
std::vector<void *> RetainedTypes;
|
|
|
|
|
2016-09-30 14:39:48 +08:00
|
|
|
/// Cache of forward declared types to RAUW at the end of compilation.
|
2014-12-10 02:39:32 +08:00
|
|
|
std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-02-07 14:39:23 +08:00
|
|
|
/// Cache of replaceable forward declarations (functions and
|
2014-11-18 11:40:51 +08:00
|
|
|
/// variables) to RAUW at the end of compilation.
|
2014-12-10 02:39:32 +08:00
|
|
|
std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>>
|
|
|
|
FwdDeclReplaceMap;
|
2014-11-18 11:40:51 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Keep track of our current nested lexical block.
|
2015-04-30 00:40:08 +08:00
|
|
|
std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
|
2014-12-10 02:39:32 +08:00
|
|
|
llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Keep track of LexicalBlockStack counter at the beginning of a
|
|
|
|
/// function. This is used to pop unbalanced regions at the end of a
|
|
|
|
/// function.
|
2012-12-18 22:30:41 +08:00
|
|
|
std::vector<unsigned> FnBeginRegionCount;
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// This is a storage for names that are constructed on demand. For
|
|
|
|
/// example, C++ destructors, C++ operators etc..
|
2012-12-18 22:30:41 +08:00
|
|
|
llvm::BumpPtrAllocator DebugInfoNames;
|
|
|
|
StringRef CWDName;
|
|
|
|
|
2014-12-10 02:39:32 +08:00
|
|
|
llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
|
|
|
|
llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Cache declarations relevant to DW_TAG_imported_declarations (C++
|
2013-05-20 12:58:53 +08:00
|
|
|
/// using declarations) that aren't covered by other more specific caches.
|
2014-12-10 02:39:32 +08:00
|
|
|
llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
|
|
|
|
llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NameSpaceCache;
|
|
|
|
llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
|
|
|
|
NamespaceAliasCache;
|
2015-07-25 02:05:58 +08:00
|
|
|
llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
|
|
|
|
StaticDataMemberCache;
|
2015-10-16 00:46:25 +08:00
|
|
|
|
|
|
|
/// Helper functions for getOrCreateType.
|
|
|
|
/// @{
|
|
|
|
/// Currently the checksum of an interface includes the number of
|
|
|
|
/// ivars and property accessors.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CreateType(const BuiltinType *Ty);
|
|
|
|
llvm::DIType *CreateType(const ComplexType *Ty);
|
|
|
|
llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
|
|
|
|
llvm::DIType *CreateType(const TypedefType *Ty, llvm::DIFile *Fg);
|
|
|
|
llvm::DIType *CreateType(const TemplateSpecializationType *Ty,
|
|
|
|
llvm::DIFile *Fg);
|
|
|
|
llvm::DIType *CreateType(const ObjCObjectPointerType *Ty, 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);
|
2015-07-09 05:18:34 +08:00
|
|
|
/// Get structure or union type.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CreateType(const RecordType *Tyg);
|
|
|
|
llvm::DIType *CreateTypeDefinition(const RecordType *Ty);
|
|
|
|
llvm::DICompositeType *CreateLimitedType(const RecordType *Ty);
|
2015-04-17 00:36:45 +08:00
|
|
|
void CollectContainingType(const CXXRecordDecl *RD,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DICompositeType *CT);
|
2015-07-09 05:18:34 +08:00
|
|
|
/// Get Objective-C interface type.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CreateType(const ObjCInterfaceType *Ty, llvm::DIFile *F);
|
|
|
|
llvm::DIType *CreateTypeDefinition(const ObjCInterfaceType *Ty,
|
|
|
|
llvm::DIFile *F);
|
2015-07-09 05:18:34 +08:00
|
|
|
/// Get Objective-C object type.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CreateType(const ObjCObjectType *Ty, llvm::DIFile *F);
|
2016-09-14 01:25:08 +08:00
|
|
|
llvm::DIType *CreateType(const ObjCTypeParamType *Ty, llvm::DIFile *Unit);
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
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 RValueReferenceType *Ty, llvm::DIFile *Unit);
|
|
|
|
llvm::DIType *CreateType(const MemberPointerType *Ty, llvm::DIFile *F);
|
|
|
|
llvm::DIType *CreateType(const AtomicType *Ty, llvm::DIFile *F);
|
2016-01-09 20:53:17 +08:00
|
|
|
llvm::DIType *CreateType(const PipeType *Ty, llvm::DIFile *F);
|
2015-07-09 05:18:34 +08:00
|
|
|
/// Get enumeration type.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CreateEnumType(const EnumType *Ty);
|
|
|
|
llvm::DIType *CreateTypeDefinition(const EnumType *Ty);
|
2015-07-09 05:18:34 +08:00
|
|
|
/// Look up the completed type for a self pointer in the TypeCache and
|
|
|
|
/// create a copy of it with the ObjectPointer and Artificial flags
|
|
|
|
/// set. If the type is not cached, a new one is created. This should
|
|
|
|
/// never happen though, since creating a type for the implicit self
|
|
|
|
/// argument implies that we already parsed the interface definition
|
|
|
|
/// and the ivar declarations in the implementation.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CreateSelfType(const QualType &QualTy, llvm::DIType *Ty);
|
2015-07-09 05:18:34 +08:00
|
|
|
/// @}
|
|
|
|
|
|
|
|
/// Get the type from the cache or return null type if it doesn't
|
|
|
|
/// exist.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *getTypeOrNull(const QualType);
|
2015-07-09 05:18:34 +08:00
|
|
|
/// Return the debug type for a C++ method.
|
|
|
|
/// \arg CXXMethodDecl is of FunctionType. This function type is
|
|
|
|
/// not updated to include implicit \c this pointer. Use this routine
|
|
|
|
/// to get a method type which includes \c this pointer.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DISubroutineType *getOrCreateMethodType(const CXXMethodDecl *Method,
|
|
|
|
llvm::DIFile *F);
|
|
|
|
llvm::DISubroutineType *
|
2015-04-17 00:36:45 +08:00
|
|
|
getOrCreateInstanceMethodType(QualType ThisPtr, const FunctionProtoType *Func,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *Unit);
|
|
|
|
llvm::DISubroutineType *
|
|
|
|
getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F);
|
2015-07-09 05:18:34 +08:00
|
|
|
/// \return debug info descriptor for vtable.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
|
2015-07-09 05:18:34 +08:00
|
|
|
/// \return namespace descriptor for the given namespace decl.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINamespace *getOrCreateNameSpace(const NamespaceDecl *N);
|
|
|
|
llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag, const Type *Ty,
|
|
|
|
QualType PointeeTy, llvm::DIFile *F);
|
|
|
|
llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&Cache);
|
2012-12-18 22:38:23 +08:00
|
|
|
|
2015-07-09 05:18:34 +08:00
|
|
|
/// A helper function to create a subprogram for a single member
|
|
|
|
/// function GlobalDecl.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DISubprogram *CreateCXXMemberFunction(const CXXMethodDecl *Method,
|
|
|
|
llvm::DIFile *F,
|
|
|
|
llvm::DIType *RecordTy);
|
2013-05-16 08:52:23 +08:00
|
|
|
|
2015-07-09 05:18:34 +08:00
|
|
|
/// A helper function to collect debug info for C++ member
|
|
|
|
/// functions. This is used while creating debug info entry for a
|
|
|
|
/// Record.
|
2015-04-30 00:40:08 +08:00
|
|
|
void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, llvm::DIFile *F,
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVectorImpl<llvm::Metadata *> &E,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *T);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 05:18:34 +08:00
|
|
|
/// A helper function to collect debug info for C++ base
|
|
|
|
/// classes. This is used while creating debug info entry for a
|
|
|
|
/// Record.
|
2015-04-30 00:40:08 +08:00
|
|
|
void CollectCXXBases(const CXXRecordDecl *Decl, llvm::DIFile *F,
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVectorImpl<llvm::Metadata *> &EltTys,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *RecordTy);
|
|
|
|
|
2016-10-26 06:19:32 +08:00
|
|
|
/// Helper function for CollectCXXBases.
|
|
|
|
/// Adds debug info entries for types in Bases that are not in SeenTypes.
|
|
|
|
void CollectCXXBasesAux(const CXXRecordDecl *RD, llvm::DIFile *Unit,
|
|
|
|
SmallVectorImpl<llvm::Metadata *> &EltTys,
|
|
|
|
llvm::DIType *RecordTy,
|
|
|
|
const CXXRecordDecl::base_class_const_range &Bases,
|
|
|
|
llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> &SeenTypes,
|
|
|
|
llvm::DINode::DIFlags StartingFlags);
|
|
|
|
|
2015-07-09 05:18:34 +08:00
|
|
|
/// A helper function to collect template parameters.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray CollectTemplateParams(const TemplateParameterList *TPList,
|
|
|
|
ArrayRef<TemplateArgument> TAList,
|
|
|
|
llvm::DIFile *Unit);
|
2015-07-09 05:18:34 +08:00
|
|
|
/// A helper function to collect debug info for function template
|
|
|
|
/// parameters.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray CollectFunctionTemplateParams(const FunctionDecl *FD,
|
|
|
|
llvm::DIFile *Unit);
|
2015-07-09 05:18:34 +08:00
|
|
|
|
|
|
|
/// A helper function to collect debug info for template
|
|
|
|
/// parameters.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINodeArray
|
2012-12-18 22:30:41 +08:00
|
|
|
CollectCXXTemplateParams(const ClassTemplateSpecializationDecl *TS,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *F);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-10-20 08:13:19 +08:00
|
|
|
llvm::DIType *createFieldType(StringRef name, QualType type,
|
|
|
|
SourceLocation loc, AccessSpecifier AS,
|
|
|
|
uint64_t offsetInBits,
|
|
|
|
uint32_t AlignInBits,
|
|
|
|
llvm::DIFile *tunit, llvm::DIScope *scope,
|
|
|
|
const RecordDecl *RD = nullptr);
|
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *createFieldType(StringRef name, QualType type,
|
2016-06-30 11:01:59 +08:00
|
|
|
SourceLocation loc, AccessSpecifier AS,
|
|
|
|
uint64_t offsetInBits, llvm::DIFile *tunit,
|
|
|
|
llvm::DIScope *scope,
|
2016-10-20 08:13:19 +08:00
|
|
|
const RecordDecl *RD = nullptr) {
|
|
|
|
return createFieldType(name, type, loc, AS, offsetInBits, 0, tunit, scope,
|
|
|
|
RD);
|
|
|
|
}
|
2013-01-16 09:22:32 +08:00
|
|
|
|
2016-06-30 11:01:59 +08:00
|
|
|
/// Create new bit field member.
|
|
|
|
llvm::DIType *createBitFieldType(const FieldDecl *BitFieldDecl,
|
|
|
|
llvm::DIScope *RecordTy,
|
|
|
|
const RecordDecl *RD);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Helpers for collecting fields of a record.
|
|
|
|
/// @{
|
2013-01-16 09:22:32 +08:00
|
|
|
void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl,
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVectorImpl<llvm::Metadata *> &E,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *RecordTy);
|
|
|
|
llvm::DIDerivedType *CreateRecordStaticField(const VarDecl *Var,
|
|
|
|
llvm::DIType *RecordTy,
|
2015-04-21 05:17:26 +08:00
|
|
|
const RecordDecl *RD);
|
2013-01-16 09:22:32 +08:00
|
|
|
void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *F,
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVectorImpl<llvm::Metadata *> &E,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *RecordTy, const RecordDecl *RD);
|
2016-07-22 02:43:20 +08:00
|
|
|
void CollectRecordNestedRecord(const RecordDecl *RD,
|
|
|
|
SmallVectorImpl<llvm::Metadata *> &E);
|
2015-04-30 00:40:08 +08:00
|
|
|
void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
|
2014-12-10 02:39:32 +08:00
|
|
|
SmallVectorImpl<llvm::Metadata *> &E,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DICompositeType *RecordTy);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 05:18:34 +08:00
|
|
|
/// If the C++ class has vtable info then insert appropriate debug
|
|
|
|
/// info entry in EltTys vector.
|
2015-04-30 00:40:08 +08:00
|
|
|
void CollectVTableInfo(const CXXRecordDecl *Decl, llvm::DIFile *F,
|
2016-09-01 00:11:43 +08:00
|
|
|
SmallVectorImpl<llvm::Metadata *> &EltTys,
|
|
|
|
llvm::DICompositeType *RecordTy);
|
2015-07-09 04:53:55 +08:00
|
|
|
/// @}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Create a new lexical block node and push it on the stack.
|
2012-12-18 22:30:41 +08:00
|
|
|
void CreateLexicalBlock(SourceLocation Loc);
|
2013-05-16 08:52:23 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
public:
|
|
|
|
CGDebugInfo(CodeGenModule &CGM);
|
|
|
|
~CGDebugInfo();
|
|
|
|
|
|
|
|
void finalize();
|
|
|
|
|
2016-01-23 05:14:41 +08:00
|
|
|
/// Module debugging: Support for building PCMs.
|
|
|
|
/// @{
|
2015-09-23 07:26:43 +08:00
|
|
|
/// Set the main CU's DwoId field to \p Signature.
|
|
|
|
void setDwoId(uint64_t Signature);
|
|
|
|
|
2015-09-21 00:51:35 +08:00
|
|
|
/// When generating debug information for a clang module or
|
|
|
|
/// precompiled header, this module map will be used to determine
|
|
|
|
/// the module of origin of each Decl.
|
|
|
|
void setModuleMap(ModuleMap &MMap) { ClangModuleMap = &MMap; }
|
|
|
|
|
2016-01-23 05:14:41 +08:00
|
|
|
/// When generating debug information for a clang module or
|
|
|
|
/// precompiled header, this module map will be used to determine
|
|
|
|
/// the module of origin of each Decl.
|
|
|
|
void setPCHDescriptor(ExternalASTSource::ASTSourceDescriptor PCH) {
|
|
|
|
PCHDescriptor = PCH;
|
|
|
|
}
|
|
|
|
/// @}
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Update the current source location. If \arg loc is invalid it is
|
|
|
|
/// ignored.
|
2012-12-18 22:30:41 +08:00
|
|
|
void setLocation(SourceLocation Loc);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit metadata to indicate a change in line/column information in
|
2015-07-09 05:18:34 +08:00
|
|
|
/// the source file. If the location is invalid, the previous
|
|
|
|
/// location will be reused.
|
2015-01-22 07:08:17 +08:00
|
|
|
void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit a call to llvm.dbg.function.start to indicate
|
2012-12-18 22:30:41 +08:00
|
|
|
/// start of a new function.
|
2014-04-11 07:21:53 +08:00
|
|
|
/// \param Loc The location of the function header.
|
|
|
|
/// \param ScopeLoc The location of the function body.
|
2015-07-09 04:53:55 +08:00
|
|
|
void EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
|
|
|
|
SourceLocation ScopeLoc, QualType FnType,
|
|
|
|
llvm::Function *Fn, CGBuilderTy &Builder);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-09-09 04:41:52 +08:00
|
|
|
/// Emit debug info for a function declaration.
|
|
|
|
void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Constructs the debug code for exiting a function.
|
2012-12-18 22:30:41 +08:00
|
|
|
void EmitFunctionEnd(CGBuilderTy &Builder);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit metadata to indicate the beginning of a new lexical block
|
|
|
|
/// and push the block onto the stack.
|
2012-12-18 22:30:41 +08:00
|
|
|
void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit metadata to indicate the end of a new lexical block and pop
|
|
|
|
/// the current block.
|
2012-12-18 22:30:41 +08:00
|
|
|
void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit call to \c llvm.dbg.declare for an automatic variable
|
|
|
|
/// declaration.
|
2012-12-18 22:30:41 +08:00
|
|
|
void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
|
|
|
|
CGBuilderTy &Builder);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit call to \c llvm.dbg.declare for an imported variable
|
|
|
|
/// declaration in a block.
|
2012-12-18 22:30:41 +08:00
|
|
|
void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable,
|
|
|
|
llvm::Value *storage,
|
|
|
|
CGBuilderTy &Builder,
|
2014-11-21 08:35:25 +08:00
|
|
|
const CGBlockInfo &blockInfo,
|
2015-09-30 04:56:43 +08:00
|
|
|
llvm::Instruction *InsertPoint = nullptr);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit call to \c llvm.dbg.declare for an argument variable
|
|
|
|
/// declaration.
|
2012-12-18 22:30:41 +08:00
|
|
|
void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
|
|
|
|
unsigned ArgNo, CGBuilderTy &Builder);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit call to \c llvm.dbg.declare for the block-literal argument
|
|
|
|
/// to a block invocation function.
|
2012-12-18 22:30:41 +08:00
|
|
|
void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
|
2014-08-09 01:10:14 +08:00
|
|
|
llvm::Value *Arg, unsigned ArgNo,
|
2013-03-15 01:53:33 +08:00
|
|
|
llvm::Value *LocalAddr,
|
2012-12-18 22:30:41 +08:00
|
|
|
CGBuilderTy &Builder);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit information about a global variable.
|
2013-08-30 16:53:09 +08:00
|
|
|
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-09-13 09:13:19 +08:00
|
|
|
/// Emit a constant global variable's debug info.
|
|
|
|
void EmitGlobalVariable(const ValueDecl *VD, const APValue &Init);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit C++ using directive.
|
2013-04-22 14:13:21 +08:00
|
|
|
void EmitUsingDirective(const UsingDirectiveDecl &UD);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit the type explicitly casted to.
|
2014-09-25 01:01:27 +08:00
|
|
|
void EmitExplicitCastType(QualType Ty);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit C++ using declaration.
|
2013-05-20 12:58:53 +08:00
|
|
|
void EmitUsingDecl(const UsingDecl &UD);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit an @import declaration.
|
2015-07-01 01:39:51 +08:00
|
|
|
void EmitImportDecl(const ImportDecl &ID);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit C++ namespace alias.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
|
2013-05-21 06:50:41 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit record type's standalone debug info.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *getOrCreateRecordType(QualType Ty, SourceLocation L);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit an Objective-C interface type standalone debug info.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-08-28 05:21:19 +08:00
|
|
|
/// Emit standalone debug info for a type.
|
|
|
|
llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
|
|
|
|
|
2014-05-07 02:35:21 +08:00
|
|
|
void completeType(const EnumDecl *ED);
|
2013-08-16 04:49:17 +08:00
|
|
|
void completeType(const RecordDecl *RD);
|
|
|
|
void completeRequiredType(const RecordDecl *RD);
|
2013-08-20 09:28:15 +08:00
|
|
|
void completeClassData(const RecordDecl *RD);
|
2013-06-21 08:40:50 +08:00
|
|
|
|
2014-03-04 07:48:23 +08:00
|
|
|
void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
private:
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Emit call to llvm.dbg.declare for a variable declaration.
|
2015-08-01 01:56:14 +08:00
|
|
|
void EmitDeclare(const VarDecl *decl, llvm::Value *AI,
|
|
|
|
llvm::Optional<unsigned> ArgNo, CGBuilderTy &Builder);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Build up structure info for the byref. See \a BuildByRefType.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
|
2015-04-21 02:51:48 +08:00
|
|
|
uint64_t *OffSet);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-09-11 02:39:45 +08:00
|
|
|
/// Get context info for the DeclContext of \p Decl.
|
|
|
|
llvm::DIScope *getDeclContextDescriptor(const Decl *D);
|
|
|
|
/// Get context info for a given DeclContext \p Decl.
|
|
|
|
llvm::DIScope *getContextDescriptor(const Decl *Context,
|
|
|
|
llvm::DIScope *Default);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIScope *getCurrentContextDescriptor(const Decl *Decl);
|
2013-05-20 12:58:53 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Create a forward decl for a RecordType in a given context.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DICompositeType *getOrCreateRecordFwdDecl(const RecordType *,
|
|
|
|
llvm::DIScope *);
|
2013-05-16 08:52:23 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Return current directory name.
|
2012-12-18 22:30:41 +08:00
|
|
|
StringRef getCurrentDirname();
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Create new compile unit.
|
2012-12-18 22:30:41 +08:00
|
|
|
void CreateCompileUnit();
|
|
|
|
|
2015-10-13 04:21:08 +08:00
|
|
|
/// Remap a given path with the current debug prefix map
|
|
|
|
std::string remapDIPath(StringRef) const;
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Get the file debug info descriptor for the input location.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *getOrCreateFile(SourceLocation Loc);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Get the file info for main compile unit.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIFile *getOrCreateMainFile();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Get the type from the cache or create a new type if necessary.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-09-19 07:01:45 +08:00
|
|
|
/// Get a reference to a clang module. If \p CreateSkeletonCU is true,
|
|
|
|
/// this also creates a split dwarf skeleton compile unit.
|
2015-07-01 01:39:51 +08:00
|
|
|
llvm::DIModule *
|
2015-09-19 07:01:45 +08:00
|
|
|
getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod,
|
|
|
|
bool CreateSkeletonCU);
|
2015-07-01 01:39:51 +08:00
|
|
|
|
2015-09-12 01:23:08 +08:00
|
|
|
/// DebugTypeExtRefs: If \p D originated in a clang module, return it.
|
|
|
|
llvm::DIModule *getParentModuleOrNull(const Decl *D);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Get the type from the cache or create a new partial type if
|
|
|
|
/// necessary.
|
2015-07-25 04:34:41 +08:00
|
|
|
llvm::DICompositeType *getOrCreateLimitedType(const RecordType *Ty,
|
|
|
|
llvm::DIFile *F);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Create type metadata for a source language type.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CreateTypeNode(QualType Ty, llvm::DIFile *Fg);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Create new member and increase Offset by FType's size.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIType *CreateMemberType(llvm::DIFile *Unit, QualType FType,
|
2015-04-21 02:51:48 +08:00
|
|
|
StringRef Name, uint64_t *Offset);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Retrieve the DIDescriptor, if any, for the canonical form of this
|
2013-05-20 12:58:53 +08:00
|
|
|
/// declaration.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DINode *getDeclarationOrDefinition(const Decl *D);
|
2013-05-20 12:58:53 +08:00
|
|
|
|
2015-07-09 05:18:34 +08:00
|
|
|
/// \return debug info descriptor to describe method
|
2012-12-18 22:30:41 +08:00
|
|
|
/// declaration for the given method definition.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DISubprogram *getFunctionDeclaration(const Decl *D);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-07-09 05:18:34 +08:00
|
|
|
/// \return debug info descriptor to describe in-class static data
|
|
|
|
/// member declaration for the given out-of-class definition. If D
|
|
|
|
/// is an out-of-class definition of a static data member of a
|
|
|
|
/// class, find its corresponding in-class declaration.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIDerivedType *
|
2013-08-20 09:28:15 +08:00
|
|
|
getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D);
|
2013-01-16 09:22:32 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Create a subprogram describing the forward declaration
|
|
|
|
/// represented in the given FunctionDecl.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DISubprogram *getFunctionForwardDeclaration(const FunctionDecl *FD);
|
2014-11-18 11:40:51 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Create a global variable describing the forward decalration
|
2015-04-22 02:43:54 +08:00
|
|
|
/// represented in the given VarDecl.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIGlobalVariable *
|
2015-04-22 02:43:54 +08:00
|
|
|
getGlobalVariableForwardDeclaration(const VarDecl *VD);
|
2014-11-18 11:40:51 +08:00
|
|
|
|
2015-07-09 05:18:34 +08:00
|
|
|
/// \brief Return a global variable that represents one of the
|
|
|
|
/// collection of global variables created for an anonmyous union.
|
|
|
|
///
|
|
|
|
/// Recursively collect all of the member fields of a global
|
|
|
|
/// anonymous decl and create static variables for them. The first
|
|
|
|
/// time this is called it needs to be on a union and then from
|
|
|
|
/// there we can have additional unnamed fields.
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIGlobalVariable *
|
|
|
|
CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile *Unit,
|
2015-04-17 00:36:45 +08:00
|
|
|
unsigned LineNo, StringRef LinkageName,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::GlobalVariable *Var, llvm::DIScope *DContext);
|
2014-04-10 13:20:00 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Get function name for the given FunctionDecl. If the name is
|
|
|
|
/// constructed on demand (e.g., C++ destructor) then the name is
|
|
|
|
/// stored on the side.
|
2012-12-18 22:30:41 +08:00
|
|
|
StringRef getFunctionName(const FunctionDecl *FD);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Returns the unmangled name of an Objective-C method.
|
2013-05-16 08:52:23 +08:00
|
|
|
/// This is the display name for the debugging info.
|
2012-12-18 22:30:41 +08:00
|
|
|
StringRef getObjCMethodName(const ObjCMethodDecl *FD);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Return selector name. This is used for debugging
|
2012-12-18 22:30:41 +08:00
|
|
|
/// info.
|
|
|
|
StringRef getSelectorName(Selector S);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Get class name including template argument list.
|
2012-12-18 22:30:41 +08:00
|
|
|
StringRef getClassName(const RecordDecl *RD);
|
|
|
|
|
2015-07-09 05:18:34 +08:00
|
|
|
/// Get the vtable name for the given class.
|
2012-12-18 22:30:41 +08:00
|
|
|
StringRef getVTableName(const CXXRecordDecl *Decl);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Get line number for the location. If location is invalid
|
2012-12-18 22:30:41 +08:00
|
|
|
/// then use current location.
|
|
|
|
unsigned getLineNumber(SourceLocation Loc);
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Get column number for the location. If location is
|
2012-12-18 22:30:41 +08:00
|
|
|
/// invalid then use current location.
|
2013-03-13 04:43:25 +08:00
|
|
|
/// \param Force Assume DebugColumnInfo option is true.
|
2015-07-09 04:53:55 +08:00
|
|
|
unsigned getColumnNumber(SourceLocation Loc, bool Force = false);
|
2013-09-10 00:39:06 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Collect various properties of a FunctionDecl.
|
2014-11-18 11:40:46 +08:00
|
|
|
/// \param GD A GlobalDecl whose getDecl() must return a FunctionDecl.
|
2015-04-30 00:40:08 +08:00
|
|
|
void collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
|
2014-11-18 11:40:46 +08:00
|
|
|
StringRef &Name, StringRef &LinkageName,
|
2015-04-30 00:40:08 +08:00
|
|
|
llvm::DIScope *&FDContext,
|
|
|
|
llvm::DINodeArray &TParamsArray,
|
2016-09-06 18:48:04 +08:00
|
|
|
llvm::DINode::DIFlags &Flags);
|
2014-11-18 11:40:46 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Collect various properties of a VarDecl.
|
2015-04-30 00:40:08 +08:00
|
|
|
void collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
|
2015-04-17 00:36:45 +08:00
|
|
|
unsigned &LineNo, QualType &T, StringRef &Name,
|
2015-04-30 00:40:08 +08:00
|
|
|
StringRef &LinkageName, llvm::DIScope *&VDContext);
|
2014-11-18 11:40:46 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Allocate a copy of \p A using the DebugInfoNames allocator
|
2013-09-10 00:39:06 +08:00
|
|
|
/// and return a reference to it. If multiple arguments are given the strings
|
|
|
|
/// are concatenated.
|
|
|
|
StringRef internString(StringRef A, StringRef B = StringRef()) {
|
|
|
|
char *Data = DebugInfoNames.Allocate<char>(A.size() + B.size());
|
2015-08-04 11:53:00 +08:00
|
|
|
if (!A.empty())
|
|
|
|
std::memcpy(Data, A.data(), A.size());
|
|
|
|
if (!B.empty())
|
|
|
|
std::memcpy(Data + A.size(), B.data(), B.size());
|
2013-09-10 00:39:06 +08:00
|
|
|
return StringRef(Data, A.size() + B.size());
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
};
|
2013-07-18 08:28:02 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// A scoped helper to set the current debug location to the specified
|
2015-02-04 02:40:38 +08:00
|
|
|
/// location or preferred location of the specified Expr.
|
2015-01-14 15:38:27 +08:00
|
|
|
class ApplyDebugLocation {
|
DebugInfo: Use the preferred location rather than the start location for expression line info
This causes things like assignment to refer to the '=' rather than the
LHS when attributing the store instruction, for example.
There were essentially 3 options for this:
* The beginning of an expression (this was the behavior prior to this
commit). This meant that stepping through subexpressions would bounce
around from subexpressions back to the start of the outer expression,
etc. (eg: x + y + z would go x, y, x, z, x (the repeated 'x's would be
where the actual addition occurred)).
* The end of an expression. This seems to be what GCC does /mostly/, and
certainly this for function calls. This has the advantage that
progress is always 'forwards' (never jumping backwards - except for
independent subexpressions if they're evaluated in interesting orders,
etc). "x + y + z" would go "x y z" with the additions occurring at y
and z after the respective loads.
The problem with this is that the user would still have to think
fairly hard about precedence to realize which subexpression is being
evaluated or which operator overload is being called in, say, an asan
backtrace.
* The preferred location or 'exprloc'. In this case you get sort of what
you'd expect, though it's a bit confusing in its own way due to going
'backwards'. In this case the locations would be: "x y + z +" in
lovely postfix arithmetic order. But this does mean that if the op+
were an operator overload, say, and in a backtrace, the backtrace will
point to the exact '+' that's being called, not to the end of one of
its operands.
(actually the operator overload case doesn't work yet for other reasons,
but that's being fixed - but this at least gets scalar/complex
assignments and other plain operators right)
llvm-svn: 227027
2015-01-25 09:19:10 +08:00
|
|
|
private:
|
2015-02-04 04:00:54 +08:00
|
|
|
void init(SourceLocation TemporaryLocation, bool DefaultToEmpty = false);
|
|
|
|
ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty,
|
|
|
|
SourceLocation TemporaryLocation);
|
DebugInfo: Use the preferred location rather than the start location for expression line info
This causes things like assignment to refer to the '=' rather than the
LHS when attributing the store instruction, for example.
There were essentially 3 options for this:
* The beginning of an expression (this was the behavior prior to this
commit). This meant that stepping through subexpressions would bounce
around from subexpressions back to the start of the outer expression,
etc. (eg: x + y + z would go x, y, x, z, x (the repeated 'x's would be
where the actual addition occurred)).
* The end of an expression. This seems to be what GCC does /mostly/, and
certainly this for function calls. This has the advantage that
progress is always 'forwards' (never jumping backwards - except for
independent subexpressions if they're evaluated in interesting orders,
etc). "x + y + z" would go "x y z" with the additions occurring at y
and z after the respective loads.
The problem with this is that the user would still have to think
fairly hard about precedence to realize which subexpression is being
evaluated or which operator overload is being called in, say, an asan
backtrace.
* The preferred location or 'exprloc'. In this case you get sort of what
you'd expect, though it's a bit confusing in its own way due to going
'backwards'. In this case the locations would be: "x y + z +" in
lovely postfix arithmetic order. But this does mean that if the op+
were an operator overload, say, and in a backtrace, the backtrace will
point to the exact '+' that's being called, not to the end of one of
its operands.
(actually the operator overload case doesn't work yet for other reasons,
but that's being fixed - but this at least gets scalar/complex
assignments and other plain operators right)
llvm-svn: 227027
2015-01-25 09:19:10 +08:00
|
|
|
|
2015-01-14 15:38:27 +08:00
|
|
|
llvm::DebugLoc OriginalLocation;
|
2015-08-13 07:49:57 +08:00
|
|
|
CodeGenFunction *CGF;
|
2015-02-04 02:40:42 +08:00
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
public:
|
|
|
|
/// Set the location to the (valid) TemporaryLocation.
|
2015-02-04 02:40:42 +08:00
|
|
|
ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation);
|
2015-02-04 04:00:54 +08:00
|
|
|
ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E);
|
|
|
|
ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
|
2015-08-13 07:49:57 +08:00
|
|
|
ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) {
|
|
|
|
Other.CGF = nullptr;
|
|
|
|
}
|
2015-02-04 04:00:54 +08:00
|
|
|
|
|
|
|
~ApplyDebugLocation();
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// \brief Apply TemporaryLocation if it is valid. Otherwise switch
|
|
|
|
/// to an artificial debug location that has a valid scope, but no
|
|
|
|
/// line information.
|
2015-02-04 02:40:42 +08:00
|
|
|
///
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Artificial locations are useful when emitting compiler-generated
|
|
|
|
/// helper functions that have no source location associated with
|
|
|
|
/// them. The DWARF specification allows the compiler to use the
|
|
|
|
/// special line number 0 to indicate code that can not be
|
|
|
|
/// attributed to any source location. Note that passing an empty
|
|
|
|
/// SourceLocation to CGDebugInfo::setLocation() will result in the
|
|
|
|
/// last valid location being reused.
|
2015-02-04 04:00:54 +08:00
|
|
|
static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF) {
|
|
|
|
return ApplyDebugLocation(CGF, false, SourceLocation());
|
|
|
|
}
|
2015-07-09 04:53:55 +08:00
|
|
|
/// \brief Apply TemporaryLocation if it is valid. Otherwise switch
|
|
|
|
/// to an artificial debug location that has a valid scope, but no
|
|
|
|
/// line information.
|
|
|
|
static ApplyDebugLocation
|
|
|
|
CreateDefaultArtificial(CodeGenFunction &CGF,
|
|
|
|
SourceLocation TemporaryLocation) {
|
2015-02-04 04:00:54 +08:00
|
|
|
return ApplyDebugLocation(CGF, false, TemporaryLocation);
|
|
|
|
}
|
|
|
|
|
2015-07-09 04:53:55 +08:00
|
|
|
/// Set the IRBuilder to not attach debug locations. Note that
|
|
|
|
/// passing an empty SourceLocation to \a CGDebugInfo::setLocation()
|
|
|
|
/// will result in the last valid location being reused. Note that
|
|
|
|
/// all instructions that do not have a location at the beginning of
|
2015-12-17 07:10:46 +08:00
|
|
|
/// a function are counted towards to function prologue.
|
2015-02-04 04:00:54 +08:00
|
|
|
static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF) {
|
|
|
|
return ApplyDebugLocation(CGF, true, SourceLocation());
|
|
|
|
}
|
|
|
|
|
2013-07-18 08:28:02 +08:00
|
|
|
};
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
} // namespace CodeGen
|
|
|
|
} // namespace clang
|
|
|
|
|
2015-09-30 04:56:43 +08:00
|
|
|
#endif // LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
|