VSCode uses gcc/g++ of MinGW-w64 to write debugger under windows

VSCode uses gcc/g++ of MinGW-w64 to write debugger under windows

If you want to reproduce it, please indicate the source: http://blog.csdn.net/itas109
QQ Technical Exchange Group: 129518033

Article Directory

Environmental Science:
OS : winows 7 64bit
MinGW-w64 Version : x86_64-8.1.0-release-win32-seh-rt_v6-rev0
VSCode : 1.37( Electron: 4.2.7 Chrome: 69.0.3497.128 Node.js: 10.11.0 V8: 6.9.427.31-electron.0)
VSCode C++ Plugin: C/C++ for Visual Studio Code 0.25.0-insiders: August 8, 2019

Related articles:
Introduction to MinGW-w64
Offline installation of MinGW-w64 under windows

Preface

Why use VSCode to debug C++ programs in Windows?Is there Visual Studio under windows?
This is mainly because Visual Studio is too heavy and cross-platform support is not perfect.

1. Install vs code

Skip

2. Install c++ plug-ins

vs code App Store All C/C++, of which Microsoft published C/C++ for Visual Studio Code

Source code:
https://github.com/microsoft/vscode-cpptools

3. Write test code

Name the file hello.cpp

#include<stdio.h>

int main()
{
    printf("Hello World");
}

4. Configure relevant parameters

4.1 C/C++ Editing Configuration

c_cpp_properties.json can configure header files, compilers, standards, and so on

//c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "D:/mingw64/bin/g++.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

4.2 tasks.json Pre-run Task Configuration

Configuration tasks can automatically compile build.exe

//tasks.json
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "g++", //Consistent with launch.json's preLaunchTask option
            "command": "D:/mingw64/bin/g++.exe",//Specify g++.
            "args": [//Setting compilation parameters
                "-g",
                "${workspaceFolder}/hello.cpp",
                "-o",
                "hello.exe"
            ],
            "options": {
                "cwd": "D:/mingw64/bin"//Specify compilation environment location
            },
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]
}

4.3 lauch.json startup configuration

Configure startup parameters with lauch.json (debug-open configuration)

//lauch.json
{
    // Use IntelliSense to learn about related properties. 
    // Hover to see a description of an existing property.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/hello.exe",//Modify the name of the running exe
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "D:/mingw64/bin/gdb.exe",//Modify gdb path
            "preLaunchTask": "g++", // Tasks performed before the debugging session starts, typically compiler, c++ g+, C G C C
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

4. Step Debugging

Breakpoint, F5 can start debugging

5. Results

I think this article is helpful for you. I can scan the QR code and donate it to the blogger. Thank you.

If you want to reproduce it, please indicate the source: http://blog.csdn.net/itas109
QQ Technical Exchange Group: 129518033

License

License under CC BY-NC-ND 4.0: Signature - Non-commercial Use - No Deduction

Reference:
1.http://www.mingw-w64.org
2.Introduction to MinGW-w64
3.Offline installation of MinGW-w64 under windows

Tags: Programming JSON Windows github shell

Posted on Sat, 17 Aug 2019 17:42:17 -0700 by chuspy