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內部做的一些優化,聚合變量和函數內聯等優化。

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM