Skip to content

Add CodeView S_LABEL32 symbols for jump table targets (for Windows debugging) #146121

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 24 additions & 5 deletions llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks; updated.

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");
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
const MCSymbol *Branch;
const MCSymbol *Table;
size_t TableSize;
std::vector<const MCSymbol *> Cases;
};

// For each function, store a vector of labels to its instructions, as well as
Expand Down
9 changes: 9 additions & 0 deletions llvm/test/DebugInfo/COFF/jump-table.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down