VSCode遠程調試Go程序方法(Attach)

  1. set launch.json
{
            "name": "Attach",
            "type": "go",
            "request": "launch",
            "mode": "remote",
            "remotePath": "${workspaceRoot}",
            "port": 2345,
            "host": "127.0.0.1",
            "program": "${workspaceRoot}",
            "env": {},
            "args": [],
            "showLog": true
        }
  1. go build && run
  2. get pid && dlv attach $pid  --headless=true --api-version=2--listen=:2345 --log
  3. in VSCode, Click begin debug button

* 注意go build要帶上這個標記 -gcflags='-N -l',目的是關閉Go內部作的一些優化,聚合變量和函數內聯等優化。json

* 或者直接這樣運行dlv --listen=:2345 --headless=true --api-version=2 exec ./demoapi

相關文章
相關標籤/搜索