
#How to single-step debug vscode?
vscode single-step debugging
VScode configuration
0. Shortcut keys
Ctrl + ` 打开默认终端; Ctrl + Shift + ` 新建新的终端; Ctrl + Shift + Y 打开调试控制台,然后再自行切换终端选项; ps: ` 在键盘数字1的左边。
Related recommendations: vscode introductory tutorial
1. Install clang
sudo apt-get install clang
2.VScodeDebug
Plug-in reference link But the configuration of large projects is still relatively complicated. Many tutorials are for configuring a single cpp file. Here is a record of the general cpp debugging of vscode configuration:
1. The overall idea is to first follow the conventional method to perform mkdir build && cd build && cmake.. && make (this step can be completed in the terminal of vscode or in the system terminal, it doesn't matter. But in order to save the interface, it is better to complete it in vscode) generate the executable file, and then use vscode to perform single step.
2. Configure the 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. Enter the launch file interface and you can see that the path is .vscode/launch.json/Launch Targets/(gbd)Launch.
3. Modify the launch file:
{
"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. Modify the CMakeLists.txt file :
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. After completing the above, recompile, and then the debugging column in vscode will no longer be gray and you can perform single-step debugging.
Picture:
3. How Cmake supports gdb debugging
SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
add_compile_options(-g) #添加语句The above is the detailed content of How to single-step debug vscode. For more information, please follow other related articles on the PHP Chinese website!
Visual Studio vs. VS Code: Exploring Features and FunctionalityApr 15, 2025 am 12:05 AMVisualStudio is suitable for large projects and full-featured needs, while VSCode is suitable for developments that require lightweight and flexibility. 1. VisualStudio provides comprehensive IDE functions, supports multiple languages and advanced project management. 2.VSCode is known for its lightweight and scalability, and is suitable for cross-platform development and personalized configuration.
Visual Studio vs. VS Code: Which is Better for Your Project?Apr 14, 2025 am 12:03 AMVisualStudio is suitable for large projects and development scenarios that require strong debugging capabilities, while VSCode is suitable for scenarios that require flexibility and cross-platform development. VisualStudio provides a comprehensive development environment, supports .NET development, and integrates debugging tools and project management functions. VSCode is known for its lightweight and extensibility. It supports multiple programming languages and enhances functions through plug-in systems, and is suitable for modern development processes.
Visual Studio: Exploring Pricing and Licensing OptionsApr 13, 2025 am 12:03 AMVisual Studio is available in three versions: Community Free Edition is for individuals and small teams, Professional Paid Edition is for professional developers and small and medium teams, and Enterprise Ultimate Edition is for large enterprises and complex projects.
Visual Studio's Value: Weighing the Cost Against Its BenefitsApr 12, 2025 am 12:06 AMVisualStudio is highly valuable in .NET development because it is powerful and comprehensive. Despite the high cost and resource consumption, the efficiency improvement and development experience it brings is significant. Community is ideal for individual developers and small teams; large enterprises are suitable for Professional or Enterprise.
Visual Studio's Availability: Which Editions Are Free?Apr 10, 2025 am 09:44 AMFree versions of VisualStudio include VisualStudioCommunity and VisualStudioCode. 1. VisualStudioCommunity is suitable for individual developers, open source projects and small teams. It is powerful and suitable for individual projects and learning programming. 2. VisualStudioCode is a lightweight code editor that supports multiple programming languages and extensions. It has a fast startup speed and low resource usage, making it suitable for developers who need flexibility and scalability.
How to install Visual Studio for Windows 8?Apr 09, 2025 am 12:19 AMThe steps to install VisualStudio on Windows 8 are as follows: 1. Download the VisualStudioCommunity2019 installation package from the official Microsoft website. 2. Run the installer and select the required components. 3. It can be used after installation is completed. Be careful to select Windows 8-compatible components and make sure there is sufficient disk space and administrator rights.
Can my computer run VS Code?Apr 08, 2025 am 12:16 AMVSCode can run on most modern computers as long as the basic system requirements are met: 1. Operating system: Windows 7 and above, macOS 10.9 and above, Linux; 2. Processor: 1.6GHz or faster; 3. Memory: at least 2GB RAM (4GB or higher recommended); 4. Storage space: at least 200MB of available space. By optimizing settings and reducing extended usage, you can get a smooth user experience on low-configuration computers.
How do I make a program compatible with Windows 8?Apr 07, 2025 am 12:09 AMTo make the program run smoothly on Windows 8, the following steps are required: 1. Use compatibility mode, detect and enable this mode through code. 2. Adjust API calls and select the appropriate API according to the Windows version. 3. Perform performance optimization, try to avoid using compatibility mode, optimize API calls and use general controls.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.






