RFC: Function epilogue tracking in DWARF information

Hi all,

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_prologue_end and 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:

  • In AsmPrinter/DwarfDebug.cpp, there’s a findPrologueEndLoc function that locates the first DebugLoc that 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::beginInstruction is called, so that each instruction’s DebugLoc can be checked against the set of epilogue beginnings. Then, if a DebugLoc corresponds to an epilogue beginning, it needs to have DWARF2_FLAG_EPILOGUE_BEGIN added 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!

William Woodruff