利用vscode+gdbserver远程调试

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.csdn.net/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"
    }
  ]
}

注意:

  1. “program”: “build/Debug/bin/desktop_gui_simulate”: 程序路径根据需要修改
  2. “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

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WuChengqian

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值