golang / vscode-go

Go extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=golang.Go
Other
3.85k stars 736 forks source link

Mac 3 silicon VSCode with dev container and golang fails to run debugger on goroutine implementation #3460

Open srinivasakp opened 1 month ago

srinivasakp commented 1 month ago

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
* Run `go version` to get version of Go from _the VS Code integrated terminal_. - go version go1.21.3 linux/amd64 ( on container ) * Run `gopls -v version` to get version of Gopls from _the VS Code integrated terminal_. - v0.16.1 * Run `code -v` or `code-insiders -v` to get version of VS Code or VS Code Insiders. - 1.91.1 (Universal) * Check your installed extensions to get the version of the VS Code Go extension - v0.42.0 * Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > `Go: Locate Configured Go Tools` command. - # Tools Configuration ## Environment GOBIN: undefined toolsGopath: gopath: /workspaces GOROOT: /cam/tools/go PATH: /workspaces/bin:/cam/tools/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PATH (vscode launched with): /vscode/vscode-server/bin/linux-x64/f1e16e1e6214d7c44d078b1f0607b2388f29d729-legacy/bin/remote-cli:/workspaces/bin:/cam/tools/go/bin:/cam/tools/gnu/gcc/11.3.0/rhe7-x86_64/bin:/cam/tools/gnu/binutils/2.40/rhe7-x86_64/bin:/cam/tools/swig/swig/4.1.1/rhe7-x86_64//bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ## Tools go: /cam/tools/go/bin/go: go version go1.21.3 linux/amd64 gopls: /workspaces/bin/gopls (version: v0.16.1 built with go: go1.21.3) gotests: /workspaces/bin/gotests (version: v1.6.0 built with go: go1.21.3) gomodifytags: not installed impl: not installed goplay: not installed dlv: /workspaces/bin/dlv (version: v1.23.0 built with go: go1.21.3) staticcheck: /workspaces/bin/staticcheck (version: v0.4.7 built with go: go1.21.3) ## Go env Workspace Folder (uniSched): /workspace/src/uniSched GO111MODULE='on' GOARCH='amd64' GOBIN='' GOCACHE='/root/.cache/go-build' GOENV='/root/.config/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='linux' GOINSECURE='' GOMODCACHE='/workspaces/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='linux' GOPATH='/workspaces' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/cam/tools/go' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/cam/tools/go/pkg/tool/linux_amd64' GOVCS='' GOVERSION='go1.21.3' GCCGO='gccgo' GOAMD64='v1' AR='ar' CC='gcc' CXX='g++' CGO_ENABLED='1' GOMOD='/workspace/src/uniSched/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-build914308139=/tmp/go-build -gno-record-gcc-switches'

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file. Share all the settings with the go. or ["go"] or gopls prefixes.

// Tags and options configured here will be used by the Add Tags command to add tags to struct fields. If promptForTags is true, then user will be prompted for tags and options. By default, json tags are added.
"go.addTags": {
    "tags": "json",
    "options": "json=omitempty",
    "promptForTags": false,
    "transform": "snakecase",
    "template": ""
},

// Alternate tools or alternate paths for the same tools used by the Go extension. Provide either absolute path or the name of the binary in GOPATH/bin, GOROOT/bin or PATH. Useful when you want to use wrapper script for the Go tools.
"go.alternateTools": {},

// Flags to `go build`/`go test` used during build-on-save or running tests. (e.g. ["-ldflags='-s'"]) This is propagated to the language server if `gopls.build.buildFlags` is not specified.
"go.buildFlags": [],

// Enable the Go language server (`go.useLanguageServer`) to diagnose compile errors.
// Compiles code on file save using 'go build' or 'go test -c'. Not applicable when using the language server.
"go.buildOnSave": "package",

// The Go build tags to use for all commands, that support a `-tags '...'` argument. When running tests, go.testTags will be used instead if it was set. This is propagated to the language server if `gopls.build.buildFlags` is not specified.
"go.buildTags": "",

// This option lets you choose the way to display code coverage. Choose either to highlight the complete line or to show a decorator in the gutter. You can customize the colors and borders for the former and the style for the latter.
"go.coverageDecorator": {
    "type": "highlight",
    "coveredHighlightColor": "rgba(64,128,128,0.5)",
    "uncoveredHighlightColor": "rgba(128,64,64,0.25)",
    "coveredBorderColor": "rgba(64,128,128,0.5)",
    "uncoveredBorderColor": "rgba(128,64,64,0.25)",
    "coveredGutterStyle": "blockblue",
    "uncoveredGutterStyle": "slashyellow"
},

