Revamp how debugging information is emitted for debug info objects.

It's not necessary for each DI class to have its own copy of `print' and
`dump'. Instead, just give DIDescriptor those methods and have it call the
appropriate debugging printing routine based on the type of the debug
information.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159237 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling 2012-06-26 22:57:33 +00:00
parent d096479f31
commit 494f8c6cfa
2 changed files with 114 additions and 197 deletions

View File

@ -104,12 +104,6 @@ namespace llvm {
return getUnsignedField(0) & ~LLVMDebugVersionMask; return getUnsignedField(0) & ~LLVMDebugVersionMask;
} }
/// print - print descriptor.
void print(raw_ostream &OS) const;
/// dump - print descriptor to dbgs() with a newline.
void dump() const;
bool isDerivedType() const; bool isDerivedType() const;
bool isCompositeType() const; bool isCompositeType() const;
bool isBasicType() const; bool isBasicType() const;
@ -130,10 +124,18 @@ namespace llvm {
bool isTemplateTypeParameter() const; bool isTemplateTypeParameter() const;
bool isTemplateValueParameter() const; bool isTemplateValueParameter() const;
bool isObjCProperty() const; bool isObjCProperty() const;
/// print - print descriptor.
void print(raw_ostream &OS) const;
/// dump - print descriptor to dbgs() with a newline.
void dump() const;
}; };
/// DISubrange - This is used to represent ranges, for array bounds. /// DISubrange - This is used to represent ranges, for array bounds.
class DISubrange : public DIDescriptor { class DISubrange : public DIDescriptor {
friend class DIDescriptor;
void printInternal(raw_ostream &OS) const;
public: public:
explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {} explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
@ -156,6 +158,9 @@ namespace llvm {
/// DIScope - A base class for various scopes. /// DIScope - A base class for various scopes.
class DIScope : public DIDescriptor { class DIScope : public DIDescriptor {
virtual void anchor(); virtual void anchor();
protected:
friend class DIDescriptor;
void printInternal(raw_ostream &OS) const;
public: public:
explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {} explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
virtual ~DIScope() {} virtual ~DIScope() {}
@ -167,6 +172,8 @@ namespace llvm {
/// DICompileUnit - A wrapper for a compile unit. /// DICompileUnit - A wrapper for a compile unit.
class DICompileUnit : public DIScope { class DICompileUnit : public DIScope {
virtual void anchor(); virtual void anchor();
friend class DIDescriptor;
void printInternal(raw_ostream &OS) const;
public: public:
explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {} explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
@ -196,17 +203,13 @@ namespace llvm {
/// Verify - Verify that a compile unit is well formed. /// Verify - Verify that a compile unit is well formed.
bool Verify() const; bool Verify() const;
/// print - print compile unit.
void print(raw_ostream &OS) const;
/// dump - print compile unit to dbgs() with a newline.
void dump() const;
}; };
/// DIFile - This is a wrapper for a file. /// DIFile - This is a wrapper for a file.
class DIFile : public DIScope { class DIFile : public DIScope {
virtual void anchor(); virtual void anchor();
friend class DIDescriptor;
void printInternal(raw_ostream &OS) const {} // FIXME: Output something?
public: public:
explicit DIFile(const MDNode *N = 0) : DIScope(N) { explicit DIFile(const MDNode *N = 0) : DIScope(N) {
if (DbgNode && !isFile()) if (DbgNode && !isFile())
@ -224,6 +227,8 @@ namespace llvm {
/// FIXME: it seems strange that this doesn't have either a reference to the /// FIXME: it seems strange that this doesn't have either a reference to the
/// type/precision or a file/line pair for location info. /// type/precision or a file/line pair for location info.
class DIEnumerator : public DIDescriptor { class DIEnumerator : public DIDescriptor {
friend class DIDescriptor;
void printInternal(raw_ostream &OS) const;
public: public:
explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {} explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
@ -237,12 +242,12 @@ namespace llvm {
class DIType : public DIScope { class DIType : public DIScope {
virtual void anchor(); virtual void anchor();
protected: protected:
friend class DIDescriptor;
void printInternal(raw_ostream &OS) const;
// This ctor is used when the Tag has already been validated by a derived // This ctor is used when the Tag has already been validated by a derived
// ctor. // ctor.
DIType(const MDNode *N, bool, bool) : DIScope(N) {} DIType(const MDNode *N, bool, bool) : DIScope(N) {}
public: public:
/// Verify - Verify that a type descriptor is well formed. /// Verify - Verify that a type descriptor is well formed.
bool Verify() const; bool Verify() const;
explicit DIType(const MDNode *N); explicit DIType(const MDNode *N);
@ -314,12 +319,6 @@ namespace llvm {
/// this descriptor. /// this descriptor.
void replaceAllUsesWith(DIDescriptor &D); void replaceAllUsesWith(DIDescriptor &D);
void replaceAllUsesWith(MDNode *D); void replaceAllUsesWith(MDNode *D);
/// print - print type.
void print(raw_ostream &OS) const;
/// dump - print type to dbgs() with a newline.
void dump() const;
}; };
/// DIBasicType - A basic type, like 'int' or 'float'. /// DIBasicType - A basic type, like 'int' or 'float'.
@ -332,18 +331,14 @@ namespace llvm {
/// Verify - Verify that a basic type descriptor is well formed. /// Verify - Verify that a basic type descriptor is well formed.
bool Verify() const; bool Verify() const;
/// print - print basic type.
void print(raw_ostream &OS) const;
/// dump - print basic type to dbgs() with a newline.
void dump() const;
}; };
/// DIDerivedType - A simple derived type, like a const qualified type, /// DIDerivedType - A simple derived type, like a const qualified type,
/// a typedef, a pointer or reference, etc. /// a typedef, a pointer or reference, etc.
class DIDerivedType : public DIType { class DIDerivedType : public DIType {
virtual void anchor(); virtual void anchor();
friend class DIDescriptor;
void printInternal(raw_ostream &OS) const;
protected: protected:
explicit DIDerivedType(const MDNode *N, bool, bool) explicit DIDerivedType(const MDNode *N, bool, bool)
: DIType(N, true, true) {} : DIType(N, true, true) {}
@ -401,12 +396,6 @@ namespace llvm {
/// Verify - Verify that a derived type descriptor is well formed. /// Verify - Verify that a derived type descriptor is well formed.
bool Verify() const; bool Verify() const;
/// print - print derived type.
void print(raw_ostream &OS) const;
/// dump - print derived type to dbgs() with a newline.
void dump() const;
}; };
/// DICompositeType - This descriptor holds a type that can refer to multiple /// DICompositeType - This descriptor holds a type that can refer to multiple
@ -414,6 +403,8 @@ namespace llvm {
/// FIXME: Why is this a DIDerivedType?? /// FIXME: Why is this a DIDerivedType??
class DICompositeType : public DIDerivedType { class DICompositeType : public DIDerivedType {
virtual void anchor(); virtual void anchor();
friend class DIDescriptor;
void printInternal(raw_ostream &OS) const;
public: public:
explicit DICompositeType(const MDNode *N = 0) explicit DICompositeType(const MDNode *N = 0)
: DIDerivedType(N, true, true) { : DIDerivedType(N, true, true) {
@ -430,12 +421,6 @@ namespace llvm {
/// Verify - Verify that a composite type descriptor is well formed. /// Verify - Verify that a composite type descriptor is well formed.
bool Verify() const; bool Verify() const;
/// print - print composite type.
void print(raw_ostream &OS) const;
/// dump - print composite type to dbgs() with a newline.
void dump() const;
}; };
/// DITemplateTypeParameter - This is a wrapper for template type parameter. /// DITemplateTypeParameter - This is a wrapper for template type parameter.
@ -478,6 +463,8 @@ namespace llvm {
/// DISubprogram - This is a wrapper for a subprogram (e.g. a function). /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
class DISubprogram : public DIScope { class DISubprogram : public DIScope {
virtual void anchor(); virtual void anchor();
friend class DIDescriptor;
void printInternal(raw_ostream &OS) const;
public: public:
explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {} explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
@ -576,12 +563,6 @@ namespace llvm {
/// Verify - Verify that a subprogram descriptor is well formed. /// Verify - Verify that a subprogram descriptor is well formed.
bool Verify() const; bool Verify() const;
/// print - print subprogram.
void print(raw_ostream &OS) const;
/// dump - print subprogram to dbgs() with a newline.
void dump() const;
/// describes - Return true if this subprogram provides debugging /// describes - Return true if this subprogram provides debugging
/// information for the function F. /// information for the function F.
bool describes(const Function *F); bool describes(const Function *F);
@ -597,6 +578,8 @@ namespace llvm {
/// DIGlobalVariable - This is a wrapper for a global variable. /// DIGlobalVariable - This is a wrapper for a global variable.
class DIGlobalVariable : public DIDescriptor { class DIGlobalVariable : public DIDescriptor {
friend class DIDescriptor;
void printInternal(raw_ostream &OS) const;
public: public:
explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {} explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
@ -634,17 +617,13 @@ namespace llvm {
/// Verify - Verify that a global variable descriptor is well formed. /// Verify - Verify that a global variable descriptor is well formed.
bool Verify() const; bool Verify() const;
/// print - print global variable.
void print(raw_ostream &OS) const;
/// dump - print global variable to dbgs() with a newline.
void dump() const;
}; };
/// DIVariable - This is a wrapper for a variable (e.g. parameter, local, /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
/// global etc). /// global etc).
class DIVariable : public DIDescriptor { class DIVariable : public DIDescriptor {
friend class DIDescriptor;
void printInternal(raw_ostream &OS) const;
public: public:
explicit DIVariable(const MDNode *N = 0) explicit DIVariable(const MDNode *N = 0)
: DIDescriptor(N) {} : DIDescriptor(N) {}
@ -706,13 +685,7 @@ namespace llvm {
/// information for an inlined function arguments. /// information for an inlined function arguments.
bool isInlinedFnArgument(const Function *CurFn); bool isInlinedFnArgument(const Function *CurFn);
/// print - print variable.
void print(raw_ostream &OS) const;
void printExtendedName(raw_ostream &OS) const; void printExtendedName(raw_ostream &OS) const;
/// dump - print variable to dbgs() with a newline.
void dump() const;
}; };
/// DILexicalBlock - This is a wrapper for a lexical block. /// DILexicalBlock - This is a wrapper for a lexical block.
@ -830,12 +803,6 @@ namespace llvm {
/// Verify - Verify that a derived type descriptor is well formed. /// Verify - Verify that a derived type descriptor is well formed.
bool Verify() const; bool Verify() const;
/// print - print derived type.
void print(raw_ostream &OS) const;
/// dump - print derived type to dbgs() with a newline.
void dump() const;
}; };
/// getDISubprogram - Find subprogram that is enclosing this scope. /// getDISubprogram - Find subprogram that is enclosing this scope.

View File

@ -694,39 +694,77 @@ void DILexicalBlockFile::anchor() { }
// DIDescriptor: dump routines for all descriptors. // DIDescriptor: dump routines for all descriptors.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// dump - Print descriptor to dbgs() with a newline.
void DIDescriptor::dump() const {
print(dbgs()); dbgs() << '\n';
}
/// print - Print descriptor. /// print - Print descriptor.
void DIDescriptor::print(raw_ostream &OS) const { void DIDescriptor::print(raw_ostream &OS) const {
OS << "[" << dwarf::TagString(getTag()) << "] "; if (!DbgNode) return;
OS.write_hex((intptr_t) &*DbgNode) << ']';
OS << "[" << dwarf::TagString(getTag()) << ']';
if (this->isSubrange()) {
DISubrange(DbgNode).printInternal(OS);
} else if (this->isScope()) {
DIScope(DbgNode).printInternal(OS);
} else if (this->isCompileUnit()) {
DICompileUnit(DbgNode).printInternal(OS);
} else if (this->isFile()) {
DIFile(DbgNode).printInternal(OS);
} else if (this->isEnumerator()) {
DIEnumerator(DbgNode).printInternal(OS);
} else if (this->isBasicType()) {
DIType(DbgNode).printInternal(OS);
} else if (this->isDerivedType()) {
DIDerivedType(DbgNode).printInternal(OS);
} else if (this->isCompositeType()) {
DICompositeType(DbgNode).printInternal(OS);
} else if (this->isSubprogram()) {
DISubprogram(DbgNode).printInternal(OS);
} else if (this->isGlobalVariable()) {
DIGlobalVariable(DbgNode).printInternal(OS);
} else if (this->isVariable()) {
DIVariable(DbgNode).printInternal(OS);
}
} }
/// print - Print compile unit. void DISubrange::printInternal(raw_ostream &OS) const {
void DICompileUnit::print(raw_ostream &OS) const { OS << " [" << getLo() << ", " << getHi() << ']';
if (getLanguage())
OS << " [" << dwarf::LanguageString(getLanguage()) << "] ";
OS << " [" << getDirectory() << "/" << getFilename() << "]";
} }
/// print - Print type. void DIScope::printInternal(raw_ostream &OS) const {
void DIType::print(raw_ostream &OS) const { OS << " [" << getDirectory() << "/" << getFilename() << ']';
}
void DICompileUnit::printInternal(raw_ostream &OS) const {
DIScope::printInternal(OS);
if (unsigned Lang = getLanguage())
OS << " [" << dwarf::LanguageString(Lang) << ']';
}
void DIEnumerator::printInternal(raw_ostream &OS) const {
OS << " [" << getName() << " :: " << getEnumValue() << ']';
}
void DIType::printInternal(raw_ostream &OS) const {
if (!DbgNode) return; if (!DbgNode) return;
StringRef Res = getName(); StringRef Res = getName();
if (!Res.empty()) if (!Res.empty())
OS << " [" << Res << "]"; OS << " [" << Res << "]";
unsigned Tag = getTag(); // TODO: Print context?
OS << " [" << dwarf::TagString(Tag) << "] ";
// TODO : Print context OS << " [line " << getLineNumber()
OS << " [" << ", size " << getSizeInBits()
<< "line " << getLineNumber() << ", " << ", align " << getAlignInBits()
<< getSizeInBits() << " bits, " << ", offset " << getOffsetInBits();
<< getAlignInBits() << " bit alignment, " if (isBasicType())
<< getOffsetInBits() << " bit offset" OS << ", enc "
<< "] "; << dwarf::AttributeEncodingString(DIBasicType(DbgNode).getEncoding());
OS << "]";
if (isPrivate()) if (isPrivate())
OS << " [private]"; OS << " [private]";
@ -735,55 +773,27 @@ void DIType::print(raw_ostream &OS) const {
if (isForwardDecl()) if (isForwardDecl())
OS << " [fwd]"; OS << " [fwd]";
if (isBasicType())
DIBasicType(DbgNode).print(OS);
else if (isDerivedType()) {
DIDerivedType DTy = DIDerivedType(DbgNode);
DTy.print(OS);
DICompositeType CTy = getDICompositeType(DTy);
if (CTy.Verify())
CTy.print(OS);
}
else if (isCompositeType())
DICompositeType(DbgNode).print(OS);
else {
OS << "Invalid DIType\n";
return;
} }
OS << "\n"; void DIDerivedType::printInternal(raw_ostream &OS) const {
DIType::printInternal(OS);
OS << " [from " << getTypeDerivedFrom().getName() << ']';
} }
/// print - Print basic type. void DICompositeType::printInternal(raw_ostream &OS) const {
void DIBasicType::print(raw_ostream &OS) const { DIType::printInternal(OS);
OS << " [" << dwarf::AttributeEncodingString(getEncoding()) << "] ";
}
/// print - Print derived type.
void DIDerivedType::print(raw_ostream &OS) const {
OS << "\n\t Derived From: ";
getTypeDerivedFrom().print(OS);
OS << "\n\t";
}
/// print - Print composite type.
void DICompositeType::print(raw_ostream &OS) const {
DIArray A = getTypeArray(); DIArray A = getTypeArray();
OS << " [" << A.getNumElements() << " elements]"; OS << " [" << A.getNumElements() << " elements]";
} }
/// print - Print subprogram. void DISubprogram::printInternal(raw_ostream &OS) const {
void DISubprogram::print(raw_ostream &OS) const {
StringRef Res = getName(); StringRef Res = getName();
if (!Res.empty()) if (!Res.empty())
OS << " [" << Res << "] "; OS << " [" << Res << ']';
unsigned Tag = getTag();
OS << " [" << dwarf::TagString(Tag) << "] ";
// TODO : Print context // TODO : Print context
OS << " [" << getLineNumber() << "] ";
OS << " [line " << getLineNumber() << ']';
if (isLocalToUnit()) if (isLocalToUnit())
OS << " [local]"; OS << " [local]";
@ -792,33 +802,31 @@ void DISubprogram::print(raw_ostream &OS) const {
OS << " [def]"; OS << " [def]";
if (getScopeLineNumber() != getLineNumber()) if (getScopeLineNumber() != getLineNumber())
OS << " [Scope: " << getScopeLineNumber() << "] "; OS << " [scope " << getScopeLineNumber() << "]";
OS << "\n";
} }
/// print - Print global variable. void DIGlobalVariable::printInternal(raw_ostream &OS) const {
void DIGlobalVariable::print(raw_ostream &OS) const {
OS << " [";
StringRef Res = getName(); StringRef Res = getName();
if (!Res.empty()) if (!Res.empty())
OS << " [" << Res << "] "; OS << " [" << Res << ']';
unsigned Tag = getTag(); OS << " [line " << getLineNumber() << ']';
OS << " [" << dwarf::TagString(Tag) << "] ";
// TODO : Print context // TODO : Print context
OS << " [" << getLineNumber() << "] ";
if (isLocalToUnit()) if (isLocalToUnit())
OS << " [local]"; OS << " [local]";
if (isDefinition()) if (isDefinition())
OS << " [def]"; OS << " [def]";
}
if (isGlobalVariable()) void DIVariable::printInternal(raw_ostream &OS) const {
DIGlobalVariable(DbgNode).print(OS); StringRef Res = getName();
OS << "]\n"; if (!Res.empty())
OS << " [" << Res << ']';
OS << " [line " << getLineNumber() << ']';
} }
static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS, static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS,
@ -857,64 +865,6 @@ void DIVariable::printExtendedName(raw_ostream &OS) const {
} }
} }
/// print - Print variable.
void DIVariable::print(raw_ostream &OS) const {
StringRef Res = getName();
if (!Res.empty())
OS << " [" << Res << "] ";
OS << " [" << getLineNumber() << "] ";
getType().print(OS);
OS << "\n";
// FIXME: Dump complex addresses
}
/// dump - Print descriptor to dbgs() with a newline.
void DIDescriptor::dump() const {
print(dbgs()); dbgs() << '\n';
}
/// dump - Print compile unit to dbgs() with a newline.
void DICompileUnit::dump() const {
print(dbgs()); dbgs() << '\n';
}
/// dump - Print type to dbgs() with a newline.
void DIType::dump() const {
print(dbgs()); dbgs() << '\n';
}
/// dump - Print basic type to dbgs() with a newline.
void DIBasicType::dump() const {
print(dbgs()); dbgs() << '\n';
}
/// dump - Print derived type to dbgs() with a newline.
void DIDerivedType::dump() const {
print(dbgs()); dbgs() << '\n';
}
/// dump - Print composite type to dbgs() with a newline.
void DICompositeType::dump() const {
print(dbgs()); dbgs() << '\n';
}
/// dump - Print subprogram to dbgs() with a newline.
void DISubprogram::dump() const {
print(dbgs()); dbgs() << '\n';
}
/// dump - Print global variable.
void DIGlobalVariable::dump() const {
print(dbgs()); dbgs() << '\n';
}
/// dump - Print variable.
void DIVariable::dump() const {
print(dbgs()); dbgs() << '\n';
}
/// fixupObjcLikeName - Replace contains special characters used /// fixupObjcLikeName - Replace contains special characters used
/// in a typical Objective-C names with '.' in a given string. /// in a typical Objective-C names with '.' in a given string.
static void fixupObjcLikeName(StringRef Str, SmallVectorImpl<char> &Out) { static void fixupObjcLikeName(StringRef Str, SmallVectorImpl<char> &Out) {