From 4a115fb3fa6fa675b38bc901137079b6386b0764 Mon Sep 17 00:00:00 2001 From: TenderIronh Date: Mon, 8 Aug 2022 23:10:37 +0800 Subject: [PATCH] doc remote debug --- doc/remote-debug-golang.md | 73 ++++++++++++++++++++++++++++++++++++++ doc/remote-debug-vscpp.md | 50 ++++++++++++++++++++++++++ install.go | 1 + 3 files changed, 124 insertions(+) create mode 100644 doc/remote-debug-golang.md create mode 100644 doc/remote-debug-vscpp.md diff --git a/doc/remote-debug-golang.md b/doc/remote-debug-golang.md new file mode 100644 index 0000000..fa9e149 --- /dev/null +++ b/doc/remote-debug-golang.md @@ -0,0 +1,73 @@ +# 1. 环境 +golang1.18.1 +调试端: win10+vscode +被调试端: ubuntu20.04LTS+dlv +## dlv安装 +参考官方文档https://github.com/go-delve/delve/tree/master/Documentation/installation +``` +go install github.com/go-delve/delve/cmd/dlv@latest +``` + +## 被调试端 +``` +cd /your-src-path #要确保两端源码一致 +dlv debug --headless --listen=:2345 --api-version=2 +# 如果失败可查看更多日志 +# dlv debug --headless --listen=:2345 --api-version=2 --log --log-output=rpc,dap,debugger +``` + +## 调试端(vscode) +``` +打开vscode,修改launch.json,增加下面远程调试配置 +{ + "version": "0.2.0", + "configurations": [ + { + "name": "RemoteDebug", + "type": "go", + "request": "attach", + "mode": "remote", + "port": 2345, + "host": "192.168.3.29", + } + ] +} +按F5启动调试 +``` + +## 没有公网IP或不在同一个局域网,无法直连如何调试 +到https://openp2p.cn/注册一个用户获得token,两端安装一个客户端程序,可将被调试端的2345端口,通过p2p连接映射到调试端本地。 +p2p连接可通过web配置 https://github.com/openp2p-cn/openp2p/blob/master/README-ZH.md#%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8 + +也可以手动下载https://github.com/openp2p-cn/openp2p/releases 通过命令行手动配置 + +``` +# 注意替换下面YOUR-开头的参数改成自己的 +./openp2p -node YOUR-DEBUG-SERVER -token YOUR-TOKEN + +openp2p.exe -node YOUR-DEBUG-CLIENT -token YOUR-TOKEN -peernode YOUR-DEBUG-SERVER -dstport 2345 -srcport 2345 + +2022/04/22 11:07:26 25680 INFO LISTEN ON PORT tcp:2345 START +#显示这条日志说明成功了 +``` + +p2p端口映射完成后,把vscode的配置改成本地127.0.0.1,一样可以顺利调试。 +``` +{ + "version": "0.2.0", + "configurations": [ + { + "name": "RemoteDebug", + "type": "go", + "request": "attach", + "mode": "remote", + "port": 2345, + "host": "127.0.0.1", + } + ] +} +``` + + +# 参考 +https://github.com/golang/vscode-go/blob/master/docs/debugging.md#remote-debugging \ No newline at end of file diff --git a/doc/remote-debug-vscpp.md b/doc/remote-debug-vscpp.md new file mode 100644 index 0000000..2325a33 --- /dev/null +++ b/doc/remote-debug-vscpp.md @@ -0,0 +1,50 @@ +# 1. 环境 +visual studio 2022 +调试端: win10 +被调试端: win10 +## 程序编译 +一般远程调试我会选择release版本,然后将优化去掉即可,这样更接近真实版本。 +![image](/image/release-debug.png) + +``` +go install github.com/go-delve/delve/cmd/dlv@latest +``` + +## 运行远程调试器 +C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Remote Debugger 拷贝到目标机器 + +如果调试x64程序则cd到Remote Debugger\x64目录 + +管理员方式打开cmd,执行 +``` + netsh advfirewall set allprofiles state off + msvsmon.exe /noauth /anyuser /silent +``` + +## visual studio + +Attach远程进程,按下Ctrl+Atl+P + +![image](/image/vs2022-remote-debug-attach.png) + + +## 没有公网IP或不在同一个局域网,无法直连如何调试 +到https://openp2p.cn/注册一个用户获得token,两端安装一个客户端程序,可将被调试端的2345端口,通过p2p连接映射到调试端本地。 +p2p连接可通过web配置 https://github.com/openp2p-cn/openp2p/blob/master/README-ZH.md#%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8 + +也可以手动下载https://github.com/openp2p-cn/openp2p/releases 通过命令行手动配置 + +``` +# 注意替换下面YOUR-开头的参数改成自己的 +./openp2p -node YOUR-DEBUG-SERVER -token YOUR-TOKEN + +openp2p.exe -node YOUR-DEBUG-CLIENT -token YOUR-TOKEN -peernode YOUR-DEBUG-SERVER -dstport 4026 -srcport 4026 + +2022/04/22 11:07:26 25680 INFO LISTEN ON PORT tcp:4026 START +#显示这条日志说明成功了 +``` + +![image](/image/p2p-debug.png) + +可以顺利远程调试 +``` \ No newline at end of file diff --git a/install.go b/install.go index 6f7a012..f4360bf 100644 --- a/install.go +++ b/install.go @@ -102,6 +102,7 @@ func installByFilename() { return } gLog.Println(LvINFO, "install end") + gLog.Println(LvINFO, "Visit WebUI on https://console.openp2p.cn") fmt.Println("Press the Any Key to exit") fmt.Scanln() os.Exit(0)