Reapply r90858, a cleanup patch.

llvm-svn: 90979
This commit is contained in:
Devang Patel 2009-12-09 18:24:21 +00:00
parent ca5f9cb18b
commit 9ccfb641d1
2 changed files with 81 additions and 166 deletions

View File

@ -739,12 +739,12 @@ void DwarfDebug::addAddress(DIE *Die, unsigned Attribute,
} }
/// addType - Add a new type attribute to the specified entity. /// addType - Add a new type attribute to the specified entity.
void DwarfDebug::addType(CompileUnit *DW_Unit, DIE *Entity, DIType Ty) { void DwarfDebug::addType(DIE *Entity, DIType Ty) {
if (Ty.isNull()) if (Ty.isNull())
return; return;
// Check for pre-existence. // Check for pre-existence.
DIEEntry *Entry = DW_Unit->getDIEEntry(Ty.getNode()); DIEEntry *Entry = ModuleCU->getDIEEntry(Ty.getNode());
// If it exists then use the existing value. // If it exists then use the existing value.
if (Entry) { if (Entry) {
@ -754,37 +754,36 @@ void DwarfDebug::addType(CompileUnit *DW_Unit, DIE *Entity, DIType Ty) {
// Set up proxy. // Set up proxy.
Entry = createDIEEntry(); Entry = createDIEEntry();
DW_Unit->insertDIEEntry(Ty.getNode(), Entry); ModuleCU->insertDIEEntry(Ty.getNode(), Entry);
// Construct type. // Construct type.
DIE *Buffer = new DIE(dwarf::DW_TAG_base_type); DIE *Buffer = new DIE(dwarf::DW_TAG_base_type);
ModuleCU->insertDIE(Ty.getNode(), Buffer); ModuleCU->insertDIE(Ty.getNode(), Buffer);
if (Ty.isBasicType()) if (Ty.isBasicType())
constructTypeDIE(DW_Unit, *Buffer, DIBasicType(Ty.getNode())); constructTypeDIE(*Buffer, DIBasicType(Ty.getNode()));
else if (Ty.isCompositeType()) else if (Ty.isCompositeType())
constructTypeDIE(DW_Unit, *Buffer, DICompositeType(Ty.getNode())); constructTypeDIE(*Buffer, DICompositeType(Ty.getNode()));
else { else {
assert(Ty.isDerivedType() && "Unknown kind of DIType"); assert(Ty.isDerivedType() && "Unknown kind of DIType");
constructTypeDIE(DW_Unit, *Buffer, DIDerivedType(Ty.getNode())); constructTypeDIE(*Buffer, DIDerivedType(Ty.getNode()));
} }
// Add debug information entry to entity and appropriate context. // Add debug information entry to entity and appropriate context.
DIE *Die = NULL; DIE *Die = NULL;
DIDescriptor Context = Ty.getContext(); DIDescriptor Context = Ty.getContext();
if (!Context.isNull()) if (!Context.isNull())
Die = DW_Unit->getDIE(Context.getNode()); Die = ModuleCU->getDIE(Context.getNode());
if (Die) if (Die)
Die->addChild(Buffer); Die->addChild(Buffer);
else else
DW_Unit->addDie(Buffer); ModuleCU->addDie(Buffer);
Entry->setEntry(Buffer); Entry->setEntry(Buffer);
Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry); Entity->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, Entry);
} }
/// constructTypeDIE - Construct basic type die from DIBasicType. /// constructTypeDIE - Construct basic type die from DIBasicType.
void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, void DwarfDebug::constructTypeDIE(DIE &Buffer, DIBasicType BTy) {
DIBasicType BTy) {
// Get core information. // Get core information.
StringRef Name = BTy.getName(); StringRef Name = BTy.getName();
Buffer.setTag(dwarf::DW_TAG_base_type); Buffer.setTag(dwarf::DW_TAG_base_type);
@ -799,8 +798,7 @@ void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
} }
/// constructTypeDIE - Construct derived type die from DIDerivedType. /// constructTypeDIE - Construct derived type die from DIDerivedType.
void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, void DwarfDebug::constructTypeDIE(DIE &Buffer, DIDerivedType DTy) {
DIDerivedType DTy) {
// Get core information. // Get core information.
StringRef Name = DTy.getName(); StringRef Name = DTy.getName();
uint64_t Size = DTy.getSizeInBits() >> 3; uint64_t Size = DTy.getSizeInBits() >> 3;
@ -813,7 +811,7 @@ void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
// Map to main type, void will not have a type. // Map to main type, void will not have a type.
DIType FromTy = DTy.getTypeDerivedFrom(); DIType FromTy = DTy.getTypeDerivedFrom();
addType(DW_Unit, &Buffer, FromTy); addType(&Buffer, FromTy);
// Add name if not anonymous or intermediate type. // Add name if not anonymous or intermediate type.
if (!Name.empty()) if (!Name.empty())
@ -829,8 +827,7 @@ void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
} }
/// constructTypeDIE - Construct type DIE from DICompositeType. /// constructTypeDIE - Construct type DIE from DICompositeType.
void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, void DwarfDebug::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
DICompositeType CTy) {
// Get core information. // Get core information.
StringRef Name = CTy.getName(); StringRef Name = CTy.getName();
@ -841,7 +838,7 @@ void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
switch (Tag) { switch (Tag) {
case dwarf::DW_TAG_vector_type: case dwarf::DW_TAG_vector_type:
case dwarf::DW_TAG_array_type: case dwarf::DW_TAG_array_type:
constructArrayTypeDIE(DW_Unit, Buffer, &CTy); constructArrayTypeDIE(Buffer, &CTy);
break; break;
case dwarf::DW_TAG_enumeration_type: { case dwarf::DW_TAG_enumeration_type: {
DIArray Elements = CTy.getTypeArray(); DIArray Elements = CTy.getTypeArray();
@ -851,7 +848,7 @@ void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
DIE *ElemDie = NULL; DIE *ElemDie = NULL;
DIEnumerator Enum(Elements.getElement(i).getNode()); DIEnumerator Enum(Elements.getElement(i).getNode());
if (!Enum.isNull()) { if (!Enum.isNull()) {
ElemDie = constructEnumTypeDIE(DW_Unit, &Enum); ElemDie = constructEnumTypeDIE(&Enum);
Buffer.addChild(ElemDie); Buffer.addChild(ElemDie);
} }
} }
@ -861,7 +858,7 @@ void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
// Add return type. // Add return type.
DIArray Elements = CTy.getTypeArray(); DIArray Elements = CTy.getTypeArray();
DIDescriptor RTy = Elements.getElement(0); DIDescriptor RTy = Elements.getElement(0);
addType(DW_Unit, &Buffer, DIType(RTy.getNode())); addType(&Buffer, DIType(RTy.getNode()));
// Add prototype flag. // Add prototype flag.
addUInt(&Buffer, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1); addUInt(&Buffer, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1);
@ -870,7 +867,7 @@ void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) { for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) {
DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter); DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
DIDescriptor Ty = Elements.getElement(i); DIDescriptor Ty = Elements.getElement(i);
addType(DW_Unit, Arg, DIType(Ty.getNode())); addType(Arg, DIType(Ty.getNode()));
Buffer.addChild(Arg); Buffer.addChild(Arg);
} }
} }
@ -892,11 +889,9 @@ void DwarfDebug::constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
continue; continue;
DIE *ElemDie = NULL; DIE *ElemDie = NULL;
if (Element.getTag() == dwarf::DW_TAG_subprogram) if (Element.getTag() == dwarf::DW_TAG_subprogram)
ElemDie = createMemberSubprogramDIE(DW_Unit, ElemDie = createMemberSubprogramDIE(DISubprogram(Element.getNode()));
DISubprogram(Element.getNode()));
else else
ElemDie = createMemberDIE(DW_Unit, ElemDie = createMemberDIE(DIDerivedType(Element.getNode()));
DIDerivedType(Element.getNode()));
Buffer.addChild(ElemDie); Buffer.addChild(ElemDie);
} }
@ -951,26 +946,26 @@ void DwarfDebug::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy){
} }
/// constructArrayTypeDIE - Construct array type DIE from DICompositeType. /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
void DwarfDebug::constructArrayTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, void DwarfDebug::constructArrayTypeDIE(DIE &Buffer,
DICompositeType *CTy) { DICompositeType *CTy) {
Buffer.setTag(dwarf::DW_TAG_array_type); Buffer.setTag(dwarf::DW_TAG_array_type);
if (CTy->getTag() == dwarf::DW_TAG_vector_type) if (CTy->getTag() == dwarf::DW_TAG_vector_type)
addUInt(&Buffer, dwarf::DW_AT_GNU_vector, dwarf::DW_FORM_flag, 1); addUInt(&Buffer, dwarf::DW_AT_GNU_vector, dwarf::DW_FORM_flag, 1);
// Emit derived type. // Emit derived type.
addType(DW_Unit, &Buffer, CTy->getTypeDerivedFrom()); addType(&Buffer, CTy->getTypeDerivedFrom());
DIArray Elements = CTy->getTypeArray(); DIArray Elements = CTy->getTypeArray();
// Get an anonymous type for index type. // Get an anonymous type for index type.
DIE *IdxTy = DW_Unit->getIndexTyDie(); DIE *IdxTy = ModuleCU->getIndexTyDie();
if (!IdxTy) { if (!IdxTy) {
// Construct an anonymous type for index type. // Construct an anonymous type for index type.
IdxTy = new DIE(dwarf::DW_TAG_base_type); IdxTy = new DIE(dwarf::DW_TAG_base_type);
addUInt(IdxTy, dwarf::DW_AT_byte_size, 0, sizeof(int32_t)); addUInt(IdxTy, dwarf::DW_AT_byte_size, 0, sizeof(int32_t));
addUInt(IdxTy, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, addUInt(IdxTy, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
dwarf::DW_ATE_signed); dwarf::DW_ATE_signed);
DW_Unit->addDie(IdxTy); ModuleCU->addDie(IdxTy);
DW_Unit->setIndexTyDie(IdxTy); ModuleCU->setIndexTyDie(IdxTy);
} }
// Add subranges to array type. // Add subranges to array type.
@ -982,7 +977,7 @@ void DwarfDebug::constructArrayTypeDIE(CompileUnit *DW_Unit, DIE &Buffer,
} }
/// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator. /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
DIE *DwarfDebug::constructEnumTypeDIE(CompileUnit *DW_Unit, DIEnumerator *ETy) { DIE *DwarfDebug::constructEnumTypeDIE(DIEnumerator *ETy) {
DIE *Enumerator = new DIE(dwarf::DW_TAG_enumerator); DIE *Enumerator = new DIE(dwarf::DW_TAG_enumerator);
StringRef Name = ETy->getName(); StringRef Name = ETy->getName();
addString(Enumerator, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); addString(Enumerator, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
@ -992,8 +987,7 @@ DIE *DwarfDebug::constructEnumTypeDIE(CompileUnit *DW_Unit, DIEnumerator *ETy) {
} }
/// createGlobalVariableDIE - Create new DIE using GV. /// createGlobalVariableDIE - Create new DIE using GV.
DIE *DwarfDebug::createGlobalVariableDIE(CompileUnit *DW_Unit, DIE *DwarfDebug::createGlobalVariableDIE(const DIGlobalVariable &GV) {
const DIGlobalVariable &GV) {
// If the global variable was optmized out then no need to create debug info // If the global variable was optmized out then no need to create debug info
// entry. // entry.
if (!GV.getGlobal()) return NULL; if (!GV.getGlobal()) return NULL;
@ -1014,7 +1008,7 @@ DIE *DwarfDebug::createGlobalVariableDIE(CompileUnit *DW_Unit,
addString(GVDie, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string, addString(GVDie, dwarf::DW_AT_MIPS_linkage_name, dwarf::DW_FORM_string,
LinkageName); LinkageName);
} }
addType(DW_Unit, GVDie, GV.getType()); addType(GVDie, GV.getType());
if (!GV.isLocalToUnit()) if (!GV.isLocalToUnit())
addUInt(GVDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1); addUInt(GVDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
addSourceLine(GVDie, &GV); addSourceLine(GVDie, &GV);
@ -1030,13 +1024,13 @@ DIE *DwarfDebug::createGlobalVariableDIE(CompileUnit *DW_Unit,
} }
/// createMemberDIE - Create new member DIE. /// createMemberDIE - Create new member DIE.
DIE *DwarfDebug::createMemberDIE(CompileUnit *DW_Unit, const DIDerivedType &DT){ DIE *DwarfDebug::createMemberDIE(const DIDerivedType &DT) {
DIE *MemberDie = new DIE(DT.getTag()); DIE *MemberDie = new DIE(DT.getTag());
StringRef Name = DT.getName(); StringRef Name = DT.getName();
if (!Name.empty()) if (!Name.empty())
addString(MemberDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name); addString(MemberDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
addType(DW_Unit, MemberDie, DT.getTypeDerivedFrom()); addType(MemberDie, DT.getTypeDerivedFrom());
addSourceLine(MemberDie, &DT); addSourceLine(MemberDie, &DT);
@ -1090,8 +1084,7 @@ DIE *DwarfDebug::createMemberDIE(CompileUnit *DW_Unit, const DIDerivedType &DT){
/// createRawSubprogramDIE - Create new partially incomplete DIE. This is /// createRawSubprogramDIE - Create new partially incomplete DIE. This is
/// a helper routine used by createMemberSubprogramDIE and /// a helper routine used by createMemberSubprogramDIE and
/// createSubprogramDIE. /// createSubprogramDIE.
DIE *DwarfDebug::createRawSubprogramDIE(CompileUnit *DW_Unit, DIE *DwarfDebug::createRawSubprogramDIE(const DISubprogram &SP) {
const DISubprogram &SP) {
DIE *SPDie = new DIE(dwarf::DW_TAG_subprogram); DIE *SPDie = new DIE(dwarf::DW_TAG_subprogram);
addString(SPDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, SP.getName()); addString(SPDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, SP.getName());
@ -1120,9 +1113,9 @@ DIE *DwarfDebug::createRawSubprogramDIE(CompileUnit *DW_Unit,
unsigned SPTag = SPTy.getTag(); unsigned SPTag = SPTy.getTag();
if (Args.isNull() || SPTag != dwarf::DW_TAG_subroutine_type) if (Args.isNull() || SPTag != dwarf::DW_TAG_subroutine_type)
addType(DW_Unit, SPDie, SPTy); addType(SPDie, SPTy);
else else
addType(DW_Unit, SPDie, DIType(Args.getElement(0).getNode())); addType(SPDie, DIType(Args.getElement(0).getNode()));
unsigned VK = SP.getVirtuality(); unsigned VK = SP.getVirtuality();
if (VK) { if (VK) {
@ -1139,11 +1132,10 @@ DIE *DwarfDebug::createRawSubprogramDIE(CompileUnit *DW_Unit,
/// createMemberSubprogramDIE - Create new member DIE using SP. This routine /// createMemberSubprogramDIE - Create new member DIE using SP. This routine
/// always returns a die with DW_AT_declaration attribute. /// always returns a die with DW_AT_declaration attribute.
DIE *DwarfDebug::createMemberSubprogramDIE(CompileUnit *DW_Unit, DIE *DwarfDebug::createMemberSubprogramDIE(const DISubprogram &SP) {
const DISubprogram &SP) {
DIE *SPDie = ModuleCU->getDIE(SP.getNode()); DIE *SPDie = ModuleCU->getDIE(SP.getNode());
if (!SPDie) if (!SPDie)
SPDie = createSubprogramDIE(DW_Unit, SP); SPDie = createSubprogramDIE(SP);
// If SPDie has DW_AT_declaration then reuse it. // If SPDie has DW_AT_declaration then reuse it.
if (!SP.isDefinition()) if (!SP.isDefinition())
@ -1154,7 +1146,7 @@ DIE *DwarfDebug::createMemberSubprogramDIE(CompileUnit *DW_Unit,
if (TopLevelDIEs.insert(SPDie)) if (TopLevelDIEs.insert(SPDie))
TopLevelDIEsVector.push_back(SPDie); TopLevelDIEsVector.push_back(SPDie);
SPDie = createRawSubprogramDIE(DW_Unit, SP); SPDie = createRawSubprogramDIE(SP);
// Add arguments. // Add arguments.
DICompositeType SPTy = SP.getType(); DICompositeType SPTy = SP.getType();
@ -1163,7 +1155,7 @@ DIE *DwarfDebug::createMemberSubprogramDIE(CompileUnit *DW_Unit,
if (SPTag == dwarf::DW_TAG_subroutine_type) if (SPTag == dwarf::DW_TAG_subroutine_type)
for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) { for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter); DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
addType(DW_Unit, Arg, DIType(Args.getElement(i).getNode())); addType(Arg, DIType(Args.getElement(i).getNode()));
addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); // ?? addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); // ??
SPDie->addChild(Arg); SPDie->addChild(Arg);
} }
@ -1173,13 +1165,12 @@ DIE *DwarfDebug::createMemberSubprogramDIE(CompileUnit *DW_Unit,
} }
/// createSubprogramDIE - Create new DIE using SP. /// createSubprogramDIE - Create new DIE using SP.
DIE *DwarfDebug::createSubprogramDIE(CompileUnit *DW_Unit, DIE *DwarfDebug::createSubprogramDIE(const DISubprogram &SP) {
const DISubprogram &SP) {
DIE *SPDie = ModuleCU->getDIE(SP.getNode()); DIE *SPDie = ModuleCU->getDIE(SP.getNode());
if (SPDie) if (SPDie)
return SPDie; return SPDie;
SPDie = createRawSubprogramDIE(DW_Unit, SP); SPDie = createRawSubprogramDIE(SP);
if (!SP.isDefinition()) { if (!SP.isDefinition()) {
addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1); addUInt(SPDie, dwarf::DW_AT_declaration, dwarf::DW_FORM_flag, 1);
@ -1193,14 +1184,14 @@ DIE *DwarfDebug::createSubprogramDIE(CompileUnit *DW_Unit,
if (SPTag == dwarf::DW_TAG_subroutine_type) if (SPTag == dwarf::DW_TAG_subroutine_type)
for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) { for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter); DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
addType(DW_Unit, Arg, DIType(Args.getElement(i).getNode())); addType(Arg, DIType(Args.getElement(i).getNode()));
addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); // ?? addUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); // ??
SPDie->addChild(Arg); SPDie->addChild(Arg);
} }
} }
// DW_TAG_inlined_subroutine may refer to this DIE. // DW_TAG_inlined_subroutine may refer to this DIE.
DW_Unit->insertDIE(SP.getNode(), SPDie); ModuleCU->insertDIE(SP.getNode(), SPDie);
return SPDie; return SPDie;
} }
@ -1213,64 +1204,6 @@ CompileUnit &DwarfDebug::findCompileUnit(DICompileUnit Unit) const {
return *I->second; return *I->second;
} }
/// createDbgScopeVariable - Create a new scope variable.
///
DIE *DwarfDebug::createDbgScopeVariable(DbgVariable *DV, CompileUnit *Unit) {
// Get the descriptor.
const DIVariable &VD = DV->getVariable();
StringRef Name = VD.getName();
if (Name.empty())
return NULL;
// Translate tag to proper Dwarf tag. The result variable is dropped for
// now.
unsigned Tag;
switch (VD.getTag()) {
case dwarf::DW_TAG_return_variable:
return NULL;
case dwarf::DW_TAG_arg_variable:
Tag = dwarf::DW_TAG_formal_parameter;
break;
case dwarf::DW_TAG_auto_variable: // fall thru
default:
Tag = dwarf::DW_TAG_variable;
break;
}
// Define variable debug information entry.
DIE *VariableDie = new DIE(Tag);
addString(VariableDie, dwarf::DW_AT_name, dwarf::DW_FORM_string, Name);
// Add source line info if available.
addSourceLine(VariableDie, &VD);
// Add variable type.
// FIXME: isBlockByrefVariable should be reformulated in terms of complex
// addresses instead.
if (VD.isBlockByrefVariable())
addType(Unit, VariableDie, getBlockByrefType(VD.getType(), Name));
else
addType(Unit, VariableDie, VD.getType());
// Add variable address.
// Variables for abstract instances of inlined functions don't get a
// location.
MachineLocation Location;
unsigned FrameReg;
int Offset = RI->getFrameIndexReference(*MF, DV->getFrameIndex(), FrameReg);
Location.set(FrameReg, Offset);
if (VD.hasComplexAddress())
addComplexAddress(DV, VariableDie, dwarf::DW_AT_location, Location);
else if (VD.isBlockByrefVariable())
addBlockByrefAddress(DV, VariableDie, dwarf::DW_AT_location, Location);
else
addAddress(VariableDie, dwarf::DW_AT_location, Location);
return VariableDie;
}
/// getUpdatedDbgScope - Find or create DbgScope assicated with the instruction. /// getUpdatedDbgScope - Find or create DbgScope assicated with the instruction.
/// Initialize scope and update scope hierarchy. /// Initialize scope and update scope hierarchy.
DbgScope *DwarfDebug::getUpdatedDbgScope(MDNode *N, const MachineInstr *MI, DbgScope *DwarfDebug::getUpdatedDbgScope(MDNode *N, const MachineInstr *MI,
@ -1376,7 +1309,7 @@ DIE *DwarfDebug::updateSubprogramScopeDIE(MDNode *SPNode) {
if (!N) continue; if (!N) continue;
DIGlobalVariable GV(N); DIGlobalVariable GV(N);
if (GV.getContext().getNode() == SPNode) { if (GV.getContext().getNode() == SPNode) {
DIE *ScopedGVDie = createGlobalVariableDIE(ModuleCU, GV); DIE *ScopedGVDie = createGlobalVariableDIE(GV);
if (ScopedGVDie) if (ScopedGVDie)
SPDie->addChild(ScopedGVDie); SPDie->addChild(ScopedGVDie);
} }
@ -1465,8 +1398,7 @@ DIE *DwarfDebug::constructInlinedScopeDIE(DbgScope *Scope) {
/// constructVariableDIE - Construct a DIE for the given DbgVariable. /// constructVariableDIE - Construct a DIE for the given DbgVariable.
DIE *DwarfDebug::constructVariableDIE(DbgVariable *DV, DIE *DwarfDebug::constructVariableDIE(DbgVariable *DV, DbgScope *Scope) {
DbgScope *Scope, CompileUnit *Unit) {
// Get the descriptor. // Get the descriptor.
const DIVariable &VD = DV->getVariable(); const DIVariable &VD = DV->getVariable();
StringRef Name = VD.getName(); StringRef Name = VD.getName();
@ -1515,9 +1447,9 @@ DIE *DwarfDebug::constructVariableDIE(DbgVariable *DV,
// FIXME: isBlockByrefVariable should be reformulated in terms of complex // FIXME: isBlockByrefVariable should be reformulated in terms of complex
// addresses instead. // addresses instead.
if (VD.isBlockByrefVariable()) if (VD.isBlockByrefVariable())
addType(Unit, VariableDie, getBlockByrefType(VD.getType(), Name)); addType(VariableDie, getBlockByrefType(VD.getType(), Name));
else else
addType(Unit, VariableDie, VD.getType()); addType(VariableDie, VD.getType());
} }
// Add variable address. // Add variable address.
@ -1586,7 +1518,7 @@ DIE *DwarfDebug::constructScopeDIE(DbgScope *Scope) {
// Add variables to scope. // Add variables to scope.
SmallVector<DbgVariable *, 8> &Variables = Scope->getVariables(); SmallVector<DbgVariable *, 8> &Variables = Scope->getVariables();
for (unsigned i = 0, N = Variables.size(); i < N; ++i) { for (unsigned i = 0, N = Variables.size(); i < N; ++i) {
DIE *VariableDIE = constructVariableDIE(Variables[i], Scope, ModuleCU); DIE *VariableDIE = constructVariableDIE(Variables[i], Scope);
if (VariableDIE) if (VariableDIE)
ScopeDIE->addChild(VariableDIE); ScopeDIE->addChild(VariableDIE);
} }
@ -1695,7 +1627,7 @@ void DwarfDebug::constructGlobalVariableDIE(MDNode *N) {
if (ModuleCU->getDIE(DI_GV.getNode())) if (ModuleCU->getDIE(DI_GV.getNode()))
return; return;
DIE *VariableDie = createGlobalVariableDIE(ModuleCU, DI_GV); DIE *VariableDie = createGlobalVariableDIE(DI_GV);
// Add to map. // Add to map.
ModuleCU->insertDIE(N, VariableDie); ModuleCU->insertDIE(N, VariableDie);
@ -1728,7 +1660,7 @@ void DwarfDebug::constructSubprogramDIE(MDNode *N) {
// class type. // class type.
return; return;
DIE *SubprogramDie = createSubprogramDIE(ModuleCU, SP); DIE *SubprogramDie = createSubprogramDIE(SP);
// Add to map. // Add to map.
ModuleCU->insertDIE(N, SubprogramDie); ModuleCU->insertDIE(N, SubprogramDie);
@ -2419,13 +2351,16 @@ void DwarfDebug::emitDIE(DIE *Die) {
} }
} }
/// emitDebugInfo / emitDebugInfoPerCU - Emit the debug info section. /// emitDebugInfo - Emit the debug info section.
/// ///
void DwarfDebug::emitDebugInfoPerCU(CompileUnit *Unit) { void DwarfDebug::emitDebugInfo() {
DIE *Die = Unit->getCUDie(); // Start debug info section.
Asm->OutStreamer.SwitchSection(
Asm->getObjFileLowering().getDwarfInfoSection());
DIE *Die = ModuleCU->getCUDie();
// Emit the compile units header. // Emit the compile units header.
EmitLabel("info_begin", Unit->getID()); EmitLabel("info_begin", ModuleCU->getID());
// Emit size of content not including length itself // Emit size of content not including length itself
unsigned ContentSize = Die->getSize() + unsigned ContentSize = Die->getSize() +
@ -2446,17 +2381,10 @@ void DwarfDebug::emitDebugInfoPerCU(CompileUnit *Unit) {
Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB"); Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB"); Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB"); Asm->EmitInt8(0); Asm->EOL("Extra Pad For GDB");
EmitLabel("info_end", Unit->getID()); EmitLabel("info_end", ModuleCU->getID());
Asm->EOL(); Asm->EOL();
}
void DwarfDebug::emitDebugInfo() {
// Start debug info section.
Asm->OutStreamer.SwitchSection(
Asm->getObjFileLowering().getDwarfInfoSection());
emitDebugInfoPerCU(ModuleCU);
} }
/// emitAbbreviations - Emit the abbreviation section. /// emitAbbreviations - Emit the abbreviation section.
@ -2754,24 +2682,30 @@ DwarfDebug::emitFunctionDebugFrame(const FunctionDebugFrameInfo&DebugFrameInfo){
Asm->EOL(); Asm->EOL();
} }
void DwarfDebug::emitDebugPubNamesPerCU(CompileUnit *Unit) { /// emitDebugPubNames - Emit visible names into a debug pubnames section.
EmitDifference("pubnames_end", Unit->getID(), ///
"pubnames_begin", Unit->getID(), true); void DwarfDebug::emitDebugPubNames() {
// Start the dwarf pubnames section.
Asm->OutStreamer.SwitchSection(
Asm->getObjFileLowering().getDwarfPubNamesSection());
EmitDifference("pubnames_end", ModuleCU->getID(),
"pubnames_begin", ModuleCU->getID(), true);
Asm->EOL("Length of Public Names Info"); Asm->EOL("Length of Public Names Info");
EmitLabel("pubnames_begin", Unit->getID()); EmitLabel("pubnames_begin", ModuleCU->getID());
Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("DWARF Version"); Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("DWARF Version");
EmitSectionOffset("info_begin", "section_info", EmitSectionOffset("info_begin", "section_info",
Unit->getID(), 0, true, false); ModuleCU->getID(), 0, true, false);
Asm->EOL("Offset of Compilation Unit Info"); Asm->EOL("Offset of Compilation Unit Info");
EmitDifference("info_end", Unit->getID(), "info_begin", Unit->getID(), EmitDifference("info_end", ModuleCU->getID(), "info_begin", ModuleCU->getID(),
true); true);
Asm->EOL("Compilation Unit Length"); Asm->EOL("Compilation Unit Length");
const StringMap<DIE*> &Globals = Unit->getGlobals(); const StringMap<DIE*> &Globals = ModuleCU->getGlobals();
for (StringMap<DIE*>::const_iterator for (StringMap<DIE*>::const_iterator
GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) { GI = Globals.begin(), GE = Globals.end(); GI != GE; ++GI) {
const char *Name = GI->getKeyData(); const char *Name = GI->getKeyData();
@ -2782,21 +2716,11 @@ void DwarfDebug::emitDebugPubNamesPerCU(CompileUnit *Unit) {
} }
Asm->EmitInt32(0); Asm->EOL("End Mark"); Asm->EmitInt32(0); Asm->EOL("End Mark");
EmitLabel("pubnames_end", Unit->getID()); EmitLabel("pubnames_end", ModuleCU->getID());
Asm->EOL(); Asm->EOL();
} }
/// emitDebugPubNames - Emit visible names into a debug pubnames section.
///
void DwarfDebug::emitDebugPubNames() {
// Start the dwarf pubnames section.
Asm->OutStreamer.SwitchSection(
Asm->getObjFileLowering().getDwarfPubNamesSection());
emitDebugPubNamesPerCU(ModuleCU);
}
void DwarfDebug::emitDebugPubTypes() { void DwarfDebug::emitDebugPubTypes() {
// Start the dwarf pubnames section. // Start the dwarf pubnames section.
Asm->OutStreamer.SwitchSection( Asm->OutStreamer.SwitchSection(

View File

@ -314,60 +314,55 @@ class DwarfDebug : public Dwarf {
const MachineLocation &Location); const MachineLocation &Location);
/// addType - Add a new type attribute to the specified entity. /// addType - Add a new type attribute to the specified entity.
void addType(CompileUnit *DW_Unit, DIE *Entity, DIType Ty); void addType(DIE *Entity, DIType Ty);
void addPubTypes(DISubprogram SP); void addPubTypes(DISubprogram SP);
/// constructTypeDIE - Construct basic type die from DIBasicType. /// constructTypeDIE - Construct basic type die from DIBasicType.
void constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, void constructTypeDIE(DIE &Buffer,
DIBasicType BTy); DIBasicType BTy);
/// constructTypeDIE - Construct derived type die from DIDerivedType. /// constructTypeDIE - Construct derived type die from DIDerivedType.
void constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, void constructTypeDIE(DIE &Buffer,
DIDerivedType DTy); DIDerivedType DTy);
/// constructTypeDIE - Construct type DIE from DICompositeType. /// constructTypeDIE - Construct type DIE from DICompositeType.
void constructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, void constructTypeDIE(DIE &Buffer,
DICompositeType CTy); DICompositeType CTy);
/// constructSubrangeDIE - Construct subrange DIE from DISubrange. /// constructSubrangeDIE - Construct subrange DIE from DISubrange.
void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy); void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy);
/// constructArrayTypeDIE - Construct array type DIE from DICompositeType. /// constructArrayTypeDIE - Construct array type DIE from DICompositeType.
void constructArrayTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, void constructArrayTypeDIE(DIE &Buffer,
DICompositeType *CTy); DICompositeType *CTy);
/// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator. /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator.
DIE *constructEnumTypeDIE(CompileUnit *DW_Unit, DIEnumerator *ETy); DIE *constructEnumTypeDIE(DIEnumerator *ETy);
/// createGlobalVariableDIE - Create new DIE using GV. /// createGlobalVariableDIE - Create new DIE using GV.
DIE *createGlobalVariableDIE(CompileUnit *DW_Unit, DIE *createGlobalVariableDIE(const DIGlobalVariable &GV);
const DIGlobalVariable &GV);
/// createMemberDIE - Create new member DIE. /// createMemberDIE - Create new member DIE.
DIE *createMemberDIE(CompileUnit *DW_Unit, const DIDerivedType &DT); DIE *createMemberDIE(const DIDerivedType &DT);
/// createSubprogramDIE - Create new DIE using SP. /// createSubprogramDIE - Create new DIE using SP.
DIE *createSubprogramDIE(CompileUnit *DW_Unit, const DISubprogram &SP); DIE *createSubprogramDIE(const DISubprogram &SP);
/// createMemberSubprogramDIE - Create new member DIE using SP. This /// createMemberSubprogramDIE - Create new member DIE using SP. This
/// routine always returns a die with DW_AT_declaration attribute. /// routine always returns a die with DW_AT_declaration attribute.
DIE *createMemberSubprogramDIE(CompileUnit *DW_Unit, const DISubprogram &SP); DIE *createMemberSubprogramDIE(const DISubprogram &SP);
/// createRawSubprogramDIE - Create new partially incomplete DIE. This is /// createRawSubprogramDIE - Create new partially incomplete DIE. This is
/// a helper routine used by createMemberSubprogramDIE and /// a helper routine used by createMemberSubprogramDIE and
/// createSubprogramDIE. /// createSubprogramDIE.
DIE *createRawSubprogramDIE(CompileUnit *DW_Unit, const DISubprogram &SP); DIE *createRawSubprogramDIE(const DISubprogram &SP);
/// findCompileUnit - Get the compile unit for the given descriptor. /// findCompileUnit - Get the compile unit for the given descriptor.
/// ///
CompileUnit &findCompileUnit(DICompileUnit Unit) const; CompileUnit &findCompileUnit(DICompileUnit Unit) const;
/// createDbgScopeVariable - Create a new scope variable.
///
DIE *createDbgScopeVariable(DbgVariable *DV, CompileUnit *Unit);
/// getUpdatedDbgScope - Find or create DbgScope assicated with /// getUpdatedDbgScope - Find or create DbgScope assicated with
/// the instruction. Initialize scope and update scope hierarchy. /// the instruction. Initialize scope and update scope hierarchy.
DbgScope *getUpdatedDbgScope(MDNode *N, const MachineInstr *MI, MDNode *InlinedAt); DbgScope *getUpdatedDbgScope(MDNode *N, const MachineInstr *MI, MDNode *InlinedAt);
@ -397,7 +392,7 @@ class DwarfDebug : public Dwarf {
DIE *constructInlinedScopeDIE(DbgScope *Scope); DIE *constructInlinedScopeDIE(DbgScope *Scope);
/// constructVariableDIE - Construct a DIE for the given DbgVariable. /// constructVariableDIE - Construct a DIE for the given DbgVariable.
DIE *constructVariableDIE(DbgVariable *DV, DbgScope *S, CompileUnit *Unit); DIE *constructVariableDIE(DbgVariable *DV, DbgScope *S);
/// constructScopeDIE - Construct a DIE for this scope. /// constructScopeDIE - Construct a DIE for this scope.
DIE *constructScopeDIE(DbgScope *Scope); DIE *constructScopeDIE(DbgScope *Scope);
@ -418,10 +413,8 @@ class DwarfDebug : public Dwarf {
/// ///
void computeSizeAndOffsets(); void computeSizeAndOffsets();
/// EmitDebugInfo / emitDebugInfoPerCU - Emit the debug info section. /// EmitDebugInfo - Emit the debug info section.
/// ///
void emitDebugInfoPerCU(CompileUnit *Unit);
void emitDebugInfo(); void emitDebugInfo();
/// emitAbbreviations - Emit the abbreviation section. /// emitAbbreviations - Emit the abbreviation section.
@ -445,8 +438,6 @@ class DwarfDebug : public Dwarf {
/// section. /// section.
void emitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo); void emitFunctionDebugFrame(const FunctionDebugFrameInfo &DebugFrameInfo);
void emitDebugPubNamesPerCU(CompileUnit *Unit);
/// emitDebugPubNames - Emit visible names into a debug pubnames section. /// emitDebugPubNames - Emit visible names into a debug pubnames section.
/// ///
void emitDebugPubNames(); void emitDebugPubNames();