As described in the Launch Configurations section of the Visual Studio Code documentation:

VS Code keeps debugging configuration information in a launch.json file located in a .vscode folder in your workspace (project root folder) or in your user settings or workspace settings.

To create a launch.json file, click the create a launch.json file link in the Run start view.

As of Visual Studio Code 1.56:

Once that's created, it should now be available under your workspace's .vscode folder.

Answer from Gino Mempin on Stack Overflow
🌐
Visual Studio Code
code.visualstudio.com › docs › debugtest › debugging-configuration
Visual Studio Code debug configuration
4 days ago - VS Code stores debugging configuration information in a launch.json file located in the .vscode folder in your workspace (project root folder), or in your user settings or workspace settings.
🌐
Visual Studio Code
code.visualstudio.com › docs › cpp › launch-json-reference
Configure C/C++ debugging
November 3, 2021 - A launch.json file is used to configure the debugger in Visual Studio Code. Visual Studio Code generates a launch.json (under a .vscode folder in your project) with almost all of the required information.
Discussions

Configuring "tasks.json" and "launch.json" for debugging C++
Got it working, you need to make sure you choose the launch.json configuration template "(gdb) Launch", them you need to set the next three fields, "program", "externalConsole" and "miDebuggerPath" just like I did below: { // 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": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "c:\\MinGW\\bin\\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "Set Disassembly Flavor to Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ] } ] } More on reddit.com
🌐 r/vscode
5
3
April 19, 2024
vscode debugger - Where is the 'launch.json' file in Visual Studio Code? - Stack Overflow
The launch.json file should be inside the .vscode folder, but it is not present there. How can I get this file so that I can modify the configurations? More on stackoverflow.com
🌐 stackoverflow.com
How to create automatic configurations for launch.json?
// Global debug launch configuration. Should be used as an alternative to 'launch.json' that is shared across workspaces. "launch": { "configurations": [], "compounds": [] }, https://code.visualstudio.com/docs/getstarted/settings More on reddit.com
🌐 r/vscode
5
2
March 2, 2024
confused about different types of VSCODE launch.json configs for debugging in Edge with DEVTOOLS
OK - maybe this will help anyone who finds this. Link to compound build scripts in VSCODE here https://code.visualstudio.com/docs/editor/debugging#_compound-launch-configurations if you're familiar with creating launch.json files and clicking 'Add configuration' then (since I am a JS/HTML developer) I use pretty much the same ones all the time. Chrome: attach Chrome: launch Edge: attach Edge: launch Microsoft Edge Tools: attach Microsoft Edge Tools: launch various node.js scripts.... I have the Microsoft Edge Tools plugin installed which is why I have that as a build config option. If you are not familiar it allows you to have an instance of Edge running inside VSCODE, the idea being that you have the browser, the devtools and your code all in the same place. I didn't want the browser to be in the IDE in VSCODE so I was playing around with launches and through adding different options (Edge:launch + Edge Tools:attach + Edge Tools:launch) simply to see what they did and if I liked it the VSCODE launch.json file was clever enough to create two different *compound* build scripts as you can see in my original post. My confusion came from not noticing this had happened auto-magically. I got rid of the build configs I didn't like but I ended up with a nice compound config that does two things - obviously I need to host my HTML using Go Live first so that the debugger can find the hosted page (e.g. " http://localhost:5500 ") it launches Edge on the localhost:5500 address it launches edge devtools *inside* VSCODE and attaches it to the launched browser. For what I am currently working on this is ideal because I can make changes to the indexedDB database I am working on and see it all happening inside VSCODE without having Edge taking up real estate in VSCODE. It looks and feels perfect for what I am working on. If anyone has any questions let me know and I will try and explain what I did if it is not clear. More on reddit.com
🌐 r/vscode
1
2
July 30, 2023
🌐
Reddit
reddit.com › r/vscode › configuring "tasks.json" and "launch.json" for debugging c++
r/vscode on Reddit: Configuring "tasks.json" and "launch.json" for debugging C++
April 19, 2024 -

I'm getting an hard time to put VSCode to debug a very simple program that asks for input, and so far it was mission impossible. The catch here is that it requires an user input, for the hello world simple example I just needed to configure the tasks.json and the VSCode debugger was good to go and stopped on all breakpoints.

The problem come when I tried a simple pow program that asks for two numbers, and for that I need to open a window, otherwise I never get the opportunity to interact with it.

So, I ended up with this configuration were the file tasks.json is known to work just fine with any launch.json created!

For the launch.json configuration, "(Windows) Launch" is able to run, despite of no debugging, but the "(gdb) Bash on Windows Launch" not even that, it simples does nothing! But for the one that runs, the breakpoints end up grayed out, it's truly annoying!

By the way, the compiler is run with the "-g" parameter enabled, I read somewhere that that was a requirement for the debugger.

tasks.json:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\MinGW\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

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": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "console": "externalTerminal",
            "logging": {
            "moduleLoad": false,
            "trace": true
            },
        },
        {
            "name": "(gdb) Bash on Windows Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": true,
            "pipeTransport": {
                "debuggerPath": "/usr/bin/gdb",
                "pipeProgram": "${env:windir}\\system32\\bash.exe",
                "pipeArgs": ["-c"],
                "pipeCwd": ""
            },
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

C++ code:

#include <iostream>
using namespace std;

// Driver Code
int main()
{
    int a, b, pow = 1;

    // Input two numbers
    cout << "Base: ";
    cin >> a;
    cout << "Exponent: ";
    cin >> b;

    // Iterate till b from 1
    for (int i = 1; i <= b; i++) {
        pow = pow * a;
    }

    // Print the value
    cout << "Pow: " << pow << endl;
}
Top answer
1 of 2
2
Got it working, you need to make sure you choose the launch.json configuration template "(gdb) Launch", them you need to set the next three fields, "program", "externalConsole" and "miDebuggerPath" just like I did below: { // 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": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "c:\\MinGW\\bin\\gdb.exe", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "Set Disassembly Flavor to Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ] } ] }
2 of 2
1
Great that you figured it out! I'd recommend you, to look at CMake and the CMakeTools vscode extension. It removes a lot of the painful setup. It adds a bit of painful CMake learning experience though, so use your working setup and try CMake out when you feel like it:) Definetly take a look at CMake when you come to the point where you need to link against 3rd party libraries. On a sidenote: There are good reasons to not use using namespace std; and it is better to not get into the habit of any using namespace declaratives. See r/cpp for a more nuanced view. See here why you might want to use the -g flag with the gcc compiler and want to use a debugger: GCC Manual https://www.learncpp.com/ is highly recommended when you want to dive deeper into c++.
🌐
Nullneuron
gigi.nullneuron.net › home › working with vs code launch configurations
Working with VS Code Launch Configurations - Gigi Labs
February 15, 2023 - Pressing F5 brings up a list of languages for which you can create launch configurations. Another way is to click on the Debug tab on the left, which looks like a play button. You can then click the link to “create a launch.json” file, shown ...
🌐
Visual Studio Code
code.visualstudio.com › docs › csharp › debugger-settings
List of configurable options
November 3, 2021 - The default launch.json template (as of C# extension v1.20.0) for ASP.NET Core projects uses the following to configure VS Code to launch a web browser when ASP.NET starts:
🌐
Devsense
docs.devsense.com › vscode › debug › launch-json
Launch Profiles - PHP Tools for Visual Studio - Documentation
Visual Studio Code stores launching configurations in a launch.json file located in a .vscode subfolder of a workspace (the project root folder).
Find elsewhere
🌐
Visual Studio Code
code.visualstudio.com › Search
Visual Studio Code documentation search
November 3, 2021 - Learn how to create and use a launch.json file to specify the debugger configuration for complex debugging scenarios or applications in VS Code. See examples, tips, and attributes for launch and attach modes.
🌐
Reddit
reddit.com › r/vscode › how to create automatic configurations for launch.json?
r/vscode on Reddit: How to create automatic configurations for launch.json?
March 2, 2024 -

I've been searching around for a few hours now and haven't found a solution, just posts for creating a launch.json in general.

When I go to create a launch.json, I'm either give a launch that's automatically populated, or I'm presented with an option to populate configurations automatically for whichever language I want to use. With C++ for example, this means that it fills out name, type, program, args, etc and generates the configurations for my launch.json.

I've created a launch.json that I want to use as a template in the future, rather than having to manually change these automatic configurations. I also want to avoid copying over launch.json from other projects. I essentially want to configure vscode so that if I create a launch.json, I can automatically populate it with my own template of parameters for configurations.

I hope this makes sense. I figure that settings.json might be the place to do so, but it seems like it just has a global default that gets used. I'm trying to find where all of the different templates for launch.json are stored. I'm not sure if they're stored, or if they're some how magically generated based off of some criteria, or if they come from language extensions themselves.

If anyone has any insight into this, I would deeply appreciate it. Thanks.

Edit: I believe this is the right answer: User Defined Snippets

Thanks u/_d_end

🌐
Reddit
reddit.com › r/vscode › confused about different types of vscode launch.json configs for debugging in edge with devtools
r/vscode on Reddit: confused about different types of VSCODE launch.json configs for debugging in Edge with DEVTOOLS
July 30, 2023 -

I was playing with creating VSCODE launch.json configurations for running Microsoft Edge with integrated devtools showing in VSCODE.

I ended up with two different launch configurations after doing the following:

  • at the start there is no launch.json

  • I click on the debugger and it offers me the opportunity to create a launch.json and selected 'Microsoft Dev Tools' and a config was added to the newly created launch.json file.

  • then inside the launch.json I can "Add configuration" and choose "Microsoft Devtools : launch" and a second config gets added.

Both configs need a fix so that it runs the page running on http://localhost:5500 (I change the url setting to do this).

I end up with two 'compound' configurations called 'Launch Edge Headless and attach DevTools' (which I shall call 'headless') and one called 'Launch Edge and attach DevTools' (which I shall call 'external' because it launches an external browser).

I will past the launch.json.config with the two configs below.

can anyone explain why the external config is only available when you choose "create launch file" from the debugger panel and no launch.json exists and not available when you click the "Add configuration" button from inside the launch.json file?

thanks in advance

{
  // 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": [
    {
      "type": "pwa-msedge",
      "name": "Launch Microsoft Edge",
      "request": "launch",
      "runtimeArgs": ["--remote-debugging-port=9222"],
      "url": "http://localhost:5500", // Provide your project's url to finish configuring
      "presentation": {
        "hidden": true
      }
    },
    {
      "type": "pwa-msedge",
      "name": "Launch Microsoft Edge in headless mode",
      "request": "launch",
      "runtimeArgs": ["--headless", "--remote-debugging-port=9222"],
      "url": "http://localhost:5500", // Provide your project's url to finish configuring
      "presentation": {
        "hidden": true
      }
    },
    {
      "type": "vscode-edge-devtools.debug",
      "name": "Open Edge DevTools",
      "request": "attach",
      "url": "http://localhost:5500", // Provide your project's url to finish configuring
      "presentation": {
        "hidden": true
      }
    }
  ],
  "compounds": [
    {
      "name": "Launch Edge Headless and attach DevTools",
      "configurations": [
        "Launch Microsoft Edge in headless mode",
        "Open Edge DevTools"
      ]
    },
    {
      "name": "Launch Edge and attach DevTools",
      "configurations": ["Launch Microsoft Edge", "Open Edge DevTools"]
    }
  ]
}

Top answer
1 of 1
1
OK - maybe this will help anyone who finds this. Link to compound build scripts in VSCODE here https://code.visualstudio.com/docs/editor/debugging#_compound-launch-configurations if you're familiar with creating launch.json files and clicking 'Add configuration' then (since I am a JS/HTML developer) I use pretty much the same ones all the time. Chrome: attach Chrome: launch Edge: attach Edge: launch Microsoft Edge Tools: attach Microsoft Edge Tools: launch various node.js scripts.... I have the Microsoft Edge Tools plugin installed which is why I have that as a build config option. If you are not familiar it allows you to have an instance of Edge running inside VSCODE, the idea being that you have the browser, the devtools and your code all in the same place. I didn't want the browser to be in the IDE in VSCODE so I was playing around with launches and through adding different options (Edge:launch + Edge Tools:attach + Edge Tools:launch) simply to see what they did and if I liked it the VSCODE launch.json file was clever enough to create two different *compound* build scripts as you can see in my original post. My confusion came from not noticing this had happened auto-magically. I got rid of the build configs I didn't like but I ended up with a nice compound config that does two things - obviously I need to host my HTML using Go Live first so that the debugger can find the hosted page (e.g. " http://localhost:5500 ") it launches Edge on the localhost:5500 address it launches edge devtools *inside* VSCODE and attaches it to the launched browser. For what I am currently working on this is ideal because I can make changes to the indexedDB database I am working on and see it all happening inside VSCODE without having Edge taking up real estate in VSCODE. It looks and feels perfect for what I am working on. If anyone has any questions let me know and I will try and explain what I did if it is not clear.
🌐
GitHub
github.com › microsoft › vscode › blob › main › .vscode › launch.json
vscode/.vscode/launch.json at main · microsoft/vscode
"configurations": [ "Launch VS Code Internal", "Attach to Main Process", "Attach to Extension Host", "Attach to Shared Process", ], "preLaunchTask": "Ensure Prelaunch Dependencies", "presentation": { "group": "0_vscode", "order": 1 ·
Author   microsoft
🌐
Read the Docs
vscode-docs.readthedocs.io › en › latest › editor › debugging
Debugging - vscode-docs
Click on the Configure gear icon on the Debug view top bar, choose your debug environment and VS Code will generate a launch.json file under your workspace's .vscode folder.
🌐
Visual Studio Code
code.visualstudio.com › docs › python › debugging
Python debugging in VS Code
November 3, 2021 - A configuration drives VS Code's behavior during a debugging session. Configurations are defined in a launch.json file that's stored in a .vscode folder in your workspace.
🌐
Alphr
alphr.com › home › how to open launch.json in vs code
How to Open launch.json in VS Code
May 26, 2023 - Set the “type” property to “python” in a new launch.json file. Configure the “request” property as “launch” or “attach.”
🌐
GitHub
github.com › solidjs › solid-start › discussions › 1567
VS Code debugger's `launch.json` configuration · solidjs/solid-start · Discussion #1567
{ "version": "0.2.0", "configurations": [ { "name": "Launch Solid-App", "request": "launch", "runtimeExecutable": "npm", "runtimeArgs": ["run", "dev"], "cwd": "${workspaceFolder}/src", "type": "node" } ] }
Author   solidjs
Top answer
1 of 1
11

I've recently had the same issues. Here is the procedure that I follow, that seem to work:

Download and install msys2 (1)

Download MSYS2 from https://www.msys2.org/

Install folder is typically C:\msys64

Go to C:\msys64 and open mingw64.ini

Change ‘#MSYS2_PATH_TYPE=inherit’ to ‘MSYS2_PATH_TYPE=inherit’ i.e. enable PATH variable.

Add PATH environment variables (2)

Type “environment” in Windows search field, and select “Edit environment variables …”

Add path to gcc.exe and g++.exe: — Add: “C:\msys64\mingw64\bin” to PATH variable.

Add path to VS Code to PATH variable as well: — This is usually the folder:

C:\Users\<username>\AppData\Local\Programs\Microsoft VS Code\

Run “msys2 mingw64” and test access to compilers and debugger (3)

In Windows Search field, type “msys2” and select “msys2 mingw64” and run the following:

To install gcc, the Gnu C compiler: pacman -S mingw-w64-ucrt-x86_64-gcc

To install gdb, the Gnu GDB debugger:

pacman -S --needed base-devel mingw-w64-x86_64-toolchain

To test that you can run compilers and debugger, run:

gcc --version
g++ --version
gdb --version

Start development in VSC (4)

Open “msys mingw64” terminal and run:

cd <common projects folder> 
mkdir <projname> 
cd <projname> 

Above changes current directory to a projects folder. I use C:\Users<username>\src\projects, i.e. this is my but you may want to use something else.

In the folder you can make a subfolder per C coding project you want to run. This is what “mkdir ” does.

You will need a little Unix Bash shell command skills here, here is an ultrashort summary:

  • cd – change directory to mkdir – makes a new directory called
  • in the current folder.
  • cd .. – change directory one up. _ cd ~ – changes directory to your home folder, I have C:\Users<username> where is my … username.
  • pwd – shows current directory.

Now, if you did above you are currently in the specific projects folder (you can verify this with pwd), and you should start VSC from there by typing:

code .

And accept Workspace trust.

Create a C source file (5)

Open folder view, click on + icon, and select ‘new file’, type “hello.c”, go into the file and add the contents:

include
int main() {
   printf("Hello World\n");
   return 0;
}

Configure VSC for building – tasks.json (6)

Press “ctrl+shift+B” to build target (or menu: -> Terminal -> Run Build Task… or press green play icon)

Select “C/C++: gcc.exe build and debug active file”

Now it tries to build, using an autogenerated tasks.json file, located in project-folder, in subfolder .vscode:

.vscode/tasks.json

An example of a tasks.json file is shown below:

  "tasks": [
  {
    "type": "cppbuild",
    "label": "C/C++: gcc.exe build active file", 
    "command": "C:\apps\msys64\mingw64\bin\gcc.exe",
    "args": [
      "-fdiagnostics-color=always",
      "-Wall",
      "-g",
      "${file}", 
      "-o",
      "${fileDirname}\${fileBasenameNoExtension}.exe"
    ],
  "options": {
  "cwd": "${fileDirname}"
  },
  "problemMatcher": [
    "$gcc"
  ],
  "group": {
    "kind": "build",
    "isDefault": true
    },
      "detail": "Task generated by Debugger."
    }
  ],
  "version": "2.0.0"
}

The important section is:

"command": "C:\msys64\mingw64\bin\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-Wall",
"-g",
"${workspaceFolder}/*.c", OR TODO "${file}"
"-o",
"${fileDirname}\${fileBasenameNoExtension}.exe"
],
  • “command” is the Gnu C compiler, gcc.exe and the full path to it.
  • “args” are arguments for the compiler:
  • -Wall means warn about everyting.
  • -g means compiler must prepare for debugging.
  • “${file}” is current file.
  • -o is output file which is specified in the next line with .exe extension.

Sometimes we have to build multi-file projects and it will break the default build-functionality in tasks.json in VSC. In some cases this can be solved by changing:

${file},

to

"${workspaceFolder}/*.c",

Configure VSC for Debugging – launch.json (7)

Go to source file hello.c, and set a break point, Click left to the line numbers to set red circle. Select play/bug icon Select “Debug C/C++ File” Choose “C/C++ gcc build and debug active file” from list of automatically detected compilers.

This will autogenerate a file, launch.json in the projects folder, in subfolder .vscode:

.vscode/launch.json

An example of a launch.json file is shown below:

{
  "configurations": [
  {
    "name": "C/C++: gcc.exe build and debug active file",
    "type": "cppdbg",
    "request": "launch",
    "program": "${fileDirname}\${fileBasenameNoExtension}.exe",
    "args": [],
    "stopAtEntry": false,
    "cwd": "${fileDirname}",
    "environment": [],
    "externalConsole": false,
    "MIMode": "gdb",
  "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
  "setupCommands": [
  {
    "description": "Enable pretty-printing for gdb",
    "text": "-enable-pretty-printing",
    "ignoreFailures": true
  },
 ]
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}

The most important parts are:

"program": "${fileDirname}\${fileBasenameNoExtension}.exe", 

and

"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",

The “program” is the program generated when building the project. I.e. the output from running the task as specified in Tasks.json.

The miDebuggerPath is the path to gdb, the GNU gdb debugger.

If these does not match with your Tasks.json settings and your installation chances are slim to make it work.

Test it by pressing the Play/Bug icon button and notice if there are errors. If not you should be able to step through the code and watch variables etc.

Configure VSC for intellisense (8)

Install extension: “C/C++ extension for VS Code” by Microsoft.

Now this extension will assist when you type code. By example you can type for to get the basics of a for-loop. Similar for if, while etc. Cool!

Save work when creating new projects (9)

Instead of having to create the tasks.json and launch.json files for each project, I copy them to a templates folder, say:

C:\Users\username\src\templates\.vscode\ 

Copy the newly created tasks.json and launch.json files to the .vscode subfolder.

Now, say you want to create a new project, e.g. hello2, and you create a folder for it:

C:\Users\<username>\src\projects\hello2\ 

Go to the templates folder by

cd C:\Users<username>\src\templates and copy the .json files to the new project by:

cp -Rp .vscode/ ../hello2/

And now the new project has the .json files.

Optional (10)

Later you may want to update msys2. To do this, open “msys2 mingw64” and type

pacman -Suy

Done (11)

Finally done … Not the easiest thing to get going, but I still think it is worth it.

🌐
Readthedocs
vscode-docs-arc.readthedocs.io › en › latest › cpp › launch-json-reference
Configuring C/C++ debugging - vscode-docs-arc
Visual Studio Code generates a launch.json with almost all of the required information. To get started with debugging you need to fill in the program field with the path to the executable you plan to debug. This must be specified for both the launch and attach (if you plan to attach to a running instance at any point) configurations...