這篇文章給大家分享的是有關(guān)怎么用vscode進(jìn)行單步調(diào)試的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個參考。一起跟隨小編過來看看吧。
創(chuàng)新互聯(lián)建站主要從事做網(wǎng)站、網(wǎng)站制作、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)汝州,10多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792快捷鍵
Ctrl + ` 打開默認(rèn)終端; Ctrl + Shift + ` 新建新的終端; Ctrl + Shift + Y 打開調(diào)試控制臺,然后再自行切換終端選項(xiàng); ps: ` 在鍵盤數(shù)字1的左邊。
安裝clang
sudo apt-get install clang
VScodeDebug
這里對vscode配置一般情況的cpp調(diào)試做個記錄:
1、整體思路就是首先按照常規(guī)方法進(jìn)行mkdir build && cd build && cmake.. && make (這一步可以在vscode的終端完成,也可以在系統(tǒng)終端完成,無所謂。但是為了少開點(diǎn)界面就在vscode里面完成比較好)生成可執(zhí)行文件,然后使用vscode進(jìn)行單步。
2、配置launch文件:點(diǎn)擊左側(cè)邊欄的Debug圖標(biāo)(Ctrl+Shift+D),再點(diǎn)上方的齒輪圖標(biāo)configure,點(diǎn)擊default configure就能自動生成launch.json文件。進(jìn)入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", //此路徑更改為最終生成的可執(zhí)行文件路徑以及可執(zhí)行文件名稱 "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole":false,//將此處的true改為false,不然他會調(diào)用系統(tǒng)的終端進(jìn)行現(xiàn)實(shí) "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、完成以上步驟后,重新進(jìn)行編譯,然后vscode中的調(diào)試一欄下面的就不再是灰色,可以進(jìn)行單步調(diào)試。
感謝各位的閱讀!關(guān)于怎么用vscode進(jìn)行單步調(diào)試就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!