// DIDescriptor
//===----------------------------------------------------------------------===//
-/// ValidDebugInfo - Return true if V represents valid debug info value.
-/// FIXME : Add DIDescriptor.isValid()
-bool DIDescriptor::ValidDebugInfo(const MDNode *N, unsigned OptLevel) {
- if (!N)
- return false;
-
- DIDescriptor DI(N);
-
- // Check current version. Allow Version7 for now.
- unsigned Version = DI.getVersion();
- if (Version != LLVMDebugVersion && Version != LLVMDebugVersion7)
- return false;
-
- switch (DI.getTag()) {
- case DW_TAG_variable:
- assert(DIVariable(N).Verify() && "Invalid DebugInfo value");
- break;
- case DW_TAG_compile_unit:
- assert(DICompileUnit(N).Verify() && "Invalid DebugInfo value");
- break;
- case DW_TAG_subprogram:
- assert(DISubprogram(N).Verify() && "Invalid DebugInfo value");
- break;
- case DW_TAG_lexical_block:
- // FIXME: This interfers with the quality of generated code during
- // optimization.
- if (OptLevel != CodeGenOpt::None)
- return false;
- // FALLTHROUGH
- default:
- break;
- }
-
- return true;
-}
-
StringRef
DIDescriptor::getStringField(unsigned Elt) const {
if (DbgNode == 0)
if (!getContext().Verify())
return false;
+ if (!getCompileUnit().Verify())
+ return false;
+
DIType Ty = getType();
if (!Ty.Verify())
return false;
return DbgNode->getNumOperands() == 4;
}
+/// Verify - Verify that a namespace descriptor is well formed.
+bool DINameSpace::Verify() const {
+ if (!DbgNode)
+ return false;
+ if (getName().empty())
+ return false;
+ if (!getCompileUnit().Verify())
+ return false;
+ return true;
+}
+
/// getOriginalTypeSize - If this type is derived from a base type then
/// return base type size.
uint64_t DIDerivedType::getOriginalTypeSize() const {
if (getLanguage())
OS << " [" << dwarf::LanguageString(getLanguage()) << "] ";
- OS << " [" << getDirectory() << "/" << getFilename() << " ]";
+ OS << " [" << getDirectory() << "/" << getFilename() << "]";
}
/// print - Print type.
OS << " [" << A.getNumElements() << " elements]";
}
-/// print - Print global.
-void DIGlobal::print(raw_ostream &OS) const {
+/// print - Print subprogram.
+void DISubprogram::print(raw_ostream &OS) const {
StringRef Res = getName();
if (!Res.empty())
OS << " [" << Res << "] ";
if (isDefinition())
OS << " [def] ";
- if (isGlobalVariable())
- DIGlobalVariable(DbgNode).print(OS);
-
OS << "\n";
}
-/// print - Print subprogram.
-void DISubprogram::print(raw_ostream &OS) const {
+/// print - Print global variable.
+void DIGlobalVariable::print(raw_ostream &OS) const {
+ OS << " [";
StringRef Res = getName();
if (!Res.empty())
OS << " [" << Res << "] ";
if (isDefinition())
OS << " [def] ";
- OS << "\n";
-}
-
-/// print - Print global variable.
-void DIGlobalVariable::print(raw_ostream &OS) const {
- OS << " [";
- getGlobal()->print(OS);
- OS << "] ";
+ if (isGlobalVariable())
+ DIGlobalVariable(DbgNode).print(OS);
+ OS << "]\n";
}
/// print - Print variable.
print(dbgs()); dbgs() << '\n';
}
-/// dump - Print global to dbgs() with a newline.
-void DIGlobal::dump() const {
- print(dbgs()); dbgs() << '\n';
-}
-
/// dump - Print subprogram to dbgs() with a newline.
void DISubprogram::dump() const {
print(dbgs()); dbgs() << '\n';
StringRef Name,
DIFile F,
unsigned LineNo,
- DIType Ty) {
+ DIType Ty, bool AlwaysPreserve) {
Value *Elts[] = {
GetTagConstant(Tag),
Context,
ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
Ty,
};
- return DIVariable(MDNode::get(VMContext, &Elts[0], 6));
+ MDNode *Node = MDNode::get(VMContext, &Elts[0], 6);
+ if (AlwaysPreserve) {
+ // The optimizer may remove local variable. If there is an interest
+ // to preserve variable info in such situation then stash it in a
+ // named mdnode.
+ NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.lv");
+ NMD->addOperand(Node);
+ }
+ return DIVariable(Node);
}
return DILocation(MDNode::get(VMContext, &Elts[0], 4));
}
-/// CreateLocation - Creates a debug info location.
-DILocation DIFactory::CreateLocation(unsigned LineNo, unsigned ColumnNo,
- DIScope S, MDNode *OrigLoc) {
- Value *Elts[] = {
- ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
- ConstantInt::get(Type::getInt32Ty(VMContext), ColumnNo),
- S,
- OrigLoc
- };
- return DILocation(MDNode::get(VMContext, &Elts[0], 4));
-}
-
//===----------------------------------------------------------------------===//
// DIFactory: Routines for inserting code into a function
//===----------------------------------------------------------------------===//