From 695ac7f345b6ba171d3961155a3582773228ecc7 Mon Sep 17 00:00:00 2001 From: McKnight22 Date: Sat, 26 Feb 2022 01:13:49 +0800 Subject: [PATCH] added the doc howto-setup-remote-debug-env-with-vscode-for-soong.md --- ...-remote-debug-env-with-vscode-for-soong.md | 144 +++++++++++++++++ ...-remote-debug-env-with-vscode-for-soong.md | 148 ++++++++++++++++++ 2 files changed, 292 insertions(+) create mode 100644 docs/howto-setup-remote-debug-env-with-vscode-for-soong.md create mode 100644 docs/zh/howto-setup-remote-debug-env-with-vscode-for-soong.md diff --git a/docs/howto-setup-remote-debug-env-with-vscode-for-soong.md b/docs/howto-setup-remote-debug-env-with-vscode-for-soong.md new file mode 100644 index 0000000..46d139f --- /dev/null +++ b/docs/howto-setup-remote-debug-env-with-vscode-for-soong.md @@ -0,0 +1,144 @@ +**How to setup remote debug environment with vscode for soong** + + + +- [1. Remote debug environment for vscode](#1-Remote-debug-environment-for-vscode) +- [2. Install dependent software](#2-Install-dependent-software) +- [3. Run debug](#3-Run-debug) +- [4. Reference](#4-Reference) + + + +# 1. Remote debug environment for vscode + +The recommendation of server end is Ubuntu PC as below: (All operations in this article have been verified under the following system environment:) + +``` +$ lsb_release -a +No LSB modules are available. +Distributor ID: Ubuntu +Description: Ubuntu 18.04.6 LTS +Release: 18.04 +Codename: bionic +``` +The client end runs vscode IDE and can choose either Windows or Linux. + + +# 2. Install dependent software + +Server end: +``` +$ sudo apt install openssh-server +$ wget https://golang.google.cn/dl/go1.18rc1.linux-amd64.tar.gz && sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.18rc1.linux-amd64.tar.gz +$ echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc +``` +The configure operation on the server end is finished. Then, it's time to configure the client end. +Note: Choosing the latest version go1.18rc1 (at the time of writing the documentation) is due to RISCV ecosystem is developing at a high speed and the new features would only be supported on the latest version of softwares. Such as, the riscv64's llvm-toolchain build is already using go1.18beta1. + +Client end: +1)Install vscode 1.64.2 or newer version; +2)Run vscode and install vscode extension Remote-SSH on the client end locally; Once the installation succeeds, there is new added "Remote Explorer" on the left side of vscode IDE; +3)Add the server end as a "Host" to the vscode which is running on the client end; +``` +"Remote Explorer" --> + "SSH TARGETS"--> + "Add New" --> + "Enter SSH Connection Command" --> + "Select SSH configuration file to update" --> + "Host added!" +``` +4)Install vscode-server to the server end; +``` +"Remote Explorer" --> + "SSH TARGETS" --> + "Connect to Host in Current Window" --> + "Select the platform of the remote host YOURSERVERIP" --> + "Are you sure want to continue" --> + "Enter password for YOURUSERNAME@YOURSERVERIP" --> +``` +The vscode-server is installed to the path (~/.vscode-server) of the server end automatically. And the client end's vscode logins the server end via vscode extension Remote-SSH; +5)Install vscode extension Go version > 0.31 when the client end's vscode logins the server end via vscode extension Remote-SSH; The vscode extension Go is installed to the server end actually; +6)Install go debug tool "go-delve"; Open vscode "Terminal" and execute the below commands: +``` +$ sudo apt install gcc +$ go install github.com/go-delve/delve/cmd/dlv@v1.8.1 +``` +The configure operation on the client end is finished. + + +# 3. Run debug + +All below operations are run on the client end: +Run vscode to login the AOSP folder in the server end via vscode extension Remote-SSH; +Open vscode "Terminal" and execute the below commands: +``` +$ source build/envsetup.sh +$ SOONG_UI_DELVE=5006 m nothing // The 5006 is a self-defined value, it should be kept same with the latter port setting value. +``` +Then, +``` +"Run and Debug" --> + "create a launch.json file" --> + "Select environment" --> + "Choose debug configuration" --> + "Enter hostname" --> + "Enter port" <5006> --> +``` +The launch.json is opened and add `"debugAdapter": "dlv-dap", ` into the lauch.json mannually, as below: +``` +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Connect to server", + "type": "go", + "debugAdapter": "dlv-dap", + "request": "attach", + "mode": "remote", + "remotePath": "${workspaceFolder}", + "port": 5006, + "host": "YOURSERVERIP" + } + ] +} +``` +Now press "F5",remotely debugging soong with vscode is started. + +Note: +When "SOONG_UI_DELVE=5006 m nothing", if there is an error as below: +``` +user@Ubuntu1804:~/riscv/aosp/plct/riscv64-android-12.0.0$ SOONG_UI_DELVE=5006 m nothing +API server listening at: [::]:5006 +2022-02-23T22:40:06+08:00 warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted) +2022-02-23T22:40:07+08:00 error layer=debugger can't find build-id note on binary +Go version 1.15.6 is too old for this version of Delve (minimum supported version 1.16, suppress this error with --check-go-version=false) +#### failed to build some targets (1 seconds) #### +``` +It's due to the go version of prebuilts/go/linux-x86 provided by riscv64-android-12.0.0 is old. +And the go version can not match the requirement from go-delve. +So a temporary solution is to create a symbol link to use the higher version go which is in the system folder /usr/local/go. +Please apply the solution as below: +``` +$ cd ${AOSP} +$ mv prebuilts/go/linux-x86 prebuilts/go/bak.linux-x86 +$ ln -s /usr/local/go prebuilts/go/linux-x86 # The "/usr/local/go" is the path of the installed higher version go in the previous step. + +``` +**But please revert the above modification before compiling AOSP to use the official provided go in prebuilts/go/linux-x86.** +The reversion is as below: +``` +$ cd ${AOSP} +$ rm prebuilts/go/linux-x86 +$ mv prebuilts/go/bak.linux-x86 prebuilts/go/linux-x86 + +``` +The final solution for the issue is the official providing the newer version go in the coming AOSP 13. + + +# 4. Reference + +* https://android.googlesource.com/platform/build/soong/+/master/README.md +* https://github.com/golang/vscode-go/blob/master/docs/debugging.md +* https://code.visualstudio.com/docs/remote/ssh +* https://code.visualstudio.com/api/advanced-topics/remote-extensions +* https://code.visualstudio.com/docs/editor/debugging diff --git a/docs/zh/howto-setup-remote-debug-env-with-vscode-for-soong.md b/docs/zh/howto-setup-remote-debug-env-with-vscode-for-soong.md new file mode 100644 index 0000000..1d7b55d --- /dev/null +++ b/docs/zh/howto-setup-remote-debug-env-with-vscode-for-soong.md @@ -0,0 +1,148 @@ +**如何搭建 soong 的基于 vscode 的远程开发调试环境** + +注:提供此文档为方便国内参与小伙伴。 + + + +- [1. vscode 的远程开发调试环境](#1-vscode-的远程开发调试环境) +- [2. 安装依赖软件](#2-安装依赖软件) +- [3. 运行 debug](#3-运行-debug) +- [4. 参考文档](#4-参考文档) + + + +# 1. vscode 的远程开发调试环境 + +Server 端建议为 Ubuntu PC ,环境如下:(本文所有操作在以下系统环境下验证通过) + +``` +$ lsb_release -a +No LSB modules are available. +Distributor ID: Ubuntu +Description: Ubuntu 18.04.6 LTS +Release: 18.04 +Codename: bionic +``` +Client 端运行 vscode IDE 可以自选 PC 系统环境, Windows 、 Linux 皆可。 + + +# 2. 安装依赖软件 + +Server 端: +``` +$ sudo apt install openssh-server +$ wget https://golang.google.cn/dl/go1.18rc1.linux-amd64.tar.gz && sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.18rc1.linux-amd64.tar.gz +$ echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc +``` +至此, Server 端配置完成。下面开始配置 Client 端。 +注:此处使用当前(文档撰写时)最新版本 go1.18rc1 的考量是 riscv 生态正在高速发展,对新引入的特性只在最新版本的软件上才会被支持。另,riscv64 的 llvm-toolchain 的构建已经在使用 go1.18beta1。 + +Client 端: +1)安装 vscode 1.64.2 或更高版本; +2)启动 vscode 并安装 vscode extension Remote-SSH 在 Client 端本地,安装成功后左侧边栏新增 Remote Explorer ; +3)将 Server 端作为 Host 添加到 Client 端运行的 vscode 中; +``` +"Remote Explorer" --> + "SSH TARGETS"--> + "Add New" --> + "Enter SSH Connection Command" --> + "Select SSH configuration file to update" --> + "Host added!" +``` +4)安装 vscode-server 到 Server 端 +``` +"Remote Explorer" --> + "SSH TARGETS" --> + "Connect to Host in Current Window" --> + "Select the platform of the remote host YOURSERVERIP" --> + "Are you sure want to continue" --> + "Enter password for YOURUSERNAME@YOURSERVERIP" --> +``` +至此这会将 vscode-server 程序自动安装到 Server 端的 ~/.vscode-server 目录下,并且 Client 端已通过 vscode extension Remote-SSH 完成登录到 Server 端; +5)在通过 vscode extension Remote-SSH 已登录到 Server 端的状态下,安装 vscode extension Go 且版本 >0.31,实际是将它安装到了 Server 端; +6)由于国内用户访问外网受限,可通过设置代理安装 go debug tool go-delve ;打开 vscode Terminal ,然后手动执行如下: +``` +$ go env -w GO111MODULE=on +$ go env -w GOPROXY=https://goproxy.cn,direct +$ echo "export GO111MODULE=on" >> ~/.profile +$ echo "export GOPROXY=https://goproxy.cn" >> ~/.profile +$ source ~/.profile +$ sudo apt install gcc +$ go install github.com/go-delve/delve/cmd/dlv@v1.8.1 +``` +至此, Client 端配置完成。 + + +# 3. 运行 debug + +如下操作都在 Client 端进行: +运行 vscode 通过其插件 Remote-SSH 远程访问 Server 端的 AOSP 代码目录 +打开 vscode Terminal 并先执行如下: +``` +$ source build/envsetup.sh +$ SOONG_UI_DELVE=5006 m nothing //此处5006为自定义值,注意后面 port 值需跟其保持一致 +``` +然后, +``` +"Run and Debug" --> + "create a launch.json file" --> + "Select environment" --> + "Choose debug configuration" --> + "Enter hostname" --> + "Enter port" <5006> --> +``` +此时 launch.json 被打开并手动加入`"debugAdapter": "dlv-dap", `, 如下: +``` +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Connect to server", + "type": "go", + "debugAdapter": "dlv-dap", + "request": "attach", + "mode": "remote", + "remotePath": "${workspaceFolder}", + "port": 5006, + "host": "YOURSERVERIP" + } + ] +} +``` +至此再"F5",即可开始远程调试 soong 。 + +注意: +"SOONG_UI_DELVE=5006 m nothing" 后,如遇错误如下: +``` +user@Ubuntu1804:~/riscv/aosp/plct/riscv64-android-12.0.0$ SOONG_UI_DELVE=5006 m nothing +API server listening at: [::]:5006 +2022-02-23T22:40:06+08:00 warning layer=rpc Listening for remote connections (connections are not authenticated nor encrypted) +2022-02-23T22:40:07+08:00 error layer=debugger can't find build-id note on binary +Go version 1.15.6 is too old for this version of Delve (minimum supported version 1.16, suppress this error with --check-go-version=false) +#### failed to build some targets (1 seconds) #### +``` +其原因是基于当前的 riscv64-android-12.0.0 代码, prebuilts/go/linux-x86 目录下的 go 版本太过老旧不满足 go-delve 的版本要求,故临时对 prebuilts/go/linux-x86 建软链接到系统路径下的高版本 go ,此问题解决。具体操作如下: +``` +$ cd ${AOSP} +$ mv prebuilts/go/linux-x86 prebuilts/go/bak.linux-x86 +$ ln -s /usr/local/go prebuilts/go/linux-x86 # 此处 /usr/local/go 为前面步骤所安装的高版本 go 的路径 + +``` +**但请记得在编译 AOSP 时回退这部分修改,使用官方提供的 go 版本,此方法仅用于调试 soong**。具体回退操作如下: +``` +$ cd ${AOSP} +$ rm prebuilts/go/linux-x86 +$ mv prebuilts/go/bak.linux-x86 prebuilts/go/linux-x86 + +``` +此问题根本解决可等待下一个版本 AOSP 13 中官方提供升级的 go 版本。 + + +# 4. 参考文档 + +* https://android.googlesource.com/platform/build/soong/+/master/README.md +* https://github.com/golang/vscode-go/blob/master/docs/debugging.md +* https://code.visualstudio.com/docs/remote/ssh +* https://code.visualstudio.com/api/advanced-topics/remote-extensions +* https://code.visualstudio.com/docs/editor/debugging +* https://goproxy.cn -- Gitee