Expand subprogram and added block descriptor.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26782 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jim Laskey 2006-03-15 19:09:58 +00:00
parent 26c2e73da6
commit 9d0ff8e6f9
3 changed files with 128 additions and 40 deletions

View File

@ -55,7 +55,7 @@ class StructType;
// Debug info constants. // Debug info constants.
enum { enum {
LLVMDebugVersion = 1 // Current version of debug information. LLVMDebugVersion = 2 // Current version of debug information.
}; };
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -274,8 +274,8 @@ class TypeDesc : public DebugInfoDesc {
private: private:
DebugInfoDesc *Context; // Context debug descriptor. DebugInfoDesc *Context; // Context debug descriptor.
std::string Name; // Type name (may be empty.) std::string Name; // Type name (may be empty.)
CompileUnitDesc *File; // Declared compile unit (may be NULL.) CompileUnitDesc *File; // Defined compile unit (may be NULL.)
int Line; // Declared line# (may be zero.) unsigned Line; // Defined line# (may be zero.)
uint64_t Size; // Type bit size (may be zero.) uint64_t Size; // Type bit size (may be zero.)
uint64_t Align; // Type bit alignment (may be zero.) uint64_t Align; // Type bit alignment (may be zero.)
uint64_t Offset; // Type bit offset (may be zero.) uint64_t Offset; // Type bit offset (may be zero.)
@ -287,14 +287,14 @@ public:
DebugInfoDesc *getContext() const { return Context; } DebugInfoDesc *getContext() const { return Context; }
const std::string &getName() const { return Name; } const std::string &getName() const { return Name; }
CompileUnitDesc *getFile() const { return File; } CompileUnitDesc *getFile() const { return File; }
int getLine() const { return Line; } unsigned getLine() const { return Line; }
uint64_t getSize() const { return Size; } uint64_t getSize() const { return Size; }
uint64_t getAlign() const { return Align; } uint64_t getAlign() const { return Align; }
uint64_t getOffset() const { return Offset; } uint64_t getOffset() const { return Offset; }
void setContext(DebugInfoDesc *C) { Context = C; } void setContext(DebugInfoDesc *C) { Context = C; }
void setName(const std::string &N) { Name = N; } void setName(const std::string &N) { Name = N; }
void setFile(CompileUnitDesc *U) { File = U; } void setFile(CompileUnitDesc *U) { File = U; }
void setLine(int L) { Line = L; } void setLine(unsigned L) { Line = L; }
void setSize(uint64_t S) { Size = S; } void setSize(uint64_t S) { Size = S; }
void setAlign(uint64_t A) { Align = A; } void setAlign(uint64_t A) { Align = A; }
void setOffset(uint64_t O) { Offset = O; } void setOffset(uint64_t O) { Offset = O; }
@ -504,6 +504,8 @@ 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.
CompileUnitDesc *File; // Defined compile unit (may be NULL.)
unsigned Line; // Defined line# (may be zero.)
TypeDesc *TyDesc; // Type debug descriptor. TypeDesc *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.
@ -515,11 +517,15 @@ public:
// 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; }
CompileUnitDesc *getFile() const { return File; }
unsigned getLine() const { return Line; }
TypeDesc *getTypeDesc() const { return TyDesc; } TypeDesc *getTypeDesc() const { return TyDesc; }
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 setContext(DebugInfoDesc *C) { Context = C; }
void setName(const std::string &N) { Name = N; } void setName(const std::string &N) { Name = N; }
void setFile(CompileUnitDesc *U) { File = U; }
void setLine(unsigned L) { Line = L; }
void setTypeDesc(TypeDesc *T) { TyDesc = T; } void setTypeDesc(TypeDesc *T) { TyDesc = T; }
void setIsStatic(bool IS) { IsStatic = IS; } void setIsStatic(bool IS) { IsStatic = IS; }
void setIsDefinition(bool ID) { IsDefinition = ID; } void setIsDefinition(bool ID) { IsDefinition = ID; }
@ -535,16 +541,13 @@ public:
class GlobalVariableDesc : public GlobalDesc { class GlobalVariableDesc : public GlobalDesc {
private: private:
GlobalVariable *Global; // llvm global. GlobalVariable *Global; // llvm global.
unsigned Line; // Source line number.
public: public:
GlobalVariableDesc(); GlobalVariableDesc();
// Accessors. // Accessors.
GlobalVariable *getGlobalVariable() const { return Global; } GlobalVariable *getGlobalVariable() const { return Global; }
unsigned getLine() const { return Line; }
void setGlobalVariable(GlobalVariable *GV) { Global = GV; } void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
void setLine(unsigned L) { Line = L; }
// Implement isa/cast/dyncast. // Implement isa/cast/dyncast.
static bool classof(const GlobalVariableDesc *) { return true; } static bool classof(const GlobalVariableDesc *) { return true; }
@ -577,19 +580,20 @@ public:
/// subprogram/function. /// subprogram/function.
class SubprogramDesc : public GlobalDesc { class SubprogramDesc : public GlobalDesc {
private: private:
// FIXME - Other attributes std::vector<DebugInfoDesc *> Elements;// Information about args, variables
// and blocks.
public: public:
SubprogramDesc(); SubprogramDesc();
// Accessors // Accessors
// FIXME - Other getters/setters. std::vector<DebugInfoDesc *> &getElements() { return Elements; }
// Implement isa/cast/dyncast. // Implement isa/cast/dyncast.
static bool classof(const SubprogramDesc *) { return true; } static bool classof(const SubprogramDesc *) { return true; }
static bool classof(const DebugInfoDesc *D); static bool classof(const DebugInfoDesc *D);
/// ApplyToFields - Target the visitor to the fields of the SubprogramDesc. /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
/// ///
virtual void ApplyToFields(DIVisitor *Visitor); virtual void ApplyToFields(DIVisitor *Visitor);
@ -611,6 +615,40 @@ public:
#endif #endif
}; };
//===----------------------------------------------------------------------===//
/// BlockDesc - This descriptor groups variables and blocks nested in a block.
///
class BlockDesc : public DebugInfoDesc {
private:
std::vector<DebugInfoDesc *> Elements;// Information about nested variables
// and blocks.
public:
BlockDesc();
// Accessors
std::vector<DebugInfoDesc *> &getElements() { return Elements; }
// Implement isa/cast/dyncast.
static bool classof(const BlockDesc *) { return true; }
static bool classof(const DebugInfoDesc *D);
/// ApplyToFields - Target the visitor to the fields of the BlockDesc.
///
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
};
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// DIDeserializer - This class is responsible for casting GlobalVariables /// DIDeserializer - This class is responsible for casting GlobalVariables
/// into DebugInfoDesc objects. /// into DebugInfoDesc objects.

View File

@ -1518,19 +1518,19 @@ DIE *DwarfWriter::NewSubprogram(SubprogramDesc *SPD) {
// Gather the details (simplify add attribute code.) // Gather the details (simplify add attribute code.)
const std::string &Name = SPD->getName(); const std::string &Name = SPD->getName();
unsigned FileID = Unit->getID(); CompileUnitDesc *FileDesc = static_cast<CompileUnitDesc *>(SPD->getFile());
// FIXME - faking the line for the time being. CompileUnit *File = FindCompileUnit(FileDesc);
unsigned Line = 1; unsigned FileID = File->getID();
DIE *Type = NewBasicType(Unit->getDie(), Type::IntTy);
// FIXME - faking the type for the time being. unsigned Line = SPD->getLine();
DIE *Type = NewBasicType(Unit->getDie(), Type::IntTy); unsigned IsExternal = SPD->isStatic() ? 0 : 1;
DIE *SubprogramDie = new DIE(DW_TAG_subprogram); DIE *SubprogramDie = new DIE(DW_TAG_subprogram);
SubprogramDie->AddString (DW_AT_name, DW_FORM_string, Name); SubprogramDie->AddString (DW_AT_name, DW_FORM_string, Name);
SubprogramDie->AddUInt (DW_AT_decl_file, 0, FileID); SubprogramDie->AddUInt (DW_AT_decl_file, 0, FileID);
SubprogramDie->AddUInt (DW_AT_decl_line, 0, Line); SubprogramDie->AddUInt (DW_AT_decl_line, 0, Line);
SubprogramDie->AddDIEntry (DW_AT_type, DW_FORM_ref4, Type); SubprogramDie->AddDIEntry (DW_AT_type, DW_FORM_ref4, Type);
SubprogramDie->AddUInt (DW_AT_external, DW_FORM_flag, 1); SubprogramDie->AddUInt (DW_AT_external, DW_FORM_flag, IsExternal);
// Add to map. // Add to map.
Slot = SubprogramDie; Slot = SubprogramDie;

View File

@ -270,16 +270,12 @@ public:
Elements.push_back(ConstantBool::get(Field)); Elements.push_back(ConstantBool::get(Field));
} }
virtual void Apply(std::string &Field) { virtual void Apply(std::string &Field) {
if (Field.empty()) {
Elements.push_back(NULL);
} else {
Elements.push_back(SR.getString(Field)); Elements.push_back(SR.getString(Field));
}
} }
virtual void Apply(DebugInfoDesc *&Field) { virtual void Apply(DebugInfoDesc *&Field) {
GlobalVariable *GV = NULL; GlobalVariable *GV = NULL;
// If non-NULL the convert to global. // If non-NULL then convert to global.
if (Field) GV = SR.Serialize(Field); if (Field) GV = SR.Serialize(Field);
// FIXME - At some point should use specific type. // FIXME - At some point should use specific type.
@ -473,19 +469,21 @@ DebugInfoDesc *DebugInfoDesc::DescFactory(unsigned Tag) {
case DW_TAG_compile_unit: return new CompileUnitDesc(); case DW_TAG_compile_unit: return new CompileUnitDesc();
case DW_TAG_variable: return new GlobalVariableDesc(); case DW_TAG_variable: return new GlobalVariableDesc();
case DW_TAG_subprogram: return new SubprogramDesc(); case DW_TAG_subprogram: return new SubprogramDesc();
case DW_TAG_lexical_block: return new BlockDesc();
case DW_TAG_base_type: return new BasicTypeDesc(); case DW_TAG_base_type: return new BasicTypeDesc();
case DW_TAG_typedef: case DW_TAG_typedef:
case DW_TAG_pointer_type: case DW_TAG_pointer_type:
case DW_TAG_reference_type: case DW_TAG_reference_type:
case DW_TAG_const_type: case DW_TAG_const_type:
case DW_TAG_volatile_type: case DW_TAG_volatile_type:
case DW_TAG_restrict_type: return new DerivedTypeDesc(Tag); case DW_TAG_restrict_type:
case DW_TAG_formal_parameter:
case DW_TAG_member: return new DerivedTypeDesc(Tag);
case DW_TAG_array_type: case DW_TAG_array_type:
case DW_TAG_structure_type: case DW_TAG_structure_type:
case DW_TAG_union_type: case DW_TAG_union_type:
case DW_TAG_enumeration_type: return new CompositeTypeDesc(Tag); case DW_TAG_enumeration_type: return new CompositeTypeDesc(Tag);
case DW_TAG_subrange_type: return new SubrangeDesc(); case DW_TAG_subrange_type: return new SubrangeDesc();
case DW_TAG_member: return new DerivedTypeDesc(DW_TAG_member);
case DW_TAG_enumerator: return new EnumeratorDesc(); case DW_TAG_enumerator: return new EnumeratorDesc();
default: break; default: break;
} }
@ -761,6 +759,7 @@ bool DerivedTypeDesc::classof(const DebugInfoDesc *D) {
case DW_TAG_const_type: case DW_TAG_const_type:
case DW_TAG_volatile_type: case DW_TAG_volatile_type:
case DW_TAG_restrict_type: case DW_TAG_restrict_type:
case DW_TAG_formal_parameter:
case DW_TAG_member: case DW_TAG_member:
return true; return true;
default: break; default: break;
@ -948,6 +947,8 @@ GlobalDesc::GlobalDesc(unsigned T)
: AnchoredDesc(T) : AnchoredDesc(T)
, Context(0) , Context(0)
, Name("") , Name("")
, File(NULL)
, Line(0)
, TyDesc(NULL) , TyDesc(NULL)
, IsStatic(false) , IsStatic(false)
, IsDefinition(false) , IsDefinition(false)
@ -960,6 +961,8 @@ void GlobalDesc::ApplyToFields(DIVisitor *Visitor) {
Visitor->Apply(Context); Visitor->Apply(Context);
Visitor->Apply(Name); Visitor->Apply(Name);
Visitor->Apply((DebugInfoDesc *&)File);
Visitor->Apply(Line);
Visitor->Apply((DebugInfoDesc *&)TyDesc); Visitor->Apply((DebugInfoDesc *&)TyDesc);
Visitor->Apply(IsStatic); Visitor->Apply(IsStatic);
Visitor->Apply(IsDefinition); Visitor->Apply(IsDefinition);
@ -983,7 +986,6 @@ void GlobalVariableDesc::ApplyToFields(DIVisitor *Visitor) {
GlobalDesc::ApplyToFields(Visitor); GlobalDesc::ApplyToFields(Visitor);
Visitor->Apply(Global); Visitor->Apply(Global);
Visitor->Apply(Line);
} }
/// getDescString - Return a string used to compose global names and labels. /// getDescString - Return a string used to compose global names and labels.
@ -1011,11 +1013,12 @@ void GlobalVariableDesc::dump() {
<< "Tag(" << getTag() << "), " << "Tag(" << getTag() << "), "
<< "Anchor(" << getAnchor() << "), " << "Anchor(" << getAnchor() << "), "
<< "Name(\"" << getName() << "\"), " << "Name(\"" << getName() << "\"), "
<< "File(" << getFile() << "),"
<< "Line(" << getLine() << "),"
<< "Type(\"" << getTypeDesc() << "\"), " << "Type(\"" << getTypeDesc() << "\"), "
<< "IsStatic(" << (isStatic() ? "true" : "false") << "), " << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
<< "IsDefinition(" << (isDefinition() ? "true" : "false") << "), " << "IsDefinition(" << (isDefinition() ? "true" : "false") << "), "
<< "Global(" << Global << "), " << "Global(" << Global << ")\n";
<< "Line(" << Line << ")\n";
} }
#endif #endif
@ -1034,6 +1037,8 @@ bool SubprogramDesc::classof(const DebugInfoDesc *D) {
/// SubprogramDesc. /// SubprogramDesc.
void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) { void SubprogramDesc::ApplyToFields(DIVisitor *Visitor) {
GlobalDesc::ApplyToFields(Visitor); GlobalDesc::ApplyToFields(Visitor);
Visitor->Apply(Elements);
} }
/// getDescString - Return a string used to compose global names and labels. /// getDescString - Return a string used to compose global names and labels.
@ -1061,6 +1066,8 @@ void SubprogramDesc::dump() {
<< "Tag(" << getTag() << "), " << "Tag(" << getTag() << "), "
<< "Anchor(" << getAnchor() << "), " << "Anchor(" << getAnchor() << "), "
<< "Name(\"" << getName() << "\"), " << "Name(\"" << getName() << "\"), "
<< "File(" << getFile() << "),"
<< "Line(" << getLine() << "),"
<< "Type(\"" << getTypeDesc() << "\"), " << "Type(\"" << getTypeDesc() << "\"), "
<< "IsStatic(" << (isStatic() ? "true" : "false") << "), " << "IsStatic(" << (isStatic() ? "true" : "false") << "), "
<< "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n"; << "IsDefinition(" << (isDefinition() ? "true" : "false") << ")\n";
@ -1069,6 +1076,44 @@ void SubprogramDesc::dump() {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
BlockDesc::BlockDesc()
: DebugInfoDesc(DW_TAG_lexical_block)
{}
// Implement isa/cast/dyncast.
bool BlockDesc::classof(const DebugInfoDesc *D) {
return D->getTag() == DW_TAG_lexical_block;
}
/// ApplyToFields - Target the visitor to the fields of the BlockDesc.
///
void BlockDesc::ApplyToFields(DIVisitor *Visitor) {
DebugInfoDesc::ApplyToFields(Visitor);
Visitor->Apply(Elements);
}
/// getDescString - Return a string used to compose global names and labels.
///
const char *BlockDesc::getDescString() const {
return "llvm.dbg.block";
}
/// getTypeString - Return a string used to label this descriptors type.
///
const char *BlockDesc::getTypeString() const {
return "llvm.dbg.block.type";
}
#ifndef NDEBUG
void BlockDesc::dump() {
std::cerr << getDescString() << " "
<< "Tag(" << getTag() << ")\n";
}
#endif
//===----------------------------------------------------------------------===//
DebugInfoDesc *DIDeserializer::Deserialize(Value *V) { DebugInfoDesc *DIDeserializer::Deserialize(Value *V) {
return Deserialize(getGlobalVariable(V)); return Deserialize(getGlobalVariable(V));
} }
@ -1159,17 +1204,22 @@ const StructType *DISerializer::getTagType(DebugInfoDesc *DD) {
Constant *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.
Constant *&Slot = StringCache[String]; Constant *&Slot = StringCache[String];
// return Constant if previously defined. // Return Constant if previously defined.
if (Slot) return Slot; if (Slot) return Slot;
// Construct string as an llvm constant. // If empty string then use a sbyte* null instead.
Constant *ConstStr = ConstantArray::get(String); if (String.empty()) {
// Otherwise create and return a new string global. Slot = ConstantPointerNull::get(getStrPtrType());
GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true, } else {
GlobalVariable::InternalLinkage, // Construct string as an llvm constant.
ConstStr, "str", M); Constant *ConstStr = ConstantArray::get(String);
StrGV->setSection("llvm.metadata"); // Otherwise create and return a new string global.
// Convert to generic string pointer. GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
Slot = ConstantExpr::getCast(StrGV, getStrPtrType()); GlobalVariable::InternalLinkage,
ConstStr, "str", M);
StrGV->setSection("llvm.metadata");
// Convert to generic string pointer.
Slot = ConstantExpr::getCast(StrGV, getStrPtrType());
}
return Slot; return Slot;
} }