使用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"
    }]
}
相关推荐
Solange__1 小时前
图片转3D导出GLB、FBX还是OBJ?按5类任务比较材质、动画与可编辑性
人工智能·3d·ai·自然语言处理·编辑器·blender·材质
techpupil2 小时前
IDEA基础配置及开发基础插件
java·ide·intellij-idea
赵庆明老师2 小时前
Android Studio Google源代理配置
android·ide·android studio
2501_916008894 小时前
iOS App 图标、启动屏和多语言搭配 方法,上架前使用KXBuild一次做好 App 图标
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
2501_915918414 小时前
iOS 推送通知怎么实现,从 APNs p8 密钥到 iOS 真机收到第一条推送
vscode·ios·objective-c·个人开发·swift·敏捷流程
ThatMonth4 小时前
vscode 编辑器怎么打开多页签,而不是覆盖已有的页签
编辑器
广东帝工21 小时前
双预警防线,筑牢智慧航道水上安全屏障
编辑器
sunshine22 girl1 天前
copilot vscode 使用技巧
人工智能·vscode·编辑器
Frag0ut1 天前
Notepad++ 零基础入门:从记事本到代码编辑器的平滑过渡(2026最新版)
python·编辑器·html·json·notepad++·markdown·记事本
行走的陀螺仪1 天前
Claude Code 从入门到实战(三):Hooks、Skills、SubAgents 高级扩展
linux·编辑器·vim