参考:https://blog.csdn.net/zy_workjob/article/details/104400805

注意:本实验vscode是安装在mac电脑上的

vscode连接步骤

安装ssh插件

vscode打开ubuntu目录

如果弹出窗口提示是否文件夹可信任,选可信任

vscode远程执行hello.cpp

vscode新建hello.cpp如下

终端远程到ubuntu机器,查看下g++的安装位置,查看命令:whereis

配vscode如下

然后会在.vscode隐藏文件夹下面生成一个tasks.json文件,如下

可以在tasks.json里修改label的名称,如改为: test,如下

这时候ubuntu机器对应目录下是生成了hello可执行文件,如下

配置gdb调试

安装gdb

universe@universe:/xx/c++$ sudo apt install gdb
[sudo] password for universe: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  gdbserver libbabeltrace1 libc6-dbg libdw1
Suggested packages:
  gdb-doc
The following NEW packages will be installed:
  gdb gdbserver libbabeltrace1 libc6-dbg libdw1
0 upgraded, 5 newly installed, 0 to remove and 81 not upgraded.
Need to get 23.8 MB of archives.
After this operation, 42.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://cn.archive.ubuntu.com/ubuntu focal/main amd64 libdw1 amd64 0.176-1.1build1 [226 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu focal/main amd64 libbabeltrace1 amd64 1.5.8-1build1 [156 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu focal-updates/main amd64 gdb amd64 9.2-0ubuntu1~20.04.1 [3,222 kB]
Get:4 http://cn.archive.ubuntu.com/ubuntu focal-updates/main amd64 gdbserver amd64 9.2-0ubuntu1~20.04.1 [222 kB]
Get:5 http://cn.archive.ubuntu.com/ubuntu focal-updates/main amd64 libc6-dbg amd64 2.31-0ubuntu9.9 [20.0 MB]
Fetched 23.8 MB in 22s (1,085 kB/s)                                            
Selecting previously unselected package libdw1:amd64.
(Reading database ... 147897 files and directories currently installed.)
Preparing to unpack .../libdw1_0.176-1.1build1_amd64.deb ...
Unpacking libdw1:amd64 (0.176-1.1build1) ...
Selecting previously unselected package libbabeltrace1:amd64.
Preparing to unpack .../libbabeltrace1_1.5.8-1build1_amd64.deb ...
Unpacking libbabeltrace1:amd64 (1.5.8-1build1) ...
Selecting previously unselected package gdb.
Preparing to unpack .../gdb_9.2-0ubuntu1~20.04.1_amd64.deb ...
Unpacking gdb (9.2-0ubuntu1~20.04.1) ...
Selecting previously unselected package gdbserver.
Preparing to unpack .../gdbserver_9.2-0ubuntu1~20.04.1_amd64.deb ...
Unpacking gdbserver (9.2-0ubuntu1~20.04.1) ...
Selecting previously unselected package libc6-dbg:amd64.
Preparing to unpack .../libc6-dbg_2.31-0ubuntu9.9_amd64.deb ...
Unpacking libc6-dbg:amd64 (2.31-0ubuntu9.9) ...
Setting up libdw1:amd64 (0.176-1.1build1) ...
Setting up libc6-dbg:amd64 (2.31-0ubuntu9.9) ...
Setting up libbabeltrace1:amd64 (1.5.8-1build1) ...
Setting up gdbserver (9.2-0ubuntu1~20.04.1) ...
Setting up gdb (9.2-0ubuntu1~20.04.1) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.7) ...

查看gdb版本

universe@universe:/xx/c++$ gdb -v
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

会在vscode右下方显示:添加配置,如下

在.vscode隐藏文件夹下生成一个launch.json配置文件

这时候的launch.json文件内容如下

可以修改name; program名称,如下

执行gdb调试

方式1

方式2

调试结果

关闭远程连接

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