@@ -1520,6 +1520,46 @@ static DebugLoc findPrologueEndLoc(const MachineFunction *MF) {
15201520 return DebugLoc ();
15211521}
15221522
1523+ // / Register a source line with debug info. Returns the unique label that was
1524+ // / emitted and which provides correspondence to the source line list.
1525+ static void recordSourceLine (AsmPrinter &Asm, unsigned Line, unsigned Col,
1526+ const MDNode *S, unsigned Flags, unsigned CUID,
1527+ uint16_t DwarfVersion,
1528+ ArrayRef<std::unique_ptr<DwarfCompileUnit>> DCUs) {
1529+ StringRef Fn;
1530+ unsigned FileNo = 1 ;
1531+ unsigned Discriminator = 0 ;
1532+ if (auto *Scope = cast_or_null<DIScope>(S)) {
1533+ Fn = Scope->getFilename ();
1534+ if (Line != 0 && DwarfVersion >= 4 )
1535+ if (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope))
1536+ Discriminator = LBF->getDiscriminator ();
1537+
1538+ FileNo = static_cast <DwarfCompileUnit &>(*DCUs[CUID])
1539+ .getOrCreateSourceID (Scope->getFile ());
1540+ }
1541+ Asm.OutStreamer ->EmitDwarfLocDirective (FileNo, Line, Col, Flags, 0 ,
1542+ Discriminator, Fn);
1543+ }
1544+
1545+ DebugLoc DwarfDebug::emitInitialLocDirective (const MachineFunction &MF,
1546+ unsigned CUID) {
1547+ // Get beginning of function.
1548+ if (DebugLoc PrologEndLoc = findPrologueEndLoc (&MF)) {
1549+ // Ensure the compile unit is created if the function is called before
1550+ // beginFunction().
1551+ (void )getOrCreateDwarfCompileUnit (
1552+ MF.getFunction ().getSubprogram ()->getUnit ());
1553+ // We'd like to list the prologue as "not statements" but GDB behaves
1554+ // poorly if we do that. Revisit this with caution/GDB (7.5+) testing.
1555+ const DISubprogram *SP = PrologEndLoc->getInlinedAtScope ()->getSubprogram ();
1556+ ::recordSourceLine (*Asm, SP->getScopeLine (), 0, SP, DWARF2_FLAG_IS_STMT,
1557+ CUID, getDwarfVersion(), getUnits());
1558+ return PrologEndLoc;
1559+ }
1560+ return DebugLoc();
1561+ }
1562+
15231563// Gather pre-function debug information. Assumes being called immediately
15241564// after the function entry point has been emitted.
15251565void DwarfDebug::beginFunctionImpl (const MachineFunction *MF) {
@@ -1542,13 +1582,8 @@ void DwarfDebug::beginFunctionImpl(const MachineFunction *MF) {
15421582 Asm->OutStreamer ->getContext ().setDwarfCompileUnitID (CU.getUniqueID ());
15431583
15441584 // Record beginning of function.
1545- PrologEndLoc = findPrologueEndLoc (MF);
1546- if (PrologEndLoc) {
1547- // We'd like to list the prologue as "not statements" but GDB behaves
1548- // poorly if we do that. Revisit this with caution/GDB (7.5+) testing.
1549- auto *SP = PrologEndLoc->getInlinedAtScope ()->getSubprogram ();
1550- recordSourceLine (SP->getScopeLine (), 0 , SP, DWARF2_FLAG_IS_STMT);
1551- }
1585+ PrologEndLoc = emitInitialLocDirective (
1586+ *MF, Asm->OutStreamer ->getContext ().getDwarfCompileUnitID ());
15521587}
15531588
15541589void DwarfDebug::skippedNonDebugFunction () {
@@ -1646,21 +1681,9 @@ void DwarfDebug::endFunctionImpl(const MachineFunction *MF) {
16461681// emitted and which provides correspondence to the source line list.
16471682void DwarfDebug::recordSourceLine (unsigned Line, unsigned Col, const MDNode *S,
16481683 unsigned Flags) {
1649- StringRef Fn;
1650- unsigned FileNo = 1 ;
1651- unsigned Discriminator = 0 ;
1652- if (auto *Scope = cast_or_null<DIScope>(S)) {
1653- Fn = Scope->getFilename ();
1654- if (Line != 0 && getDwarfVersion () >= 4 )
1655- if (auto *LBF = dyn_cast<DILexicalBlockFile>(Scope))
1656- Discriminator = LBF->getDiscriminator ();
1657-
1658- unsigned CUID = Asm->OutStreamer ->getContext ().getDwarfCompileUnitID ();
1659- FileNo = static_cast <DwarfCompileUnit &>(*InfoHolder.getUnits ()[CUID])
1660- .getOrCreateSourceID (Scope->getFile ());
1661- }
1662- Asm->OutStreamer ->EmitDwarfLocDirective (FileNo, Line, Col, Flags, 0 ,
1663- Discriminator, Fn);
1684+ ::recordSourceLine (*Asm, Line, Col, S, Flags,
1685+ Asm->OutStreamer->getContext ().getDwarfCompileUnitID(),
1686+ getDwarfVersion(), getUnits());
16641687}
16651688
16661689// ===----------------------------------------------------------------------===//
0 commit comments