vscode-go
vscode-go copied to clipboard
Unhandled error in debug adapter: TypeError: Cannot read properties of undefined (reading 'addr')
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.13 darwin/amd64
- Run
gopls -v versionto get version of Gopls from the VS Code integrated terminal.- Build info
golang.org/x/tools/gopls v0.9.1 golang.org/x/tools/[email protected] h1:SigsTL4Hpv3a6b/a7oPCLRv5QUeSM6PZNdta1oKY4B0= 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/exp/[email protected] h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM= golang.org/x/[email protected] h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= 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:Ljlba2fVWOA1049JjsKii44g8nZN2GjpxMlzVc8AnQM= golang.org/x/[email protected] h1:r5bbIROBQtRRgoutV8Q3sFY58VzHW6jMBYl48ANSyS4= honnef.co/go/[email protected] h1:ytYb4rOqyp1TSa2EPvNVwtPQJctSELKaMyLfqNP4+34= mvdan.cc/[email protected] h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4= mvdan.cc/xurls/[email protected] h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc= go: go1.19
- Run
code -vorcode-insiders -vto get version of VS Code or VS Code Insiders.- 1.70.0 da76f93349a72022ca4670c1b84860304616aaa2 arm64
- Check your installed extensions to get the version of the VS Code Go extension
- v0.35.1
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.
Describe the bug
below is my launch.json configuration:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Connect to server",
"type": "go",
"request": "attach",
"mode": "remote",
"port": 8017,
"host": "{my remote host ip}",
"trace": "log",
"showLog": true
}
]
}
I'v added some breakpoints on several lines, after launch.json configuration was set, I connected to the remote dlv debugger server, and it's log shows all fine.
When I triggered the API request on remote host, the debug session created an VS Code show Local and Global varibles, but shortly, the debug session ended an the debug log show the following error message:
Unhandled error in debug adapter: TypeError: Cannot read properties of undefined (reading 'addr')
at GoDebugSession.convertDebugVariableToProtocolVariable (/Users/didi/.vscode/extensions/golang.go-0.35.1/dist/debugAdapter.js:16709:25)
at /Users/didi/.vscode/extensions/golang.go-0.35.1/dist/debugAdapter.js:16249:55
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Promise.all (index 2)
I'v Googled around and found some information about legacy and dlv-dap mode, but I am not sure what exactly it is. So I modified the launch.json configuration by add debugAdapter, as follow:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Connect to server",
"type": "go",
"request": "attach",
"mode": "remote",
"port": 8017,
"host": "{my remote host ip}",
"debugAdapter": "dlv-dap", // New Add
"trace": "log",
"showLog": true
}
]
}
after try again, the debug session created but VS Code automatically open the response file I added breakpoints but in another path, like /tmp.go-buildxxxxxxxxx/src/xxx......, the VS Code UI as follow:

