How to Use Vscode Debug

· · 科技·工程

About Vscode Debug:

1.tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "C/C++: g++.exe 生成活动文件",
            "command": "C:\\Program Files (x86)\\Dev-Cpp\\MinGW64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "-std=c++14",
                "-O2",
                "-Wall",
                "a.cpp",
                "-o",
                "D:/work/a.exe"
            ],
            "options": {
                "cwd": "D:/work"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "编译器: C:\\Program Files (x86)\\Dev-Cpp\\MinGW64\\bin\\g++.exe"
        }
    ]
}
//"command"填g++路径
//"args"就是编译选项+要调试的源程序名字+exe位置
//"cwd"填工作文件夹路径

2.launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "D:/work/a.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "D:/work",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/gdb.exe",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe 生成活动文件"
        }



    ]
}
//"externalConsole": true 表示生成额外命令行窗口 填true
//"preLaunchTask": "C/C++: g++.exe 生成活动文件"和tasks.json的"lebel"一致
//"miDebuggerPath"填gdb路径
//"program" 是要调试的exe的路径(最重要)