Skip to content

[DWARF] Identify prologue_end by instruction rather than DILocation #107264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/CodeGen/DebugHandlerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class DebugHandlerBase {

/// This location indicates end of function prologue and beginning of
/// function body.
DebugLoc PrologEndLoc;
const MachineInstr *PrologEndLoc;

/// This block includes epilogue instructions.
const MachineBasicBlock *EpilogBeginBlock = nullptr;
Expand Down
28 changes: 14 additions & 14 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2114,9 +2114,9 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
// (The new location might be an explicit line 0, which we do emit.)
if (DL.getLine() == 0 && LastAsmLine == 0)
return;
if (DL == PrologEndLoc) {
if (MI == PrologEndLoc) {
Flags |= DWARF2_FLAG_PROLOGUE_END | DWARF2_FLAG_IS_STMT;
PrologEndLoc = DebugLoc();
PrologEndLoc = nullptr;
}
// If the line changed, we call that a new statement; unless we went to
// line 0 and came back, in which case it is not a new statement.
Expand All @@ -2132,10 +2132,11 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
PrevInstLoc = DL;
}

static std::pair<DebugLoc, bool> findPrologueEndLoc(const MachineFunction *MF) {
static std::pair<const MachineInstr *, bool>
findPrologueEndLoc(const MachineFunction *MF) {
// First known non-DBG_VALUE and non-frame setup location marks
// the beginning of the function body.
DebugLoc LineZeroLoc;
const MachineInstr *LineZeroLoc = nullptr;
const Function &F = MF->getFunction();

// Some instructions may be inserted into prologue after this function. Must
Expand All @@ -2152,9 +2153,9 @@ static std::pair<DebugLoc, bool> findPrologueEndLoc(const MachineFunction *MF) {
// meaningful breakpoint. If none is found, return the first
// location after the frame setup.
if (MI.getDebugLoc().getLine())
return std::make_pair(MI.getDebugLoc(), IsEmptyPrologue);
return std::make_pair(&MI, IsEmptyPrologue);

LineZeroLoc = MI.getDebugLoc();
LineZeroLoc = &MI;
}
IsEmptyPrologue = false;
}
Expand Down Expand Up @@ -2185,10 +2186,10 @@ static void recordSourceLine(AsmPrinter &Asm, unsigned Line, unsigned Col,
Discriminator, Fn);
}

DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF,
unsigned CUID) {
std::pair<DebugLoc, bool> PrologEnd = findPrologueEndLoc(&MF);
DebugLoc PrologEndLoc = PrologEnd.first;
const MachineInstr *
DwarfDebug::emitInitialLocDirective(const MachineFunction &MF, unsigned CUID) {
std::pair<const MachineInstr *, bool> PrologEnd = findPrologueEndLoc(&MF);
const MachineInstr *PrologEndLoc = PrologEnd.first;
bool IsEmptyPrologue = PrologEnd.second;

// Get beginning of function.
Expand All @@ -2199,16 +2200,15 @@ DebugLoc DwarfDebug::emitInitialLocDirective(const MachineFunction &MF,

// Ensure the compile unit is created if the function is called before
// beginFunction().
(void)getOrCreateDwarfCompileUnit(
MF.getFunction().getSubprogram()->getUnit());
DISubprogram *SP = MF.getFunction().getSubprogram();
(void)getOrCreateDwarfCompileUnit(SP->getUnit());
// We'd like to list the prologue as "not statements" but GDB behaves
// poorly if we do that. Revisit this with caution/GDB (7.5+) testing.
const DISubprogram *SP = PrologEndLoc->getInlinedAtScope()->getSubprogram();
::recordSourceLine(*Asm, SP->getScopeLine(), 0, SP, DWARF2_FLAG_IS_STMT,
CUID, getDwarfVersion(), getUnits());
return PrologEndLoc;
}
return DebugLoc();
return nullptr;
}

// Gather pre-function debug information. Assumes being called immediately
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/CodeGen/AsmPrinter/DwarfDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,10 @@ class DwarfDebug : public DebugHandlerBase {
/// Emit all Dwarf sections that should come after the content.
void endModule() override;

/// Emits inital debug location directive.
DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID);
/// Emits inital debug location directive. Returns instruction at which
/// the function prologue ends.
const MachineInstr *emitInitialLocDirective(const MachineFunction &MF,
unsigned CUID);

/// Process beginning of an instruction.
void beginInstruction(const MachineInstr *MI) override;
Expand Down
Loading