使用vscode查bug

具体操作

  1. 修改CMakeList.txt
cpp 复制代码
# set(CMAKE_BUILD_TYPE "Release")//注释Release模式
set(CMAKE_BUILD_TYPE "Debug")//设置为Debug模式
# set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g")//注释

*这行代码是用来设置 CMake 构建系统中 Release 模式下 C++ 编译器的标志(flags)。
set: 这是 CMake 中用于设置变量的命令,它将一个变量设置为指定的值。
CMAKE_CXX_FLAGS_RELEASE: 这是一个预定义的 CMake 变量,用于存储 Release 模式下 C++ 编译器的标志。
"-O3 -Wall -g": 这是被设置的值,它是一个字符串,包含了一系列的编译器标志。具体解释如下:
-O3: 启用高级优化级别,这通常会提高代码的执行速度。
-Wall: 启用警告信息,让编译器产生更多的警告,帮助开发者发现潜在的问题。
-g: 在生成的可执行文件中包含调试信息,以便在调试时能够获取更多的信息。
因此,这行代码的作用是在 Release 模式下,为 C++ 编译器设置了一些优化和调试相关的标志,以提高代码性能并帮助调试。*
  1. 点击 creat a launch .json file. 在vscdoe右下角会出现一个蓝色按钮"Add Configuration",点击这个蓝色按钮,创建一个launch.json文件,该文件位于工作空间的.vscode隐藏文件夹下。launch.json文件内容默认如下:
cpp 复制代码
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": []
}

  1. 以调试ROS程序为例,可以选择ROS: Attach 或 ROS: Launch。其中,ROS: Attach 表示对一个可执行节点(node) debug,ROS: Launch 表示对一个launch 文件 debug。
cpp 复制代码
自动补全选择 ROS: Launch 后的launch.json文件如下,在target: 粘贴launch文件的绝对路径
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [{
        "name": "ROS: Launch",
        "type": "ros",
        "request": "launch",
        "target": "absolute path to launch file"
    }]
}

然后点击这个三角按钮,程序运行,若出现bug, 可自动捕获异常

cpp 复制代码
自动补全选择 ROS: Attach 后的launch.json文件如下,这是需要rosrun pkg type,而后点击三角按钮 attach/连接 到这个节点, 程序运行,若出现bug,  可自动捕获异常
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [{
        "name": "ROS: Attach",
        "type": "ros",
        "request": "attach"
    }]
}
相关推荐
️学习的小王5 小时前
Anaconda国内镜像配置与conda常用命令
ide·经验分享·python·conda
雾沉川7 小时前
Rust IDE 选型:除 VS Code 之外,RustRover 非商业场景可免费使用
ide·vscode·rust
界面开发小八哥7 小时前
界面控件DevExpress Blazor v26.1新版亮点 - TreeList & 数据编辑器
javascript·编辑器·.net·界面控件·blazor·devexpress·用户界面
精英的英1 天前
记一次 Qt5 Language Server 开发
开发语言·vscode·qt
蹦跶的小羊羔1 天前
Sublime 调用的 py 命令找不到
编辑器·sublime text
2501_915918411 天前
iOS 真机调试工具推荐,安装运行、性能分析有哪些工具
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
FZdydz1 天前
大禹电子多普勒流量计小管径生活污水排污口流量监测应用案例
百度·编辑器·新浪微博
C++ 老炮儿的技术栈2 天前
Qt5.9.1 Windows 完整开发环境搭建流程
开发语言·c++·windows·qt·编辑器·代码化
笨鸟先飞,勤能补拙2 天前
AI与深度学习:从原理到应用
人工智能·windows·vscode·深度学习·机器学习·网络安全·github
Albert Edison2 天前
PyCharm 字体大小设置
ide·python·pycharm