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

Unhandled error in debug adapter: TypeError: Cannot read properties of undefined (reading 'addr') #2397

Closed
slyang-git opened this issue Aug 10, 2022 · 14 comments
Labels
Debug Issues related to the debugging functionality of the extension. FrozenDueToAge
Milestone

Comments

@slyang-git
Copy link

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.17.13 darwin/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • Build info

golang.org/x/tools/gopls v0.9.1
golang.org/x/tools/gopls@v0.9.1 h1:SigsTL4Hpv3a6b/a7oPCLRv5QUeSM6PZNdta1oKY4B0=
github.com/BurntSushi/toml@v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
github.com/google/go-cmp@v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
golang.org/x/exp/typeparams@v0.0.0-20220218215828-6cf2b201936e h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=
golang.org/x/mod@v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sys@v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/tools@v0.1.12-0.20220713141851-7464a5a40219 h1:Ljlba2fVWOA1049JjsKii44g8nZN2GjpxMlzVc8AnQM=
golang.org/x/vuln@v0.0.0-20220613164644-4eb5ba49563c h1:r5bbIROBQtRRgoutV8Q3sFY58VzHW6jMBYl48ANSyS4=
honnef.co/go/tools@v0.3.2 h1:ytYb4rOqyp1TSa2EPvNVwtPQJctSELKaMyLfqNP4+34=
mvdan.cc/gofumpt@v0.3.0 h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.19

  • Run code -v or code-insiders -v to 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:

WX20220810-105552

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
@gopherbot gopherbot added this to the Untriaged milestone Aug 10, 2022
@findleyr
Copy link
Contributor

CC @suzmue

@findleyr findleyr added the Debug Issues related to the debugging functionality of the extension. label Aug 11, 2022
@findleyr findleyr modified the milestones: Untriaged, vscode-go/later Aug 11, 2022
@Rakhmanov
Copy link

Rakhmanov commented Sep 24, 2022

Weirdly it works if Variable panel is closed while in debug mode.

@cheng470
Copy link

cheng470 commented Oct 9, 2022

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.

@thgruiz
Copy link

thgruiz commented Oct 23, 2022

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/gopls@v0.9.5 h1:F3TO5th6TUg40FHrpxZfMkMlVaaTmByeEvylgVHGH2A=

The Variable panel trick is getting me going...

@thgruiz
Copy link

thgruiz commented Oct 23, 2022

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?

@tsuzukit
Copy link

tsuzukit commented Oct 30, 2022

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 }"
        }
      ]
    }
  ]

@ankon
Copy link
Contributor

ankon commented Dec 12, 2022

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:
image

@rjseibert
Copy link

@ankon thank you! This worked for me.

@scottchen625
Copy link

@ankon this worked for me as well! Thanks!

ankon added a commit to ankon/vscode-go that referenced this issue Jan 19, 2023
It seems that we might hit variables here that "exist" but do not have information for
them at all. Handle that case by reporting them as "gone".

Fixes golang#2397
@ankon
Copy link
Contributor

ankon commented Jan 19, 2023

I guess it's worth trying a PR then: See #2618 for what I hope should be fine. :)

@gopherbot
Copy link
Collaborator

Change https://go.dev/cl/462289 mentions this issue: src/debugAdapter: handle missing variables gracefully

@suzmue suzmue modified the milestones: vscode-go/later, v0.38.0 Feb 21, 2023
@Kevinello
Copy link

Has this fix been released yet?

@slyang-git
Copy link
Author

Has this fix been released yet?

It's seems not yet.

@slyang-git
Copy link
Author

slyang-git commented Feb 28, 2023

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: image

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.

@golang golang locked and limited conversation to collaborators Feb 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Debug Issues related to the debugging functionality of the extension. FrozenDueToAge
Projects
None yet
Development

Successfully merging a pull request may close this issue.