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.
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,
return ScopeDIE;
const SmallVectorImpl<InsnRange> &ScopeRanges = Scope->getRanges();
+
// If we have multiple ranges, emit them into the range section.
if (ScopeRanges.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.
- TheCU->addSectionLabel(
- ScopeDIE, dwarf::DW_AT_ranges,
- Asm->GetTempSymbol("debug_ranges", GlobalRangeCount));
- RangeSpanList *List = new RangeSpanList(GlobalRangeCount++);
- for (SmallVectorImpl<InsnRange>::const_iterator RI = ScopeRanges.begin(),
- RE = ScopeRanges.end();
- RI != RE; ++RI) {
- RangeSpan Range(getLabelBeforeInsn(RI->first),
- getLabelAfterInsn(RI->second));
- List->addRange(Range);
- }
-
- // Add the range list to the set of ranges to be emitted.
- TheCU->addRangeList(List);
+ addScopeRangeList(TheCU, ScopeDIE, ScopeRanges);
return ScopeDIE;
}
DIE *ScopeDIE = new DIE(dwarf::DW_TAG_inlined_subroutine);
TheCU->addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin, OriginDIE);
- if (ScopeRanges.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.
- TheCU->addSectionLabel(
- ScopeDIE, dwarf::DW_AT_ranges,
- Asm->GetTempSymbol("debug_ranges", GlobalRangeCount));
- RangeSpanList *List = new RangeSpanList(GlobalRangeCount++);
- for (SmallVectorImpl<InsnRange>::const_iterator RI = ScopeRanges.begin(),
- RE = ScopeRanges.end();
- RI != RE; ++RI) {
- RangeSpan Range(getLabelBeforeInsn(RI->first),
- getLabelAfterInsn(RI->second));
- List->addRange(Range);
- }
-
- // Add the range list to the set of ranges to be emitted.
- TheCU->addRangeList(List);
- } else {
+ // 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