#include "DIE.h"
#include "DIEHash.h"
#include "DwarfAccelTable.h"
-#include "DwarfCompileUnit.h"
+#include "DwarfUnit.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
return TmpSym;
}
+DwarfUnits::~DwarfUnits() {
+ for (SmallVectorImpl<Unit *>::iterator I = CUs.begin(), E = CUs.end(); I != E;
+ ++I)
+ delete *I;
+}
+
MCSymbol *DwarfUnits::getStringPoolSym() {
return Asm->GetTempSymbol(StringPref);
}
// TODO: Determine whether or not we should add names for programs
// that do not have a DW_AT_name or DW_AT_linkage_name field - this
// is only slightly different than the lookup of non-standard ObjC names.
-static void addSubprogramNames(CompileUnit *TheCU, DISubprogram SP, DIE *Die) {
+static void addSubprogramNames(Unit *TheCU, DISubprogram SP, DIE *Die) {
if (!SP.isDefinition())
return;
TheCU->addAccelName(SP.getName(), Die);
// If we have multiple ranges, emit them into the range section.
if (Ranges.size() > 1) {
// .debug_range section has not been laid out yet. Emit offset in
- // .debug_range as a uint, size 4, for now. emitDIE will handle
- // DW_AT_ranges appropriately.
- TheCU->addSectionOffset(ScopeDIE, dwarf::DW_AT_ranges,
- DebugRangeSymbols.size() *
- Asm->getDataLayout().getPointerSize());
+ // .debug_range as a relocatable label. emitDIE will handle
+ // emitting it appropriately.
+ unsigned Offset = DebugRangeSymbols.size();
+ TheCU->addSectionLabel(ScopeDIE, dwarf::DW_AT_ranges,
+ Asm->GetTempSymbol("debug_ranges", Offset));
for (SmallVectorImpl<InsnRange>::const_iterator RI = Ranges.begin(),
RE = Ranges.end();
RI != RE; ++RI) {
if (Ranges.size() > 1) {
// .debug_range section has not been laid out yet. Emit offset in
- // .debug_range as a uint, size 4, for now. emitDIE will handle
- // DW_AT_ranges appropriately.
- TheCU->addSectionOffset(ScopeDIE, dwarf::DW_AT_ranges,
- DebugRangeSymbols.size() *
- Asm->getDataLayout().getPointerSize());
+ // .debug_range as a relocatable label. emitDIE will handle
+ // emitting it appropriately.
+ unsigned Offset = DebugRangeSymbols.size();
+ TheCU->addSectionLabel(ScopeDIE, dwarf::DW_AT_ranges,
+ Asm->GetTempSymbol("debug_ranges", Offset));
for (SmallVectorImpl<InsnRange>::const_iterator RI = Ranges.begin(),
RE = Ranges.end();
RI != RE; ++RI) {
if (DS.isSubprogram() && ObjectPointer != NULL)
TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_object_pointer, ObjectPointer);
- if (DS.isSubprogram())
- TheCU->addPubTypes(DISubprogram(DS));
-
return ScopeDIE;
}
continue;
// Construct subprogram DIE and add variables DIEs.
- CompileUnit *SPCU = CUMap.lookup(TheCU);
+ CompileUnit *SPCU = static_cast<CompileUnit *>(CUMap.lookup(TheCU));
assert(SPCU && "Unable to find Compile Unit!");
// FIXME: See the comment in constructSubprogramDIE about duplicate
// subprogram DIEs.
/// Test if the current CU language is C++ and that we have
/// a named type that is not contained in an anonymous namespace.
-static bool shouldAddODRHash(CompileUnit *CU, DIE *Die) {
+static bool shouldAddODRHash(TypeUnit *CU, DIE *Die) {
return CU->getLanguage() == dwarf::DW_LANG_C_plus_plus &&
getDIEStringAttr(Die, dwarf::DW_AT_name) != "" &&
!isContainedInAnonNamespace(Die);
computeInlinedDIEs();
// Handle anything that needs to be done on a per-cu basis.
- for (DenseMap<const MDNode *, CompileUnit *>::iterator CUI = CUMap.begin(),
- CUE = CUMap.end();
- CUI != CUE; ++CUI) {
- CompileUnit *TheCU = CUI->second;
+ for (SmallVectorImpl<Unit *>::const_iterator I = getUnits().begin(),
+ E = getUnits().end();
+ I != E; ++I) {
+ Unit *TheCU = *I;
// Emit DW_AT_containing_type attribute to connect types with their
// vtable holding type.
TheCU->constructContainingTypeDIEs();
// If we're splitting the dwarf out now that we've got the entire
// CU then construct a skeleton CU based upon it.
- if (useSplitDwarf()) {
+ if (useSplitDwarf() &&
+ TheCU->getCUDie()->getTag() == dwarf::DW_TAG_compile_unit) {
uint64_t ID = 0;
if (GenerateCUHash) {
DIEHash CUHash;
TheCU->addUInt(TheCU->getCUDie(), dwarf::DW_AT_GNU_dwo_id,
dwarf::DW_FORM_data8, ID);
// Now construct the skeleton CU associated.
- CompileUnit *SkCU = constructSkeletonCU(TheCU);
+ CompileUnit *SkCU =
+ constructSkeletonCU(static_cast<CompileUnit *>(TheCU));
// This should be a unique identifier when we want to build .dwp files.
SkCU->addUInt(SkCU->getCUDie(), dwarf::DW_AT_GNU_dwo_id,
dwarf::DW_FORM_data8, ID);
// clean up.
SPMap.clear();
- for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
- E = CUMap.end();
- I != E; ++I)
- delete I->second;
-
- for (SmallVectorImpl<CompileUnit *>::iterator I = SkeletonCUs.begin(),
- E = SkeletonCUs.end();
- I != E; ++I)
- delete *I;
// Reset these for the next Module if we have one.
FirstCU = NULL;
// Iterate over each compile unit and set the size and offsets for each
// DIE within each compile unit. All offsets are CU relative.
- for (SmallVectorImpl<CompileUnit *>::iterator I = CUs.begin(), E = CUs.end();
+ for (SmallVectorImpl<Unit *>::const_iterator I = CUs.begin(), E = CUs.end();
I != E; ++I) {
(*I)->setDebugInfoOffset(SecOffset);
}
case dwarf::DW_AT_ranges: {
// DW_AT_range Value encodes offset in debug_range section.
- DIEInteger *V = cast<DIEInteger>(Values[i]);
+ DIELabel *V = cast<DIELabel>(Values[i]);
- if (Asm->MAI->doesDwarfUseRelocationsAcrossSections()) {
- Asm->EmitLabelPlusOffset(DwarfDebugRangeSectionSym, V->getValue(), 4);
- } else {
- Asm->EmitLabelOffsetDifference(DwarfDebugRangeSectionSym, V->getValue(),
- DwarfDebugRangeSectionSym, 4);
- }
+ if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
+ Asm->EmitSectionOffset(V->getValue(), DwarfDebugRangeSectionSym);
+ else
+ Asm->EmitLabelDifference(V->getValue(), DwarfDebugRangeSectionSym, 4);
break;
}
case dwarf::DW_AT_location: {
const MCSection *ASection,
const MCSymbol *ASectionSym) {
Asm->OutStreamer.SwitchSection(USection);
- for (SmallVectorImpl<CompileUnit *>::iterator I = CUs.begin(), E = CUs.end();
- I != E; ++I) {
- CompileUnit *TheCU = *I;
+ for (SmallVectorImpl<Unit *>::iterator I = CUs.begin(), E = CUs.end(); I != E;
+ ++I) {
+ Unit *TheCU = *I;
DIE *Die = TheCU->getCUDie();
// Emit the compile units header.
void DwarfDebug::emitAccelNames() {
DwarfAccelTable AT(
DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4));
- for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
- E = CUMap.end();
+ for (SmallVectorImpl<Unit *>::const_iterator I = getUnits().begin(),
+ E = getUnits().end();
I != E; ++I) {
- CompileUnit *TheCU = I->second;
+ Unit *TheCU = *I;
const StringMap<std::vector<const DIE *> > &Names = TheCU->getAccelNames();
for (StringMap<std::vector<const DIE *> >::const_iterator
GI = Names.begin(),
void DwarfDebug::emitAccelObjC() {
DwarfAccelTable AT(
DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4));
- for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
- E = CUMap.end();
+ for (SmallVectorImpl<Unit *>::const_iterator I = getUnits().begin(),
+ E = getUnits().end();
I != E; ++I) {
- CompileUnit *TheCU = I->second;
+ Unit *TheCU = *I;
const StringMap<std::vector<const DIE *> > &Names = TheCU->getAccelObjC();
for (StringMap<std::vector<const DIE *> >::const_iterator
GI = Names.begin(),
void DwarfDebug::emitAccelNamespaces() {
DwarfAccelTable AT(
DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4));
- for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
- E = CUMap.end();
+ for (SmallVectorImpl<Unit *>::const_iterator I = getUnits().begin(),
+ E = getUnits().end();
I != E; ++I) {
- CompileUnit *TheCU = I->second;
+ Unit *TheCU = *I;
const StringMap<std::vector<const DIE *> > &Names =
TheCU->getAccelNamespace();
for (StringMap<std::vector<const DIE *> >::const_iterator
Atoms.push_back(
DwarfAccelTable::Atom(dwarf::DW_ATOM_type_flags, dwarf::DW_FORM_data1));
DwarfAccelTable AT(Atoms);
- for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
- E = CUMap.end();
+ for (SmallVectorImpl<Unit *>::const_iterator I = getUnits().begin(),
+ E = getUnits().end();
I != E; ++I) {
- CompileUnit *TheCU = I->second;
+ Unit *TheCU = *I;
const StringMap<std::vector<std::pair<const DIE *, unsigned> > > &Names =
TheCU->getAccelTypes();
for (StringMap<
// reference in the pubname header doesn't change.
/// computeIndexValue - Compute the gdb index value for the DIE and CU.
-static dwarf::PubIndexEntryDescriptor computeIndexValue(CompileUnit *CU,
+static dwarf::PubIndexEntryDescriptor computeIndexValue(Unit *CU,
const DIE *Die) {
dwarf::GDBIndexEntryLinkage Linkage = dwarf::GIEL_STATIC;
GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubNamesSection()
: Asm->getObjFileLowering().getDwarfPubNamesSection();
- typedef DenseMap<const MDNode *, CompileUnit *> CUMapType;
- for (CUMapType::iterator I = CUMap.begin(), E = CUMap.end(); I != E; ++I) {
- CompileUnit *TheCU = I->second;
+ for (SmallVectorImpl<Unit *>::const_iterator I = getUnits().begin(),
+ E = getUnits().end();
+ I != E; ++I) {
+ Unit *TheCU = *I;
unsigned ID = TheCU->getUniqueID();
// Start the dwarf pubnames section.
GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubTypesSection()
: Asm->getObjFileLowering().getDwarfPubTypesSection();
- for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
- E = CUMap.end();
+ for (SmallVectorImpl<Unit *>::const_iterator I = getUnits().begin(),
+ E = getUnits().end();
I != E; ++I) {
- CompileUnit *TheCU = I->second;
+ Unit *TheCU = *I;
// Start the dwarf pubtypes section.
Asm->OutStreamer.SwitchSection(PSec);
}
};
-static bool CUSort(const CompileUnit *A, const CompileUnit *B) {
+static bool CUSort(const Unit *A, const Unit *B) {
return (A->getUniqueID() < B->getUniqueID());
}
Asm->OutStreamer.SwitchSection(
Asm->getObjFileLowering().getDwarfRangesSection());
unsigned char Size = Asm->getDataLayout().getPointerSize();
- for (SmallVectorImpl<const MCSymbol *>::iterator
- I = DebugRangeSymbols.begin(),
- E = DebugRangeSymbols.end();
- I != E; ++I) {
- if (*I)
- Asm->OutStreamer.EmitSymbolValue(const_cast<MCSymbol *>(*I), Size);
+ for (uint32_t i = 0, e = DebugRangeSymbols.size(); i < e; ++i) {
+ // Only emit a symbol for every range pair for now.
+ // FIXME: Make this per range list.
+ if ((i % 2) == 0)
+ Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("debug_ranges", i));
+
+ const MCSymbol *I = DebugRangeSymbols[i];
+ if (I)
+ Asm->OutStreamer.EmitSymbolValue(I, Size);
else
Asm->OutStreamer.EmitIntValue(0, Size);
}
}
SkeletonHolder.addUnit(NewCU);
- SkeletonCUs.push_back(NewCU);
return NewCU;
}
OffSec, StrSym);
}
-void DwarfDebug::addTypeUnitType(DIE *RefDie, DICompositeType CTy) {
- DenseMap<const MDNode*, std::pair<uint64_t, SmallVectorImpl<DIE*>* > >::iterator I = TypeUnits.find(CTy);
+void DwarfDebug::addTypeUnitType(uint16_t Language, DIE *RefDie,
+ DICompositeType CTy) {
+ DenseMap<const MDNode *,
+ std::pair<uint64_t, SmallVectorImpl<DIE *> *> >::iterator I =
+ TypeUnits.find(CTy);
SmallVector<DIE *, 8> References;
References.push_back(RefDie);
if (I != TypeUnits.end()) {
}
} else {
DIE *UnitDie = new DIE(dwarf::DW_TAG_type_unit);
- CompileUnit *NewCU =
- new CompileUnit(GlobalCUIndexCount++, UnitDie,
- dwarf::DW_LANG_C_plus_plus, Asm, this, &InfoHolder);
- CUDieMap.insert(std::make_pair(UnitDie, NewCU));
- NewCU->addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
- dwarf::DW_LANG_C_plus_plus);
+ TypeUnit *NewTU = new TypeUnit(GlobalCUIndexCount++, UnitDie, Language, Asm,
+ this, &InfoHolder);
+ NewTU->addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
+ Language);
// Register the type in the TypeUnits map with a vector of references to be
// populated whenever a reference is required.
// Construct the type, this may, recursively, require more type units that
// may in turn require this type again - in which case they will add DIEs to
// the References vector.
- DIE *Die = NewCU->createTypeDIE(CTy);
+ DIE *Die = NewTU->createTypeDIE(CTy);
- if (GenerateODRHash && shouldAddODRHash(NewCU, Die))
- NewCU->addUInt(UnitDie, dwarf::DW_AT_GNU_odr_signature,
+ if (GenerateODRHash && shouldAddODRHash(NewTU, Die))
+ NewTU->addUInt(UnitDie, dwarf::DW_AT_GNU_odr_signature,
dwarf::DW_FORM_data8,
DIEHash().computeDIEODRSignature(*Die));
// FIXME: This won't handle circularly referential structures, as the DIE
I->second.first = Signature;
I->second.second = NULL;
-
- InfoHolder.addUnit(NewCU);
+ InfoHolder.addUnit(NewTU);
}
// Populate all the signatures.