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 process started with go run can't be debugged #42600

Closed
nitishch opened this issue Nov 13, 2020 · 2 comments
Closed

cmd/go process started with go run can't be debugged #42600

nitishch opened this issue Nov 13, 2020 · 2 comments

Comments

@nitishch
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.15.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/nitishch/Library/Caches/go-build"
GOENV="/Users/nitishch/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/nitishch/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/nitishch/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.15.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/k6/1g590ls933j17r_sqm5_nnw40000gn/T/go-build190492030=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Run a simple go file using go run <file>. Start another process using go build -o output <file>; ./output. Then I tried to attach debuggers to both these processes.

What did you expect to see?

I expected to be able to successfully attach debuggers to these processes.

What did you see instead?

But, the debug symbols are missing from the executable created using go run. In https://golang.org/src/cmd/go/internal/run/run.go, there is p.Internal.OmitDebug = true without any option to override.

There is no mention of this behavior in https://golang.org/pkg/cmd/go/internal/run/. Without looking at the source code, it's quite difficult to understand why debugger can't be attached to the process run using go run.

@ianlancetaylor
Copy link
Contributor

This is intentional behavior. go run is a convenience function that builds and runs a program for you. Since a program that is run by go run is not run under the debugger, go run is made a little faster by not building any debug information. Attaching a debugger to a program run by go run is corner case that we have decided to not support. Use go build instead.

@nitishch
Copy link
Author

If that's the case, shouldn't the intent be at least mentioned in the documentation? https://golang.org/pkg/cmd/go/internal/run/ doesn't say anything about this.

@golang golang locked and limited conversation to collaborators Nov 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants