這篇文章給大家分享的是有關(guān)怎么用vscode進(jìn)行單步調(diào)試的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧。
創(chuàng)新互聯(lián)主要從事成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)沈丘,十多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專(zhuān)業(yè),歡迎來(lái)電咨詢(xún)建站服務(wù):18982081108
快捷鍵
Ctrl + ` 打開(kāi)默認(rèn)終端; Ctrl + Shift + ` 新建新的終端; Ctrl + Shift + Y 打開(kāi)調(diào)試控制臺(tái),然后再自行切換終端選項(xiàng); ps: ` 在鍵盤(pán)數(shù)字1的左邊。
安裝clang
sudo apt-get install clang
VScodeDebug
這里對(duì)vscode配置一般情況的cpp調(diào)試做個(gè)記錄:
1、整體思路就是首先按照常規(guī)方法進(jìn)行mkdir build && cd build && cmake.. && make (這一步可以在vscode的終端完成,也可以在系統(tǒng)終端完成,無(wú)所謂。但是為了少開(kāi)點(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í)行文件名稱(chēng) "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") #添加語(yǔ)句 add_compile_options(-g) #添加語(yǔ)句 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)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
網(wǎng)頁(yè)題目:怎么用vscode進(jìn)行單步調(diào)試
URL標(biāo)題:http://www.rwnh.cn/article14/ghcpde.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、全網(wǎng)營(yíng)銷(xiāo)推廣、域名注冊(cè)、用戶(hù)體驗(yàn)、微信公眾號(hào)、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)