diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index 5e1b313b4d2fa..87bc9a8035f50 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -3566,15 +3566,34 @@ void CodeViewDebug::collectDebugInfoForJumpTables(const MachineFunction *MF, break; } - CurFn->JumpTables.push_back( - {EntrySize, Base, BaseOffset, Branch, - MF->getJTISymbol(JumpTableIndex, MMI->getContext()), - JTI.getJumpTables()[JumpTableIndex].MBBs.size()}); + const MachineJumpTableEntry &JTE = JTI.getJumpTables()[JumpTableIndex]; + JumpTableInfo CVJTI{EntrySize, + Base, + BaseOffset, + Branch, + MF->getJTISymbol(JumpTableIndex, MMI->getContext()), + JTE.MBBs.size()}; + for (const auto &MBB : JTE.MBBs) + CVJTI.Cases.push_back(MBB->getSymbol()); + CurFn->JumpTables.push_back(std::move(CVJTI)); }); } void CodeViewDebug::emitDebugInfoForJumpTables(const FunctionInfo &FI) { - for (auto JumpTable : FI.JumpTables) { + // Emit S_LABEL32 records for each jump target + for (const auto &JumpTable : FI.JumpTables) { + for (const auto &CaseSym : JumpTable.Cases) { + MCSymbol *LabelEnd = beginSymbolRecord(SymbolKind::S_LABEL32); + OS.AddComment("Offset and segment"); + OS.emitCOFFSecRel32(CaseSym, 0); + OS.AddComment("Flags"); + OS.emitInt8(0); + emitNullTerminatedSymbolName(OS, CaseSym->getName()); + endSymbolRecord(LabelEnd); + } + } + + for (const auto &JumpTable : FI.JumpTables) { MCSymbol *JumpTableEnd = beginSymbolRecord(SymbolKind::S_ARMSWITCHTABLE); if (JumpTable.Base) { OS.AddComment("Base offset"); diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h index c862802d835d7..c2b878e52e1c3 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h @@ -146,6 +146,7 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase { const MCSymbol *Branch; const MCSymbol *Table; size_t TableSize; + std::vector Cases; }; // For each function, store a vector of labels to its instructions, as well as diff --git a/llvm/test/DebugInfo/COFF/jump-table.ll b/llvm/test/DebugInfo/COFF/jump-table.ll index 3eda2438ea88a..be1de2be55788 100644 --- a/llvm/test/DebugInfo/COFF/jump-table.ll +++ b/llvm/test/DebugInfo/COFF/jump-table.ll @@ -118,6 +118,15 @@ ; CV: GlobalProcIdSym { ; CV: DisplayName: func ; CV-NOT: GlobalProcIdSym +; CV: LabelSym { +; CV-NEXT: Kind: S_LABEL32 (0x1105) +; CV-NEXT: CodeOffset: 0xC0 +; CV-NEXT: Segment: 0x0 +; CV-NEXT: Flags: 0x0 +; CV-NEXT: Flags [ (0x0) +; CV-NEXT: ] +; CV-NEXT: DisplayName: +; CV-NEXT: } ; CV: JumpTableSym { ; CV-NEXT: Kind: S_ARMSWITCHTABLE (0x1159) ; CV-NEXT: BaseOffset: 0x0