https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53927
Pierre-Marie de Rodat <derodat at adacore dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |derodat at adacore dot com --- Comment #13 from Pierre-Marie de Rodat <derodat at adacore dot com> --- (In reply to Tom Tromey from comment #8) > > Yes, but you can do something useful even with this value of > > DW_AT_static_link, albeit not exactly what DWARF means. > > Regardless, I think GCC should emit correct DWARF. I gave it a try: see the attached patch. Jason suggested to change DW_AT_frame_base in order to make it equal to the address of the FRAME object. I was not sure: 1) how to do it: location descriptions for all local variables would need to be updated; 2) whether it's safe to do this: what if optimizers move/duplicate this FRAME object in the stack frame or do similar "disturbing" things? I'm not familiar enough with optimization passes to estimate if it's likely: feedback welcome. :-) I thought: why not make DW_AT_static_link compute the parent frame base address from the current static link argument? Well, when generating DW_AT_static_link for a nested subprogram, we do not know yet the offset between the FRAME object and the frame base address. This is because nested subprograms reach the back-end before their parent. Besides, see point 2: are we only sure that such a constant offset exists? So instead, I patched tree-nested.c in order to append a field at the end of the FRAME object to hold the frame base address (computed with the DWARF_CFA builtin). Then, dwarf2out.c just has to emit a location description for nested subprograms' DW_AT_static_link that fetches this using the static link argument. It's consuming a little stack space, I'm not sure if it's a problem. Once again: feedback welcome! Besides, this does not work yet with Fortran since for this front-end, the DWARF_CFA builtin is not registered. None of builtins.def are registered by the way: how could I register only this one without duplicating code? Is it a good idea anyway? For the record, I bootstrapped and reg-tested this patch on x86_64-linux and preliminary manual testing with a patched GDB[1] and Ada reproducers shows that this approach is working. Thoughts? [1] This patch teaches GDB how to use DW_AT_static_link in order to find the frame corresponding to the lexically enclosing scope. I think I will try to submit it to GDB soon.