Place dwarf headers at earliest possible point. Well behaved when skipping

functions.

llvm-svn: 28781
This commit is contained in:
Jim Laskey 2006-06-14 11:35:03 +00:00
parent 0c4f5a655a
commit f67bec0579
5 changed files with 81 additions and 58 deletions

View File

@ -106,6 +106,15 @@ protected:
///
bool didInitial;
/// shouldEmit - Flag to indicate if debug information should be emitted.
///
bool shouldEmit;
/// IsNormalText - Flag to indicate if routine is not special case text
/// (coalesced.)
// FIXME - should be able to debug coalesced functions.
bool IsNormalText;
/// SubprogramCount - The running count of functions being compiled.
///
unsigned SubprogramCount;
@ -372,7 +381,7 @@ private:
/// EmitInitial - Emit initial Dwarf declarations.
///
void EmitInitial() const;
void EmitInitial();
/// EmitDIE - Recusively Emits a debug information entry.
///
@ -448,9 +457,8 @@ private:
void ConstructSubprogramDIEs();
/// ShouldEmitDwarf - Returns true if Dwarf declarations should be made.
/// When called it also checks to see if debug info is newly available. if
/// so the initial Dwarf headers are emitted.
bool ShouldEmitDwarf();
///
bool ShouldEmitDwarf() const { return shouldEmit; }
public:
@ -475,11 +483,15 @@ public:
/// BeginFunction - Gather pre-function debug information. Assumes being
/// emitted immediately after the function entry point.
void BeginFunction(MachineFunction *MF);
void BeginFunction(MachineFunction *MF, bool IsNormalText);
/// EndFunction - Gather and emit post-function debug information.
///
void EndFunction();
/// NonFunction - Function does not have a true body.
///
void NonFunction();
};
} // end llvm namespace

View File

