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# eigenfind_package(eigen required)include_directories(${eigen_include_dir})# opencvfind_package(opencv 4 required)include_directories(${opencv_include_dirs})# glogfind_package(glog required)include_directories(${glog_include_dirs})# sophusinclude_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教程
以上就是如何用vscode进行单步调试的详细内容。
