一、VSCode 自帶
新建文件夾 Test -> VSCode 打開 Test -> 新建文件 main.cpp ->?
DEBUG “執行按鈕”右邊“add configuration...” ?選擇 “g++ build and debug” ->?
VSCode 自動生成 tasks.json 和 laugh.json 即可斷點調試
二、makefile 文件
1. VSCode 新建文件?makefile 內容如下:
.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
此時,打開命令行,make,可以生成可執行文件
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", ?// 配置名稱,將會在啟動配置的下拉菜單中顯示
? ? ? ? ? ? "type": "cppdbg",
? ? ? ? ? ? "request": "launch", ?// 請求配置類型,可以為launch(啟動)或attach(附加)
? ? ? ? ? ? "program": "${fileDirname}/main", ?//將要進行調試的程序的路徑,與?makefile 中的 main 一致
? ? ? ? ? ? "args": [],
? ? ? ? ? ? "stopAtEntry": true, ?// 設為true時程序將暫停在程序入口處
? ? ? ? ? ? "cwd": "${workspaceFolder}",
? ? ? ? ? ? "environment": [],
? ? ? ? ? ? "externalConsole": true,?// 調試時是否顯示控制臺窗口,必須為true顯示控制臺,才能輸入,交互
? ? ? ? ? ? "MIMode": "lldb", ?// 指定連接的調試器,可以為gdb或lldb。
? ? ? ? ? ? "preLaunchTask": "shell" ? //調試會話開始前執行的任務,一般為編譯程序。與 tasks.json 的?label 一致
? ? ? ? }
? ? ]
}
點擊 VSCode 執行按鈕即可斷點調試,找到彈出的窗口,即可輸入,交互
注意斷點打到 ?std::cout<<"start"<<std::endl; ?不停留