First, mission preparation
launch.json
{ "version": "0.2.0", "configurations": [ { "name": "C/C++", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}.exe", //创建可执行文件 "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/gdb.exe", //本机gdb安装位置 "preLaunchTask": "g++", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], }, ] }
tasks.json
{ "version": "2.0.0", "command": "g++", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}.exe" ], "problemMatcher": { "owner": "cpp", "fileLocation": [ "relative", "${workspaceRoot}" ], "pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 } }, "group": { "kind": "build", "isDefault": true } }
Second, the configuration step
Method One: In the main program directory New .vscode folder, this folder under the new task to prepare the launch.json and tasks.json file, modify launch.json in gdb location.
Method 2: Click vscode leftmost taskbar Debug ladybug button or press Ctrl + Shift + D, in the Options box pops up, do the following
Check to see if the file generated launch.json gdb.exe file needs to be modified. Then the next step to create task.json operation, as follows
If there is no C / C ++: gcc.exe build active file option, choose Create task.json file from template option to display the following page
After generating task.json Return to C file page, click Debug button again, as follows
Checks to see if task.json file.
When you click the Debug button or the English state again after setting a breakpoint run press Ctrl + Shift + B.