Rumah > alat pembangunan > VSCode > 如何用vscode进行单步调试

如何用vscode进行单步调试

王林
Lepaskan: 2020-02-12 15:03:44
asal
15313 orang telah melayarinya

如何用vscode进行单步调试

快捷键

Ctrl + `  打开默认终端;
Ctrl + Shift + `  新建新的终端;
Ctrl + Shift + Y  打开调试控制台,然后再自行切换终端选项;
ps: ` 在键盘数字1的左边。
Salin selepas log masuk

安装clang

sudo apt-get install clang
Salin selepas log masuk

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
                }
            ],
        }
    ]
}
Salin selepas log masuk

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 ()
Salin selepas log masuk

5、完成以上步骤后,重新进行编译,然后vscode中的调试一栏下面的就不再是灰色,可以进行单步调试。

f2d369fbed554ef084bfec59417d408.png

相关推荐:vscode教程

Atas ialah kandungan terperinci 如何用vscode进行单步调试. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan