summaryrefslogtreecommitdiffstats
path: root/lib/Analysis/DebugInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Analysis/DebugInfo.cpp')
-rw-r--r--lib/Analysis/DebugInfo.cpp146
1 files changed, 58 insertions, 88 deletions
diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp
index adda5ee..6b27cf4 100644
--- a/lib/Analysis/DebugInfo.cpp
+++ b/lib/Analysis/DebugInfo.cpp
@@ -73,22 +73,22 @@ bool DIDescriptor::ValidDebugInfo(Value *V, CodeGenOpt::Level OptLevel) {
return true;
}
-DIDescriptor::DIDescriptor(GlobalVariable *gv, unsigned RequiredTag) {
- GV = gv;
+DIDescriptor::DIDescriptor(GlobalVariable *GV, unsigned RequiredTag) {
+ DbgGV = GV;
// If this is non-null, check to see if the Tag matches. If not, set to null.
if (GV && getTag() != RequiredTag)
- GV = 0;
+ DbgGV = 0;
}
const std::string &
DIDescriptor::getStringField(unsigned Elt, std::string &Result) const {
- if (GV == 0) {
+ if (DbgGV == 0) {
Result.clear();
return Result;
}
- Constant *C = GV->getInitializer();
+ Constant *C = DbgGV->getInitializer();
if (C == 0 || Elt >= C->getNumOperands()) {
Result.clear();
return Result;
@@ -102,9 +102,9 @@ DIDescriptor::getStringField(unsigned Elt, std::string &Result) const {
}
uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
- if (GV == 0) return 0;
+ if (DbgGV == 0) return 0;
- Constant *C = GV->getInitializer();
+ Constant *C = DbgGV->getInitializer();
if (C == 0 || Elt >= C->getNumOperands())
return 0;
@@ -114,9 +114,9 @@ uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
}
DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
- if (GV == 0) return DIDescriptor();
+ if (DbgGV == 0) return DIDescriptor();
- Constant *C = GV->getInitializer();
+ Constant *C = DbgGV->getInitializer();
if (C == 0 || Elt >= C->getNumOperands())
return DIDescriptor();
@@ -125,9 +125,9 @@ DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
}
GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
- if (GV == 0) return 0;
+ if (DbgGV == 0) return 0;
- Constant *C = GV->getInitializer();
+ Constant *C = DbgGV->getInitializer();
if (C == 0 || Elt >= C->getNumOperands())
return 0;
@@ -140,12 +140,12 @@ GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
//===----------------------------------------------------------------------===//
// Needed by DIVariable::getType().
-DIType::DIType(GlobalVariable *gv) : DIDescriptor(gv) {
- if (!gv) return;
+DIType::DIType(GlobalVariable *GV) : DIDescriptor(GV) {
+ if (!GV) return;
unsigned tag = getTag();
if (tag != dwarf::DW_TAG_base_type && !DIDerivedType::isDerivedType(tag) &&
!DICompositeType::isCompositeType(tag))
- GV = 0;
+ DbgGV = 0;
}
/// isDerivedType - Return true if the specified tag is legal for
@@ -198,8 +198,8 @@ bool DIVariable::isVariable(unsigned Tag) {
}
unsigned DIArray::getNumElements() const {
- assert (GV && "Invalid DIArray");
- Constant *C = GV->getInitializer();
+ assert (DbgGV && "Invalid DIArray");
+ Constant *C = DbgGV->getInitializer();
assert (C && "Invalid DIArray initializer");
return C->getNumOperands();
}
@@ -367,71 +367,10 @@ Constant *DIFactory::GetStringConstant(const std::string &String) {
return Slot = ConstantExpr::getBitCast(StrGV, DestTy);
}
-/// GetOrCreateAnchor - Look up an anchor for the specified tag and name. If it
-/// already exists, return it. If not, create a new one and return it.
-DIAnchor DIFactory::GetOrCreateAnchor(unsigned TAG, const char *Name) {
- const Type *EltTy = StructType::get(Type::Int32Ty, Type::Int32Ty, NULL);
-
- // Otherwise, create the global or return it if already in the module.
- Constant *C = M.getOrInsertGlobal(Name, EltTy);
- assert(isa<GlobalVariable>(C) && "Incorrectly typed anchor?");
- GlobalVariable *GV = cast<GlobalVariable>(C);
-
- // If it has an initializer, it is already in the module.
- if (GV->hasInitializer())
- return SubProgramAnchor = DIAnchor(GV);
-
- GV->setLinkage(GlobalValue::LinkOnceAnyLinkage);
- GV->setSection("llvm.metadata");
- GV->setConstant(true);
- M.addTypeName("llvm.dbg.anchor.type", EltTy);
-
- // Otherwise, set the initializer.
- Constant *Elts[] = {
- GetTagConstant(dwarf::DW_TAG_anchor),
- ConstantInt::get(Type::Int32Ty, TAG)
- };
-
- GV->setInitializer(ConstantStruct::get(Elts, 2));
- return DIAnchor(GV);
-}
-
-
-
//===----------------------------------------------------------------------===//
// DIFactory: Primary Constructors
//===----------------------------------------------------------------------===//
-/// GetOrCreateCompileUnitAnchor - Return the anchor for compile units,
-/// creating a new one if there isn't already one in the module.
-DIAnchor DIFactory::GetOrCreateCompileUnitAnchor() {
- // If we already created one, just return it.
- if (!CompileUnitAnchor.isNull())
- return CompileUnitAnchor;
- return CompileUnitAnchor = GetOrCreateAnchor(dwarf::DW_TAG_compile_unit,
- "llvm.dbg.compile_units");
-}
-
-/// GetOrCreateSubprogramAnchor - Return the anchor for subprograms,
-/// creating a new one if there isn't already one in the module.
-DIAnchor DIFactory::GetOrCreateSubprogramAnchor() {
- // If we already created one, just return it.
- if (!SubProgramAnchor.isNull())
- return SubProgramAnchor;
- return SubProgramAnchor = GetOrCreateAnchor(dwarf::DW_TAG_subprogram,
- "llvm.dbg.subprograms");
-}
-
-/// GetOrCreateGlobalVariableAnchor - Return the anchor for globals,
-/// creating a new one if there isn't already one in the module.
-DIAnchor DIFactory::GetOrCreateGlobalVariableAnchor() {
- // If we already created one, just return it.
- if (!GlobalVariableAnchor.isNull())
- return GlobalVariableAnchor;
- return GlobalVariableAnchor = GetOrCreateAnchor(dwarf::DW_TAG_variable,
- "llvm.dbg.global_variables");
-}
-
/// GetOrCreateArray - Create an descriptor for an array of descriptors.
/// This implicitly uniques the arrays created.
DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
@@ -494,7 +433,7 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
unsigned RunTimeVer) {
Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_compile_unit),
- getCastToEmpty(GetOrCreateCompileUnitAnchor()),
+ Constant::getNullValue(EmptyStructPtr),
ConstantInt::get(Type::Int32Ty, LangID),
GetStringConstant(Filename),
GetStringConstant(Directory),
@@ -509,7 +448,7 @@ DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
M.addTypeName("llvm.dbg.compile_unit.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
- GlobalValue::InternalLinkage,
+ GlobalValue::LinkOnceAnyLinkage,
Init, "llvm.dbg.compile_unit", &M);
GV->setSection("llvm.metadata");
return DICompileUnit(GV);
@@ -655,7 +594,7 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_subprogram),
- getCastToEmpty(GetOrCreateSubprogramAnchor()),
+ Constant::getNullValue(EmptyStructPtr),
getCastToEmpty(Context),
GetStringConstant(Name),
GetStringConstant(DisplayName),
@@ -671,7 +610,7 @@ DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
M.addTypeName("llvm.dbg.subprogram.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
- GlobalValue::InternalLinkage,
+ GlobalValue::LinkOnceAnyLinkage,
Init, "llvm.dbg.subprogram", &M);
GV->setSection("llvm.metadata");
return DISubprogram(GV);
@@ -687,7 +626,7 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
bool isDefinition, llvm::GlobalVariable *Val) {
Constant *Elts[] = {
GetTagConstant(dwarf::DW_TAG_variable),
- getCastToEmpty(GetOrCreateGlobalVariableAnchor()),
+ Constant::getNullValue(EmptyStructPtr),
getCastToEmpty(Context),
GetStringConstant(Name),
GetStringConstant(DisplayName),
@@ -704,7 +643,7 @@ DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
M.addTypeName("llvm.dbg.global_variable.type", Init->getType());
GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
- GlobalValue::InternalLinkage,
+ GlobalValue::LinkOnceAnyLinkage,
Init, "llvm.dbg.global_variable", &M);
GV->setSection("llvm.metadata");
return DIGlobalVariable(GV);
@@ -954,12 +893,42 @@ namespace llvm {
Unit.getDirectory(Dir);
return true;
}
+
+ /// CollectDebugInfoAnchors - Collect debugging information anchors.
+ void CollectDebugInfoAnchors(Module &M,
+ SmallVector<GlobalVariable *, 2> &CUs,
+ SmallVector<GlobalVariable *, 4> &GVs,
+ SmallVector<GlobalVariable *, 4> &SPs) {
+
+ for (Module::global_iterator GVI = M.global_begin(), E = M.global_end();
+ GVI != E; GVI++) {
+ GlobalVariable *GV = GVI;
+ if (GV->hasName() && strncmp(GV->getNameStart(), "llvm.dbg", 8) == 0
+ && GV->isConstant() && GV->hasInitializer()) {
+ DICompileUnit C(GV);
+ if (C.isNull() == false) {
+ CUs.push_back(GV);
+ continue;
+ }
+ DIGlobalVariable G(GV);
+ if (G.isNull() == false) {
+ GVs.push_back(GV);
+ continue;
+ }
+ DISubprogram S(GV);
+ if (S.isNull() == false) {
+ SPs.push_back(GV);
+ continue;
+ }
+ }
+ }
+ }
}
/// dump - Print descriptor.
void DIDescriptor::dump() const {
cerr << "[" << dwarf::TagString(getTag()) << "] ";
- cerr << std::hex << "[GV:" << GV << "]" << std::dec;
+ cerr << std::hex << "[GV:" << DbgGV << "]" << std::dec;
}
/// dump - Print compile unit.
@@ -1000,11 +969,11 @@ void DIType::dump() const {
cerr << " [fwd] ";
if (isBasicType(Tag))
- DIBasicType(GV).dump();
+ DIBasicType(DbgGV).dump();
else if (isDerivedType(Tag))
- DIDerivedType(GV).dump();
+ DIDerivedType(DbgGV).dump();
else if (isCompositeType(Tag))
- DICompositeType(GV).dump();
+ DICompositeType(DbgGV).dump();
else {
cerr << "Invalid DIType\n";
return;
@@ -1051,7 +1020,7 @@ void DIGlobal::dump() const {
cerr << " [def] ";
if (isGlobalVariable(Tag))
- DIGlobalVariable(GV).dump();
+ DIGlobalVariable(DbgGV).dump();
cerr << "\n";
}
@@ -1077,3 +1046,4 @@ void DIVariable::dump() const {
getType().dump();
cerr << "\n";
}
+
OpenPOWER on IntegriCloud