温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么使用Vscode-insiders的docker扩展

发布时间:2021-12-13 14:28:51 来源:亿速云 阅读:261 作者:iii 栏目:云计算

本篇内容介绍了“怎么使用Vscode-insiders的docker扩展”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

一、Vscode-insiders简介

VsCode是微软第一款支持Linux的轻量级代码编辑器,其功能介于编辑器与IDE之间,但更倾向于一个编辑器。Vscode有两个版本,蓝色的Vscode是非常稳定的发行版本,Vscode-insiders,相当于Bate版本,测试版,会有一些新的功能。

本文使用Vscode-insiders 的Docker 和Remote - Containers 扩展,可以便捷地调试Apollo项目,而蓝色的Vscode不具备该调试功能。

二、安装Vscode-insiders及扩展

安装Vscode-insiders

Vscode-insiders有两种安装方式,分别是Apt安装Deb包安装。Vscode-insiders 和蓝色的Vscode 可以同时使用,安装Vscode-insiders 无需卸载蓝色的Vscode。

Apt方式安装:

1sudo apt-get update
2sudo apt-get install code-insiders

Deb方式安装:

在 https://code.visualstudio.com/insiders/ 下载 Vscode-insiders 的Deb包,

1sudo dpkg -i code-insiders_xxx.deb

安装 Docker 和 Remote-Containers 扩展

运行Vscode-insiders,在扩展栏中搜索 Docker 和 Remote - Containers 扩展并安装。


在 https://code.visualstudio.com/docs/remote/containers 中可查看Docker扩展的详细教程。

怎么使用Vscode-insiders的docker扩展

▲Docker安装

怎么使用Vscode-insiders的docker扩展

▲Remote - Containers安装

由于Apollo项目是用C++进行开发,所以还需安装C++扩展

怎么使用Vscode-insiders的docker扩展

▲C++扩展

安装完毕后如图所示:

怎么使用Vscode-insiders的docker扩展

▲Docker 和 Remote - Containers 安装图示

三、配置Vscode-insiders

启动Apollo Docker

关于如何构建 Apollo3.5或5.0 已在Ubuntu14.04搭建GPU版本的百度Apollo3.5自动驾驶平台详细介绍。 

1cd apollo
2bash docker/scripts/dev_start.sh 
3bash docker/scripts/dev_into.sh 
4bash scripts/bootstrap.sh

在Vscode-insiders中配置Apollo

Apollo Docker 启动后,打开Vscode-insiders,选中Docker图标,出现Apollo镜像,如图所示:

怎么使用Vscode-insiders的docker扩展

▲启动Vscode-insiders

右键选中Apolloauto/apollo:dev-x86_64-xxx 镜像,选中Attach visual studio code(蓝色的Vscode即使安装了Docker扩展也没有此选项)

怎么使用Vscode-insiders的docker扩展

▲选中Attach visual studio code

此时Vscode会自动打开一个新窗口加载Container,若左下角出现 Attached container 字样,则表示 Vscode 已加载完成。

怎么使用Vscode-insiders的docker扩展

▲Vscode 加载完成

然后选择 【打开文件夹】,键入 /apollo/ 后确定

怎么使用Vscode-insiders的docker扩展

▲键入 /apollo/ 

此时Vscode-insiders 已经加载 Apollo 镜像中的/apollo 文件夹,接着打开扩展栏,在Docker中安装C++ 扩展(部分电脑会自动安装),安装后点击【重新加载】。

怎么使用Vscode-insiders的docker扩展

▲在Docker中安装C++ 扩展

加载完成后即配置好环境

怎么使用Vscode-insiders的docker扩展

▲加载完成

四、调试Apollo模块和单元测试程序

调试Apollo单元测试程序

完成环境配置后,选择【调试】-【打开配置】,自动打开 /Apollo/.vscode/launch.json 配置文件:

根据自己的需要,修改 Program 和 Args 参数,即可调试Apollo单元测试程序,以下给出一个例子:

 1{
 2    "version": "0.2.0",
 3    "configurations": [
 4
 5        {
 6            "name": "(gdb) Launch",
 7            "type": "cppdbg",
 8            "request": "launch",
 9            "program": "/apollo/bazel-bin/modules/perception/camera/test/camera_lib_lane_postprocessor_denseline_lane_postprocessor_test",
10            "args": [],
11            "stopAtEntry": false,
12            "cwd": "${workspaceFolder}",
13            "environment": [],
14            "externalConsole": false,
15            "MIMode": "gdb",
16            "setupCommands": [
17                {
18                    "description": "Enable pretty-printing for gdb",
19                    "text": "-enable-pretty-printing",
20                    "ignoreFailures": true
21                }
22            ]
23        }
24    ]
25}

打开对应的测试代码文件,加入断点,选择【调试】-【启动调试】,即可像其他IDE进行方便的代码调试。

  • F10:单步调试

  • F11:单步跳入

  • Shift+F11:单步跳出

左侧可直观地看到堆栈和变量信息:

怎么使用Vscode-insiders的docker扩展

▲堆栈和变量信息

修改代码后在Docker中运行Build,完成编译后即可再次启动调试。

调试Apollo模块

Apollo开发者社区公众号曾发过的《开发者说 | Apollo 3.5各功能模块启动过程解析》详细地介绍了Apollo3.5 的模块启动过程。

通过在 /apollo/cyber/mainboard/mainboard.cc 加入断点,可以详细地看到模块的启动过程(如何加载Dag和Conf文件进行初始化),极大地方便了开发者理解和调试Apollo模块。

PS: Apollo3.0及以前的版本仍然可用此种方式调试,只需把 Program 改成Ros可执行程序路径,以及 Args改成对应的参数。

 
 1{
 2    "version": "0.2.0",
 3    "configurations": [
 4
 5        {
 6            "name": "(gdb) Launch",
 7            "type": "cppdbg",
 8            "request": "launch",
 9            "program": "/apollo/bazel-bin/cyber/mainboard",
10            "args": ["-d","/apollo/modules/drivers/gnss/dag/gnss.dag"],
11            "stopAtEntry": false,
12            "cwd": "${workspaceFolder}",
13            "environment": [],
14            "externalConsole": false,
15            "MIMode": "gdb",
16            "setupCommands": [
17                {
18                    "description": "Enable pretty-printing for gdb",
19                    "text": "-enable-pretty-printing",
20                    "ignoreFailures": true
21                }
22            ]
23        }
24    ]
25}
 
怎么使用Vscode-insiders的docker扩展

▲调试Apollo板块

“怎么使用Vscode-insiders的docker扩展”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI