小編給大家分享一下vscode怎樣單步調(diào)試,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
創(chuàng)新互聯(lián)公司長(zhǎng)期為數(shù)千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為江華企業(yè)提供專業(yè)的成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè),江華網(wǎng)站改版等技術(shù)服務(wù)。擁有10年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
vscode如何單步調(diào)試?
vscode單步調(diào)試
VScode配置
0.快捷鍵
Ctrl + ` 打開默認(rèn)終端; Ctrl + Shift + ` 新建新的終端; Ctrl + Shift + Y 打開調(diào)試控制臺(tái),然后再自行切換終端選項(xiàng); ps: ` 在鍵盤數(shù)字1的左邊。
相關(guān)推薦:vscode入門教程
1.安裝clang
sudo apt-get install clang
2.VScodeDebug
插件參考鏈接但大型的工程配置還是比較復(fù)雜,很多教程都是針對(duì)單個(gè)cpp文件進(jìn)行配置,這里對(duì)vscode配置一般情況的cpp調(diào)試做個(gè)記錄:
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就能自動(dòng)生成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,不然他會(huì)調(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)試。
如圖:
3.Cmake支持gdb調(diào)試的方法
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) #添加語句
以上是“vscode怎樣單步調(diào)試”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!