vscode dlv调试配置

调试参数refer:  https://github.com/golang/vscode-go/blob/master/docs/debugging.md

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        //调试单个文件
        {
            "name": "Launch file",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${file}"
        },

        //调试包
        {
            "name": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            //"program": "${fileDirname}",        //当前文件
            "program": "${workspaceFolder}/gamesrv",  //项目所在目录, 当前工作空间根目录/gamesrv
            "cwd": "${workspaceFolder}/../",       //服务根路径, 调试启动时目录
            "output": "${workspaceFolder}/../bin/gamesrv.exe",  //编译结果存放地,如果不指定具体文件,则以目录为文件名
            "env": {},
            "args": [  //参数
                "0.0.0.0:9877",
                "0.0.0.0:8080",
                "./log/server",
                "root",
                "123456",
                "127.0.0.1:3306",
                "db_game",
            ]
        },

        //调试test文件
        {
            "name": "Launch test function",
            "type": "go",
            "request": "launch",
            "mode": "test",
            "program": "${workspaceFolder}",
            "args": [
                "-test.run",
                "MyTestFunction"
            ]
        },

        //调试本地进程
        {
            "name": "Attach to Local Process",
            "type": "go",
            "request": "attach",
            "mode": "local",
            "processId": 1936460    //进程号
        },

        //调试远程进程
        //先在远程服务器上运行:dlv --listen=192.168.68.2:53358 --headless=true --api-version=2 attach 1234(进程号:1234)
        {
            "name": "Connect to server",
            "type": "go",
            "request": "attach",
            "mode": "remote",
            "remotePath": "${workspaceFolder}", //项目所在目录
            "port": 53358,                      //远程端口
            "host": "192.168.68.2"              //远程地址
        }
    ]
}

 

posted @ 2022-10-27 22:07  小夜天  阅读(444)  评论(0编辑  收藏  举报