2008-11-10 02:56:27 +00:00
|
|
|
//===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines a bunch of datatypes that are useful for creating and
|
2009-05-14 18:26:15 +00:00
|
|
|
// walking debug info in LLVM IR form. They essentially provide wrappers around
|
|
|
|
// the information in the global variables that's needed when constructing the
|
|
|
|
// DWARF information.
|
2008-11-10 02:56:27 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-01-26 07:31:20 +00:00
|
|
|
#ifndef LLVM_ANALYSIS_DEBUGINFO_H
|
|
|
|
#define LLVM_ANALYSIS_DEBUGINFO_H
|
2008-11-10 02:56:27 +00:00
|
|
|
|
2009-05-03 08:50:41 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2008-11-10 02:56:27 +00:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2009-06-26 01:49:18 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-01-12 21:38:43 +00:00
|
|
|
#include "llvm/Support/Dwarf.h"
|
2008-11-10 02:56:27 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class BasicBlock;
|
|
|
|
class Constant;
|
|
|
|
class Function;
|
|
|
|
class GlobalVariable;
|
|
|
|
class Module;
|
2008-11-10 04:10:34 +00:00
|
|
|
class Type;
|
2008-11-10 02:56:27 +00:00
|
|
|
class Value;
|
2009-02-14 16:06:42 +00:00
|
|
|
struct DbgStopPointInst;
|
|
|
|
struct DbgDeclareInst;
|
2009-07-02 01:15:24 +00:00
|
|
|
struct DbgFuncStartInst;
|
|
|
|
struct DbgRegionStartInst;
|
|
|
|
struct DbgRegionEndInst;
|
|
|
|
class DebugLoc;
|
2009-07-12 22:46:08 +00:00
|
|
|
struct DebugLocTracker;
|
2008-12-16 09:07:36 +00:00
|
|
|
class Instruction;
|
2009-07-07 17:12:53 +00:00
|
|
|
class LLVMContext;
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
class DIDescriptor {
|
|
|
|
protected:
|
2009-06-23 22:25:41 +00:00
|
|
|
GlobalVariable *DbgGV;
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// DIDescriptor constructor. If the specified GV is non-null, this checks
|
|
|
|
/// to make sure that the tag in the descriptor matches 'RequiredTag'. If
|
|
|
|
/// not, the debug info is corrupt and we ignore it.
|
|
|
|
DIDescriptor(GlobalVariable *GV, unsigned RequiredTag);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2009-03-13 04:39:26 +00:00
|
|
|
const std::string &getStringField(unsigned Elt, std::string &Result) const;
|
2008-11-10 02:56:27 +00:00
|
|
|
unsigned getUnsignedField(unsigned Elt) const {
|
|
|
|
return (unsigned)getUInt64Field(Elt);
|
|
|
|
}
|
|
|
|
uint64_t getUInt64Field(unsigned Elt) const;
|
|
|
|
DIDescriptor getDescriptorField(unsigned Elt) const;
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
template <typename DescTy>
|
|
|
|
DescTy getFieldAs(unsigned Elt) const {
|
2008-12-13 08:25:29 +00:00
|
|
|
return DescTy(getDescriptorField(Elt).getGV());
|
2008-11-10 02:56:27 +00:00
|
|
|
}
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
GlobalVariable *getGlobalVariableField(unsigned Elt) const;
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
public:
|
2009-06-23 22:25:41 +00:00
|
|
|
explicit DIDescriptor() : DbgGV(0) {}
|
|
|
|
explicit DIDescriptor(GlobalVariable *GV) : DbgGV(GV) {}
|
2008-11-10 02:56:27 +00:00
|
|
|
|
2009-06-23 22:25:41 +00:00
|
|
|
bool isNull() const { return DbgGV == 0; }
|
2008-11-10 02:56:27 +00:00
|
|
|
|
2009-06-23 22:25:41 +00:00
|
|
|
GlobalVariable *getGV() const { return DbgGV; }
|
2009-01-05 18:06:21 +00:00
|
|
|
|
2009-01-05 22:35:52 +00:00
|
|
|
unsigned getVersion() const {
|
2009-01-20 19:22:03 +00:00
|
|
|
return getUnsignedField(0) & LLVMDebugVersionMask;
|
2009-01-05 22:35:52 +00:00
|
|
|
}
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2009-01-05 18:06:21 +00:00
|
|
|
unsigned getTag() const {
|
2009-01-20 19:22:03 +00:00
|
|
|
return getUnsignedField(0) & ~LLVMDebugVersionMask;
|
2009-01-05 18:06:21 +00:00
|
|
|
}
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2009-05-03 08:50:41 +00:00
|
|
|
/// ValidDebugInfo - Return true if V represents valid debug info value.
|
|
|
|
static bool ValidDebugInfo(Value *V, CodeGenOpt::Level OptLevel);
|
|
|
|
|
2009-05-05 22:19:25 +00:00
|
|
|
/// dump - print descriptor.
|
|
|
|
void dump() const;
|
2008-11-10 02:56:27 +00:00
|
|
|
};
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2009-01-05 18:33:01 +00:00
|
|
|
/// DISubrange - This is used to represent ranges, for array bounds.
|
|
|
|
class DISubrange : public DIDescriptor {
|
|
|
|
public:
|
2009-05-14 18:26:15 +00:00
|
|
|
explicit DISubrange(GlobalVariable *GV = 0)
|
|
|
|
: DIDescriptor(GV, dwarf::DW_TAG_subrange_type) {}
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2009-01-05 18:33:01 +00:00
|
|
|
int64_t getLo() const { return (int64_t)getUInt64Field(1); }
|
|
|
|
int64_t getHi() const { return (int64_t)getUInt64Field(2); }
|
|
|
|
};
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// DIArray - This descriptor holds an array of descriptors.
|
|
|
|
class DIArray : public DIDescriptor {
|
|
|
|
public:
|
|
|
|
explicit DIArray(GlobalVariable *GV = 0) : DIDescriptor(GV) {}
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
unsigned getNumElements() const;
|
2009-01-05 19:55:07 +00:00
|
|
|
DIDescriptor getElement(unsigned Idx) const {
|
|
|
|
return getDescriptorField(Idx);
|
2009-01-05 18:33:01 +00:00
|
|
|
}
|
2008-11-10 02:56:27 +00:00
|
|
|
};
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// DICompileUnit - A wrapper for a compile unit.
|
|
|
|
class DICompileUnit : public DIDescriptor {
|
|
|
|
public:
|
2009-05-14 18:26:15 +00:00
|
|
|
explicit DICompileUnit(GlobalVariable *GV = 0)
|
|
|
|
: DIDescriptor(GV, dwarf::DW_TAG_compile_unit) {}
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
unsigned getLanguage() const { return getUnsignedField(2); }
|
2009-03-13 04:39:26 +00:00
|
|
|
const std::string &getFilename(std::string &F) const {
|
|
|
|
return getStringField(3, F);
|
2009-03-09 05:04:40 +00:00
|
|
|
}
|
2009-03-13 04:39:26 +00:00
|
|
|
const std::string &getDirectory(std::string &F) const {
|
|
|
|
return getStringField(4, F);
|
2009-03-09 05:04:40 +00:00
|
|
|
}
|
2009-03-13 04:39:26 +00:00
|
|
|
const std::string &getProducer(std::string &F) const {
|
|
|
|
return getStringField(5, F);
|
2009-03-09 05:04:40 +00:00
|
|
|
}
|
2009-01-30 18:20:31 +00:00
|
|
|
|
|
|
|
/// isMain - Each input file is encoded as a separate compile unit in LLVM
|
|
|
|
/// debugging information output. However, many target specific tool chains
|
|
|
|
/// prefer to encode only one compile unit in an object file. In this
|
|
|
|
/// situation, the LLVM code generator will include debugging information
|
|
|
|
/// entities in the compile unit that is marked as main compile unit. The
|
|
|
|
/// code generator accepts maximum one main compile unit per module. If a
|
|
|
|
/// module does not contain any main compile unit then the code generator
|
|
|
|
/// will emit multiple compile units in the output object file.
|
2009-02-17 22:43:44 +00:00
|
|
|
|
2009-02-17 21:23:59 +00:00
|
|
|
bool isMain() const { return getUnsignedField(6); }
|
|
|
|
bool isOptimized() const { return getUnsignedField(7); }
|
2009-03-13 04:39:26 +00:00
|
|
|
const std::string &getFlags(std::string &F) const {
|
|
|
|
return getStringField(8, F);
|
|
|
|
}
|
2009-02-17 22:43:44 +00:00
|
|
|
unsigned getRunTimeVersion() const { return getUnsignedField(9); }
|
2009-01-20 18:13:03 +00:00
|
|
|
|
2009-01-19 23:21:49 +00:00
|
|
|
/// Verify - Verify that a compile unit is well formed.
|
|
|
|
bool Verify() const;
|
2009-01-30 01:03:10 +00:00
|
|
|
|
|
|
|
/// dump - print compile unit.
|
|
|
|
void dump() const;
|
2008-11-10 02:56:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
|
|
|
|
/// FIXME: it seems strange that this doesn't have either a reference to the
|
|
|
|
/// type/precision or a file/line pair for location info.
|
|
|
|
class DIEnumerator : public DIDescriptor {
|
|
|
|
public:
|
2009-05-14 18:26:15 +00:00
|
|
|
explicit DIEnumerator(GlobalVariable *GV = 0)
|
|
|
|
: DIDescriptor(GV, dwarf::DW_TAG_enumerator) {}
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2009-03-13 04:39:26 +00:00
|
|
|
const std::string &getName(std::string &F) const {
|
|
|
|
return getStringField(1, F);
|
2009-03-09 05:04:40 +00:00
|
|
|
}
|
2009-01-05 18:38:38 +00:00
|
|
|
uint64_t getEnumValue() const { return getUInt64Field(2); }
|
2008-11-10 02:56:27 +00:00
|
|
|
};
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// DIType - This is a wrapper for a type.
|
|
|
|
/// FIXME: Types should be factored much better so that CV qualifiers and
|
|
|
|
/// others do not require a huge and empty descriptor full of zeros.
|
|
|
|
class DIType : public DIDescriptor {
|
2009-01-20 22:27:02 +00:00
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
FlagPrivate = 1 << 0,
|
|
|
|
FlagProtected = 1 << 1,
|
2009-01-21 00:08:04 +00:00
|
|
|
FlagFwdDecl = 1 << 2
|
2009-01-20 22:27:02 +00:00
|
|
|
};
|
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
protected:
|
|
|
|
DIType(GlobalVariable *GV, unsigned Tag) : DIDescriptor(GV, Tag) {}
|
|
|
|
// This ctor is used when the Tag has already been validated by a derived
|
|
|
|
// ctor.
|
|
|
|
DIType(GlobalVariable *GV, bool, bool) : DIDescriptor(GV) {}
|
2009-01-12 21:38:43 +00:00
|
|
|
|
2009-01-15 19:26:23 +00:00
|
|
|
public:
|
2009-01-12 21:38:43 +00:00
|
|
|
/// isDerivedType - Return true if the specified tag is legal for
|
|
|
|
/// DIDerivedType.
|
|
|
|
static bool isDerivedType(unsigned TAG);
|
|
|
|
|
|
|
|
/// isCompositeType - Return true if the specified tag is legal for
|
|
|
|
/// DICompositeType.
|
|
|
|
static bool isCompositeType(unsigned TAG);
|
|
|
|
|
|
|
|
/// isBasicType - Return true if the specified tag is legal for
|
|
|
|
/// DIBasicType.
|
|
|
|
static bool isBasicType(unsigned TAG) {
|
|
|
|
return TAG == dwarf::DW_TAG_base_type;
|
|
|
|
}
|
|
|
|
|
2009-01-19 23:21:49 +00:00
|
|
|
/// Verify - Verify that a type descriptor is well formed.
|
|
|
|
bool Verify() const;
|
2008-11-10 02:56:27 +00:00
|
|
|
public:
|
|
|
|
explicit DIType(GlobalVariable *GV);
|
|
|
|
explicit DIType() {}
|
2009-01-05 22:35:52 +00:00
|
|
|
virtual ~DIType() {}
|
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
DIDescriptor getContext() const { return getDescriptorField(1); }
|
2009-03-13 04:39:26 +00:00
|
|
|
const std::string &getName(std::string &F) const {
|
|
|
|
return getStringField(2, F);
|
|
|
|
}
|
2008-11-10 02:56:27 +00:00
|
|
|
DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
|
|
|
|
unsigned getLineNumber() const { return getUnsignedField(4); }
|
|
|
|
uint64_t getSizeInBits() const { return getUInt64Field(5); }
|
|
|
|
uint64_t getAlignInBits() const { return getUInt64Field(6); }
|
|
|
|
// FIXME: Offset is only used for DW_TAG_member nodes. Making every type
|
|
|
|
// carry this is just plain insane.
|
|
|
|
uint64_t getOffsetInBits() const { return getUInt64Field(7); }
|
|
|
|
unsigned getFlags() const { return getUnsignedField(8); }
|
2009-01-20 22:27:02 +00:00
|
|
|
bool isPrivate() const { return (getFlags() & FlagPrivate) != 0; }
|
|
|
|
bool isProtected() const { return (getFlags() & FlagProtected) != 0; }
|
|
|
|
bool isForwardDecl() const { return (getFlags() & FlagFwdDecl) != 0; }
|
2009-01-05 22:35:52 +00:00
|
|
|
|
2009-01-30 01:03:10 +00:00
|
|
|
/// dump - print type.
|
|
|
|
void dump() const;
|
2008-11-10 02:56:27 +00:00
|
|
|
};
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// DIBasicType - A basic type, like 'int' or 'float'.
|
|
|
|
class DIBasicType : public DIType {
|
|
|
|
public:
|
2009-05-14 18:26:15 +00:00
|
|
|
explicit DIBasicType(GlobalVariable *GV)
|
|
|
|
: DIType(GV, dwarf::DW_TAG_base_type) {}
|
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
unsigned getEncoding() const { return getUnsignedField(9); }
|
2009-01-30 01:03:10 +00:00
|
|
|
|
|
|
|
/// dump - print basic type.
|
|
|
|
void dump() const;
|
2008-11-10 02:56:27 +00:00
|
|
|
};
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// DIDerivedType - A simple derived type, like a const qualified type,
|
|
|
|
/// a typedef, a pointer or reference, etc.
|
|
|
|
class DIDerivedType : public DIType {
|
|
|
|
protected:
|
|
|
|
explicit DIDerivedType(GlobalVariable *GV, bool, bool)
|
|
|
|
: DIType(GV, true, true) {}
|
|
|
|
public:
|
2009-05-14 18:26:15 +00:00
|
|
|
explicit DIDerivedType(GlobalVariable *GV)
|
|
|
|
: DIType(GV, true, true) {
|
|
|
|
if (GV && !isDerivedType(getTag()))
|
2009-06-23 22:25:41 +00:00
|
|
|
DbgGV = 0;
|
2009-05-14 18:26:15 +00:00
|
|
|
}
|
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
|
2009-01-30 01:03:10 +00:00
|
|
|
|
2009-02-17 21:23:59 +00:00
|
|
|
/// getOriginalTypeSize - If this type is derived from a base type then
|
|
|
|
/// return base type size.
|
|
|
|
uint64_t getOriginalTypeSize() const;
|
2009-01-30 01:03:10 +00:00
|
|
|
/// dump - print derived type.
|
|
|
|
void dump() const;
|
2009-07-22 18:23:44 +00:00
|
|
|
|
|
|
|
/// replaceAllUsesWith - Replace all uses of debug info referenced by
|
|
|
|
/// this descriptor. After this completes, the current debug info value
|
|
|
|
/// is erased.
|
|
|
|
void replaceAllUsesWith(DIDescriptor &D);
|
2008-11-10 02:56:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// DICompositeType - This descriptor holds a type that can refer to multiple
|
|
|
|
/// other types, like a function or struct.
|
|
|
|
/// FIXME: Why is this a DIDerivedType??
|
|
|
|
class DICompositeType : public DIDerivedType {
|
|
|
|
public:
|
2009-05-14 18:26:15 +00:00
|
|
|
explicit DICompositeType(GlobalVariable *GV)
|
|
|
|
: DIDerivedType(GV, true, true) {
|
|
|
|
if (GV && !isCompositeType(getTag()))
|
2009-06-23 22:25:41 +00:00
|
|
|
DbgGV = 0;
|
2009-05-14 18:26:15 +00:00
|
|
|
}
|
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
|
2009-02-17 22:43:44 +00:00
|
|
|
unsigned getRunTimeLang() const { return getUnsignedField(11); }
|
2009-01-19 23:21:49 +00:00
|
|
|
|
|
|
|
/// Verify - Verify that a composite type descriptor is well formed.
|
|
|
|
bool Verify() const;
|
2009-01-30 01:03:10 +00:00
|
|
|
|
|
|
|
/// dump - print composite type.
|
|
|
|
void dump() const;
|
2008-11-10 02:56:27 +00:00
|
|
|
};
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// DIGlobal - This is a common class for global variables and subprograms.
|
|
|
|
class DIGlobal : public DIDescriptor {
|
|
|
|
protected:
|
2008-11-10 03:11:39 +00:00
|
|
|
explicit DIGlobal(GlobalVariable *GV, unsigned RequiredTag)
|
2008-11-10 02:56:27 +00:00
|
|
|
: DIDescriptor(GV, RequiredTag) {}
|
2009-01-12 21:38:43 +00:00
|
|
|
|
|
|
|
/// isSubprogram - Return true if the specified tag is legal for
|
|
|
|
/// DISubprogram.
|
|
|
|
static bool isSubprogram(unsigned TAG) {
|
|
|
|
return TAG == dwarf::DW_TAG_subprogram;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isGlobalVariable - Return true if the specified tag is legal for
|
|
|
|
/// DIGlobalVariable.
|
|
|
|
static bool isGlobalVariable(unsigned TAG) {
|
|
|
|
return TAG == dwarf::DW_TAG_variable;
|
|
|
|
}
|
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
public:
|
2009-01-05 22:35:52 +00:00
|
|
|
virtual ~DIGlobal() {}
|
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
DIDescriptor getContext() const { return getDescriptorField(2); }
|
2009-03-13 04:39:26 +00:00
|
|
|
const std::string &getName(std::string &F) const {
|
|
|
|
return getStringField(3, F);
|
2009-03-09 05:04:40 +00:00
|
|
|
}
|
2009-03-13 04:39:26 +00:00
|
|
|
const std::string &getDisplayName(std::string &F) const {
|
|
|
|
return getStringField(4, F);
|
2009-03-09 05:04:40 +00:00
|
|
|
}
|
2009-03-13 04:39:26 +00:00
|
|
|
const std::string &getLinkageName(std::string &F) const {
|
|
|
|
return getStringField(5, F);
|
2009-03-09 05:04:40 +00:00
|
|
|
}
|
2008-11-10 02:56:27 +00:00
|
|
|
DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); }
|
|
|
|
unsigned getLineNumber() const { return getUnsignedField(7); }
|
|
|
|
DIType getType() const { return getFieldAs<DIType>(8); }
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// isLocalToUnit - Return true if this subprogram is local to the current
|
|
|
|
/// compile unit, like 'static' in C.
|
|
|
|
unsigned isLocalToUnit() const { return getUnsignedField(9); }
|
|
|
|
unsigned isDefinition() const { return getUnsignedField(10); }
|
2009-01-05 22:35:52 +00:00
|
|
|
|
2009-01-30 01:03:10 +00:00
|
|
|
/// dump - print global.
|
|
|
|
void dump() const;
|
2008-11-10 02:56:27 +00:00
|
|
|
};
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
|
|
|
|
class DISubprogram : public DIGlobal {
|
|
|
|
public:
|
2009-05-14 18:26:15 +00:00
|
|
|
explicit DISubprogram(GlobalVariable *GV = 0)
|
|
|
|
: DIGlobal(GV, dwarf::DW_TAG_subprogram) {}
|
|
|
|
|
2009-01-05 18:59:44 +00:00
|
|
|
DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
|
2009-01-19 23:21:49 +00:00
|
|
|
|
2009-06-23 22:07:48 +00:00
|
|
|
/// getReturnTypeName - Subprogram return types are encoded either as
|
|
|
|
/// DIType or as DICompositeType.
|
|
|
|
const std::string &getReturnTypeName(std::string &F) const {
|
|
|
|
DICompositeType DCT(getFieldAs<DICompositeType>(8));
|
|
|
|
if (!DCT.isNull()) {
|
|
|
|
DIArray A = DCT.getTypeArray();
|
|
|
|
DIType T(A.getElement(0).getGV());
|
|
|
|
return T.getName(F);
|
|
|
|
}
|
|
|
|
DIType T(getFieldAs<DIType>(8));
|
|
|
|
return T.getName(F);
|
|
|
|
}
|
|
|
|
|
2009-01-19 23:21:49 +00:00
|
|
|
/// Verify - Verify that a subprogram descriptor is well formed.
|
|
|
|
bool Verify() const;
|
2009-01-30 01:03:10 +00:00
|
|
|
|
|
|
|
/// dump - print subprogram.
|
|
|
|
void dump() const;
|
2009-04-15 00:06:07 +00:00
|
|
|
|
|
|
|
/// describes - Return true if this subprogram provides debugging
|
|
|
|
/// information for the function F.
|
|
|
|
bool describes(const Function *F);
|
2008-11-10 02:56:27 +00:00
|
|
|
};
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// DIGlobalVariable - This is a wrapper for a global variable.
|
|
|
|
class DIGlobalVariable : public DIGlobal {
|
|
|
|
public:
|
2009-05-14 18:26:15 +00:00
|
|
|
explicit DIGlobalVariable(GlobalVariable *GV = 0)
|
|
|
|
: DIGlobal(GV, dwarf::DW_TAG_variable) {}
|
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
|
2009-01-19 23:21:49 +00:00
|
|
|
|
|
|
|
/// Verify - Verify that a global variable descriptor is well formed.
|
|
|
|
bool Verify() const;
|
2009-01-30 01:03:10 +00:00
|
|
|
|
|
|
|
/// dump - print global variable.
|
|
|
|
void dump() const;
|
2008-11-10 02:56:27 +00:00
|
|
|
};
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
|
|
|
|
/// global etc).
|
|
|
|
class DIVariable : public DIDescriptor {
|
|
|
|
public:
|
2009-06-23 22:25:41 +00:00
|
|
|
explicit DIVariable(GlobalVariable *GV = 0)
|
|
|
|
: DIDescriptor(GV) {
|
|
|
|
if (GV && !isVariable(getTag()))
|
|
|
|
DbgGV = 0;
|
2009-05-14 18:26:15 +00:00
|
|
|
}
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
DIDescriptor getContext() const { return getDescriptorField(1); }
|
2009-03-13 04:39:26 +00:00
|
|
|
const std::string &getName(std::string &F) const {
|
|
|
|
return getStringField(2, F);
|
2009-03-09 05:04:40 +00:00
|
|
|
}
|
2008-11-10 02:56:27 +00:00
|
|
|
DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); }
|
|
|
|
unsigned getLineNumber() const { return getUnsignedField(4); }
|
|
|
|
DIType getType() const { return getFieldAs<DIType>(5); }
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// isVariable - Return true if the specified tag is legal for DIVariable.
|
|
|
|
static bool isVariable(unsigned Tag);
|
2009-01-19 23:21:49 +00:00
|
|
|
|
|
|
|
/// Verify - Verify that a variable descriptor is well formed.
|
|
|
|
bool Verify() const;
|
2009-01-30 01:03:10 +00:00
|
|
|
|
|
|
|
/// dump - print variable.
|
|
|
|
void dump() const;
|
2008-11-10 02:56:27 +00:00
|
|
|
};
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc).
|
|
|
|
class DIBlock : public DIDescriptor {
|
|
|
|
public:
|
2009-05-14 18:26:15 +00:00
|
|
|
explicit DIBlock(GlobalVariable *GV = 0)
|
|
|
|
: DIDescriptor(GV, dwarf::DW_TAG_lexical_block) {}
|
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
DIDescriptor getContext() const { return getDescriptorField(1); }
|
|
|
|
};
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// DIFactory - This object assists with the construction of the various
|
|
|
|
/// descriptors.
|
|
|
|
class DIFactory {
|
|
|
|
Module &M;
|
2009-07-07 17:12:53 +00:00
|
|
|
LLVMContext& VMContext;
|
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
// Cached values for uniquing and faster lookups.
|
2008-11-10 04:10:34 +00:00
|
|
|
const Type *EmptyStructPtr; // "{}*".
|
2008-11-10 02:56:27 +00:00
|
|
|
Function *StopPointFn; // llvm.dbg.stoppoint
|
|
|
|
Function *FuncStartFn; // llvm.dbg.func.start
|
|
|
|
Function *RegionStartFn; // llvm.dbg.region.start
|
|
|
|
Function *RegionEndFn; // llvm.dbg.region.end
|
|
|
|
Function *DeclareFn; // llvm.dbg.declare
|
|
|
|
StringMap<Constant*> StringCache;
|
|
|
|
DenseMap<Constant*, DIDescriptor> SimpleConstantCache;
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
DIFactory(const DIFactory &); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const DIFactory&); // DO NOT IMPLEMENT
|
|
|
|
public:
|
2008-11-10 04:10:34 +00:00
|
|
|
explicit DIFactory(Module &m);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// GetOrCreateArray - Create an descriptor for an array of descriptors.
|
|
|
|
/// This implicitly uniques the arrays created.
|
|
|
|
DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys);
|
|
|
|
|
|
|
|
/// GetOrCreateSubrange - Create a descriptor for a value range. This
|
|
|
|
/// implicitly uniques the values returned.
|
|
|
|
DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// CreateCompileUnit - Create a new descriptor for the specified compile
|
|
|
|
/// unit.
|
|
|
|
DICompileUnit CreateCompileUnit(unsigned LangID,
|
|
|
|
const std::string &Filename,
|
|
|
|
const std::string &Directory,
|
2009-01-23 22:33:47 +00:00
|
|
|
const std::string &Producer,
|
2009-01-30 18:20:31 +00:00
|
|
|
bool isMain = false,
|
2009-01-23 22:33:47 +00:00
|
|
|
bool isOptimized = false,
|
2009-02-17 22:43:44 +00:00
|
|
|
const char *Flags = "",
|
|
|
|
unsigned RunTimeVer = 0);
|
2008-11-10 02:56:27 +00:00
|
|
|
|
|
|
|
/// CreateEnumerator - Create a single enumerator value.
|
|
|
|
DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// CreateBasicType - Create a basic type like int, float, etc.
|
|
|
|
DIBasicType CreateBasicType(DIDescriptor Context, const std::string &Name,
|
|
|
|
DICompileUnit CompileUnit, unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits, uint64_t AlignInBits,
|
|
|
|
uint64_t OffsetInBits, unsigned Flags,
|
2009-01-30 18:20:31 +00:00
|
|
|
unsigned Encoding);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// CreateDerivedType - Create a derived type like const qualified type,
|
|
|
|
/// pointer, typedef, etc.
|
|
|
|
DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context,
|
|
|
|
const std::string &Name,
|
|
|
|
DICompileUnit CompileUnit,
|
|
|
|
unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits, uint64_t AlignInBits,
|
|
|
|
uint64_t OffsetInBits, unsigned Flags,
|
2009-01-30 18:20:31 +00:00
|
|
|
DIType DerivedFrom);
|
2008-11-10 02:56:27 +00:00
|
|
|
|
|
|
|
/// CreateCompositeType - Create a composite type like array, struct, etc.
|
|
|
|
DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context,
|
|
|
|
const std::string &Name,
|
|
|
|
DICompileUnit CompileUnit,
|
|
|
|
unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint64_t AlignInBits,
|
|
|
|
uint64_t OffsetInBits, unsigned Flags,
|
|
|
|
DIType DerivedFrom,
|
2009-02-17 22:43:44 +00:00
|
|
|
DIArray Elements,
|
|
|
|
unsigned RunTimeLang = 0);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// CreateSubprogram - Create a new descriptor for the specified subprogram.
|
|
|
|
/// See comments in DISubprogram for descriptions of these fields.
|
|
|
|
DISubprogram CreateSubprogram(DIDescriptor Context, const std::string &Name,
|
|
|
|
const std::string &DisplayName,
|
|
|
|
const std::string &LinkageName,
|
|
|
|
DICompileUnit CompileUnit, unsigned LineNo,
|
|
|
|
DIType Type, bool isLocalToUnit,
|
2009-01-30 18:20:31 +00:00
|
|
|
bool isDefinition);
|
2008-11-10 02:56:27 +00:00
|
|
|
|
|
|
|
/// CreateGlobalVariable - Create a new descriptor for the specified global.
|
|
|
|
DIGlobalVariable
|
|
|
|
CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
|
|
|
|
const std::string &DisplayName,
|
|
|
|
const std::string &LinkageName,
|
|
|
|
DICompileUnit CompileUnit,
|
|
|
|
unsigned LineNo, DIType Type, bool isLocalToUnit,
|
2009-01-30 18:20:31 +00:00
|
|
|
bool isDefinition, llvm::GlobalVariable *GV);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// CreateVariable - Create a new descriptor for the specified variable.
|
|
|
|
DIVariable CreateVariable(unsigned Tag, DIDescriptor Context,
|
|
|
|
const std::string &Name,
|
|
|
|
DICompileUnit CompileUnit, unsigned LineNo,
|
2009-01-30 18:20:31 +00:00
|
|
|
DIType Type);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// CreateBlock - This creates a descriptor for a lexical block with the
|
|
|
|
/// specified parent context.
|
|
|
|
DIBlock CreateBlock(DIDescriptor Context);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
|
|
|
|
/// inserting it at the end of the specified basic block.
|
|
|
|
void InsertStopPoint(DICompileUnit CU, unsigned LineNo, unsigned ColNo,
|
|
|
|
BasicBlock *BB);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
|
|
|
|
/// mark the start of the specified subprogram.
|
|
|
|
void InsertSubprogramStart(DISubprogram SP, BasicBlock *BB);
|
|
|
|
|
|
|
|
/// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
|
|
|
|
/// mark the start of a region for the specified scoping descriptor.
|
|
|
|
void InsertRegionStart(DIDescriptor D, BasicBlock *BB);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
|
|
|
|
/// mark the end of a region for the specified scoping descriptor.
|
|
|
|
void InsertRegionEnd(DIDescriptor D, BasicBlock *BB);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
/// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
|
|
|
|
void InsertDeclare(llvm::Value *Storage, DIVariable D, BasicBlock *BB);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
private:
|
|
|
|
Constant *GetTagConstant(unsigned TAG);
|
|
|
|
Constant *GetStringConstant(const std::string &String);
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-11-10 04:10:34 +00:00
|
|
|
/// getCastToEmpty - Return the descriptor as a Constant* with type '{}*'.
|
|
|
|
Constant *getCastToEmpty(DIDescriptor D);
|
2008-11-10 02:56:27 +00:00
|
|
|
};
|
2009-01-20 19:08:39 +00:00
|
|
|
|
2008-12-16 09:07:36 +00:00
|
|
|
/// Finds the stoppoint coressponding to this instruction, that is the
|
|
|
|
/// stoppoint that dominates this instruction
|
|
|
|
const DbgStopPointInst *findStopPoint(const Instruction *Inst);
|
|
|
|
|
|
|
|
/// Finds the stoppoint corresponding to first real (non-debug intrinsic)
|
|
|
|
/// instruction in this Basic Block, and returns the stoppoint for it.
|
|
|
|
const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB);
|
|
|
|
|
|
|
|
/// Finds the dbg.declare intrinsic corresponding to this value if any.
|
|
|
|
/// It looks through pointer casts too.
|
|
|
|
const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true);
|
2009-03-10 13:41:26 +00:00
|
|
|
|
|
|
|
/// Find the debug info descriptor corresponding to this global variable.
|
|
|
|
Value *findDbgGlobalDeclare(GlobalVariable *V);
|
|
|
|
|
|
|
|
bool getLocationInfo(const Value *V, std::string &DisplayName, std::string &Type,
|
|
|
|
unsigned &LineNo, std::string &File, std::string &Dir);
|
2009-06-26 01:49:18 +00:00
|
|
|
|
|
|
|
/// CollectDebugInfoAnchors - Collect debugging information anchors.
|
|
|
|
void CollectDebugInfoAnchors(Module &M,
|
|
|
|
SmallVector<GlobalVariable *, 2> &CompileUnits,
|
|
|
|
SmallVector<GlobalVariable *, 4> &GlobalVars,
|
|
|
|
SmallVector<GlobalVariable *, 4> &Subprograms);
|
|
|
|
|
2009-07-02 01:15:24 +00:00
|
|
|
/// isValidDebugInfoIntrinsic - Return true if SPI is a valid debug
|
2009-07-02 17:17:03 +00:00
|
|
|
/// info intrinsic.
|
2009-07-02 01:15:24 +00:00
|
|
|
bool isValidDebugInfoIntrinsic(DbgStopPointInst &SPI,
|
|
|
|
CodeGenOpt::Level OptLev);
|
|
|
|
|
|
|
|
/// isValidDebugInfoIntrinsic - Return true if FSI is a valid debug
|
2009-07-02 17:17:03 +00:00
|
|
|
/// info intrinsic.
|
2009-07-02 01:15:24 +00:00
|
|
|
bool isValidDebugInfoIntrinsic(DbgFuncStartInst &FSI,
|
|
|
|
CodeGenOpt::Level OptLev);
|
|
|
|
|
|
|
|
/// isValidDebugInfoIntrinsic - Return true if RSI is a valid debug
|
2009-07-02 17:17:03 +00:00
|
|
|
/// info intrinsic.
|
2009-07-02 01:15:24 +00:00
|
|
|
bool isValidDebugInfoIntrinsic(DbgRegionStartInst &RSI,
|
|
|
|
CodeGenOpt::Level OptLev);
|
|
|
|
|
|
|
|
/// isValidDebugInfoIntrinsic - Return true if REI is a valid debug
|
2009-07-02 17:17:03 +00:00
|
|
|
/// info intrinsic.
|
2009-07-02 01:15:24 +00:00
|
|
|
bool isValidDebugInfoIntrinsic(DbgRegionEndInst &REI,
|
|
|
|
CodeGenOpt::Level OptLev);
|
|
|
|
|
|
|
|
/// isValidDebugInfoIntrinsic - Return true if DI is a valid debug
|
2009-07-02 17:17:03 +00:00
|
|
|
/// info intrinsic.
|
2009-07-02 01:15:24 +00:00
|
|
|
bool isValidDebugInfoIntrinsic(DbgDeclareInst &DI,
|
|
|
|
CodeGenOpt::Level OptLev);
|
|
|
|
|
|
|
|
/// ExtractDebugLocation - Extract debug location information
|
|
|
|
/// from llvm.dbg.stoppoint intrinsic.
|
|
|
|
DebugLoc ExtractDebugLocation(DbgStopPointInst &SPI,
|
|
|
|
DebugLocTracker &DebugLocInfo);
|
|
|
|
|
|
|
|
/// ExtractDebugLocation - Extract debug location information
|
|
|
|
/// from llvm.dbg.func_start intrinsic.
|
|
|
|
DebugLoc ExtractDebugLocation(DbgFuncStartInst &FSI,
|
|
|
|
DebugLocTracker &DebugLocInfo);
|
|
|
|
|
|
|
|
/// isInlinedFnStart - Return true if FSI is starting an inlined function.
|
|
|
|
bool isInlinedFnStart(DbgFuncStartInst &FSI, const Function *CurrentFn);
|
|
|
|
|
|
|
|
/// isInlinedFnEnd - Return true if REI is ending an inlined function.
|
|
|
|
bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn);
|
|
|
|
|
2008-11-10 02:56:27 +00:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|