1、修改终端IP地址配置为动态获取IP (或者正确修改DNS服务器配置和网关)
请先将终端ip地址设置为DHCP方式,否则apt update可能会失败
1.1 修改以下配置文件:
# sudo vi /etc/network/interfaces.d/FE0
auto FE0
allow-hotplug FE0
iface FE0 inet dhcp
1.2 保存重启终端,确认终端正确获取ip地址
sysadm@SCT230A:~$ ifconfig
FE0 Link encap:Ethernet HWaddr 26:a5:78:57:8c:0d
inet addr:192.168.2.238 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::24a5:78ff:fe57:8c0d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:461935 errors:0 dropped:0 overruns:0 frame:0
TX packets:131747 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:48093705 (48.0 MB) TX bytes:55169793 (55.1 MB)
Interrupt:117
1.3 执行apt update命令,确认工作正常。
sysadm@SCT230A:~$ sudo apt update
Hit:1 https://download.docker.com/linux/ubuntu xenial InRelease
Hit:2 http://ports.ubuntu.com xenial InRelease
Hit:3 http://ports.ubuntu.com xenial-security InRelease
Hit:4 http://ports.ubuntu.com xenial-updates InRelease
Hit:5 http://ports.ubuntu.com xenial-backports InRelease
Hit:6 http://ports.ubuntu.com/ubuntu-ports xenial InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
155 packages can be upgraded. Run 'apt list --upgradable' to see them.
2、使用Debug方式编译源代码,并配置好运行环境
2.1 在project_root代码目录下,执行./build.sh Debug 编译
wcq@wcq-Vostro-3583:project_root$ ./build.sh Debug
BuildType Debug
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_TOOLCHAIN_FILE
-- Build files have been written to: /home/wcq/Project/project_root/build/Debug
ninja: no work to do.
-- Install configuration: "Debug"
3、使用gdbserver + vscode调试代码
3.1 配置好vscode相关插件
推荐:C/C++ Extension Pack, 它包含c/c++开发过程中常用的插件,也集成了Remote - SSH 插件。
3.2 配置好SSH远程开发环境,确保能够访问开发服务器的代码工程。
参考:https://blog.youkuaiyun.com/fengxiaolu311/article/details/104774530/
3.3 .vscode/launch.json配置如下:
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "build/Debug/bin/desktop_gui_simulate",
"args": [
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{ "name" : "LD_LIBRARY_PATH",
"value": "/lib/hal_lib:/lib/hal_lib/local"
}
],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerPath": "/opt/ext-toolchain/bin/arm-linux-gnueabihf-gdb",
"miDebuggerServerAddress": "192.168.2.238:9999"
}
]
}
注意:
- “program”: “build/Debug/bin/desktop_gui_simulate”: 程序路径根据需要修改
- “miDebuggerServerAddress”: “192.168.2.238:9999”: ip地址和端口需要根据需要进行修改
3.4 终端启动gdbserver
sysadm@SCT230A:~/project/bin$ sudo gdbserver :9999 ./desktop_gui_simulate
Process ./desktop_gui_simulate created; pid = 6093
Listening on port 9999
3.5 vscode 快捷键 F5进入调试模式,Enjoy it!
4、参考资料
1、https://code.visualstudio.com/docs/remote/ssh
2、https://nnfw.readthedocs.io/en/stable/howto/how-to-remote-debugging-with-visual-studio-code.html