// This file contains support for writing dwarf debug info into asm files.
//
//===----------------------------------------------------------------------===//
+
#define DEBUG_TYPE "dwarfdebug"
#include "DwarfDebug.h"
#include "llvm/Module.h"
} // end llvm namespace
DwarfDebug::DwarfDebug(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T)
- : DwarfPrinter(OS, A, T, "dbg"), ModuleCU(0),
+ : DwarfPrinter(OS, A, T), ModuleCU(0),
AbbreviationsSet(InitAbbreviationsSetSize), Abbreviations(),
DIEValues(), StringPool(),
SectionSourceLines(), didInitial(false), shouldEmit(false),
///
void DwarfDebug::addSectionOffset(DIE *Die, unsigned Attribute, unsigned Form,
const MCSymbol *Label,const MCSymbol *Section,
- bool isEH, bool useSet) {
- DIEValue *Value = new DIESectionOffset(Label, Section, isEH, useSet);
+ bool isEH) {
+ DIEValue *Value = new DIESectionOffset(Label, Section, isEH);
DIEValues.push_back(Value);
Die->addValue(Attribute, Form, Value);
}
/// constructLexicalScope - Construct new DW_TAG_lexical_block
/// for this scope and attach DW_AT_low_pc/DW_AT_high_pc labels.
DIE *DwarfDebug::constructLexicalScopeDIE(DbgScope *Scope) {
- unsigned StartID = MMI->MappedLabel(Scope->getStartLabelID());
- unsigned EndID = MMI->MappedLabel(Scope->getEndLabelID());
+ unsigned StartID = Scope->getStartLabelID();
+ unsigned EndID = Scope->getEndLabelID();
+ assert(!MMI->isLabelDeleted(StartID) &&
+ "Invalid starting label for an inlined scope!");
+ assert(!MMI->isLabelDeleted(EndID) &&
+ "Invalid end label for an inlined scope!");
+
// Ignore empty scopes.
if (StartID == EndID && StartID != 0)
return NULL;
/// a function. Construct DIE to represent this concrete inlined copy
/// of the function.
DIE *DwarfDebug::constructInlinedScopeDIE(DbgScope *Scope) {
- unsigned StartID = MMI->MappedLabel(Scope->getStartLabelID());
- unsigned EndID = MMI->MappedLabel(Scope->getEndLabelID());
- assert (StartID && "Invalid starting label for an inlined scope!");
- assert (EndID && "Invalid end label for an inlined scope!");
+ unsigned StartID = Scope->getStartLabelID();
+ unsigned EndID = Scope->getEndLabelID();
+ assert(!MMI->isLabelDeleted(StartID) &&
+ "Invalid starting label for an inlined scope!");
+ assert(!MMI->isLabelDeleted(EndID) &&
+ "Invalid end label for an inlined scope!");
// Ignore empty scopes.
- if (StartID == EndID && StartID != 0)
+ if (StartID == EndID)
return NULL;
if (!Scope->getScopeNode())
return NULL;
addDIEEntry(ScopeDIE, dwarf::DW_AT_abstract_origin,
dwarf::DW_FORM_ref4, OriginDIE);
- addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
- getDWLabel("label", StartID));
+ MCSymbol *StartLabel = getDWLabel("label", StartID);
+
+ addLabel(ScopeDIE, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, StartLabel);
addLabel(ScopeDIE, dwarf::DW_AT_high_pc, dwarf::DW_FORM_addr,
getDWLabel("label", EndID));
I = InlineInfo.find(InlinedSP.getNode());
if (I == InlineInfo.end()) {
- InlineInfo[InlinedSP.getNode()].push_back(std::make_pair(StartID,
+ InlineInfo[InlinedSP.getNode()].push_back(std::make_pair(StartLabel,
ScopeDIE));
InlinedSPNodes.push_back(InlinedSP.getNode());
} else
- I->second.push_back(std::make_pair(StartID, ScopeDIE));
+ I->second.push_back(std::make_pair(StartLabel, ScopeDIE));
StringPool.insert(InlinedSP.getName());
StringPool.insert(getRealLinkageName(InlinedSP.getLinkageName()));
unsigned Label = MMI->NextLabelID();
Asm->printLabel(Label);
- O << '\n';
SmallVector<DbgScope *, 2> &SD = I->second;
for (SmallVector<DbgScope *, 2>::iterator SDI = SD.begin(), SDE = SD.end();
DLT.getColumnNumber(),
DLT.getScope().getNode());
Asm->printLabel(LabelID);
- O << '\n';
}
if (TimePassesIsEnabled)
DebugTimer->stopTimer();
Asm->EmitInt8(0); EOL("Extended Op");
Asm->EmitInt8(TD->getPointerSize() + 1); EOL("Op size");
Asm->EmitInt8(dwarf::DW_LNE_set_address); EOL("DW_LNE_set_address");
- EmitReference("section_end", SectionEnd); EOL("Section end label");
+ EmitReference(getDWLabel("section_end", SectionEnd));
+ EOL("Section end label");
// Mark end of matrix.
Asm->EmitInt8(0); EOL("DW_LNE_end_sequence");
// Construct rows of the address, source, line, column matrix.
for (unsigned i = 0, N = LineInfos.size(); i < N; ++i) {
const SrcLineInfo &LineInfo = LineInfos[i];
- unsigned LabelID = MMI->MappedLabel(LineInfo.getLabelID());
- if (!LabelID) continue;
+ unsigned LabelID = LineInfo.getLabelID();
+ if (MMI->isLabelDeleted(LabelID)) continue;
if (LineInfo.getLine() == 0) continue;
Asm->EmitInt8(0); EOL("Extended Op");
Asm->EmitInt8(TD->getPointerSize() + 1); EOL("Op size");
Asm->EmitInt8(dwarf::DW_LNE_set_address); EOL("DW_LNE_set_address");
- EmitReference("label", LabelID); EOL("Location label");
+ EmitReference(getDWLabel("label", LabelID)); EOL("Location label");
// If change of source, then switch to the new source.
if (Source != LineInfo.getSourceID()) {
Asm->getObjFileLowering().getDwarfFrameSection());
Asm->OutStreamer.EmitLabel(getTempLabel("debug_frame_common"));
- EmitDifference("debug_frame_common_end", 0,
- "debug_frame_common_begin", 0, true);
+ EmitDifference(getTempLabel("debug_frame_common_end"),
+ getTempLabel("debug_frame_common_begin"), true);
EOL("Length of Common Information Entry");
Asm->OutStreamer.EmitLabel(getTempLabel("debug_frame_common_begin"));
Asm->OutStreamer.SwitchSection(
Asm->getObjFileLowering().getDwarfFrameSection());
- EmitDifference("debug_frame_end", DebugFrameInfo.Number,
- "debug_frame_begin", DebugFrameInfo.Number, true);
+ EmitDifference(getDWLabel("debug_frame_end", DebugFrameInfo.Number),
+ getDWLabel("debug_frame_begin", DebugFrameInfo.Number), true);
EOL("Length of Frame Information Entry");
Asm->OutStreamer.EmitLabel(getDWLabel("debug_frame_begin",
getTempLabel("section_debug_frame"), true, false);
EOL("FDE CIE offset");
- EmitReference("func_begin", DebugFrameInfo.Number);
+ EmitReference(getDWLabel("func_begin", DebugFrameInfo.Number));
EOL("FDE initial location");
- EmitDifference("func_end", DebugFrameInfo.Number,
- "func_begin", DebugFrameInfo.Number);
+ EmitDifference(getDWLabel("func_end", DebugFrameInfo.Number),
+ getDWLabel("func_begin", DebugFrameInfo.Number));
EOL("FDE address range");
EmitFrameMoves("func_begin", DebugFrameInfo.Number, DebugFrameInfo.Moves,
Asm->EmitAlignment(2, 0, 0, false);
Asm->OutStreamer.EmitLabel(getDWLabel("debug_frame_end",
DebugFrameInfo.Number));
- Asm->O << '\n';
}
/// emitDebugPubNames - Emit visible names into a debug pubnames section.
Asm->OutStreamer.SwitchSection(
Asm->getObjFileLowering().getDwarfPubNamesSection());
- EmitDifference("pubnames_end", ModuleCU->getID(),
- "pubnames_begin", ModuleCU->getID(), true);
+ EmitDifference(getDWLabel("pubnames_end", ModuleCU->getID()),
+ getDWLabel("pubnames_begin", ModuleCU->getID()), true);
EOL("Length of Public Names Info");
Asm->OutStreamer.EmitLabel(getDWLabel("pubnames_begin", ModuleCU->getID()));
true, false);
EOL("Offset of Compilation Unit Info");
- EmitDifference("info_end", ModuleCU->getID(), "info_begin", ModuleCU->getID(),
+ EmitDifference(getDWLabel("info_end", ModuleCU->getID()),
+ getDWLabel("info_begin", ModuleCU->getID()),
true);
EOL("Compilation Unit Length");
// Start the dwarf pubnames section.
Asm->OutStreamer.SwitchSection(
Asm->getObjFileLowering().getDwarfPubTypesSection());
- EmitDifference("pubtypes_end", ModuleCU->getID(),
- "pubtypes_begin", ModuleCU->getID(), true);
+ EmitDifference(getDWLabel("pubtypes_end", ModuleCU->getID()),
+ getDWLabel("pubtypes_begin", ModuleCU->getID()), true);
EOL("Length of Public Types Info");
Asm->OutStreamer.EmitLabel(getDWLabel("pubtypes_begin", ModuleCU->getID()));
getTempLabel("section_info"), true, false);
EOL("Offset of Compilation ModuleCU Info");
- EmitDifference("info_end", ModuleCU->getID(), "info_begin", ModuleCU->getID(),
+ EmitDifference(getDWLabel("info_end", ModuleCU->getID()),
+ getDWLabel("info_begin", ModuleCU->getID()),
true);
EOL("Compilation ModuleCU Length");
// Range 1
EmitReference("text_begin", 0); EOL("Address");
- EmitDifference("text_end", 0, "text_begin", 0, true); EOL("Length");
+ EmitDifference(getTempLabel("text_end"), getTempLabel("text_begin"),
+ true); EOL("Length");
Asm->EmitInt32(0); EOL("EOM (1)");
Asm->EmitInt32(0); EOL("EOM (2)");
Asm->OutStreamer.SwitchSection(
Asm->getObjFileLowering().getDwarfDebugInlineSection());
- EmitDifference("debug_inlined_end", 1,
- "debug_inlined_begin", 1, true);
+ EmitDifference(getDWLabel("debug_inlined_end", 1),
+ getDWLabel("debug_inlined_begin", 1), true);
EOL("Length of Debug Inlined Information Entry");
Asm->OutStreamer.EmitLabel(getDWLabel("debug_inlined_begin", 1));
for (SmallVector<InlineInfoLabels, 4>::iterator LI = Labels.begin(),
LE = Labels.end(); LI != LE; ++LI) {
- DIE *SP = LI->second;
- Asm->EmitInt32(SP->getOffset()); EOL("DIE offset");
-
- if (TD->getPointerSize() == sizeof(int32_t))
- O << MAI->getData32bitsDirective();
- else
- O << MAI->getData64bitsDirective();
+ if (Asm->VerboseAsm) Asm->OutStreamer.AddComment("DIE offset");
+ Asm->EmitInt32(LI->second->getOffset());
- PrintLabelName("label", LI->first); EOL("low_pc");
+ if (Asm->VerboseAsm) Asm->OutStreamer.AddComment("low_pc");
+ Asm->OutStreamer.EmitSymbolValue(LI->first, TD->getPointerSize(), 0);
}
}