Skip to content
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

proc: add regression test for issue #3548 #3553

Merged
merged 1 commit into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions _fixtures/issue3548.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"fmt"
)

type Thing struct {
str string
}

func (d *Thing) Test() bool {
return d != nil
}

func callit(f func()) {
f()
}

func main() {
cases := []struct {
name string
thing Thing
}{
{
name: "Success",
thing: Thing{str: "hello"},
},
}

for _, c := range cases {
callit(func() {
fmt.Println("hello", c.thing.Test())
})
}
}
20 changes: 20 additions & 0 deletions pkg/proc/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1722,3 +1722,23 @@ func TestBadUnsafePtr(t *testing.T) {
}
})
}

func TestCapturedVariable(t *testing.T) {
// Checks that variables captured by a closure (that are not pointers) are
// readable. See issue #3548.
// This was broken in Go 1.21 due to a compiler bug.
if goversion.VersionAfterOrEqual(runtime.Version(), 1, 21) && !goversion.VersionAfterOrEqual(runtime.Version(), 1, 22) {
t.Skip("broken")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add more context here, like broken in versions prior to 1.22 due to a compiler bug. Also, does this affect all versions < 1.22 or was the bug introduced in 1.21 and we didn't catch it? If the latter, we should be more specific in the skip.

Finally, can you add a link to the Github issue in a comment somewhere for more context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I hadn't checked before but it really is a regression in 1.21.

}
withTestProcess("issue3548", t, func(p *proc.Target, grp *proc.TargetGroup, fixture protest.Fixture) {
setFileBreakpoint(p, t, fixture.Source, 32)
assertNoError(grp.Continue(), t, "Continue()")
v := evalVariable(p, t, "c")
assertVariable(t, v, varTest{
name: "c",
preserveName: true,
value: "struct { main.name string; main.thing main.Thing } {name: \"Success\", thing: main.Thing {str: \"hello\"}}",
varType: "struct { main.name string; main.thing main.Thing }",
})
})
}