DI_TAG_typedef,
DI_TAG_pointer,
DI_TAG_reference,
+ DI_TAG_array,
+ DI_TAG_struct,
+ DI_TAG_union,
+ DI_TAG_enum,
+ DI_TAG_subrange,
DI_TAG_const,
DI_TAG_volatile,
DI_TAG_restrict
/// appropriate action for the type of field.
virtual void Apply(int &Field) = 0;
virtual void Apply(unsigned &Field) = 0;
+ virtual void Apply(int64_t &Field) = 0;
virtual void Apply(uint64_t &Field) = 0;
virtual void Apply(bool &Field) = 0;
virtual void Apply(std::string &Field) = 0;
// Subclasses should supply the following static methods.
// Implement isa/cast/dyncast.
- static bool classof(const DebugInfoDesc *) { return true; }
+ static bool classof(const DebugInfoDesc *) { return true; }
//===--------------------------------------------------------------------===//
// Subclasses should supply the following virtual methods.
void setEncoding(unsigned E) { Encoding = E; }
// Implement isa/cast/dyncast.
- static bool classof(const BasicTypeDesc *) { return true; }
+ static bool classof(const BasicTypeDesc *) { return true; }
static bool classof(const DebugInfoDesc *D) {
return D->getTag() == DI_TAG_basictype;
}
///
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
void setFromType(TypeDesc *F) { FromType = F; }
// Implement isa/cast/dyncast.
- static bool classof(const DerivedTypeDesc *) { return true; }
+ static bool classof(const DerivedTypeDesc *) { return true; }
static bool classof(const DebugInfoDesc *D) {
unsigned T = D->getTag();
switch (T) {
case DI_TAG_volatile:
case DI_TAG_restrict:
return true;
- default: return false;
+ default: break;
}
+ return false;
}
/// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
///
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
+};
+
+//===----------------------------------------------------------------------===//
+/// CompositeTypeDesc - This class packages debug information associated with a
+/// array/struct types (eg., arrays, struct, union, enums.)
+class CompositeTypeDesc : public DerivedTypeDesc {
+private:
+ std::vector<DebugInfoDesc *> Elements;// Information used to compose type.
+
+public:
+ CompositeTypeDesc(unsigned T);
+
+ // Accessors
+ std::vector<DebugInfoDesc *> &getElements() { return Elements; }
+
+ // Implement isa/cast/dyncast.
+ static bool classof(const CompositeTypeDesc *) { return true; }
+ static bool classof(const DebugInfoDesc *D) {
+ unsigned T = D->getTag();
+ switch (T) {
+ case DI_TAG_array:
+ case DI_TAG_struct:
+ case DI_TAG_union:
+ case DI_TAG_enum:
+ return true;
+ default: break;
+ }
+ return false;
+ }
+
+ /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
+ ///
+ 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
+};
+
+//===----------------------------------------------------------------------===//
+/// SubrangeDesc - This class packages debug information associated with integer
+/// value ranges.
+class SubrangeDesc : public DebugInfoDesc {
+private:
+ int64_t Lo; // Low value of range
+ int64_t Hi; // High value of range
+
+public:
+ SubrangeDesc();
+
+ // Accessors
+ int64_t getLo() const { return Lo; }
+ int64_t getHi() const { return Hi; }
+ void setLo(int64_t L) { Lo = L; }
+ void setHi(int64_t H) { Hi = H; }
+
+ // Implement isa/cast/dyncast.
+ static bool classof(const SubrangeDesc *) { return true; }
+ static bool classof(const DebugInfoDesc *D) {
+ return D->getTag() == DI_TAG_subrange;
+ }
+
+ /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
+ ///
+ 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
void setLine(unsigned L) { Line = L; }
// Implement isa/cast/dyncast.
- static bool classof(const GlobalVariableDesc *) { return true; }
+ static bool classof(const GlobalVariableDesc *) { return true; }
static bool classof(const DebugInfoDesc *D) {
return D->getTag() == DI_TAG_global_variable;
}
// FIXME - Other getters/setters.
// Implement isa/cast/dyncast.
- static bool classof(const SubprogramDesc *) { return true; }
+ static bool classof(const SubprogramDesc *) { return true; }
static bool classof(const DebugInfoDesc *D) {
return D->getTag() == DI_TAG_subprogram;
}
// Determine which derived type.
unsigned T = 0;
switch (DerivedTy->getTag()) {
- case DI_TAG_typedef: T = DW_TAG_typedef; break;
- case DI_TAG_pointer: T = DW_TAG_pointer_type; break;
- case DI_TAG_reference: T = DW_TAG_reference_type; break;
- case DI_TAG_const: T = DW_TAG_const_type; break;
- case DI_TAG_volatile: T = DW_TAG_volatile_type; break;
- case DI_TAG_restrict: T = DW_TAG_restrict_type; break;
+ case DI_TAG_typedef: T = DW_TAG_typedef; break;
+ case DI_TAG_pointer: T = DW_TAG_pointer_type; break;
+ case DI_TAG_reference: T = DW_TAG_reference_type; break;
+ case DI_TAG_const: T = DW_TAG_const_type; break;
+ case DI_TAG_volatile: T = DW_TAG_volatile_type; break;
+ case DI_TAG_restrict: T = DW_TAG_restrict_type; break;
default: assert( 0 && "Unknown tag on derived type");
}
if (TypeDesc *FromTy = DerivedTy->getFromType()) {
Ty->AddDIEntry(DW_AT_type, DW_FORM_ref4, NewType(Unit, FromTy));
}
+ } else if (CompositeTypeDesc *CompTy = dyn_cast<CompositeTypeDesc>(TyDesc)) {
+ // Determine which composite type.
+ unsigned T = 0;
+ switch (CompTy->getTag()) {
+ case DI_TAG_array: T = DW_TAG_array_type; break;
+ case DI_TAG_struct: T = DW_TAG_structure_type; break;
+ case DI_TAG_union: T = DW_TAG_union_type; break;
+ case DI_TAG_enum: T = DW_TAG_enumeration_type; break;
+ default: assert( 0 && "Unknown tag on composite type");
+ }
+
+ // Create specific DIE.
+ Slot = Ty = new DIE(T);
+ std::vector<DebugInfoDesc *> &Elements = CompTy->getElements();
+
+ switch (CompTy->getTag()) {
+ case DI_TAG_array: {
+ // Add element type.
+ if (TypeDesc *FromTy = CompTy->getFromType()) {
+ Ty->AddDIEntry(DW_AT_type, DW_FORM_ref4, NewType(Unit, FromTy));
+ }
+ // Don't emit size attribute.
+ Size = 0;
+
+ // Construct an anonymous type for index type.
+ DIE *IndexTy = new DIE(DW_TAG_base_type);
+ IndexTy->AddUInt(DW_AT_byte_size, 0, 4);
+ IndexTy->AddUInt(DW_AT_encoding, DW_FORM_data1, DW_ATE_signed);
+ // Add to context.
+ Unit->getDie()->AddChild(IndexTy);
+
+ // Add subranges to array type.
+ for(unsigned i = 0, N = Elements.size(); i < N; ++i) {
+ SubrangeDesc *SRD = cast<SubrangeDesc>(Elements[i]);
+ int64_t Lo = SRD->getLo();
+ int64_t Hi = SRD->getHi();
+ DIE *Subrange = new DIE(DW_TAG_subrange_type);
+
+ // If a range is available.
+ if (Lo != Hi) {
+ Subrange->AddDIEntry(DW_AT_type, DW_FORM_ref4, IndexTy);
+ // Only add low if non-zero.
+ if (Lo) Subrange->AddUInt(DW_AT_lower_bound, 0, Lo);
+ Subrange->AddUInt(DW_AT_upper_bound, 0, Hi);
+ }
+ Ty->AddChild(Subrange);
+ }
+
+ break;
+ }
+ case DI_TAG_struct: {
+ break;
+ }
+ case DI_TAG_union: {
+ break;
+ }
+ case DI_TAG_enum: {
+ break;
+ }
+ default: break;
+ }
}
assert(Ty && "Type not supported yet");
///
virtual void Apply(int &Field) { ++Count; }
virtual void Apply(unsigned &Field) { ++Count; }
+ virtual void Apply(int64_t &Field) { ++Count; }
virtual void Apply(uint64_t &Field) { ++Count; }
virtual void Apply(bool &Field) { ++Count; }
virtual void Apply(std::string &Field) { ++Count; }
Constant *C = CI->getOperand(I++);
Field = cast<ConstantUInt>(C)->getValue();
}
+ virtual void Apply(int64_t &Field) {
+ Constant *C = CI->getOperand(I++);
+ Field = cast<ConstantSInt>(C)->getValue();
+ }
virtual void Apply(uint64_t &Field) {
Constant *C = CI->getOperand(I++);
Field = cast<ConstantUInt>(C)->getValue();
virtual void Apply(unsigned &Field) {
Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
}
+ virtual void Apply(int64_t &Field) {
+ Elements.push_back(ConstantSInt::get(Type::IntTy, Field));
+ }
virtual void Apply(uint64_t &Field) {
Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
}
}
Constant *CA = ConstantArray::get(AT, ArrayElements);
- Constant *CAE = ConstantExpr::getCast(CA, EmptyTy);
+ GlobalVariable *CAGV = new GlobalVariable(AT, true,
+ GlobalValue::InternalLinkage,
+ CA, "llvm.dbg.array",
+ SR.getModule());
+ Constant *CAE = ConstantExpr::getCast(CAGV, EmptyTy);
Elements.push_back(CAE);
}
};
virtual void Apply(unsigned &Field) {
Fields.push_back(Type::UIntTy);
}
+ virtual void Apply(int64_t &Field) {
+ Fields.push_back(Type::IntTy);
+ }
virtual void Apply(uint64_t &Field) {
Fields.push_back(Type::UIntTy);
}
Constant *C = CI->getOperand(I++);
IsValid = IsValid && isa<ConstantInt>(C);
}
+ virtual void Apply(int64_t &Field) {
+ Constant *C = CI->getOperand(I++);
+ IsValid = IsValid && isa<ConstantInt>(C);
+ }
virtual void Apply(uint64_t &Field) {
Constant *C = CI->getOperand(I++);
IsValid = IsValid && isa<ConstantInt>(C);
case DI_TAG_const:
case DI_TAG_volatile:
case DI_TAG_restrict: return new DerivedTypeDesc(Tag);
+ case DI_TAG_array:
+ case DI_TAG_struct:
+ case DI_TAG_union:
+ case DI_TAG_enum: return new CompositeTypeDesc(Tag);
+ case DI_TAG_subrange: return new SubrangeDesc();
default: break;
}
return NULL;
Visitor->Apply(Encoding);
}
+/// getDescString - Return a string used to compose global names and labels.
+///
+const char *BasicTypeDesc::getDescString() const {
+ return "llvm.dbg.basictype";
+}
+
+/// getTypeString - Return a string used to label this descriptor's type.
+///
+const char *BasicTypeDesc::getTypeString() const {
+ return "llvm.dbg.basictype.type";
+}
+
#ifndef NDEBUG
void BasicTypeDesc::dump() {
std::cerr << getDescString() << " "
<< "Encoding(" << Encoding << ")\n";
}
#endif
+
//===----------------------------------------------------------------------===//
DerivedTypeDesc::DerivedTypeDesc(unsigned T)
: TypeDesc(T)
, FromType(NULL)
-{
- assert(classof((const DebugInfoDesc *)this) && "Unknown derived type.");
-}
+{}
/// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
///
Visitor->Apply((DebugInfoDesc *&)FromType);
}
+/// getDescString - Return a string used to compose global names and labels.
+///
+const char *DerivedTypeDesc::getDescString() const {
+ return "llvm.dbg.derivedtype";
+}
+
+/// getTypeString - Return a string used to label this descriptor's type.
+///
+const char *DerivedTypeDesc::getTypeString() const {
+ return "llvm.dbg.derivedtype.type";
+}
+
#ifndef NDEBUG
void DerivedTypeDesc::dump() {
std::cerr << getDescString() << " "
//===----------------------------------------------------------------------===//
+CompositeTypeDesc::CompositeTypeDesc(unsigned T)
+: DerivedTypeDesc(T)
+, Elements()
+{}
+
+/// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
+///
+void CompositeTypeDesc::ApplyToFields(DIVisitor *Visitor) {
+ DerivedTypeDesc::ApplyToFields(Visitor);
+
+ Visitor->Apply(Elements);
+}
+
+/// getDescString - Return a string used to compose global names and labels.
+///
+const char *CompositeTypeDesc::getDescString() const {
+ return "llvm.dbg.compositetype";
+}
+
+/// getTypeString - Return a string used to label this descriptor's type.
+///
+const char *CompositeTypeDesc::getTypeString() const {
+ return "llvm.dbg.compositetype.type";
+}
+
+#ifndef NDEBUG
+void CompositeTypeDesc::dump() {
+ std::cerr << getDescString() << " "
+ << "Tag(" << getTag() << "), "
+ << "Context(" << getContext() << "), "
+ << "Name(\"" << getName() << "\"), "
+ << "Size(" << getSize() << "), "
+ << "File(" << getFile() << "), "
+ << "Line(" << getLine() << "), "
+ << "FromType(" << getFromType() << "), "
+ << "Elements.size(" << Elements.size() << ")\n";
+}
+#endif
+
+//===----------------------------------------------------------------------===//
+
+SubrangeDesc::SubrangeDesc()
+: DebugInfoDesc(DI_TAG_subrange)
+, Lo(0)
+, Hi(0)
+{}
+
+/// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
+///
+void SubrangeDesc::ApplyToFields(DIVisitor *Visitor) {
+ DebugInfoDesc::ApplyToFields(Visitor);
+
+ Visitor->Apply(Lo);
+ Visitor->Apply(Hi);
+}
+
+/// getDescString - Return a string used to compose global names and labels.
+///
+const char *SubrangeDesc::getDescString() const {
+ return "llvm.dbg.subrange";
+}
+
+/// getTypeString - Return a string used to label this descriptor's type.
+///
+const char *SubrangeDesc::getTypeString() const {
+ return "llvm.dbg.subrange.type";
+}
+
+#ifndef NDEBUG
+void SubrangeDesc::dump() {
+ std::cerr << getDescString() << " "
+ << "Tag(" << getTag() << "), "
+ << "Lo(" << Lo << "), "
+ << "Hi(" << Hi << ")\n";
+}
+#endif
+
+//===----------------------------------------------------------------------===//
+
GlobalDesc::GlobalDesc(unsigned T)
: AnchoredDesc(T)
, Context(0)