无法启动dlv dap。

huangapple go评论86阅读模式
英文:

Couldn't start dlv dap

问题

当我在VSCode中启动dlv dap调试时,我收到以下消息:

无法启动dlv dap:
错误:等待DAP服务器启动超时

我已经为项目设置了启动配置:

launch.json:

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Launch file",
        "type": "go",
        "request": "launch",
        "mode": "debug",
        "program": "${workspaceFolder}",
        "showLog": true,
        "env": {
            "GO111MODULE": "on"
        }
    }
]
}

并且setting.json是:

{
"folders": [
    {
        "path": "."
    }
],
"settings": {
    "go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
    "go.autocompleteUnimportedPackages": true,
    "go.gocodePackageLookupMode": "go",
    "go.gotoSymbol.includeImports": true,
    "go.useCodeSnippetsOnFunctionSuggest": true,
    "explorer.confirmDelete": false,
    "go.formatTool": "goimports",
    "go.docsTool": "gogetdoc",
    "go.buildFlags": [],
    "explorer.confirmDragAndDrop": false,
    "window.zoomLevel": 0.8,
    "editor.minimap.enabled": false,
    "go.useLanguageServer": true,
    "go.delveConfig":{
        "debugAdapter":"dlv-dap"
        },
    "": {
        "editor.snippetSuggestions": "none",
        "editor.formatOnType": true,
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        }
    },
    "gopls": {
        "experimentalWorkspaceModule": true,
        "usePlaceholders": true,
        "completionDocumentation": true
    }
}
}

项目的结构如下图所示:

无法启动dlv dap。

英文:

When I launch in VSCode dlv dap debug, I get this message:

Couldn't start dlv dap:
Error:timed out while waiting for DAP server to start

无法启动dlv dap。

I already have launch configurations for the project:

lunch.json:

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Launch file",
        "type": "go",
        "request": "launch",
        "mode": "debug",
        "program": "${workspaceFolder}",
        "showLog": true,
        "env": {
            "GO111MODULE": "on"
        }
    }
]
}

and setting.json is :

{
"folders": [
	{
		"path": "."
	}
],
"settings": {
	"go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
    "go.autocompleteUnimportedPackages": true, 
    "go.gocodePackageLookupMode": "go",
    "go.gotoSymbol.includeImports": true,
    "go.useCodeSnippetsOnFunctionSuggest": true,
    "explorer.confirmDelete": false,
    "go.formatTool": "goimports",
    "go.docsTool": "gogetdoc",
    "go.buildFlags": [],
    "explorer.confirmDragAndDrop": false,
    "window.zoomLevel": 0.8,
    "editor.minimap.enabled": false,
    "go.useLanguageServer": true,
    "go.delveConfig":{
        "debugAdapter":"dlv-dap"
        },
    "": {
        "editor.snippetSuggestions": "none",
        "editor.formatOnType": true,
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        }
    },
    "gopls": {
        "experimentalWorkspaceModule": true,
        "usePlaceholders": true, // add parameter placeholders when completing a function
        "completionDocumentation": true // for documentation in completion items
    }
},
    
}

The structure of the project is shown in the figure:

无法启动dlv dap。

答案1

得分: 25

这可能是由于最近对VS Code Go 扩展的更新导致的。

第一种选择是通过在命令面板中运行"Go: Install/Update Tools"命令来修复它(Linux/Windows: Ctrl+Shift+PMac: ++P)。

然后,从菜单中选择dlvdlv-dap,点击确定开始安装/更新。

> Delve的原生DAP实现正在积极开发中,因此通过使用从其主分支构建的最新版本的Delve,可以利用最新的功能和错误修复。Go扩展将此最新版本的Delve与官方发布的dlv版本分开维护,并将其安装为dlv-dap。

第二种选择是使用旧版调试适配器。有关详细信息,请查看下面的链接...

请访问完整文档:https://github.com/golang/vscode-go/blob/master/docs/debugging.md

英文:

This might be happening due to recent updates to VS Code Go extension.

First options is to fix it by running &quot;Go: Install/Update Tools&quot; command from the Command Palette (Linux/Windows: <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>, Mac: <kbd>⇧</kbd>+<kbd>⌘</kbd>+<kbd>P</kbd>).

Then, mark dlv & dlv-dap from the menu, and hit ok to start install/update.

>Delve’s native DAP implementation is under active development, so take advantage of the most recent features and bug fixes by using Delve built from its master branch. The Go extension maintains this newest version of Delve separately from the officially released version of dlv and installs it with the name dlv-dap.

Second option, is to use legacy debug adapter. More on this in the link below ...

Check out the full documentation at https://github.com/golang/vscode-go/blob/master/docs/debugging.md

答案2

得分: 8

你可以尝试将delveConfig切换到使用legacy模式:

"go.delveConfig":{
    "debugAdapter":"legacy"
}

我和我的团队最近在更新VSCode后遇到了相同的问题。关于这个设置的更多信息可以在这里找到:https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#switching-to-legacy-debug-adapter,但我相信(如果这确实解决了你的问题)根本原因是你的Golang版本不是dlv-dap所针对的版本。低于Go 1.15的任何版本都需要使用legacy模式,而最新版本的delve调试器默认跳过了legacy模式。

在进行此更改生效之前,我还需要关闭VSCode。根据dlv-dap文档的说明,你还可以通过将launch.json的模式切换为"remote"来强制进入legacy模式,所以可能有几种(也许更好的)方法来解决这个问题。

英文:

You might have some luck switching the delveConfig to use legacy mode:

    &quot;go.delveConfig&quot;:{
        &quot;debugAdapter&quot;:&quot;legacy&quot;
        }

My team and I recently began seeing the same issue after updating VSCode. There's a little more info on this setting here: https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#switching-to-legacy-debug-adapter, but I believe root cause (if this does indeed solve your issue) is going to be your version of Golang is not the version targeted by dlv-dap. Anything below Go version 1.15 needs to use legacy mode, and the latest version of the delve debugger happens to skip legacy mode by default now.

I also needed to kill VSCode before this change took effect. According to the dlv-dap docs, you can also force it into legacy mode by switching launch.json's mode to "remote", so there's likely a few (maybe better) ways to resolve this issue.

答案3

得分: 0

对于 macOS 用户:

brew install delve
英文:

For macOS users:

brew install delve

答案4

得分: 0

Linux/Windows: Ctrl+Shift+P,Mac: ⇧+⌘+P

无法启动dlv dap。

无法启动dlv dap。

英文:

Linux/Windows: Ctrl+Shift+P, Mac: ⇧+⌘+P
无法启动dlv dap。

无法启动dlv dap。

huangapple
  • 本文由 发表于 2021年8月12日 15:26:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/68753251.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定