@ -1646,7 +1646,11 @@ void DwarfWriter::ConstructRootScope(DebugScope *RootScope) {
/// EmitInitial - Emit initial Dwarf declarations. This is necessary for cc
/// tools to recognize the object file contains Dwarf information.
///
void DwarfWriter::EmitInitial() const {
void DwarfWriter::EmitInitial() {
// Check to see if we already emitted intial headers.
if (didInitial) return;
didInitial = true;
// Dwarf sections base addresses.
Asm->SwitchToDataSection(DwarfFrameSection, 0);
EmitLabel("section_frame", 0);
@ -1676,6 +1680,9 @@ void DwarfWriter::EmitInitial() const {
EmitLabel("text_begin", 0);
Asm->SwitchToDataSection(DataSection, 0);
EmitLabel("data_begin", 0);
// Emit common frame information.
EmitInitialDebugFrame();
}
/// EmitDIE - Recusively Emits a debug information entry.
@ -2286,35 +2293,6 @@ void DwarfWriter::ConstructSubprogramDIEs() {
}
}
/// ShouldEmitDwarf - Determine if Dwarf declarations should be made.
///
bool DwarfWriter::ShouldEmitDwarf() {
// Check if debug info is present.
if (!DebugInfo || !DebugInfo->hasInfo()) return false;
// Make sure initial declarations are made.
if (!didInitial) {
EmitInitial();
// Emit common frame information.
EmitInitialDebugFrame();
// Create all the compile unit DIEs.
ConstructCompileUnitDIEs();
// Create DIEs for each of the externally visible global variables.
ConstructGlobalDIEs();
// Create DIEs for each of the externally visible subprograms.
ConstructSubprogramDIEs();
didInitial = true;
}
// Okay to emit.
return true;
}
//===----------------------------------------------------------------------===//
// Main entry points.
//
@ -2328,6 +2306,8 @@ DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A)
, MF(NULL)
, DebugInfo(NULL)
, didInitial(false)
, shouldEmit(false)
, IsNormalText(false)
, SubprogramCount(0)
, CompileUnits()
, Abbreviations()
@ -2363,7 +2343,23 @@ DwarfWriter::~DwarfWriter() {
/// SetDebugInfo - Set DebugInfo when it's known that pass manager has
/// created it. Set by the target AsmPrinter.
void DwarfWriter::SetDebugInfo(MachineDebugInfo *DI) {
// Make sure initial declarations are made.
if (!DebugInfo && DI->hasInfo()) {
DebugInfo = DI;
shouldEmit = true;
// Emit initial sections
EmitInitial();
// Create all the compile unit DIEs.
ConstructCompileUnitDIEs();
// Create DIEs for each of the externally visible global variables.
ConstructGlobalDIEs();
// Create DIEs for each of the externally visible subprograms.
ConstructSubprogramDIEs();
}
}
/// BeginModule - Emit all Dwarf sections that should come prior to the content.
@ -2420,9 +2416,13 @@ void DwarfWriter::EndModule() {
/// BeginFunction - Gather pre-function debug information. Assumes being
/// emitted immediately after the function entry point.
void DwarfWriter::BeginFunction(MachineFunction *MF) {
void DwarfWriter::BeginFunction(MachineFunction *MF, bool IsNormalText) {
this->MF = MF;
// FIXME - should be able to debug coalesced functions.
this->IsNormalText = IsNormalText;
// FIXME - should be able to debug coalesced functions.
if (IsNormalText) {
// Begin accumulating function debug information.
DebugInfo->BeginFunction(MF);
@ -2431,6 +2431,9 @@ void DwarfWriter::BeginFunction(MachineFunction *MF) {
// Assumes in correct section after the entry point.
EmitLabel("func_begin", ++SubprogramCount);
} else {
ShouldEmitDwarf();
}
}
/// EndFunction - Gather and emit post-function debug information.
@ -2439,6 +2442,8 @@ void DwarfWriter::EndFunction() {
if (!ShouldEmitDwarf()) return;
EOL("Dwarf End Function");
// FIXME - should be able to debug coalesced functions.
if (IsNormalText) {
// Define end label for subprogram.
EmitLabel("func_end", SubprogramCount);
@ -2447,6 +2452,7 @@ void DwarfWriter::EndFunction() {
// Emit function frame information.
EmitFunctionDebugFrame();
}
// Clear function debug information.
DebugInfo->EndFunction();

View File

@ -262,10 +262,10 @@ public:
Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
}
virtual void Apply(int64_t &Field) {
Elements.push_back(ConstantSInt::get(Type::IntTy, Field));
Elements.push_back(ConstantSInt::get(Type::LongTy, Field));
}
virtual void Apply(uint64_t &Field) {
Elements.push_back(ConstantUInt::get(Type::UIntTy, Field));
Elements.push_back(ConstantUInt::get(Type::ULongTy, Field));
}
virtual void Apply(bool &Field) {
Elements.push_back(ConstantBool::get(Field));
@ -345,10 +345,10 @@ public:
Fields.push_back(Type::UIntTy);
}
virtual void Apply(int64_t &Field) {
Fields.push_back(Type::IntTy);
Fields.push_back(Type::LongTy);
}
virtual void Apply(uint64_t &Field) {
Fields.push_back(Type::UIntTy);
Fields.push_back(Type::ULongTy);
}
virtual void Apply(bool &Field) {
Fields.push_back(Type::BoolTy);

View File

@ -488,8 +488,9 @@ void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
/// method to print assembly for each instruction.
///
bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// FIXME - is this the earliest this can be set?
DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>());
// FIXME - should be able to debug coalesced functions.
bool IsNormalText = true;
SetupMachineFunction(MF);
O << "\n\n";
@ -517,13 +518,14 @@ bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F);
O << "\t.globl\t" << CurrentFnName << "\n";
O << "\t.weak_definition\t" << CurrentFnName << "\n";
IsNormalText = false;
break;
}
EmitAlignment(4, F);
O << CurrentFnName << ":\n";
// Emit pre-function debug information.
DW.BeginFunction(&MF);
DW.BeginFunction(&MF, IsNormalText);
// Print out code for the function.
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();

View File

@ -29,6 +29,8 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// Let PassManager know we need debug information and relay
// the MachineDebugInfo address on to DwarfWriter.
DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>());
// FIXME - should be able to debug coalesced functions.
bool IsNormalText = true;
SetupMachineFunction(MF);
O << "\n\n";
@ -72,13 +74,14 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
SwitchToTextSection("", F);
O << "\t.weak " << CurrentFnName << "\n";
}
IsNormalText = false;
break;
}
O << CurrentFnName << ":\n";
if (Subtarget->TargetType == X86Subtarget::isDarwin) {
// Emit pre-function debug information.
DW.BeginFunction(&MF);
DW.BeginFunction(&MF, IsNormalText);
}
// Print out code for the function.