这篇文章给大家分享的是有关怎么用vscode进行单步调试的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。
创新互联主要从事成都网站建设、成都网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务沈丘,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108
快捷键
Ctrl + ` 打开默认终端; Ctrl + Shift + ` 新建新的终端; Ctrl + Shift + Y 打开调试控制台,然后再自行切换终端选项; ps: ` 在键盘数字1的左边。
安装clang
sudo apt-get install clang
VScodeDebug
这里对vscode配置一般情况的cpp调试做个记录:
1、整体思路就是首先按照常规方法进行mkdir build && cd build && cmake.. && make (这一步可以在vscode的终端完成,也可以在系统终端完成,无所谓。但是为了少开点界面就在vscode里面完成比较好)生成可执行文件,然后使用vscode进行单步。
2、配置launch文件:点击左侧边栏的Debug图标(Ctrl+Shift+D),再点上方的齿轮图标configure,点击default configure就能自动生成launch.json文件。进入launch文件界面可以看到路径为.vscode/launch.json/Launch Targets/(gbd)Launch.
3、修改launch文件
{ "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/build/app/testMonoBA", //此路径更改为最终生成的可执行文件路径以及可执行文件名称 "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole":false,//将此处的true改为false,不然他会调用系统的终端进行现实 "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], } ] }
4、修改CMakeLists.txt文件
cmake_minimum_required(VERSION 2.8) project(slam_demo) set(DEFAULT_BUILD_TYPE "Debug") #修改处,讲release改为debug,也可以直接删除 if (NOT CMAKE_BUILD_TYPE) message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.") set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE) # Set the possible values of build type for cmake-gui set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif () set(CMAKE_CXX_FLAGS "-std=c++11") FIND_PACKAGE( OpenMP REQUIRED) if(OPENMP_FOUND) message("OPENMP FOUND") ADD_DEFINITIONS(-DUSE_OPENMP) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") endif() #set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -Wno-reorder" CACHE STRING "" FORCE) #set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -DNDEBUG -Wno-reorder -O2" CACHE STRING "" FORCE) set(CMAKE_CXX_FLAGS_DEBUG "{CMAKE_CXX_FLAGS} -o0 -ggbd") #添加语句 add_compile_options(-g) #添加语句 list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") option(BUILD_APPS "Build APPs for slam course" YES) option(BUILD_TESTS "Build test for slam course" No) # third party libs # eigen find_package(Eigen REQUIRED) include_directories(${EIGEN_INCLUDE_DIR}) # opencv find_package(OpenCV 4 REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS}) # glog find_package(Glog REQUIRED) include_directories(${GLOG_INCLUDE_DIRS}) # sophus include_directories(${PROJECT_SOURCE_DIR}/thirdparty/Sophus) include_directories(${PROJECT_SOURCE_DIR}) add_subdirectory(frontend) add_subdirectory(backend) add_subdirectory(utils) if (BUILD_APPS) add_subdirectory(app) endif () if (BUILD_TESTS) enable_testing() add_subdirectory(test) endif ()
5、完成以上步骤后,重新进行编译,然后vscode中的调试一栏下面的就不再是灰色,可以进行单步调试。
感谢各位的阅读!关于怎么用vscode进行单步调试就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!