// Use these options to control whether only covered or only uncovered code or both should be highlighted after running test coverage
"go.coverageOptions": "showBothCoveredAndUncoveredCode",

// When generating code coverage, the value for -covermode. 'default' is the default value chosen by the 'go test' command.
"go.coverMode": "default",

// If true, runs 'go test -coverprofile' on save and shows test coverage.
"go.coverOnSave": false,

// If true, shows test coverage when Go: Test Function at cursor command is run.
"go.coverOnSingleTest": false,

// If true, shows test coverage when Go: Test Single File command is run.
"go.coverOnSingleTestFile": false,

// If true, shows test coverage when Go: Test Package command is run.
"go.coverOnTestPackage": true,

// When generating code coverage, should counts be shown as --374--
"go.coverShowCounts": false,

// Delve settings that applies to all debugging sessions. Debug configuration in the launch.json file will override these values.
"go.delveConfig": {},

// (Experimental) vulncheck enables vulnerability scanning.
// 
//  - Imports: `"Imports"`: In Imports mode, `gopls` will report vulnerabilities that affect packages
// directly and indirectly used by the analyzed main module.
// 
//  - Off: `"Off"`: Disable vulnerability analysis.
// 
"go.diagnostic.vulncheck": "Off",

// If true, tests will not run concurrently. When a new test run is started, the previous will be cancelled.
"go.disableConcurrentTests": false,

// Experimental Feature: Enable/Disable entries from the context menu in the editor.
"go.editorContextMenuCommands": {
    "toggleTestFile": true,
    "addTags": true,
    "removeTags": false,
    "fillStruct": false,
    "testAtCursor": true,
    "testFile": false,
    "testPackage": false,
    "generateTestForFunction": true,
    "generateTestForFile": false,
    "generateTestForPackage": false,
    "addImport": true,
    "testCoverage": true,
    "playground": true,
    "debugTestAtCursor": true,
    "benchmarkAtCursor": false
},

// Feature level setting to enable/disable code lens for references and run/debug tests
"go.enableCodeLens": {
    "runtest": true
},

// Flags to pass to format tool (e.g. ["-s"]). Not applicable when using the language server.
"go.formatFlags": [],

// When the language server is enabled and one of `default`/`gofmt`/`goimports`/`gofumpt` is chosen, the language server will handle formatting. If `custom` tool is selected, the extension will use the `customFormatter` tool in the `go.alternateTools` section.
//  - default: If the language server is enabled, format via the language server, which already supports gofmt, goimports, goreturns, and gofumpt. Otherwise, goimports.
//  - gofmt: Formats the file according to the standard Go style. (not applicable when the language server is enabled)
//  - goimports: Organizes imports and formats the file with gofmt. (not applicable when the language server is enabled)
//  - goformat: Configurable gofmt, see https://github.com/mbenkmann/goformat.
//  - gofumpt: Stricter version of gofmt, see https://github.com/mvdan/gofumpt. . Use `gopls.format.gofumpt` instead)
//  - custom: Formats using the custom tool specified as `customFormatter` in the `go.alternateTools` setting. The tool should take the input as STDIN and output the formatted code as STDOUT.
"go.formatTool": "default",

// Additional command line flags to pass to `gotests` for generating tests.
"go.generateTestsFlags": [],

// Specify GOPATH here to override the one that is set as environment variable. The inferred GOPATH from workspace root overrides this, if go.inferGopath is set to true.
"go.gopath": null,

// Specifies the GOROOT to use when no environment variable is set.
"go.goroot": null,

// Infer GOPATH from the workspace root. This is ignored when using Go Modules.
"go.inferGopath": false,

// Enable/disable inlay hints for variable types in assign statements:
// ```go
//  i/* int*/, j/* int*/ := 0, len(r)-1
// ```
"go.inlayHints.assignVariableTypes": false,

// Enable/disable inlay hints for composite literal field names:
// ```go
//  {/*in: */"Hello, world", /*want: */"dlrow ,olleH"}
// ```
"go.inlayHints.compositeLiteralFields": false,

// Enable/disable inlay hints for composite literal types:
// ```go
//  for _, c := range []struct {
//      in, want string
//  }{
//      /*struct{ in string; want string }*/{"Hello, world", "dlrow ,olleH"},
//  }
// ```
"go.inlayHints.compositeLiteralTypes": false,

// Enable/disable inlay hints for constant values:
// ```go
//  const (
//      KindNone   Kind = iota/* = 0*/
//      KindPrint/*  = 1*/
//      KindPrintf/* = 2*/
//      KindErrorf/* = 3*/
//  )
// ```
"go.inlayHints.constantValues": false,

// Enable/disable inlay hints for implicit type parameters on generic functions:
// ```go
//  myFoo/*[int, string]*/(1, "hello")
// ```
"go.inlayHints.functionTypeParameters": false,

// Enable/disable inlay hints for parameter names:
// ```go
//  parseInt(/* str: */ "123", /* radix: */ 8)
// ```
"go.inlayHints.parameterNames": false,

// Enable/disable inlay hints for variable types in range statements:
// ```go
//  for k/* int*/, v/* string*/ := range []string{} {
//      fmt.Println(k, v)
//  }
// ```
"go.inlayHints.rangeVariableTypes": false,

// If true, then `-i` flag will be passed to `go build` everytime the code is compiled. Since Go 1.10, setting this may be unnecessary unless you are in GOPATH mode and do not use the language server.
"go.installDependenciesWhenBuilding": false,

// Flags like -rpc.trace and -logfile to be used while running the language server.
"go.languageServerFlags": [],

// Flags to pass to Lint tool (e.g. ["-min_confidence=.8"])
"go.lintFlags": [],

// Lints code on file save using the configured Lint tool. Options are 'file', 'package', 'workspace' or 'off'.
//  - file: lint the current file on file saving
//  - package: lint the current package on file saving
//  - workspace: lint all the packages in the current workspace root folder on file saving
//  - off: do not run lint automatically
"go.lintOnSave": "package",

// Specifies Lint tool name.
"go.lintTool": "staticcheck",

// This setting is deprecated. Use 'Developer: Set Log Level...' command to control logging level instead.
// 
"go.logging.level": "",

// The flags configured here will be passed through to command `goplay`
"go.playground": {
    "openbrowser": true,
    "share": true,
    "run": true
},

// Tags and options configured here will be used by the Remove Tags command to remove tags to struct fields. If promptForTags is true, then user will be prompted for tags and options. By default, all tags and options will be removed.
"go.removeTags": {
    "tags": "",
    "options": "",
    "promptForTags": false
},

// Specifies whether to show the Welcome experience on first install
"go.showWelcome": true,

// Prompt for surveys, including the gopls survey and the Go developer survey.
"go.survey.prompt": true,

// enable the default go build/test task provider.
"go.tasks.provideDefault": true,

// Apply the Go & PATH environment variables used by the extension to all integrated terminals.
"go.terminal.activateEnvironment": true,

// Absolute path to a file containing environment variables definitions. File contents should be of the form key=value.
"go.testEnvFile": null,

// Environment variables that will be passed to the process that runs the Go tests
"go.testEnvVars": {},

// Run benchmarks when running all tests in a file or folder.
"go.testExplorer.alwaysRunBenchmarks": false,

// Concatenate all test log messages for a given location into a single message.
"go.testExplorer.concatenateMessages": true,

// Enable the Go test explorer
"go.testExplorer.enable": true,

// Present packages in the test explorer flat or nested.
"go.testExplorer.packageDisplayMode": "flat",

// Set the source location of dynamically discovered subtests to the location of the containing function. As a result, dynamically discovered subtests will be added to the gutter test widget of the containing function.
"go.testExplorer.showDynamicSubtestsInEditor": false,

// Open the test output terminal when a test run is started.
"go.testExplorer.showOutput": true,

// Flags to pass to `go test`. If null, then buildFlags will be used. This is not propagated to the language server.
"go.testFlags": null,

// Run 'go test' on save for current package. It is not advised to set this to `true` when you have Auto Save enabled.
"go.testOnSave": false,

// The Go build tags to use for when running tests. If null, then buildTags will be used.
"go.testTags": null,

// Specifies the timeout for go test in ParseDuration format.
"go.testTimeout": "30s",

// Environment variables that will be passed to the tools that run the Go tools (e.g. CGO_CFLAGS) and debuggee process launched by Delve. Format as string key:value pairs. When debugging, merged with `envFile` and `env` values with precedence `env` > `envFile` > `go.toolsEnvVars`.
"go.toolsEnvVars": {},

// Location to install the Go tools that the extension depends on if you don't want them in your GOPATH.
"go.toolsGopath": null,

// Automatically update the tools used by the extension, without prompting the user.
"go.toolsManagement.autoUpdate": false,

// Specify whether to prompt about new versions of Go and the Go tools (currently, only `gopls`) the extension depends on
//  - proxy: keeps notified of new releases by checking the Go module proxy (GOPROXY)
//  - local: checks only the minimum tools versions required by the extension
//  - off: completely disables version check (not recommended)
"go.toolsManagement.checkForUpdates": "proxy",

// The path to the `go` binary used to install the Go tools. If it's empty, the same `go` binary chosen for the project will be used for tool installation.
"go.toolsManagement.go": "",

// Trace the communication between VS Code and the Go language server.
"go.trace.server": "off",

// Enable intellisense, code navigation, refactoring, formatting & diagnostics for Go. The features are powered by the Go language server "gopls".
"go.useLanguageServer": true,

// Flags to pass to `go tool vet` (e.g. ["-all", "-shadow"]). Not applicable when using the language server's diagnostics.
"go.vetFlags": [],

// Vets code on file save using 'go tool vet'. Not applicable when using the language server's diagnostics.
//  - package: vet the current package on file saving
//  - workspace: vet all the packages in the current workspace root folder on file saving
//  - off: do not run vet automatically
"go.vetOnSave": "package",

// Configure the default Go language server ('gopls'). In most cases, configuring this section is unnecessary. See [the documentation](https://github.com/golang/tools/blob/master/gopls/doc/settings.md) for all available settings.
"gopls": {},

Describe the bug

This issues is specifically on Mac 3 silicon

Installed Xcode ( 15.4 (15F31d) ) Installed VSCode ( 1.91.1 (Universal) ) dev container extension ( v0.375.1 ) golang in container ( go1.21.3 linux/amd64 ) install docker desktop ( 4.32.0 (157355) )

We are using dev container integrated with vs code for golang project, the setting devcontainer.json has all details related to the docker image to use for the development work, when we rebuild the the container ( command palette), tools will be installed along with golang and all the dependencies.

Once the project is set and the container is ready for developemnt, import the project and navigate to one of the test file, we test the code with debug_test option available in the vs code

As soon as the Debug Test is clicked, and continue by clicking continue button, the vs code throws following error message

Starting: /workspaces/bin/dlv dap --listen=127.0.0.1:36991 --log-dest=3 from /workspace/src/TestCode DAP server listening at: 127.0.0.1:36991 Type 'dlv help' for list of commands. 2024-07-19T06:46:49Z error layer=dap runtime error: input/output error 2 Unable to retrieve goroutines: input/output error PASS Process 21251 has exited with status 0 Detaching dlv dap (21021) exited with code: 0

Steps to reproduce the behavior:

  1. Mac 3 ( silicon ), install VSCode latest (install dev container extension), Xcode, docker desktop
  2. any go project with goroutine implementation
  3. write the test case and then run the debug test

Screenshots or recordings

image

srinivasakp commented 1 month ago

Anyone working on this?

abourget commented 1 month ago

Seeing the same here. Makes dev containers not workable for any Go development on Mac. Quite the blocker for us.

hyangah commented 1 month ago

Unfortunately, we need more information to triage. Do you have a minimal repro case that we can try?

And please follow https://github.com/golang/vscode-go/wiki/debugging#troubleshooting and share the trace.

hyangah commented 1 month ago

Ah, is the dev container also running in an emulated program? Then, can you please take a look at https://github.com/go-delve/delve/issues/3714 and see if that describes your setup? If so, sorry that there is nothing we can help with.

srinivasakp commented 1 month ago

@hyangah thank you for your response, I went through the issues 3714, and I can see that the issue is similar. However, I haven't tried to use the container build based on arm64 which I have to check and if that works then I my issue is solved, however I couldn't get much information on why the emulators program doesn't support for mac3 + dev container + amd64 container although you mentioned that you cannot help on this, but hoping that there will be solution in future because arm based devices need to fill up the gap on incompatibility.

by the way we are running go program within the docker container and it's used only for running go test and build the binaries.