: Asm(A), MMI(Asm->MMI), FirstCU(0),
AbbreviationsSet(InitAbbreviationsSetSize),
SourceIdMap(DIEValueAllocator), PrevLabel(NULL), GlobalCUIndexCount(0),
- InfoHolder(A, &AbbreviationsSet, Abbreviations, "info_string",
- DIEValueAllocator),
+ GlobalRangeCount(0), InfoHolder(A, &AbbreviationsSet, Abbreviations,
+ "info_string", DIEValueAllocator),
SkeletonAbbrevSet(InitAbbreviationsSetSize),
SkeletonHolder(A, &SkeletonAbbrevSet, SkeletonAbbrevs, "skel_string",
DIEValueAllocator) {
DwarfAddrSectionSym = 0;
DwarfAbbrevDWOSectionSym = DwarfStrDWOSectionSym = 0;
FunctionBeginSym = FunctionEndSym = 0;
+ CurFn = 0; CurMI = 0;
// Turn on accelerator tables for Darwin by default, pubnames by
// default for non-Darwin, and handle split dwarf.
}
}
- SPCU->addLabelAddress(
- SPDie, dwarf::DW_AT_low_pc,
- Asm->GetTempSymbol("func_begin", Asm->getFunctionNumber()));
- SPCU->addLabelAddress(
- SPDie, dwarf::DW_AT_high_pc,
- Asm->GetTempSymbol("func_end", Asm->getFunctionNumber()));
+ MCSymbol *FuncBegin =
+ Asm->GetTempSymbol("func_begin", Asm->getFunctionNumber());
+ MCSymbol *FuncEnd = Asm->GetTempSymbol("func_end", Asm->getFunctionNumber());
+ SPCU->addLabelAddress(SPDie, dwarf::DW_AT_low_pc, FuncBegin);
+ SPCU->addLabelAddress(SPDie, dwarf::DW_AT_high_pc, FuncEnd);
+
const TargetRegisterInfo *RI = Asm->TM.getRegisterInfo();
MachineLocation Location(RI->getFrameRegister(*Asm->MF));
SPCU->addAddress(SPDie, dwarf::DW_AT_frame_base, Location);
return !End;
}
+void DwarfDebug::addScopeRangeList(CompileUnit *TheCU, DIE *ScopeDIE,
+ const SmallVectorImpl<InsnRange> &Range) {
+ // Emit offset in .debug_range as a relocatable label. emitDIE will handle
+ // emitting it appropriately.
+ TheCU->addSectionLabel(ScopeDIE, dwarf::DW_AT_ranges,
+ Asm->GetTempSymbol("debug_ranges", GlobalRangeCount));
+ RangeSpanList *List = new RangeSpanList(GlobalRangeCount++);
+ for (SmallVectorImpl<InsnRange>::const_iterator RI = Range.begin(),
+ RE = Range.end();
+ RI != RE; ++RI) {
+ RangeSpan Span(getLabelBeforeInsn(RI->first),
+ getLabelAfterInsn(RI->second));
+ List->addRange(Span);
+ }
+
+ // Add the range list to the set of ranges to be emitted.
+ TheCU->addRangeList(List);
+}
+
// Construct new DW_TAG_lexical_block for this scope and attach
// DW_AT_low_pc/DW_AT_high_pc labels.
DIE *DwarfDebug::constructLexicalScopeDIE(CompileUnit *TheCU,
if (Scope->isAbstractScope())
return ScopeDIE;
- const SmallVectorImpl<InsnRange> &Ranges = Scope->getRanges();
- // 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 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) {
- DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first));
- DebugRangeSymbols.push_back(getLabelAfterInsn(RI->second));
- }
+ const SmallVectorImpl<InsnRange> &ScopeRanges = Scope->getRanges();
- // Terminate the range list.
- DebugRangeSymbols.push_back(NULL);
- DebugRangeSymbols.push_back(NULL);
+ // If we have multiple ranges, emit them into the range section.
+ if (ScopeRanges.size() > 1) {
+ addScopeRangeList(TheCU, ScopeDIE, ScopeRanges);
return ScopeDIE;
}
// Construct the address range for this DIE.
- SmallVectorImpl<InsnRange>::const_iterator RI = Ranges.begin();
+ SmallVectorImpl<InsnRange>::const_iterator RI = ScopeRanges.begin();
MCSymbol *Start = getLabelBeforeInsn(RI->first);
MCSymbol *End = getLabelAfterInsn(RI->second);
assert(End && "End label should not be null!");
// represent this concrete inlined copy of the function.
DIE *DwarfDebug::constructInlinedScopeDIE(CompileUnit *TheCU,
LexicalScope *Scope) {
- const SmallVectorImpl<InsnRange> &Ranges = Scope->getRanges();
- assert(Ranges.empty() == false &&
+ const SmallVectorImpl<InsnRange> &ScopeRanges = Scope->getRanges();
+ assert(ScopeRanges.empty() == false &&
"LexicalScope does not have instruction markers!");
if (!Scope->getScopeNode())
DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine);
TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin, OriginDIE);
- if (Ranges.size() > 1) {
- // .debug_range section has not been laid out yet. Emit offset in
- // .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) {
- DebugRangeSymbols.push_back(getLabelBeforeInsn(RI->first));
- DebugRangeSymbols.push_back(getLabelAfterInsn(RI->second));
- }
- DebugRangeSymbols.push_back(NULL);
- DebugRangeSymbols.push_back(NULL);
- } else {
- SmallVectorImpl<InsnRange>::const_iterator RI = Ranges.begin();
+ // If we have multiple ranges, emit them into the range section.
+ if (ScopeRanges.size() > 1)
+ addScopeRangeList(TheCU, ScopeDIE, ScopeRanges);
+ else {
+ SmallVectorImpl<InsnRange>::const_iterator RI = ScopeRanges.begin();
MCSymbol *StartLabel = getLabelBeforeInsn(RI->first);
MCSymbol *EndLabel = getLabelAfterInsn(RI->second);
// Emit all Dwarf sections that should come after the content.
void DwarfDebug::endModule() {
+ assert(CurFn == 0);
+ assert(CurMI == 0);
if (!FirstCU)
return;
}
// If Var is a current function argument then add it to CurrentFnArguments list.
-bool DwarfDebug::addCurrentFnArgument(const MachineFunction *MF,
- DbgVariable *Var, LexicalScope *Scope) {
+bool DwarfDebug::addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope) {
if (!LScopes.isCurrentFunctionScope(Scope))
return false;
DIVariable DV = Var->getVariable();
size_t Size = CurrentFnArguments.size();
if (Size == 0)
- CurrentFnArguments.resize(MF->getFunction()->arg_size());
+ CurrentFnArguments.resize(CurFn->getFunction()->arg_size());
// llvm::Function argument size is not good indicator of how many
// arguments does the function have at source level.
if (ArgNo > Size)
// Collect variable information from side table maintained by MMI.
void DwarfDebug::collectVariableInfoFromMMITable(
- const MachineFunction *MF, SmallPtrSet<const MDNode *, 16> &Processed) {
+ SmallPtrSet<const MDNode *, 16> &Processed) {
MachineModuleInfo::VariableDbgInfoMapTy &VMap = MMI->getVariableDbgInfo();
for (MachineModuleInfo::VariableDbgInfoMapTy::iterator VI = VMap.begin(),
VE = VMap.end();
DbgVariable *AbsDbgVariable = findAbstractVariable(DV, VP.second);
DbgVariable *RegVar = new DbgVariable(DV, AbsDbgVariable, this);
RegVar->setFrameIndex(VP.first);
- if (!addCurrentFnArgument(MF, RegVar, Scope))
+ if (!addCurrentFnArgument(RegVar, Scope))
addScopeVariable(Scope, RegVar);
if (AbsDbgVariable)
AbsDbgVariable->setFrameIndex(VP.first);
// Find variables for each lexical scope.
void
-DwarfDebug::collectVariableInfo(const MachineFunction *MF,
- SmallPtrSet<const MDNode *, 16> &Processed) {
+DwarfDebug::collectVariableInfo(SmallPtrSet<const MDNode *, 16> &Processed) {
// Grab the variable info that was squirreled away in the MMI side-table.
- collectVariableInfoFromMMITable(MF, Processed);
+ collectVariableInfoFromMMITable(Processed);
for (SmallVectorImpl<const MDNode *>::const_iterator
UVI = UserVariables.begin(),
DIVariable DV(Var);
LexicalScope *Scope = NULL;
if (DV.getTag() == dwarf::DW_TAG_arg_variable &&
- DISubprogram(DV.getContext()).describes(MF->getFunction()))
+ DISubprogram(DV.getContext()).describes(CurFn->getFunction()))
Scope = LScopes.getCurrentFunctionScope();
else if (MDNode *IA = DV.getInlinedAt())
Scope = LScopes.findInlinedScope(DebugLoc::getFromDILocation(IA));
assert(MInsn->isDebugValue() && "History must begin with debug value");
DbgVariable *AbsVar = findAbstractVariable(DV, MInsn->getDebugLoc());
DbgVariable *RegVar = new DbgVariable(DV, AbsVar, this);
- if (!addCurrentFnArgument(MF, RegVar, Scope))
+ if (!addCurrentFnArgument(RegVar, Scope))
addScopeVariable(Scope, RegVar);
if (AbsVar)
AbsVar->setMInsn(MInsn);
// Process beginning of an instruction.
void DwarfDebug::beginInstruction(const MachineInstr *MI) {
+ assert(CurMI == 0);
+ CurMI = MI;
// Check if source location changes, but ignore DBG_VALUE locations.
if (!MI->isDebugValue()) {
DebugLoc DL = MI->getDebugLoc();
}
// Process end of an instruction.
-void DwarfDebug::endInstruction(const MachineInstr *MI) {
+void DwarfDebug::endInstruction() {
+ assert(CurMI != 0);
// Don't create a new label after DBG_VALUE instructions.
// They don't generate code.
- if (!MI->isDebugValue())
+ if (!CurMI->isDebugValue())
PrevLabel = 0;
DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
- LabelsAfterInsn.find(MI);
+ LabelsAfterInsn.find(CurMI);
+ CurMI = 0;
// No label needed.
if (I == LabelsAfterInsn.end())
// Gather pre-function debug information. Assumes being called immediately
// after the function entry point has been emitted.
void DwarfDebug::beginFunction(const MachineFunction *MF) {
+ CurFn = MF;
// If there's no debug info for the function we're not going to do anything.
if (!MMI->hasDebugInfo())
// Gather and emit post-function debug information.
void DwarfDebug::endFunction(const MachineFunction *MF) {
- if (!MMI->hasDebugInfo() || LScopes.empty())
+ // Every beginFunction(MF) call should be followed by an endFunction(MF) call,
+ // though the beginFunction may not be called at all.
+ // We should handle both cases.
+ if (CurFn == 0)
+ CurFn = MF;
+ else
+ assert(CurFn == MF);
+ assert(CurFn != 0);
+
+ if (!MMI->hasDebugInfo() || LScopes.empty()) {
+ CurFn = 0;
return;
+ }
// Define end label for subprogram.
FunctionEndSym = Asm->GetTempSymbol("func_end", Asm->getFunctionNumber());
Asm->OutStreamer.getContext().setDwarfCompileUnitID(0);
SmallPtrSet<const MDNode *, 16> ProcessedVars;
- collectVariableInfo(MF, ProcessedVars);
+ collectVariableInfo(ProcessedVars);
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
CompileUnit *TheCU = SPMap.lookup(FnScope->getScopeNode());
DIE *CurFnDIE = constructScopeDIE(TheCU, FnScope);
- if (!MF->getTarget().Options.DisableFramePointerElim(*MF))
+ if (!CurFn->getTarget().Options.DisableFramePointerElim(*CurFn))
TheCU->addFlag(CurFnDIE, dwarf::DW_AT_APPLE_omit_frame_ptr);
// Clear debug info
LabelsBeforeInsn.clear();
LabelsAfterInsn.clear();
PrevLabel = NULL;
+ CurFn = 0;
}
// Register a source line with debug info. Returns the unique label that was
// Start the dwarf ranges section.
Asm->OutStreamer.SwitchSection(
Asm->getObjFileLowering().getDwarfRangesSection());
+
+ // Size for our labels.
unsigned char Size = Asm->getDataLayout().getPointerSize();
- 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
+
+ // Grab the specific ranges for the compile units in the module.
+ for (DenseMap<const MDNode *, CompileUnit *>::iterator I = CUMap.begin(),
+ E = CUMap.end();
+ I != E; ++I) {
+ CompileUnit *TheCU = I->second;
+ unsigned ID = TheCU->getUniqueID();
+
+ // Emit a symbol so we can find the beginning of our ranges.
+ Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("gnu_ranges", ID));
+
+ // Iterate over the misc ranges for the compile units in the module.
+ const SmallVectorImpl<RangeSpanList *> &RangeLists = TheCU->getRangeLists();
+ for (SmallVectorImpl<RangeSpanList *>::const_iterator
+ I = RangeLists.begin(),
+ E = RangeLists.end();
+ I != E; ++I) {
+ RangeSpanList *List = *I;
+
+ // Emit a symbol so we can find the beginning of the range.
+ Asm->OutStreamer.EmitLabel(
+ Asm->GetTempSymbol("debug_ranges", List->getIndex()));
+
+ for (SmallVectorImpl<RangeSpan>::const_iterator
+ I = List->getRanges().begin(),
+ E = List->getRanges().end();
+ I != E; ++I) {
+ RangeSpan Range = *I;
+ // We occasionally have ranges without begin/end labels.
+ // FIXME: Verify and fix.
+ const MCSymbol *Begin = Range.getStart();
+ const MCSymbol *End = Range.getEnd();
+ Begin ? Asm->OutStreamer.EmitSymbolValue(Begin, Size)
+ : Asm->OutStreamer.EmitIntValue(0, Size);
+ End ? Asm->OutStreamer.EmitSymbolValue(End, Size)
+ : Asm->OutStreamer.EmitIntValue(0, Size);
+ }
+
+ // And terminate the list with two 0 values.
Asm->OutStreamer.EmitIntValue(0, Size);
+ Asm->OutStreamer.EmitIntValue(0, Size);
+ }
}
}
DwarfGnuPubTypesSectionSym);
}
- // Flag if we've emitted any ranges and their location for the compile unit.
- if (DebugRangeSymbols.size()) {
+ // Attribute if we've emitted any ranges and their location for the compile unit.
+ if (CU->getRangeLists().size()) {
if (Asm->MAI->doesDwarfUseRelocationsAcrossSections())
- NewCU->addSectionLabel(Die, dwarf::DW_AT_GNU_ranges_base,
- DwarfDebugRangeSectionSym);
+ NewCU->addSectionLabel(
+ Die, dwarf::DW_AT_GNU_ranges_base,
+ Asm->GetTempSymbol("gnu_ranges", NewCU->getUniqueID()));
else
- NewCU->addUInt(Die, dwarf::DW_AT_GNU_ranges_base, dwarf::DW_FORM_data4,
- 0);
+ NewCU->addSectionDelta(
+ Die, dwarf::DW_AT_GNU_ranges_base,
+ Asm->GetTempSymbol("gnu_ranges", NewCU->getUniqueID()),
+ DwarfDebugRangeSectionSym);
}
SkeletonHolder.addUnit(NewCU);