vscode環境配置(二)——C Program Debug


一、任務准備

  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
    }
}

 

二、配置步驟

  方法一:在程序主目錄下新建.vscode文件夾,在此文件夾下新建任務准備中的launch.json和tasks.json文件,修改launch.json中gdb位置即可。

  方法二:點擊vscode最左邊任務欄中的Debug瓢蟲按鈕或按Ctrl+Shift+D,在跳出的選項框中,進行如下操作      

 

 

   

 

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  查看生成的launch.json文件看gdb.exe文件是否需要修改。然后進行下一步創建task.json操作,操作如下

 

 

   如果沒有C/C++:gcc.exe build active file選項,就選擇Create task.json file from template選項,出現如下頁面

  生成task.json文件后回到C文件頁面再次點擊Debug按鈕,操作如下

  查看是否生成task.json文件。  

  設置斷點后再次點擊Debug按鈕或英文狀態時按Ctrl+Shift+B運行。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM