【问题标题】:Golang debug in VSCode on macOS issuesmacOS 问题上的 VSCode 中的 Golang 调试
【发布时间】:2021-11-02 11:07:51
【问题描述】:

我需要在 macos 上的 vscode 中调试一个 golang 应用程序,但没有成功。 得到的错误是:

API server listening at: 127.0.0.1:49512
could not launch process: not an executable file
Process exiting with code: 1

这是我的 GO ENV

go version go1.16.6 darwin/amd64

Delve Debugger
Version: 1.7.0
Build: $Id: e353a65161e6ed74952b96bbb62ebfc56090832b $

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/francois/Library/Caches/go-build"
GOENV="/Users/francois/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/francois/go/pkg/mod"
GONOPROXY="gitlab.com/baltussen"
GONOSUMDB="gitlab.com/baltussen"
GOOS="linux"
GOPATH="/Users/francois/go"
GOPRIVATE="gitlab.com/baltussen"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.16.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16.6/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="0"
GOMOD="/Users/francois/DiVision/baltussen/pat-be/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/n8/xbwvwsg55_s5clpxq778nrg80000gn/T/go-build3775586407=/tmp/go-build -gno-record-gcc-switches"

我已经卸载了 go 并重新安装了它。 我还从 vs-code 中删除了 go 扩展并重新添加了它。 我也尝试了各种 launch.json 版本,但到目前为止还没有运气。 这是我的 launch.json 文件:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "GoLang",
      "type": "go",
      "request": "launch",
      "mode": "auto",
      "program": "${workspaceFolder}",
      "env": {
        "PATH": "/usr/local/go/bin:${fileDirname}"
      },
      "args": []
    }
  ]
}

欢迎任何想法或建议。

【问题讨论】:

    标签: go debugging visual-studio-code


    【解决方案1】:

    您需要指定 main.go 文件的路径,如果该文件不直接位于您的工作区目录中。

    我的配置如下所示:

    {
        // 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": "Launch file",
                "type": "go",
                "request": "launch",
                "mode": "debug",
                "program": "${file}",
                "env": {         
                },
                "args": [     
                ]
            },
            {
                "name": "Launch",
                "type": "go",
                "request": "launch",
                "mode": "auto",
                "program": "${workspaceFolder}/cmd/service/main.go",
                "env": {            
                },
                "args": [
                ]           
            }
        ]
    }
    

    它由两部分组成。

    1. 启动当前打开的文件
    2. 使用"program": "${workspaceFolder}/cmd/service/main.go"在指定路径下启动main.go文件

    您可以将/cmd/service/main.go 路径交换为与您的项目结构匹配的路径。

    当有多个配置时,您可以在运行和调试选项卡中切换它们。

    【讨论】:

      【解决方案2】:

      你在 golang-project 文件夹中运行了$ dlv debug 吗?

      Go 调试器必须在没有 VSCode 的情况下工作。尝试为您的ENV 修复一些参数:

      GOOS="darwin"
      CGO_ENABLED="1"
      

      • [x]$ dlv debug

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-22
        • 2023-03-20
        • 2018-12-02
        • 1970-01-01
        • 2018-09-13
        • 1970-01-01
        • 1970-01-01
        • 2021-07-20
        相关资源
        最近更新 更多