hello world

随笔 - 2, 文章 - 63, 评论 - 0, 引用 - 0
数据加载中……

vscode调试go程序

随着互联网时代的飞速发展,我们编码使用的开发利器也在不断更新换代,古话说工欲善其事必先利其器。对于Go语言程序的开发者而言,当下最火的IDE应该非微软的Visual Studio Code莫属,下面给出怎样在vscode中调试go程序的过程,以mac本为示例。
当前已经准备好go的待调试代码,main.go的函数位置为:
/Users/tingfeng/Workspace/go/src/github.com/nsharecome/caccount/main.go

1、编辑launch.json文件

{
    // 使用 IntelliSense 了解相关属性。 
    
// 悬停以查看现有属性的描述。
    
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "debug",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "port": 8899,
            "host": "127.0.0.1",
            "program": "/Users/tingfeng/Workspace/go/src/github.com/nsharecome/caccount/main.go",
            "env": {},
            "args": [    ],
            "output": "${workspaceRoot}/bin/debug_caccount",
            "showLog": true
        },
    ]
}

2、点击运行,报错如下:
2021/02/07 16:51:52 /Users/tingfeng/Workspace/go/src/github.com/nsharecome/caccount/main.go/debugger.go:101: launching process with args: [/Users/tingfeng/Workspace/go/src/github.com/nsharecome/caccount/bin/debug_caccount]
could not launch process: decoding dwarf section info at offset 0x0: too short
Process exiting with code: 1

错误原因如下:安装delve

解决方式:
git clone https://github.com/go-delve/delve.git $GOPATH/src/github.com/go-delve/delve
go get -u github.com/derekparker/delve/cmd/dl

利用delve手动调试可以参考:Delve调试器



posted on 2021-02-07 16:58 听风 阅读(853) 评论(0)  编辑  收藏 所属分类: go


只有注册用户登录后才能发表评论。


网站导航: