一、VSCode 自帶
新建文件夾 Test -> VSCode 打開 Test -> 新建文件 main.cpp ->?
DEBUG “執(zhí)行按鈕”右邊“add configuration...” ?選擇 “g++ build and debug” ->?
VSCode 自動(dòng)生成 tasks.json 和 laugh.json 即可斷點(diǎn)調(diào)試
二、makefile 文件
1. VSCode 新建文件?makefile 內(nèi)容如下:
.default: all
all: main
main: main.o
????g++ -Wall -Werror -std=c++14 -g -O -o $@ $^
%.o: %.cpp
????g++ -Wall -Werror -std=c++14 -g -O -c $^
clean:
????rm -rf qwirkle *.o *.dSYM
此時(shí)骡技,打開命令行仅父,make现诀,可以生成可執(zhí)行文件
2. task.json 改成如下:
{
? ? "tasks": [
? ? ? ? {
? ? ? ? ? ? "type": "shell",
? ? ? ? ? ? "label": "shell",
? ? ? ? ? ? "command": "/usr/bin/make",
? ? ? ? }
? ? ],
? ? "version": "2.0.0"
}
3. launch.json 改成如下:
{
? ? // Use IntelliSense to learn about possible attributes.
? ? // Hover to view descriptions of existing attributes.
? ? // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
? ? "version": "0.2.0",
? ? "configurations": [
? ? ? ? {
? ? ? ? ? ? "name": "g++ build and debug active file", ?// 配置名稱脸甘,將會(huì)在啟動(dòng)配置的下拉菜單中顯示
? ? ? ? ? ? "type": "cppdbg",
? ? ? ? ? ? "request": "launch", ?// 請(qǐng)求配置類型阶牍,可以為launch(啟動(dòng))或attach(附加)
? ? ? ? ? ? "program": "${fileDirname}/main", ?//將要進(jìn)行調(diào)試的程序的路徑喷面,與?makefile 中的 main 一致
? ? ? ? ? ? "args": [],
? ? ? ? ? ? "stopAtEntry": true, ?// 設(shè)為true時(shí)程序?qū)和T诔绦蛉肟谔?/p>
? ? ? ? ? ? "cwd": "${workspaceFolder}",
? ? ? ? ? ? "environment": [],
? ? ? ? ? ? "externalConsole": true,?// 調(diào)試時(shí)是否顯示控制臺(tái)窗口,必須為true顯示控制臺(tái)走孽,才能輸入惧辈,交互
? ? ? ? ? ? "MIMode": "lldb", ?// 指定連接的調(diào)試器,可以為gdb或lldb磕瓷。
? ? ? ? ? ? "preLaunchTask": "shell" ? //調(diào)試會(huì)話開始前執(zhí)行的任務(wù)盒齿,一般為編譯程序念逞。與 tasks.json 的?label 一致
? ? ? ? }
? ? ]
}
點(diǎn)擊 VSCode 執(zhí)行按鈕即可斷點(diǎn)調(diào)試,找到彈出的窗口边翁,即可輸入翎承,交互
注意斷點(diǎn)打到 ?std::cout<<"start"<<std::endl; ?不停留