-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: unexpected reuse of memory when debugging #73117
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
Comments
Kind of an odd behavior, but not too terribly surprising. Are you compiling with At the It does look tricky though, as the backing store for |
yes, it set
I'm not sure, New observation: |
We generally don't want to change the lifetime of variables when debugging. That would affect the GC behavior of the program, which is probably not what you want when trying to reproduce a problem under the debugger.
That makes sense, using only the length means the pointer to the backing slice is dead at the panic point. Using the whole thing means the pointer is still live. I think there could be some help from the debugger here to let you know that the variable you're trying to inspect is dead/stale, kind of like how we print |
In |
That's a good point, I missed that In your original code, |
just move |
I think I see what is going on here. Delve stops at the panic line after having run all the defers. So code in the deferred function that accesses |
Here's a simplified, import-free reproducer:
Run
It should print |
@aarzilli @derekparker Not sure if there is really anything to do here, but perhaps dlv could warn when trying to print a dead variable that its contents might not be correct? |
It does look like it is, the DW_AT_location for s is just
We have no indication of this in dwarf and so far we have refrained from digging through the GC data due to concerns with maintainability (hard to keep it working, hard to notice if something changes from a version to another). If we can figure out a way to do this that's easy (ish) to keep working, we could do it. Other than that I don't think we can do anything about this (the other solution, extending the lifetimes to match the scope when optimizations are disabled, has already been dismissed because it creates its own set of problems). |
Ok, then I think we can close this as unfortunate but not feasibly fixable. |
Go version
go version go1.24.1 linux/amd64
Output of
go env
in your module/workspace:What did you do?
panic
(w/o breakpoint)s
What did you see happen?
Sometimes its value is the expected
0, 1, 2, 3, ...
.Sometimes its value is the unexpected
MaxUint, 0, MaxUint, 0, ...
. (It looks like the memory ofs
is reused in the deferred function)Occasionally its value is meaningless.
What did you expect to see?
Its value is always
0, 1, 2, 3, ...
The text was updated successfully, but these errors were encountered: