X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FDebugInfo.cpp;h=12bb2921f51ee5dc04869149c788a5599f6eced2;hb=ef4cfc749a61d0d0252196c957697436ba7ec068;hp=98335ae2dcca65bed9e4c3cf477bd914775135ec;hpb=b79b5359fbe44bc82bedff2c081ed1db787f8d49;p=oota-llvm.git diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index 98335ae2dcc..12bb2921f51 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -20,6 +20,7 @@ #include "llvm/Instructions.h" #include "llvm/Module.h" #include "llvm/Analysis/ValueTracking.h" +#include "llvm/Support/Streams.h" using namespace llvm; //===----------------------------------------------------------------------===// @@ -168,8 +169,8 @@ bool DIVariable::isVariable(unsigned Tag) { } } -DIVariable::DIVariable(GlobalVariable *GV) : DIDescriptor(GV) { - if (GV && !isVariable(getTag())) +DIVariable::DIVariable(GlobalVariable *gv) : DIDescriptor(gv) { + if (gv && !isVariable(getTag())) GV = 0; } @@ -272,7 +273,16 @@ bool DIVariable::Verify() const { return true; } - +/// getOriginalTypeSize - If this type is derived from a base type then +/// return base type size. +uint64_t DIDerivedType::getOriginalTypeSize() const { + if (getTag() != dwarf::DW_TAG_member) + return getSizeInBits(); + DIType BT = getTypeDerivedFrom(); + if (BT.getTag() != dwarf::DW_TAG_base_type) + return getSizeInBits(); + return BT.getSizeInBits(); +} //===----------------------------------------------------------------------===// // DIFactory: Basic Helpers @@ -291,9 +301,9 @@ Constant *DIFactory::getCastToEmpty(DIDescriptor D) { } Constant *DIFactory::GetTagConstant(unsigned TAG) { - assert((TAG & DIDescriptor::VersionMask) == 0 && + assert((TAG & LLVMDebugVersionMask) == 0 && "Tag too large for debug encoding!"); - return ConstantInt::get(Type::Int32Ty, TAG | DIDescriptor::Version7); + return ConstantInt::get(Type::Int32Ty, TAG | LLVMDebugVersion); } Constant *DIFactory::GetStringConstant(const std::string &String) { @@ -440,14 +450,22 @@ DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) { DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID, const std::string &Filename, const std::string &Directory, - const std::string &Producer) { + const std::string &Producer, + bool isMain, + bool isOptimized, + const char *Flags, + unsigned RunTimeVer) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_compile_unit), getCastToEmpty(GetOrCreateCompileUnitAnchor()), ConstantInt::get(Type::Int32Ty, LangID), GetStringConstant(Filename), GetStringConstant(Directory), - GetStringConstant(Producer) + GetStringConstant(Producer), + ConstantInt::get(Type::Int1Ty, isMain), + ConstantInt::get(Type::Int1Ty, isOptimized), + GetStringConstant(Flags), + ConstantInt::get(Type::Int32Ty, RunTimeVer) }; Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); @@ -487,9 +505,7 @@ DIBasicType DIFactory::CreateBasicType(DIDescriptor Context, uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, - unsigned Encoding, - const std::string *FileName, - const std::string *Directory) { + unsigned Encoding) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_base_type), getCastToEmpty(Context), @@ -500,9 +516,7 @@ DIBasicType DIFactory::CreateBasicType(DIDescriptor Context, ConstantInt::get(Type::Int64Ty, AlignInBits), ConstantInt::get(Type::Int64Ty, OffsetInBits), ConstantInt::get(Type::Int32Ty, Flags), - ConstantInt::get(Type::Int32Ty, Encoding), - GetStringConstant(FileName ? FileName->c_str() : ""), - GetStringConstant(Directory ? Directory->c_str() : "") + ConstantInt::get(Type::Int32Ty, Encoding) }; Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); @@ -526,9 +540,7 @@ DIDerivedType DIFactory::CreateDerivedType(unsigned Tag, uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, - DIType DerivedFrom, - const std::string *FileName, - const std::string *Directory) { + DIType DerivedFrom) { Constant *Elts[] = { GetTagConstant(Tag), getCastToEmpty(Context), @@ -539,9 +551,7 @@ DIDerivedType DIFactory::CreateDerivedType(unsigned Tag, ConstantInt::get(Type::Int64Ty, AlignInBits), ConstantInt::get(Type::Int64Ty, OffsetInBits), ConstantInt::get(Type::Int32Ty, Flags), - getCastToEmpty(DerivedFrom), - GetStringConstant(FileName ? FileName->c_str() : ""), - GetStringConstant(Directory ? Directory->c_str() : "") + getCastToEmpty(DerivedFrom) }; Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); @@ -566,8 +576,7 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag, unsigned Flags, DIType DerivedFrom, DIArray Elements, - const std::string *FileName, - const std::string *Directory) { + unsigned RuntimeLang) { Constant *Elts[] = { GetTagConstant(Tag), @@ -581,8 +590,7 @@ DICompositeType DIFactory::CreateCompositeType(unsigned Tag, ConstantInt::get(Type::Int32Ty, Flags), getCastToEmpty(DerivedFrom), getCastToEmpty(Elements), - GetStringConstant(FileName ? FileName->c_str() : ""), - GetStringConstant(Directory ? Directory->c_str() : "") + ConstantInt::get(Type::Int32Ty, RuntimeLang) }; Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); @@ -606,9 +614,7 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context, DICompileUnit CompileUnit, unsigned LineNo, DIType Type, bool isLocalToUnit, - bool isDefinition, - const std::string *FileName, - const std::string *Directory) { + bool isDefinition) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_subprogram), @@ -621,9 +627,7 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context, ConstantInt::get(Type::Int32Ty, LineNo), getCastToEmpty(Type), ConstantInt::get(Type::Int1Ty, isLocalToUnit), - ConstantInt::get(Type::Int1Ty, isDefinition), - GetStringConstant(FileName ? FileName->c_str() : ""), - GetStringConstant(Directory ? Directory->c_str() : "") + ConstantInt::get(Type::Int1Ty, isDefinition) }; Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); @@ -643,9 +647,7 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name, const std::string &LinkageName, DICompileUnit CompileUnit, unsigned LineNo, DIType Type,bool isLocalToUnit, - bool isDefinition, llvm::GlobalVariable *Val, - const std::string *FileName, - const std::string *Directory) { + bool isDefinition, llvm::GlobalVariable *Val) { Constant *Elts[] = { GetTagConstant(dwarf::DW_TAG_variable), getCastToEmpty(GetOrCreateGlobalVariableAnchor()), @@ -658,9 +660,7 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name, getCastToEmpty(Type), ConstantInt::get(Type::Int1Ty, isLocalToUnit), ConstantInt::get(Type::Int1Ty, isDefinition), - ConstantExpr::getBitCast(Val, EmptyStructPtr), - GetStringConstant(FileName ? FileName->c_str() : ""), - GetStringConstant(Directory ? Directory->c_str() : "") + ConstantExpr::getBitCast(Val, EmptyStructPtr) }; Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); @@ -678,20 +678,14 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name, DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context, const std::string &Name, DICompileUnit CompileUnit, unsigned LineNo, - DIType Type, - const std::string *FileName, - const std::string *Directory) { - - + DIType Type) { Constant *Elts[] = { GetTagConstant(Tag), getCastToEmpty(Context), GetStringConstant(Name), getCastToEmpty(CompileUnit), ConstantInt::get(Type::Int32Ty, LineNo), - getCastToEmpty(Type), - GetStringConstant(FileName ? FileName->c_str() : ""), - GetStringConstant(Directory ? Directory->c_str() : "") + getCastToEmpty(Type) }; Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); @@ -866,3 +860,103 @@ namespace llvm { } } +/// dump - print compile unit. +void DICompileUnit::dump() const { + cerr << " [" << dwarf::LanguageString(getLanguage()) << "] "; + cerr << " [" << getDirectory() << "/" << getFilename() << " ]"; +} + +/// dump - print type. +void DIType::dump() const { + if (isNull()) return; + if (!getName().empty()) + cerr << " [" << getName() << "] "; + unsigned Tag = getTag(); + cerr << " [" << dwarf::TagString(Tag) << "] "; + // TODO : Print context + getCompileUnit().dump(); + cerr << " [" + << getLineNumber() << ", " + << getSizeInBits() << ", " + << getAlignInBits() << ", " + << getOffsetInBits() + << "] "; + if (isPrivate()) + cerr << " [private] "; + else if (isProtected()) + cerr << " [protected] "; + if (isForwardDecl()) + cerr << " [fwd] "; + + if (isBasicType(Tag)) + DIBasicType(GV).dump(); + else if (isDerivedType(Tag)) + DIDerivedType(GV).dump(); + else if (isCompositeType(Tag)) + DICompositeType(GV).dump(); + else { + cerr << "Invalid DIType\n"; + return; + } + cerr << "\n"; +} + +/// dump - print basic type. +void DIBasicType::dump() const { + cerr << " [" << dwarf::AttributeEncodingString(getEncoding()) << "] "; + +} + +/// dump - print derived type. +void DIDerivedType::dump() const { + cerr << "\n\t Derived From: "; getTypeDerivedFrom().dump(); +} + +/// dump - print composite type. +void DICompositeType::dump() const { + DIArray A = getTypeArray(); + if (A.isNull()) + return; + cerr << " [" << A.getNumElements() << " elements]"; +} + +/// dump - print global. +void DIGlobal::dump() const { + + if (!getName().empty()) + cerr << " [" << getName() << "] "; + unsigned Tag = getTag(); + cerr << " [" << dwarf::TagString(Tag) << "] "; + // TODO : Print context + getCompileUnit().dump(); + cerr << " [" << getLineNumber() << "] "; + if (isLocalToUnit()) + cerr << " [local] "; + if (isDefinition()) + cerr << " [def] "; + + if (isGlobalVariable(Tag)) + DIGlobalVariable(GV).dump(); + + cerr << "\n"; +} + +/// dump - print subprogram. +void DISubprogram::dump() const { + DIGlobal::dump(); +} + +/// dump - print global variable. +void DIGlobalVariable::dump() const { + cerr << " ["; getGlobal()->dump(); cerr << "] "; +} + +/// dump - print variable. +void DIVariable::dump() const { + if (!getName().empty()) + cerr << " [" << getName() << "] "; + getCompileUnit().dump(); + cerr << " [" << getLineNumber() << "] "; + getType().dump(); + cerr << "\n"; +}