I'v degraded Go extension to lower version as well, but the same result.
the remote dlv debugger server run command is:
dlv attach {process_id} --listen=:{port}--headless --accept-multiclient --continue --api-version=2 --log
CC @suzmue
Weirdly it works if Variable panel is closed while in debug mode.
Weirdly it works if Variable panel is closed while in debug mode.
When I move the mouse to variable name in code, it failed again.
Happened with me to...
go version: go version go1.19.2 linux/amd64
gopls version golang.org/x/tools/gopls v0.9.5 golang.org/x/tools/[email protected] h1:F3TO5th6TUg40FHrpxZfMkMlVaaTmByeEvylgVHGH2A=
The Variable panel trick is getting me going...
Strangely, this do not occur during my normal debug sessions, only when I'm doing something on early stages of app startup. Maybe its related to some init() phase?
I have encountered same issue and solved it by setting substitutePath in launch.json .
Not sure if this applies every situation, but hope it might help someone!
may launch.json is like below
"configurations": [
{
"name": "{ my name }",
"type": "go",
"request": "attach",
"mode": "remote",
"port": { my port },
"showLog": true,
"debugAdapter": "dlv-dap",
"substitutePath": [
{
"from": { local path },
"to": { remote path }"
}
]
}
]
Maybe this helps: I hit this now while trying to debug a locally-built podman where I had all standard build flags enabled (i.e. no -gcflags=all="-N -l"). Debuggee started via:
dlv exec ${workspaceFolder}/bin/podman --api-version 2 --headless --listen 127.0.0.1:2345 --accept-multiclient -- version
(modified the /usr/bin/docker wrapper script to do that; my goal is to debug podman while docker-compose talks to it)
VSCode launch config used to connect:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Connect to server",
"type": "go",
"request": "attach",
"mode": "remote",
"remotePath": "${workspaceFolder}",
"port": 2345,
"host": "127.0.0.1"
}
]
}
Breakpoint to hit is at version.go.
I didn't want to spend too much time now to figure this out, and I definitely need the variables panel, so I went ahead and modified my debugAdapter.js in ~/.vscode-insiders/extensions/golang.go-0.36.0/dist to basically ignore an undefined:
--- debugAdapter.js.orig 2022-12-12 18:50:04.836913630 +0100
+++ debugAdapter.js 2022-12-12 18:40:57.545961396 +0100
@@ -16725,7 +16725,12 @@
variablesReference: 0
};
} else if (v.kind === 22) {
- if (v.children[0].addr === 0) {
+ if (!v.children[0]) {
+ return {
+ result: "gone <" + v.type + ">",
+ variablesReference: 0
+ };
+ } else if (v.children[0].addr === 0) {
return {
result: "nil <" + v.type + ">",
variablesReference: 0
Works for me, and in the variables window I see one "gone" variable:

@ankon thank you! This worked for me.
@ankon this worked for me as well! Thanks!
I guess it's worth trying a PR then: See #2618 for what I hope should be fine. :)
Change https://go.dev/cl/462289 mentions this issue: src/debugAdapter: handle missing variables gracefully
Has this fix been released yet?
Has this fix been released yet?
It's seems not yet.
Maybe this helps: I hit this now while trying to debug a locally-built podman where I had all standard build flags enabled (i.e. no
-gcflags=all="-N -l"). Debuggee started via:dlv exec ${workspaceFolder}/bin/podman --api-version 2 --headless --listen 127.0.0.1:2345 --accept-multiclient -- version(modified the
/usr/bin/dockerwrapper script to do that; my goal is to debug podman while docker-compose talks to it)VSCode launch config used to connect:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Connect to server", "type": "go", "request": "attach", "mode": "remote", "remotePath": "${workspaceFolder}", "port": 2345, "host": "127.0.0.1" } ] }Breakpoint to hit is at version.go.
I didn't want to spend too much time now to figure this out, and I definitely need the variables panel, so I went ahead and modified my debugAdapter.js in ~/.vscode-insiders/extensions/golang.go-0.36.0/dist to basically ignore an undefined:
--- debugAdapter.js.orig 2022-12-12 18:50:04.836913630 +0100 +++ debugAdapter.js 2022-12-12 18:40:57.545961396 +0100 @@ -16725,7 +16725,12 @@ variablesReference: 0 }; } else if (v.kind === 22) { - if (v.children[0].addr === 0) { + if (!v.children[0]) { + return { + result: "gone <" + v.type + ">", + variablesReference: 0 + }; + } else if (v.children[0].addr === 0) { return { result: "nil <" + v.type + ">", variablesReference: 0Works for me, and in the variables window I see one "gone" variable:
Great solution 👍
Almost 5 months later and after try and error, I finally found the root cause of this exception.
When we build the application, the go complier will optimize the source code by default which will remove some variables and functions by inlining and other tricks. But vscode's debugAdapter didn't know this, it will crash when the variable should be there and the application not offer.
the final solution is to turn off build optimization and build the application again, for example:
GOOS=linux GOARCH=amd64 go build -gcflags=all='-N -l' -o [application name]
after restart the application, there is no Exception again, all were went well.
Hope this message can help you all guys.