cmd/compile: missing DWARF location list for function arg; stack spill not used for loclist #61703
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
It also reproduces with 1.20, 1.19, and maybe older versions too.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Meta-comment: I understand that the production of DWARF location lists for optimized code is not perfect. I'd like to generally form an understanding about which problems are hard and which are tractable. I have found one case where I'm hoping the debug info can be improved, stemming from a real case where a variable that I've tried to read is unavailable where I think it should be available.
With the (optimized) CockroachDB binary, I'm frequently trying to read
context.Context
function arguments with a debugger, and more often than not they are not available. I have failed to create a small repro (my experimentation is also hindered by #61700), but the problems seem widespread in the CockroachDB binary. For this report, I have selected a Cockroach case that seems the simplest, out of multiple that I've investigated by hand.In this example, what seems to happen is that a function argument that starts off in registers becomes unavailable once the registers are clobbered by a function call, even though the argument was spilled to the stack (and not just spilled anywhere, but spilled in its designated regabi spill slot, FWIW). In other cases, I see the compiler able to use the spill locations and switch the location lists from registers to the stack; I'd like to understand if there's a good reason why this doesn't happen in this example.
Consider the following method (Github link):
The location lists for the
ctx
argument are quite incomplete:The 128-bit argument starts off in
RBX, RCX
. Then, the PC location2fb8fd1
corresponds to the first function call ->bic.stopwatch.Start()
. That's where the location lists stop, so, for the majority of the function's code,ctx
is not available.The 2nd location list (
2fb8fc9 - 2fb8fd1
) corresponds to only two instructions whereRBX
continues to be available afterRCX
was just clobbered; I believe this is not very interesting.Now, I claim that the compiler should be able to give me a location list for all of this function, based on the fact that
ctx
is spilled to the stack in the beginning of the function. Again, in other random instances I've looked at, the compiler does sometimes seem to be able to make use of the stack spill.Here is the function's disassembly with minor commentary: https://gist.github.com/andreimatei/fa1575dbfa8e04fb0271d02587a0bdf6
I'll paste the beginning here:
Notice that
RBX
andRCX
are spilled in the beginning. And note how the callStopWatch.Start
marks the end of the 2nd location list, and there's no further location list.What did you expect to see?
I expected a location list pointing to the
ctx
value on the stack.If this proves to be a tractable problem, myself or one of my colleagues might be interested in putting some effort in improving it.
cc @dr2chase @randall77 @thanm
The text was updated successfully, but these errors were encountered: