vscode-go
vscode-go copied to clipboard
debug: clearly document common debug configurations
What version of Go, VS Code & VS Code Go extension are you using?
Version Information
-
Run
go versionto get version of Go from the VS Code integrated terminal.- go version go1.17.8 linux/amd64
-
Run
gopls -v versionto get version of Gopls from the VS Code integrated terminal.- golang.org/x/tools/gopls v0.8.0 golang.org/x/tools/[email protected] h1:a71KO95TfIvCCMQJrZBSQIGQ9lkc0kWL+dSlEdZd7HI= github.com/BurntSushi/[email protected] h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU= github.com/google/[email protected] h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/sergi/[email protected] h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= golang.org/x/[email protected] h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o= golang.org/x/[email protected] h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/[email protected] h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c= golang.org/x/[email protected] h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/[email protected] h1:UVkOvSIhR/pX6OflsXS9hsDvaUJn8SLHqTlvdfUDiNo= golang.org/x/[email protected] h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= honnef.co/go/[email protected] h1:MNh1AVMyVX23VUHE2O27jm6lNj3vjO5DexS4A1xvnzk= mvdan.cc/[email protected] h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4= mvdan.cc/xurls/[email protected] h1:59Olnbt67UKpxF1EwVBopJvkSUBmgtb468E4GVWIZ1I=
-
Run
code -vorcode-insiders -vto get version of VS Code or VS Code Insiders.- 1.65.1 8908a9ca0f221f36507231afb39d2d8d1e182702 arm64
-
Check your installed extensions to get the version of the VS Code Go extension
- v0.32.0 - 8 Mar, 2022
-
Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) >
Go: Locate Configured Go Toolscommand. Checking configured tools.... GOBIN: undefined toolsGopath: gopath: /home/user/go GOROOT: /usr/local/go PATH: /home/user/.vscode-server/bin/8908a9ca0f221f36507231afb39d2d8d1e182702/bin/remote-cli:/home/user/.poetry/bin:/home/user/.cargo/bin:/home/user/go/bin:/bin:/home/user/.pyenv/bin:/home/user/.nvm/versions/node/v16.13.0/bin:/home/user/.rbenv/shims:/home/user/.rbenv/bin:/usr/local/opt/python/libexec/bin:/home/user/bin:/home/user/.local/bin:/Users/user/.local/share/solana/install/active_release/bin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bingo: /usr/local/go/bin/go: go version go1.17.8 linux/amd64
go-outline: /home/user/go/bin/go-outline (version: v0.0.0-20210608161538-9736a4bde949 built with go: go1.17.8) gotests: /home/user/go/bin/gotests (version: v1.6.0 built with go: go1.17.8) gomodifytags: not installed impl: not installed goplay: /home/user/go/bin/goplay (version: v1.0.0 built with go: go1.17.8) dlv: /home/user/go/bin/dlv (version: v1.8.1 built with go: go1.17.6) golangci-lint: /home/user/go/bin/golangci-lint (version: (devel) built with go: go1.17.7) gopls: /home/user/go/bin/gopls (version: v0.8.0 built with go: go1.17.8)
go env Workspace Folder (same-cli): /home/user/code/same-cli GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/user/.cache/go-build" GOENV="/home/user/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/user/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/user/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.17.8" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/user/code/same-cli/go.mod" 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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build740438953=/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.
Copied from here: https://stackoverflow.com/questions/71452550/debugging-a-specific-golang-unit-test-with-vscode
Describe the bug
I am trying to add a launch.json setting that allows me to launch and debug a specific unit test, replicating the functionality of the "Debug" link in the test explorer, but with additional arguments.
Steps to reproduce the behavior:
I am trying to debug one specific unit test in VSCode with breakpoints.
On the command line, this works perfectly to execute:
go test -v ./cmd/bacalhau -run TestCommands
However, when I select the below to run, I get the following:
{
"name": "Debug Specific Test",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/bacalhau/devstack_test.go",
"args": [
"-test.run",
"TestCommands"
],
"env": {
"LOG_LEVEL": "debug"
},
"showLog": true,
}
Output:
Starting: /home/user/go/bin/dlv dap --check-go-version=false --log=true --log-output=debugger --listen=127.0.0.1:43095 --log-dest=3 from /home/user/code/bacalhau
DAP server listening at: 127.0.0.1:43095
2022-03-12T19:31:11Z info layer=debugger launching process with args: [/home/user/code/bacalhau/__debug_bin -test.run TestCommands]
2022-03-12T19:31:11Z error layer=debugger can't find build-id note on binary
Type 'dlv help' for list of commands.
2022-03-12T19:31:12Z debug layer=debugger continuing
19h31m12.78 DEBUG runtime/proc.go:6498 Log level from LOG_LEVEL_ENV_VAR: debug
Zap log level: debug
19h31m12.82 DEBUG bacalhau/main.go:12 Top of execution - 2022-03-12 19:31:12.824219499 +0000 UTC
Error: unknown command "TestCommands" for "bacalhau"
Run 'bacalhau --help' for usage.
unknown command "TestCommands" for "bacalhau"
Process 3552701 has exited with status 1
Detaching
2022-03-12T19:31:12Z debug layer=debugger detaching
dlv dap (3552580) exited with code: 0
I have also tried setting "program": "${workspaceFolder}/cmd/bacalhau/devstack_test.go",
which results in
Starting: /home/user/go/bin/dlv dap --check-go-version=false --log=true --log-output=debugger --listen=127.0.0.1:33479 --log-dest=3 from /home/user/code/bacalhau/cmd/bacalhau
DAP server listening at: 127.0.0.1:33479
Build Error: go build -o /home/user/code/bacalhau/cmd/bacalhau/__debug_bin -gcflags all=-N -l ./devstack_test.go
no packages to build (exit status 1)`
I have looked at the following resources:
- https://stackoverflow.com/questions/43092364/debugging-go-tests-in-visual-studio-code
- https://stackoverflow.com/questions/43092364/debugging-go-tests-in-visual-studio-code
- https://github.com/golang/vscode-go/blob/master/docs/debugging.md
#1 in the above list looks almost perfect, but I could not get it to work (I don't want to debug ${file} I want the same unit test to run no matter what file I have open.
How do I set this up correctly?
@aronchick Could you try switching your configuration to have "mode": "test"?
Yep, that did it. Just not obvious (since I want to debug a test).
Here was the final set - maybe add it to the docs/FAQ?
{
"name": "Debug Specific Test",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}/cmd/bacalhau/devstack_test.go",
"args": [
"-test.run",
"^TestCatchBadActors$",
"github.com/filecoin-project/bacalhau/cmd/bacalhau/"
],
"env": {
"LOG_LEVEL": "debug"
},
"showLog": true,
}
@aronchick Glad that worked!
We have several snippets of sample configurations, but I'm not sure these show up in our documentation. Will leave this open to track updating of the documentation.