Reorg for integration with gcc4. Old style debug info will not be passed though

to SelIDAG.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26115 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jim Laskey
2006-02-11 01:01:30 +00:00
parent c23580969f
commit ce72b1755f
3 changed files with 435 additions and 192 deletions

View File

@@ -32,6 +32,7 @@
#include "llvm/Support/Dwarf.h" #include "llvm/Support/Dwarf.h"
#include "llvm/ADT/UniqueVector.h" #include "llvm/ADT/UniqueVector.h"
#include "llvm/GlobalValue.h"
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/User.h" #include "llvm/User.h"
@@ -42,6 +43,7 @@ namespace llvm {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Forward declarations. // Forward declarations.
class Constant;
class DebugInfoDesc; class DebugInfoDesc;
class GlobalVariable; class GlobalVariable;
class Module; class Module;
@@ -57,12 +59,13 @@ enum {
// DebugInfoDesc type identifying tags. // DebugInfoDesc type identifying tags.
// FIXME - Change over with gcc4. // FIXME - Change over with gcc4.
DI_TAG_anchor = 0,
#if 1 #if 1
DI_TAG_compile_unit = DW_TAG_compile_unit, DI_TAG_compile_unit = DW_TAG_compile_unit,
DI_TAG_global_variable = DW_TAG_variable, DI_TAG_global_variable = DW_TAG_variable,
DI_TAG_subprogram = DW_TAG_subprogram DI_TAG_subprogram = DW_TAG_subprogram
#else #else
DI_TAG_compile_unit = 1, DI_TAG_compile_unit,
DI_TAG_global_variable, DI_TAG_global_variable,
DI_TAG_subprogram DI_TAG_subprogram
#endif #endif
@@ -117,6 +120,10 @@ public:
/// Return NULL if not a recognized Tag. /// Return NULL if not a recognized Tag.
static DebugInfoDesc *DescFactory(unsigned Tag); static DebugInfoDesc *DescFactory(unsigned Tag);
/// getLinkage - get linkage appropriate for this type of descriptor.
///
virtual GlobalValue::LinkageTypes getLinkage() const;
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
// Subclasses should supply the following static methods. // Subclasses should supply the following static methods.
@@ -128,11 +135,15 @@ public:
/// ApplyToFields - Target the vistor to the fields of the descriptor. /// ApplyToFields - Target the vistor to the fields of the descriptor.
/// ///
virtual void ApplyToFields(DIVisitor *Visitor) = 0; virtual void ApplyToFields(DIVisitor *Visitor);
/// TypeString - Return a string used to compose globalnames and labels. /// getDescString - Return a string used to compose global names and labels.
/// ///
virtual const char *TypeString() const = 0; virtual const char *getDescString() const = 0;
/// getTypeString - Return a string used to label this descriptor's type.
///
virtual const char *getTypeString() const = 0;
#ifndef NDEBUG #ifndef NDEBUG
virtual void dump() = 0; virtual void dump() = 0;
@@ -140,28 +151,91 @@ public:
}; };
//===----------------------------------------------------------------------===//
/// AnchorDesc - Descriptors of this class act as markers for identifying
/// descriptors of certain groups.
class AnchorDesc : public DebugInfoDesc {
private:
std::string Name; // Anchor type string.
public:
AnchorDesc()
: DebugInfoDesc(DI_TAG_anchor)
, Name("")
{}
AnchorDesc(const std::string &N)
: DebugInfoDesc(DI_TAG_anchor)
, Name(N)
{}
// Accessors
const std::string &getName() const { return Name; }
// Implement isa/cast/dyncast.
static bool classof(const AnchorDesc *) { return true; }
static bool classof(const DebugInfoDesc *D) {
return D->getTag() == DI_TAG_anchor;
}
/// getLinkage - get linkage appropriate for this type of descriptor.
///
virtual GlobalValue::LinkageTypes getLinkage() const;
/// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
///
virtual void ApplyToFields(DIVisitor *Visitor);
/// getDescString - Return a string used to compose global names and labels.
///
virtual const char *getDescString() const;
/// getTypeString - Return a string used to label this descriptor's type.
///
virtual const char *getTypeString() const;
#ifndef NDEBUG
virtual void dump();
#endif
};
//===----------------------------------------------------------------------===//
/// AnchoredDesc - This class manages anchors for a variety of top level
/// descriptors.
class AnchoredDesc : public DebugInfoDesc {
private:
AnchorDesc *Anchor; // Anchor for all descriptors of the
// same type.
protected:
AnchoredDesc(unsigned T);
public:
// Accessors.
AnchorDesc *getAnchor() const { return Anchor; }
void setAnchor(AnchorDesc *A) { Anchor = A; }
//===--------------------------------------------------------------------===//
// Subclasses should supply the following virtual methods.
/// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
///
virtual void ApplyToFields(DIVisitor *Visitor);
};
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// CompileUnitDesc - This class packages debug information associated with a /// CompileUnitDesc - This class packages debug information associated with a
/// source/header file. /// source/header file.
class CompileUnitDesc : public DebugInfoDesc { class CompileUnitDesc : public AnchoredDesc {
private: private:
unsigned DebugVersion; // LLVM debug version when produced. unsigned DebugVersion; // LLVM debug version when produced.
unsigned Language; // Language number (ex. DW_LANG_C89.) unsigned Language; // Language number (ex. DW_LANG_C89.)
std::string FileName; // Source file name. std::string FileName; // Source file name.
std::string Directory; // Source file directory. std::string Directory; // Source file directory.
std::string Producer; // Compiler string. std::string Producer; // Compiler string.
GlobalVariable *TransUnit; // Translation unit - ignored.
public: public:
CompileUnitDesc() CompileUnitDesc();
: DebugInfoDesc(DI_TAG_compile_unit)
, DebugVersion(LLVMDebugVersion)
, Language(0)
, FileName("")
, Directory("")
, Producer("")
, TransUnit(NULL)
{}
// Accessors // Accessors
unsigned getDebugVersion() const { return DebugVersion; } unsigned getDebugVersion() const { return DebugVersion; }
@@ -173,6 +247,7 @@ public:
void setFileName(const std::string &FN) { FileName = FN; } void setFileName(const std::string &FN) { FileName = FN; }
void setDirectory(const std::string &D) { Directory = D; } void setDirectory(const std::string &D) { Directory = D; }
void setProducer(const std::string &P) { Producer = P; } void setProducer(const std::string &P) { Producer = P; }
// FIXME - Need translation unit getter/setter. // FIXME - Need translation unit getter/setter.
// Implement isa/cast/dyncast. // Implement isa/cast/dyncast.
@@ -189,9 +264,17 @@ public:
/// ///
virtual void ApplyToFields(DIVisitor *Visitor); virtual void ApplyToFields(DIVisitor *Visitor);
/// TypeString - Return a string used to compose globalnames and labels. /// getDescString - Return a string used to compose global names and labels.
/// ///
virtual const char *TypeString() const; virtual const char *getDescString() const;
/// getTypeString - Return a string used to label this descriptor's type.
///
virtual const char *getTypeString() const;
/// getAnchorString - Return a string used to label this descriptor's anchor.
///
virtual const char *getAnchorString() const;
#ifndef NDEBUG #ifndef NDEBUG
virtual void dump(); virtual void dump();
@@ -199,42 +282,49 @@ public:
}; };
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// GlobalVariableDesc - This class packages debug information associated with a /// GlobalDesc - This class is the base descriptor for global functions and
/// GlobalVariable. /// variables.
class GlobalVariableDesc : public DebugInfoDesc { class GlobalDesc : public AnchoredDesc {
private: private:
DebugInfoDesc *Context; // Context debug descriptor. DebugInfoDesc *Context; // Context debug descriptor.
std::string Name; // Global name. std::string Name; // Global name.
GlobalVariable *TransUnit; // Translation unit - ignored.
// FIXME - Use a descriptor. // FIXME - Use a descriptor.
GlobalVariable *TyDesc; // Type debug descriptor. GlobalVariable *TyDesc; // Type debug descriptor.
bool IsStatic; // Is the global a static. bool IsStatic; // Is the global a static.
bool IsDefinition; // Is the global defined in context. bool IsDefinition; // Is the global defined in context.
GlobalVariable *Global; // llvm global.
protected:
GlobalDesc(unsigned T);
public: public:
GlobalVariableDesc()
: DebugInfoDesc(DI_TAG_global_variable)
, Context(0)
, Name("")
, TransUnit(NULL)
, TyDesc(NULL)
, IsStatic(false)
, IsDefinition(false)
, Global(NULL)
{}
// Accessors // Accessors
DebugInfoDesc *getContext() const { return Context; } DebugInfoDesc *getContext() const { return Context; }
const std::string &getName() const { return Name; } const std::string &getName() const { return Name; }
bool isStatic() const { return IsStatic; } bool isStatic() const { return IsStatic; }
bool isDefinition() const { return IsDefinition; } bool isDefinition() const { return IsDefinition; }
GlobalVariable *getGlobalVariable() const { return Global; } void setContext(DebugInfoDesc *C) { Context = C; }
void setName(const std::string &N) { Name = N; } void setName(const std::string &N) { Name = N; }
void setIsStatic(bool IS) { IsStatic = IS; } void setIsStatic(bool IS) { IsStatic = IS; }
void setIsDefinition(bool ID) { IsDefinition = ID; } void setIsDefinition(bool ID) { IsDefinition = ID; }
/// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
///
virtual void ApplyToFields(DIVisitor *Visitor);
};
//===----------------------------------------------------------------------===//
/// GlobalVariableDesc - This class packages debug information associated with a
/// GlobalVariable.
class GlobalVariableDesc : public GlobalDesc {
private:
GlobalVariable *Global; // llvm global.
public:
GlobalVariableDesc();
// Accessors.
GlobalVariable *getGlobalVariable() const { return Global; }
void setGlobalVariable(GlobalVariable *GV) { Global = GV; } void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
// FIXME - Other getters/setters.
// Implement isa/cast/dyncast. // Implement isa/cast/dyncast.
static bool classof(const GlobalVariableDesc *) { return true; } static bool classof(const GlobalVariableDesc *) { return true; }
@@ -246,9 +336,17 @@ public:
/// GlobalVariableDesc. /// GlobalVariableDesc.
virtual void ApplyToFields(DIVisitor *Visitor); virtual void ApplyToFields(DIVisitor *Visitor);
/// TypeString - Return a string used to compose globalnames and labels. /// getDescString - Return a string used to compose global names and labels.
/// ///
virtual const char *TypeString() const; virtual const char *getDescString() const;
/// getTypeString - Return a string used to label this descriptor's type.
///
virtual const char *getTypeString() const;
/// getAnchorString - Return a string used to label this descriptor's anchor.
///
virtual const char *getAnchorString() const;
#ifndef NDEBUG #ifndef NDEBUG
virtual void dump(); virtual void dump();
@@ -258,32 +356,24 @@ public:
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// SubprogramDesc - This class packages debug information associated with a /// SubprogramDesc - This class packages debug information associated with a
/// subprogram/function. /// subprogram/function.
class SubprogramDesc : public DebugInfoDesc { class SubprogramDesc : public GlobalDesc {
private: private:
DebugInfoDesc *Context; // Context debug descriptor. DebugInfoDesc *Context; // Context debug descriptor.
std::string Name; // Subprogram name. std::string Name; // Subprogram name.
GlobalVariable *TransUnit; // Translation unit - ignored.
// FIXME - Use a descriptor. // FIXME - Use a descriptor.
GlobalVariable *TyDesc; // Type debug descriptor. GlobalVariable *TyDesc; // Type debug descriptor.
bool IsStatic; // Is the subprogram a static. bool IsStatic; // Is the subprogram a static.
bool IsDefinition; // Is the subprogram defined in context. bool IsDefinition; // Is the subprogram defined in context.
public: public:
SubprogramDesc() SubprogramDesc();
: DebugInfoDesc(DI_TAG_subprogram)
, Context(0)
, Name("")
, TransUnit(NULL)
, TyDesc(NULL)
, IsStatic(false)
, IsDefinition(false)
{}
// Accessors // Accessors
DebugInfoDesc *getContext() const { return Context; } DebugInfoDesc *getContext() const { return Context; }
const std::string &getName() const { return Name; } const std::string &getName() const { return Name; }
bool isStatic() const { return IsStatic; } bool isStatic() const { return IsStatic; }
bool isDefinition() const { return IsDefinition; } bool isDefinition() const { return IsDefinition; }
void setContext(DebugInfoDesc *C) { Context = C; }
void setName(const std::string &N) { Name = N; } void setName(const std::string &N) { Name = N; }
void setIsStatic(bool IS) { IsStatic = IS; } void setIsStatic(bool IS) { IsStatic = IS; }
void setIsDefinition(bool ID) { IsDefinition = ID; } void setIsDefinition(bool ID) { IsDefinition = ID; }
@@ -299,9 +389,17 @@ public:
/// ///
virtual void ApplyToFields(DIVisitor *Visitor); virtual void ApplyToFields(DIVisitor *Visitor);
/// TypeString - Return a string used to compose globalnames and labels. /// getDescString - Return a string used to compose global names and labels.
/// ///
virtual const char *TypeString() const; virtual const char *getDescString() const;
/// getTypeString - Return a string used to label this descriptor's type.
///
virtual const char *getTypeString() const;
/// getAnchorString - Return a string used to label this descriptor's anchor.
///
virtual const char *getAnchorString() const;
#ifndef NDEBUG #ifndef NDEBUG
virtual void dump(); virtual void dump();
@@ -313,18 +411,15 @@ public:
/// into DebugInfoDesc objects. /// into DebugInfoDesc objects.
class DIDeserializer { class DIDeserializer {
private: private:
Module *M; // Definition space module.
unsigned DebugVersion; // Version of debug information in use. unsigned DebugVersion; // Version of debug information in use.
std::map<GlobalVariable *, DebugInfoDesc *> GlobalDescs; std::map<GlobalVariable *, DebugInfoDesc *> GlobalDescs;
// Previously defined gloabls. // Previously defined gloabls.
public: public:
DIDeserializer() : M(NULL), DebugVersion(LLVMDebugVersion) {} DIDeserializer() : DebugVersion(LLVMDebugVersion) {}
~DIDeserializer() {} ~DIDeserializer() {}
// Accessors // Accessors
Module *getModule() const { return M; };
void setModule(Module *module) { M = module; }
unsigned getDebugVersion() const { return DebugVersion; } unsigned getDebugVersion() const { return DebugVersion; }
/// Deserialize - Reconstitute a GlobalVariable into it's component /// Deserialize - Reconstitute a GlobalVariable into it's component
@@ -345,10 +440,18 @@ private:
// Types per Tag. Created lazily. // Types per Tag. Created lazily.
std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals; std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals;
// Previously defined descriptors. // Previously defined descriptors.
std::map<const std::string, GlobalVariable*> StringCache; std::map<const std::string, Constant *> StringCache;
// Previously defined strings. // Previously defined strings.
public: public:
DISerializer() : M(NULL) {} DISerializer()
: M(NULL)
, StrPtrTy(NULL)
, EmptyStructPtrTy(NULL)
, TagTypes()
, DescGlobals()
, StringCache()
{}
~DISerializer() {} ~DISerializer() {}
// Accessors // Accessors
@@ -369,7 +472,7 @@ public:
/// getString - Construct the string as constant string global. /// getString - Construct the string as constant string global.
/// ///
GlobalVariable *getString(const std::string &String); Constant *getString(const std::string &String);
/// Serialize - Recursively cast the specified descriptor into a /// Serialize - Recursively cast the specified descriptor into a
/// GlobalVariable so that it can be serialized to a .bc or .ll file. /// GlobalVariable so that it can be serialized to a .bc or .ll file.
@@ -395,6 +498,7 @@ public:
/// Verify - Return true if the GlobalVariable appears to be a valid /// Verify - Return true if the GlobalVariable appears to be a valid
/// serialization of a DebugInfoDesc. /// serialization of a DebugInfoDesc.
bool Verify(Value *V);
bool Verify(GlobalVariable *GV); bool Verify(GlobalVariable *GV);
}; };
@@ -454,9 +558,7 @@ public:
class MachineDebugInfo : public ImmutablePass { class MachineDebugInfo : public ImmutablePass {
private: private:
// Use the same serializer/deserializer/verifier for the module. // Use the same serializer/deserializer/verifier for the module.
DISerializer SR;
DIDeserializer DR; DIDeserializer DR;
DIVerifier VR;
// CompileUnits - Uniquing vector for compile units. // CompileUnits - Uniquing vector for compile units.
UniqueVector<CompileUnitDesc *> CompileUnits; UniqueVector<CompileUnitDesc *> CompileUnits;
@@ -482,6 +584,14 @@ public:
/// ///
bool doFinalization(); bool doFinalization();
/// Deserialize - Convert a Value to a debug information descriptor.
///
DebugInfoDesc *Deserialize(Value *V);
/// Verify - Verify that a Value is debug information descriptor.
///
bool Verify(Value *V);
/// AnalyzeModule - Scan the module for global debug information. /// AnalyzeModule - Scan the module for global debug information.
/// ///
void AnalyzeModule(Module &M); void AnalyzeModule(Module &M);

View File

@@ -50,9 +50,13 @@ static std::vector<GlobalVariable*>
getGlobalVariablesUsing(Module &M, const std::string &RootName) { getGlobalVariablesUsing(Module &M, const std::string &RootName) {
std::vector<GlobalVariable*> Result; // GlobalVariables matching criteria. std::vector<GlobalVariable*> Result; // GlobalVariables matching criteria.
std::vector<const Type*> FieldTypes;
FieldTypes.push_back(Type::UIntTy);
FieldTypes.push_back(PointerType::get(Type::SByteTy));
// Get the GlobalVariable root. // Get the GlobalVariable root.
GlobalVariable *UseRoot = M.getGlobalVariable(RootName, GlobalVariable *UseRoot = M.getGlobalVariable(RootName,
StructType::get(std::vector<const Type*>())); StructType::get(FieldTypes));
// If present and linkonce then scan for users. // If present and linkonce then scan for users.
if (UseRoot && UseRoot->hasLinkOnceLinkage()) { if (UseRoot && UseRoot->hasLinkOnceLinkage()) {
@@ -168,28 +172,6 @@ static ConstantUInt *getUIntOperand(GlobalVariable *GV, unsigned i) {
// Check constant. // Check constant.
return dyn_cast<ConstantUInt>(CI->getOperand(i)); return dyn_cast<ConstantUInt>(CI->getOperand(i));
} }
//===----------------------------------------------------------------------===//
/// TagFromGlobal - Returns the Tag number from a debug info descriptor
/// GlobalVariable.
unsigned DebugInfoDesc::TagFromGlobal(GlobalVariable *GV) {
ConstantUInt *C = getUIntOperand(GV, 0);
return C ? (unsigned)C->getValue() : (unsigned)DIInvalid;
}
/// DescFactory - Create an instance of debug info descriptor based on Tag.
/// Return NULL if not a recognized Tag.
DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) {
switch (Tag) {
case DI_TAG_compile_unit: return new CompileUnitDesc();
case DI_TAG_global_variable: return new GlobalVariableDesc();
case DI_TAG_subprogram: return new SubprogramDesc();
default: break;
}
return NULL;
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// ApplyToFields - Target the visitor to each field of the debug information /// ApplyToFields - Target the visitor to each field of the debug information
@@ -206,7 +188,7 @@ private:
unsigned Count; // Running count of fields. unsigned Count; // Running count of fields.
public: public:
DICountVisitor() : DIVisitor(), Count(1) {} DICountVisitor() : DIVisitor(), Count(0) {}
// Accessors. // Accessors.
unsigned getCount() const { return Count; } unsigned getCount() const { return Count; }
@@ -234,7 +216,7 @@ public:
DIDeserializeVisitor(DIDeserializer &D, GlobalVariable *GV) DIDeserializeVisitor(DIDeserializer &D, GlobalVariable *GV)
: DIVisitor() : DIVisitor()
, DR(D) , DR(D)
, I(1) , I(0)
, CI(cast<ConstantStruct>(GV->getInitializer())) , CI(cast<ConstantStruct>(GV->getInitializer()))
{} {}
@@ -284,7 +266,7 @@ public:
/// Apply - Set the value of each of the fields. /// Apply - Set the value of each of the fields.
/// ///
virtual void Apply(int &Field) { virtual void Apply(int &Field) {
Elements.push_back(ConstantUInt::get(Type::IntTy, Field)); Elements.push_back(ConstantSInt::get(Type::IntTy, Field));
} }
virtual void Apply(unsigned &Field) { virtual void Apply(unsigned &Field) {
Elements.push_back(ConstantUInt::get(Type::UIntTy, Field)); Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
@@ -314,7 +296,11 @@ public:
} }
virtual void Apply(GlobalVariable *&Field) { virtual void Apply(GlobalVariable *&Field) {
const PointerType *EmptyTy = SR.getEmptyStructPtrType(); const PointerType *EmptyTy = SR.getEmptyStructPtrType();
Elements.push_back(ConstantExpr::getCast(Field, EmptyTy)); if (Field) {
Elements.push_back(ConstantExpr::getCast(Field, EmptyTy));
} else {
Elements.push_back(ConstantPointerNull::get(EmptyTy));
}
} }
}; };
@@ -373,7 +359,7 @@ public:
: DIVisitor() : DIVisitor()
, VR(V) , VR(V)
, IsValid(true) , IsValid(true)
, I(1) , I(0)
, CI(cast<ConstantStruct>(GV->getInitializer())) , CI(cast<ConstantStruct>(GV->getInitializer()))
{ {
} }
@@ -410,36 +396,146 @@ public:
} }
}; };
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// TagFromGlobal - Returns the Tag number from a debug info descriptor
/// GlobalVariable.
unsigned DebugInfoDesc::TagFromGlobal(GlobalVariable *GV) {
ConstantUInt *C = getUIntOperand(GV, 0);
return C ? (unsigned)C->getValue() : (unsigned)DIInvalid;
}
/// DescFactory - Create an instance of debug info descriptor based on Tag.
/// Return NULL if not a recognized Tag.
DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) {
switch (Tag) {
case DI_TAG_anchor: return new AnchorDesc();
case DI_TAG_compile_unit: return new CompileUnitDesc();
case DI_TAG_global_variable: return new GlobalVariableDesc();
case DI_TAG_subprogram: return new SubprogramDesc();
default: break;
}
return NULL;
}
/// getLinkage - get linkage appropriate for this type of descriptor.
///
GlobalValue::LinkageTypes DebugInfoDesc::getLinkage() const {
return GlobalValue::InternalLinkage;
}
/// ApplyToFields - Target the vistor to the fields of the descriptor.
///
void DebugInfoDesc::ApplyToFields(DIVisitor *Visitor) {
Visitor->Apply(Tag);
}
//===----------------------------------------------------------------------===//
/// getLinkage - get linkage appropriate for this type of descriptor.
///
GlobalValue::LinkageTypes AnchorDesc::getLinkage() const {
return GlobalValue::LinkOnceLinkage;
}
/// ApplyToFields - Target the visitor to the fields of the TransUnitDesc.
///
void AnchorDesc::ApplyToFields(DIVisitor *Visitor) {
DebugInfoDesc::ApplyToFields(Visitor);
Visitor->Apply(Name);
}
/// getDescString - Return a string used to compose global names and labels.
///
const char *AnchorDesc::getDescString() const {
return Name.c_str();
}
/// getTypeString - Return a string used to label this descriptors type.
///
const char *AnchorDesc::getTypeString() const {
return "llvm.dbg.anchor.type";
}
#ifndef NDEBUG
void AnchorDesc::dump() {
std::cerr << getDescString() << " "
<< "Tag(" << getTag() << "), "
<< "Name(" << Name << ")\n";
}
#endif
//===----------------------------------------------------------------------===//
AnchoredDesc::AnchoredDesc(unsigned T)
: DebugInfoDesc(T)
, Anchor(NULL)
{}
/// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
///
void AnchoredDesc::ApplyToFields(DIVisitor *Visitor) {
DebugInfoDesc::ApplyToFields(Visitor);
Visitor->Apply((DebugInfoDesc *&)Anchor);
}
//===----------------------------------------------------------------------===//
CompileUnitDesc::CompileUnitDesc()
: AnchoredDesc(DI_TAG_compile_unit)
, DebugVersion(LLVMDebugVersion)
, Language(0)
, FileName("")
, Directory("")
, Producer("")
{}
/// DebugVersionFromGlobal - Returns the version number from a compile unit /// DebugVersionFromGlobal - Returns the version number from a compile unit
/// GlobalVariable. /// GlobalVariable.
unsigned CompileUnitDesc::DebugVersionFromGlobal(GlobalVariable *GV) { unsigned CompileUnitDesc::DebugVersionFromGlobal(GlobalVariable *GV) {
ConstantUInt *C = getUIntOperand(GV, 1); ConstantUInt *C = getUIntOperand(GV, 2);
return C ? (unsigned)C->getValue() : (unsigned)DIInvalid; return C ? (unsigned)C->getValue() : (unsigned)DIInvalid;
} }
/// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc. /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
/// ///
void CompileUnitDesc::ApplyToFields(DIVisitor *Visitor) { void CompileUnitDesc::ApplyToFields(DIVisitor *Visitor) {
AnchoredDesc::ApplyToFields(Visitor);
Visitor->Apply(DebugVersion); Visitor->Apply(DebugVersion);
Visitor->Apply(Language); Visitor->Apply(Language);
Visitor->Apply(FileName); Visitor->Apply(FileName);
Visitor->Apply(Directory); Visitor->Apply(Directory);
Visitor->Apply(Producer); Visitor->Apply(Producer);
Visitor->Apply(TransUnit);
} }
/// TypeString - Return a string used to compose globalnames and labels. /// getDescString - Return a string used to compose global names and labels.
/// ///
const char *CompileUnitDesc::TypeString() const { const char *CompileUnitDesc::getDescString() const {
return "compile_unit"; return "llvm.dbg.compile_unit";
}
/// getTypeString - Return a string used to label this descriptors type.
///
const char *CompileUnitDesc::getTypeString() const {
return "llvm.dbg.compile_unit.type";
}
/// getAnchorString - Return a string used to label this descriptor's anchor.
///
const char *CompileUnitDesc::getAnchorString() const {
return "llvm.dbg.compile_units";
} }
#ifndef NDEBUG #ifndef NDEBUG
void CompileUnitDesc::dump() { void CompileUnitDesc::dump() {
std::cerr << TypeString() << " " std::cerr << getDescString() << " "
<< "Tag(" << getTag() << "), " << "Tag(" << getTag() << "), "
<< "Anchor(" << getAnchor() << "), "
<< "DebugVersion(" << DebugVersion << "), "
<< "Language(" << Language << "), " << "Language(" << Language << "), "
<< "FileName(\"" << FileName << "\"), " << "FileName(\"" << FileName << "\"), "
<< "Directory(\"" << Directory << "\"), " << "Directory(\"" << Directory << "\"), "
@@ -449,76 +545,122 @@ void CompileUnitDesc::dump() {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// ApplyToFields - Target the visitor to the fields of the GlobalVariableDesc. GlobalDesc::GlobalDesc(unsigned T)
: AnchoredDesc(T)
, Context(0)
, Name("")
, TyDesc(NULL)
, IsStatic(false)
, IsDefinition(false)
{}
/// ApplyToFields - Target the visitor to the fields of the global.
/// ///
void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) { void GlobalDesc::ApplyToFields(DIVisitor *Visitor) {
AnchoredDesc::ApplyToFields(Visitor);
Visitor->Apply(Context); Visitor->Apply(Context);
Visitor->Apply(Name); Visitor->Apply(Name);
Visitor->Apply(TransUnit);
Visitor->Apply(TyDesc); Visitor->Apply(TyDesc);
Visitor->Apply(IsStatic); Visitor->Apply(IsStatic);
Visitor->Apply(IsDefinition); Visitor->Apply(IsDefinition);
}
//===----------------------------------------------------------------------===//
GlobalVariableDesc::GlobalVariableDesc()
: GlobalDesc(DI_TAG_global_variable)
, Global(NULL)
{}
/// ApplyToFields - Target the visitor to the fields of the GlobalVariableDesc.
///
void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) {
GlobalDesc::ApplyToFields(Visitor);
Visitor->Apply(Global); Visitor->Apply(Global);
} }
/// TypeString - Return a string used to compose globalnames and labels. /// getDescString - Return a string used to compose global names and labels.
/// ///
const char *GlobalVariableDesc::TypeString() const { const char *GlobalVariableDesc::getDescString() const {
return "global_variable"; return "llvm.dbg.global_variable";
}
/// getTypeString - Return a string used to label this descriptors type.
///
const char *GlobalVariableDesc::getTypeString() const {
return "llvm.dbg.global_variable.type";
}
/// getAnchorString - Return a string used to label this descriptor's anchor.
///
const char *GlobalVariableDesc::getAnchorString() const {
return "llvm.dbg.global_variables";
} }
#ifndef NDEBUG #ifndef NDEBUG
void GlobalVariableDesc::dump() { void GlobalVariableDesc::dump() {
std::cerr << TypeString() << " " std::cerr << getDescString() << " "
<< "Tag(" << getTag() << "), " << "Tag(" << getTag() << "), "
<< "Name(\"" << Name << "\"), " << "Anchor(" << getAnchor() << "), "
<< "Type(" << TyDesc << "), " << "Name(\"" << getName() << "\"), "
<< "IsStatic(" << (IsStatic ? "true" : "false") << "), " << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
<< "IsDefinition(" << (IsDefinition ? "true" : "false") << "), " << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), "
<< "Global(" << Global << ")\n"; << "Global(" << Global << ")\n";
} }
#endif #endif
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
SubprogramDesc::SubprogramDesc()
: GlobalDesc(DI_TAG_subprogram)
{}
/// ApplyToFields - Target the visitor to the fields of the /// ApplyToFields - Target the visitor to the fields of the
/// SubprogramDesc. /// SubprogramDesc.
void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) { void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) {
Visitor->Apply(Context); GlobalDesc::ApplyToFields(Visitor);
Visitor->Apply(Name);
Visitor->Apply(TransUnit);
Visitor->Apply(TyDesc);
Visitor->Apply(IsStatic);
Visitor->Apply(IsDefinition);
// FIXME - Temp variable until restructured.
GlobalVariable *Tmp;
Visitor->Apply(Tmp);
} }
/// TypeString - Return a string used to compose globalnames and labels. /// getDescString - Return a string used to compose global names and labels.
/// ///
const char *SubprogramDesc::TypeString() const { const char *SubprogramDesc::getDescString() const {
return "subprogram"; return "llvm.dbg.subprogram";
}
/// getTypeString - Return a string used to label this descriptors type.
///
const char *SubprogramDesc::getTypeString() const {
return "llvm.dbg.subprogram.type";
}
/// getAnchorString - Return a string used to label this descriptor's anchor.
///
const char *SubprogramDesc::getAnchorString() const {
return "llvm.dbg.subprograms";
} }
#ifndef NDEBUG #ifndef NDEBUG
void SubprogramDesc::dump() { void SubprogramDesc::dump() {
std::cerr << TypeString() << " " std::cerr << getDescString() << " "
<< "Tag(" << getTag() << "), " << "Tag(" << getTag() << "), "
<< "Name(\"" << Name << "\"), " << "Anchor(" << getAnchor() << "), "
<< "Type(" << TyDesc << "), " << "Name(\"" << getName() << "\"), "
<< "IsStatic(" << (IsStatic ? "true" : "false") << "), " << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
<< "IsDefinition(" << (IsDefinition ? "true" : "false") << ")\n"; << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n";
} }
#endif #endif
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
DebugInfoDesc *DIDeserializer::Deserialize(Value *V) { DebugInfoDesc *DIDeserializer::Deserialize(Value *V) {
return Deserialize(cast<GlobalVariable>(V)); return Deserialize(getGlobalVariable(V));
} }
DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) { DebugInfoDesc *DIDeserializer::Deserialize(GlobalVariable *GV) {
// Handle NULL.
if (!GV) return NULL;
// Check to see if it has been already deserialized. // Check to see if it has been already deserialized.
DebugInfoDesc *&Slot = GlobalDescs[GV]; DebugInfoDesc *&Slot = GlobalDescs[GV];
if (Slot) return Slot; if (Slot) return Slot;
@@ -579,25 +721,17 @@ const StructType *DISerializer::getTagType(DebugInfoDesc *DD) {
// If not already defined. // If not already defined.
if (!Ty) { if (!Ty) {
// Get descriptor type name.
const char *TS = DD->TypeString();
// Set up fields vector. // Set up fields vector.
std::vector<const Type*> Fields; std::vector<const Type*> Fields;
// Add tag field. // Get types of fields.
Fields.push_back(Type::UIntTy);
// Get types of remaining fields.
DIGetTypesVisitor GTAM(*this, Fields); DIGetTypesVisitor GTAM(*this, Fields);
GTAM.ApplyToFields(DD); GTAM.ApplyToFields(DD);
// Construct structured type. // Construct structured type.
Ty = StructType::get(Fields); Ty = StructType::get(Fields);
// Construct a name for the type.
const std::string Name = std::string("lldb.") + DD->TypeString() + ".type";
// Register type name with module. // Register type name with module.
M->addTypeName(Name, Ty); M->addTypeName(DD->getTypeString(), Ty);
} }
return Ty; return Ty;
@@ -605,17 +739,21 @@ const StructType *DISerializer::getTagType(DebugInfoDesc *DD) {
/// getString - Construct the string as constant string global. /// getString - Construct the string as constant string global.
/// ///
GlobalVariable *DISerializer::getString(const std::string &String) { Constant *DISerializer::getString(const std::string &String) {
// Check string cache for previous edition. // Check string cache for previous edition.
GlobalVariable *&Slot = StringCache[String]; Constant *&Slot = StringCache[String];
// return GlobalVariable if previously defined. // return Constant if previously defined.
if (Slot) return Slot; if (Slot) return Slot;
// Construct strings as an llvm constant. // Construct string as an llvm constant.
Constant *ConstStr = ConstantArray::get(String); Constant *ConstStr = ConstantArray::get(String);
// Otherwise create and return a new string global. // Otherwise create and return a new string global.
return Slot = new GlobalVariable(ConstStr->getType(), true, GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
GlobalVariable::InternalLinkage, GlobalVariable::InternalLinkage,
ConstStr, "str", M); ConstStr, "str", M);
// Convert to generic string pointer.
Slot = ConstantExpr::getCast(StrGV, getStrPtrType());
return Slot;
} }
/// Serialize - Recursively cast the specified descriptor into a GlobalVariable /// Serialize - Recursively cast the specified descriptor into a GlobalVariable
@@ -627,29 +765,19 @@ GlobalVariable *DISerializer::Serialize(DebugInfoDesc *DD) {
// See if DebugInfoDesc exists, if so return prior GlobalVariable. // See if DebugInfoDesc exists, if so return prior GlobalVariable.
if (Slot) return Slot; if (Slot) return Slot;
// Get DebugInfoDesc type Tag.
unsigned Tag = DD->getTag();
// Construct name.
const std::string Name = std::string("lldb.") +
DD->TypeString();
// Get the type associated with the Tag. // Get the type associated with the Tag.
const StructType *Ty = getTagType(DD); const StructType *Ty = getTagType(DD);
// Create the GlobalVariable early to prevent infinite recursion. // Create the GlobalVariable early to prevent infinite recursion.
GlobalVariable *GV = new GlobalVariable(Ty, true, GlobalVariable *GV = new GlobalVariable(Ty, true, DD->getLinkage(),
GlobalValue::InternalLinkage, NULL, DD->getDescString(), M);
NULL, Name, M);
// Insert new GlobalVariable in DescGlobals map. // Insert new GlobalVariable in DescGlobals map.
Slot = GV; Slot = GV;
// Set up elements vector // Set up elements vector
std::vector<Constant*> Elements; std::vector<Constant*> Elements;
// Add Tag value. // Add fields.
Elements.push_back(ConstantUInt::get(Type::UIntTy, Tag));
// Add remaining fields.
DISerializeVisitor SRAM(*this, Elements); DISerializeVisitor SRAM(*this, Elements);
SRAM.ApplyToFields(DD); SRAM.ApplyToFields(DD);
@@ -678,6 +806,9 @@ bool DIVerifier::markVisited(GlobalVariable *GV) {
/// Verify - Return true if the GlobalVariable appears to be a valid /// Verify - Return true if the GlobalVariable appears to be a valid
/// serialization of a DebugInfoDesc. /// serialization of a DebugInfoDesc.
bool DIVerifier::Verify(Value *V) {
return Verify(getGlobalVariable(V));
}
bool DIVerifier::Verify(GlobalVariable *GV) { bool DIVerifier::Verify(GlobalVariable *GV) {
// Check if seen before. // Check if seen before.
if (markVisited(GV)) return true; if (markVisited(GV)) return true;
@@ -732,9 +863,7 @@ bool DIVerifier::Verify(GlobalVariable *GV) {
MachineDebugInfo::MachineDebugInfo() MachineDebugInfo::MachineDebugInfo()
: SR() : DR()
, DR()
, VR()
, CompileUnits() , CompileUnits()
, Directories() , Directories()
, SourceFiles() , SourceFiles()
@@ -758,22 +887,32 @@ bool MachineDebugInfo::doFinalization() {
return false; return false;
} }
/// Deserialize - Convert a Value to a debug information descriptor.
///
DebugInfoDesc *MachineDebugInfo::Deserialize(Value *V) {
return DR.Deserialize(V);
}
/// Verify - Verify that a Value is debug information descriptor.
///
bool MachineDebugInfo::Verify(Value *V) {
DIVerifier VR;
return VR.Verify(V);
}
/// AnalyzeModule - Scan the module for global debug information. /// AnalyzeModule - Scan the module for global debug information.
/// ///
void MachineDebugInfo::AnalyzeModule(Module &M) { void MachineDebugInfo::AnalyzeModule(Module &M) {
SR.setModule(&M);
DR.setModule(&M);
SetupCompileUnits(M); SetupCompileUnits(M);
} }
/// SetupCompileUnits - Set up the unique vector of compile units. /// SetupCompileUnits - Set up the unique vector of compile units.
/// ///
void MachineDebugInfo::SetupCompileUnits(Module &M) { void MachineDebugInfo::SetupCompileUnits(Module &M) {
SR.setModule(&M);
DR.setModule(&M);
// Get vector of all debug compile units. // Get vector of all debug compile units.
CompileUnitDesc CompileUnit;
std::vector<GlobalVariable*> Globals = std::vector<GlobalVariable*> Globals =
getGlobalVariablesUsing(M, "llvm.dbg.translation_units"); getGlobalVariablesUsing(M, CompileUnit.getAnchorString());
// Scan all compile unit globals. // Scan all compile unit globals.
for (unsigned i = 0, N = Globals.size(); i < N; ++i) { for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
@@ -793,11 +932,10 @@ const UniqueVector<CompileUnitDesc *> MachineDebugInfo::getCompileUnits()const{
/// ///
std::vector<GlobalVariableDesc *> std::vector<GlobalVariableDesc *>
MachineDebugInfo::getGlobalVariables(Module &M) { MachineDebugInfo::getGlobalVariables(Module &M) {
SR.setModule(&M);
DR.setModule(&M);
// Get vector of all debug global objects. // Get vector of all debug global objects.
GlobalVariableDesc Global;
std::vector<GlobalVariable*> Globals = std::vector<GlobalVariable*> Globals =
getGlobalVariablesUsing(M, "llvm.dbg.globals"); getGlobalVariablesUsing(M, Global.getAnchorString());
// Accumulation of GlobalVariables. // Accumulation of GlobalVariables.
std::vector<GlobalVariableDesc *> GlobalVariables; std::vector<GlobalVariableDesc *> GlobalVariables;
@@ -805,11 +943,9 @@ MachineDebugInfo::getGlobalVariables(Module &M) {
// Scan all globals. // Scan all globals.
for (unsigned i = 0, N = Globals.size(); i < N; ++i) { for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
GlobalVariable *GV = Globals[i]; GlobalVariable *GV = Globals[i];
if (DebugInfoDesc::TagFromGlobal(GV) == DI_TAG_global_variable) { GlobalVariableDesc *GVD =
GlobalVariableDesc *GVD = static_cast<GlobalVariableDesc *>(DR.Deserialize(GV));
static_cast<GlobalVariableDesc *>(DR.Deserialize(GV)); GlobalVariables.push_back(GVD);
GlobalVariables.push_back(GVD);
}
} }
return GlobalVariables; return GlobalVariables;

View File

@@ -941,33 +941,30 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
if (TLI.getTargetMachine().getIntrinsicLowering().EmitDebugFunctions()) if (TLI.getTargetMachine().getIntrinsicLowering().EmitDebugFunctions())
return "llvm_debugger_stop"; return "llvm_debugger_stop";
std::string fname = "<unknown>"; MachineDebugInfo *DebugInfo = DAG.getMachineDebugInfo();
std::vector<SDOperand> Ops; if (DebugInfo && DebugInfo->Verify(I.getOperand(4))) {
std::vector<SDOperand> Ops;
// Input Chain // Input Chain
Ops.push_back(getRoot()); Ops.push_back(getRoot());
// line number // line number
Ops.push_back(getValue(I.getOperand(2))); Ops.push_back(getValue(I.getOperand(2)));
// column // column
Ops.push_back(getValue(I.getOperand(3))); Ops.push_back(getValue(I.getOperand(3)));
// filename/working dir DebugInfoDesc *DD = DebugInfo->Deserialize(I.getOperand(4));
// Pull the filename out of the the compilation unit. assert(DD && "Not a debug information descriptor");
const GlobalVariable *cunit = dyn_cast<GlobalVariable>(I.getOperand(4)); CompileUnitDesc *CompileUnit = dyn_cast<CompileUnitDesc>(DD);
if (cunit && cunit->hasInitializer()) { assert(CompileUnit && "Not a compile unit");
if (ConstantStruct *CS = Ops.push_back(DAG.getString(CompileUnit->getFileName()));
dyn_cast<ConstantStruct>(cunit->getInitializer())) { Ops.push_back(DAG.getString(CompileUnit->getDirectory()));
if (CS->getNumOperands() > 0) {
Ops.push_back(DAG.getString(getStringValue(CS->getOperand(3)))); if (Ops.size() == 5) // Found filename/workingdir.
Ops.push_back(DAG.getString(getStringValue(CS->getOperand(4)))); DAG.setRoot(DAG.getNode(ISD::LOCATION, MVT::Other, Ops));
}
}
} }
if (Ops.size() == 5) // Found filename/workingdir.
DAG.setRoot(DAG.getNode(ISD::LOCATION, MVT::Other, Ops));
setValue(&I, DAG.getNode(ISD::UNDEF, TLI.getValueType(I.getType()))); setValue(&I, DAG.getNode(ISD::UNDEF, TLI.getValueType(I.getType())));
return 0; return 0;
} }