• Vscode调试golang的debug


    配置启动项

      打开调试面板:VSCode->查看->调试

      添加调试目标:点击添加配置

      添加目标调试配置

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch",
                "type": "go",
                "request": "launch",
                "mode": "debug",
                "remotePath": "",
                "port": 2345,
                "host": "127.0.0.1",
                "program": "${fileDirname}",
                "env": {
                    "GOPATH":"D:/Develop/vscodegolang"
                },
                "args": [],
                "showLog": true
            }
        ]
    }
    

        其中"post","host"都是go插件自动生成的,“env”为设置环境变量,设置为工程目录包含bin、src的文件夹

    准备调试插件

      选中要调试的main.go,点击F5会报错误提示:Failded to continue:"Cannot find Delve debugger. Install from https://github.com/derekparker/delve & ensure it is in your "GOPATH/bin" or "PATH"

      使用命令编译调试器:go get github.com/derekparker/delve/cmd/dlv  将dlv调试器放在GOPATH的bin目录下

    开始调试

      选中要调试的main.go,点击F5可以开始调试

      调试快捷键:

          F9 切换断点

          F10 Step over

          F11 Step in

          Shift+F11 Step out

      注意:有些结构体成员法务直接显示时,可以直接选中变量名,添加到监视,或者右键点击"调试:求值"

    多项目调试

      在launch.json中可以添加多组调试入口,通过调试面板中选中对应的配置开启不同目标的调试

    在launch.json中可以添加多组调试入口, 通过调试面板中选中对应的配置开启不同目标的调试
    
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "client",
                "type": "go",
                "request": "launch",
                "mode": "debug",
                "remotePath": "",
                "port": 2345,
                "host": "127.0.0.1",
                "program": "${fileDirname}",
                "env": {
                    "GOPATH":"D:/Develop/vscodegolang"
                },
                "args": [],
                "showLog": true
            },
    
            {
                "name": "server",
                "type": "go",
                "request": "launch",
                "mode": "debug",
                "remotePath": "",
                "port": 2345,
                "host": "127.0.0.1",
                "program": "${workspaceRoot}/src/server",
                "env": {
                    "GOPATH":"D:/Develop/vscodegolang"
                },
                "args": [],
                "showLog": true
            }
        ]
    }
    "program"中的"${fileDirname}"是以当前选中文件作为启动点
    
    更建议使用"program"的"${workspaceRoot}", 以包名作为启动点的方式进行配置
    

      

  • 相关阅读:
    android 图片加载库 Glide 的使用介绍
    Android Glide数据更新及内存缓存、硬盘缓存清理
    Android中<meta-data>的使用
    分层,工厂模式,依赖注入控制反转
    Asp.Net_Web身份验证
    aspx后缀映射成html
    网站跳舞人代码
    Sqlerver_各类函数
    Sqlserver_时间用法
    Sqlserver_视图
  • 原文地址:https://www.cnblogs.com/parallel-Y/p/11577430.html
Copyright © 2020-2023  润新知