I tagged this as
LLVM Project > LLVM since I couldn’t find a more specific tag for the debug components/DWARF emission, but feel free to re-tag.
I’m currently looking into LLVM’s handling of some fields in the DWARF line program state machine, namely
DW_LNS_set_epilogue_begin. These state machine flags control whether a line program entry indicates the end/beginning of a function’s prologue(s) and epilogue(s), respectively, which is useful both for debuggers (tracking stack object liveness) and program analysis.
As far as I can tell, LLVM has supported
DW_LNS_set_prologue_end for years, and emits it as expected. On the other hand, while there are references to
DW_LNS_set_epilogue_begin throughout the codebase, I can’t get LLVM to actually produce line entries that contain it as a state.
I think the solution to this involves a couple of files:
AsmPrinter/DwarfDebug.cpp, there’s a
findPrologueEndLocfunction that locates the first
DebugLocthat isn’t inside of the function prologue (i.e., the prologue’s end). I think we need a corresponding function, something like
findEpilogueBeginLocs, for locating each of the function’s epilogues (since there can be multiple).
We need call that new function in a context before
DwarfDebug::beginInstructionis called, so that each instruction’s
DebugLoccan be checked against the set of epilogue beginnings. Then, if a
DebugLoccorresponds to an epilogue beginning, it needs to have
DWARF2_FLAG_EPILOGUE_BEGINadded to its flags. I think the right context for that is
DwarfDebug::beginFunctionImpl, since that’s where the current implementation handles prologue ends.
I’d appreciate any sanity checking of this approach, as well as any tips/advice!