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

cmd/go: breakpoints with dlv yields incorrect behaviour on tests #64854

Closed
soypat opened this issue Dec 24, 2023 · 2 comments
Closed

cmd/go: breakpoints with dlv yields incorrect behaviour on tests #64854

soypat opened this issue Dec 24, 2023 · 2 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Debugging NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@soypat
Copy link

soypat commented Dec 24, 2023

Go version

go version go1.21.4 linux/amd64

What operating system and processor architecture are you using (go env)?

GO111MODULE=''
GOARCH='amd64'
GOBIN='/home/pato/local/bin'
GOCACHE='/home/pato/.cache/go-build'
GOENV='/home/pato/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/pato/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/pato/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/pato/src/tg/seqs/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2782340955=/tmp/go-build -gno-record-gcc-switches'

What did you do?

  1. Run test for a simple ring buffer implementation using go test ./... or with VSCode visual debugging and no breakpoint
  2. Run test with a breakpoint at a certain line.

The code in question is from an open source library: soypat/seqs#8 (comment). This comment is perhaps a bit confusing, but the TL;DR is if you clone the repo and run the test with go test ./... in that commit hash you'll get a different output than if you run the test with a breakpoint on the println statement (I'm using VSCode default visual debugging with dlv).

I actually tried to replicate it on a computer with same OS, arch, go version and had to change the case a bit, here's the line on which you have to add the breakpoint to see the bug for a different computer (different commit hash than first case above).

Previous investigation

@Jorropo investigated this bug. The conversation is on slack. They arrived on a conclusion there was a compiler bug that occurs in go version devel go1.22-2184a39477 Thu Dec 21 18:36:41 2023 +0000 linux/amd64 , though it is my understanding it is unrelated to this breakpoint bug I am detailing here.

What did you expect to see?

I expected to see same behaviour, same things printed since there is no concurrency at play. Running test with -race yields no race.

What did you see instead?

Values are different, and also variables take on "impossible" values. i.e: There are two int type variables, one variable is assigned the value of the other. On the following statement the variable values differ.

First case

No breakpoint output:

test 10 8 8 0xc000196810
test 0 0 0 0xc000196810
--- FAIL: TestRing (0.00s)
    internal_test.go:72: 0 did not write data correctly: got 8; want 4
    internal_test.go:82: got 0; want 6 (2+4)
FAIL

Breakpoint output:

test 0 0 8 0xc000016840
test 0 0 0 0xc000016840
--- FAIL: TestRing (3.42s)
    internal_test.go:82: got 4; want 6 (2+4)
    internal_test.go:85: got "llo "; want "hell"
FAIL

Second case

No breakpoint output:

0 0 1 1
--- FAIL: TestRing2 (0.00s)
    internal_test.go:67: failed test 2
FAIL

With breakpoint output

0 0 0 1
0 0 0 2
0 0 0 1
2 0 0 1
0 0 0 1
1 0 0 1
0 0 0 1
1 0 0 1
0 0 0 1
... it goes on ...
--- FAIL: TestRing2 (1.83s)
    internal_test.go:106: got 1; want 2 (1+1)
    internal_test.go:109: got "\x94"; want "\x01"
    internal_test.go:96: did not write data correctly: got 3; want 2
    internal_test.go:106: got 5; want 4 (2+2)
FAIL
@mauri870 mauri870 added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Debugging compiler/runtime Issues related to the Go compiler and/or runtime. labels Dec 25, 2023
@aarzilli
Copy link
Contributor

aarzilli commented Jan 2, 2024

I tried reproducing this but I couldn't, with either PR. It could be that I'm running the wrong version of the code, the branch you used for both PR has been deleted and the diff from either PRs does not apply cleanly, so there could be differences between the code that I ran and what I should have run.

Other possibilities:

  • you have a watch expression that calls a function that alters the state of the target
  • you have a watch expression that calls a function that does not alter the state of the target but your version of delve is old and has a bug that leaves the cpu flags dirty

@mknyszek mknyszek added this to the Backlog milestone Jan 3, 2024
@mknyszek mknyszek added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 3, 2024
@gopherbot
Copy link
Contributor

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@gopherbot gopherbot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. Debugging NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants