Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use vscode for single-step debugging

Shulou Source: shulou.com Published: 2022-06-02 17:43:25 09月30日 Update

This article is about how to use vscode for single-step debugging. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

Shortcut key

Ctrl + `opens the default terminal; Ctrl + Shift +` creates a new terminal; Ctrl + Shift + Y opens the debugging console, and then switches the terminal options by itself; ps: `is on the left side of the number 1 on the keyboard.

Install clang

Sudo apt-get install clang

VScodeDebug

Here is a record of cpp debugging in general vscode configuration:

1. The overall idea is to first carry out mkdir build & & cd build & & cmake.. according to the conventional method. & & make (this step can be done at the vscode terminal or at the system terminal, it doesn't matter. But in order to open a little less interface, it is better to finish in vscode) generate executable file, and then use vscode to step.

2, configure launch file: click the Debug icon (Ctrl+Shift+D) in the left sidebar, then click the gear icon configure above, and click default configure to automatically generate the launch.json file. When you enter the launch file interface, you can see that the path is .vscode / launch.json/Launch Targets/ (gbd) Launch.

3. Modify launch file

{"version": "0.2.0", "configurations": [{"name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder} / build/app/testMonoBA" / / this path is changed to the final generated executable file path and the executable file name "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false,// changes the true here to false Otherwise, he will call the terminal of the system to carry out the actual "MIMode": "gdb", "setupCommands": [{"description": "Enable pretty-printing for gdb", "text": "- enable-pretty-printing", "ignoreFailures": true}] }]}

4. Modify CMakeLists.txt file

Cmake_minimum_required (VERSION 2.8) project (slam_demo) set (DEFAULT_BUILD_TYPE "Debug") # change release to debug, or you can delete if (NOT CMAKE_BUILD_TYPE) message directly (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 statement add_compile_options (- g) # add statement 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. After completing the above steps, compile again, and then the one below the debugging column in vscode is no longer gray and can be debugged step by step.

Thank you for reading! On how to use vscode for single-step debugging to share here, I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

Tags: Files terminals paths generation content icons more interfaces systems statements configuration good practical it doesn't matter that is general shortcuts ideas situations console Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft macOS Docker Xiaomi Shulou Tech Info