Configure launch.json for C/C++ debugging in Visual Studio Code (2023)

Alaunch.jsonThe file is used to convert theWashing machineno Visual Studio code.

Visual Studio Code genera unlaunch.json(low.vscodefolder in your project) with almost all the information you need. To begin debugging, you must complete theprogramField with the path to the executable that you want to debug. This must be specified for the startup and connection configuration (if you intend to connect to a running instance at any time).

The generated file contains two sections, one that configures startup debugging and a second that configures attachment debugging.

Configure VS Code debugging behavior

Set or change the following options to control the debugging behavior of VS Code:

Program (mandatory)

Specifies the full path to the executable that launches or attaches the debugger. The debugger needs this location to load debugging symbols.


Tells the Visual Studio Windows Debugger which paths to look for symbol (.pdb) files. Separate multiple paths with a semicolon. For example:"C:\\Symbol;C:\\SymbolDir2".


An optional flag that tells the Visual Studio Windows debugger that the current source code should match the pdb.

SOLibSearchPath adicional

Tells GDB or LLDB which paths to look for .so files. Separate multiple paths with a semicolon. For example:"/users/users/directory1;/users/users/directory2".

external console

It is only used when starting debugging. Forattach, this parameter does not change the behavior of the debugger.

  • Ventana: If set to true, an external console is created. If set to false, the VS Code IntegratedTerminal is used.
  • linux: If set to true, VS Code will be notified to generate an external console. If set to false, the VS Code IntegratedTerminal is used.
  • MacOS: if set to true, an external console will be generated vialldb-mi. When set to false, the output can be seen in the VS Code debug console. Due to restrictions withinlldb-mi, built-in terminal support is not available.

Avoid Windows Console Redirection

To support VS Code's built-in terminal with gdb on Windows, the extension adds console redirection commands to the debugger arguments so that console input and output appear in the built-in terminal. Set this option toTRUEwill disable it.

(Video) Debug a C++ project in VS Code


Optional flags to specify what types of messages should be logged in the debugging console.

  • exceptions: Optional flag to determine if exception messages should be logged in the debugging console. The defect is true.
  • load module: Optional flag to determine if module load events should be logged in the debug console. The defect is true.
  • program exit: Optional flag to specify whether to log program output to the debugging console. The defect is true.
  • engine log: Optional flag to determine if diagnostic engine logs should be logged to the debugging console. The default is false.
  • look for: Optional flag to determine whether to log the diagnostic adapter command trace to the debug console. The default is false.
  • TraceResponse: Optional flag to determine whether to log the diagnostic adapter command and trace the response to the debug console. The default is false.

file viewer

.EveningFile to use when debugging. To seeCreate custom views of native objectsInformation about creating Natvis files.


Yes, onefile viewerfixed,showDisplayStringactivates the display chain. Enabling this option may result in slower performance while debugging.


{ "Name":"Start C++ (Windows)", "Type":"cppvsdbg", "Consultation":"to throw", "Program":"C:\\application1\\debugging\\app1.exe", "símboloSearchPath":"C:\\Symbol; VS:\\SymbolDir2", "external console":TRUE, "log in": { "module load":INCORRECT, "look for":TRUE}, "fileviewer":"${workspace folder}/my.natvis", "show display string":TRUE}

Configure the target application

You can use the following options to change the state of the target application at startup:


JSON array of command line arguments passed to the program at program startup. Example["arg1", "arg2"]. When escaping from the characters, you have to escape from them twice. For example,["{\\\"arg1\\\": true}"]send to{"arg1": true}to your application.


Defines the working directory of the application launched by the debugger.


Environment variables to be added to the program's environment. Example:[ { "name": "config", "value": "Debug" } ], NO[ { "config": "Debugging" } ].


{ "Name":"C++-Home", "Type":"cppdbg", "Consultation":"to throw", "Program":"${workspace folder}/a.out", "arg": ["arg1","arg2"], "Surroundings": [{"Name":"Ideas","Courage":"Debug"}], "cwd":"${workbook}"}

Personaliza GDB o LLDB

You can change the behavior of GDB or LLDB by setting the following options:

IM mode

Specifies the debugger that VS Code connects to. Must be defined asgdbolldb. This is preconfigured for each operating system and can be changed if necessary.


The path to the debugger (for example, gdb). If only the executable is specified, the operating system PATH variable is searched for a debugger (GDB on Linux and Windows, LLDB on OS X).

(Video) Debugging C/C++ with Visual Studio Code


Additional arguments to pass to the debugger (for example, gdb).

stop at the entrance

If set to true, the debugger should stop at the target entry point (skipped on attach). The default isINCORRECT.


If set to true, the debugger should stop after connecting to the target. If the value is false, the debugger continues after the connection. The default isINCORRECT.

configuration commands

JSON array of commands to execute to configure GDB or LLDB. Example:"setupCommands": [ { "texto": "target-run", "description": "run target", "ignoreFailures": false }].


If specified, replaces the default commands used to start a target with other commands. For example, it could be "-target-attach" to attach to a target process. An empty command list replaces startup commands with nothing, which can be useful when the debugger is given startup options as command line options. Example:"customLaunchSetupCommands": [ { "texto": "target-run", "description": "run target", "ignoreFailures": false }].


The command to run after the debugger is fully configured to cause the target process to run. Allowed values ​​are "exec-run", "exec-continue", "None". The default is "exec-run".


{ "Name":"C++-Home", "Type":"cppdbg", "Consultation":"to throw", "Program":"${workspace folder}/a.out", "stop at the entrance":INCORRECT, "comandos customLaunchSetup": [{"Text":"finish running","Description":"run target","Ignore errors":INCORRECT}], "LaunchCommandComplete":"executive-execute", "linux": { "IM mode":"gdb", "miDebuggerPfad":"/usr/bin/gdb"}, "osx": { "IM mode":"lldb"}, "Ventana": { "IM mode":"gdb", "miDebuggerPfad":"C:\\MinGw\\container\\gdb.exe"}}


  • load all: If true, symbols from all libraries will be loaded; otherwise the solib symbols will not be loaded. Modified from the exception list. The defect is true.
  • exception list: List of file names (wildcards allowed), separated by semicolons;. Change the behavior of LoadAll. If LoadAll is true, symbols are not loaded for libraries matching any name in the list. Otherwise, only load symbols for matching libraries. Example:";"

Debug dump files

The C/C++ extension allows you to debug Windows dump files and Linux and OS X kernel dump files.


If you want to debug a Windows dump file, set this as the path to the dump file to start throwideas


Full path to a main debug dump file for the given program. Set this as the path to the main dump file to start debuggingto throwideasNote: MinGw does not support debugging crash dumps.

Remote debugging or debugging with a local debugger server


Network address of the debugger server (eg gdbserver) to connect to for remote debugging (example:Venue Host: 1234).


Full path to debug the server to get started.

(Video) How to set up Visual Studio Code for Executing and Debugging C Programs | Tutorial


Arguments to the debugger server.

server started

Server-initiated pattern to search the debug server output. Regular expressions are supported.


If set to true, search forstandard outletstream for the server-initiated pattern and stdout logging for debug output. The default isTRUE.


If set to true, search forstandardstream for the server-initiated pattern and stderr log for debug output. The default isINCORRECT.


The time in milliseconds that the debugger has to wait for the debugServer to start. The default is 10000.

pipeline transportation

For information on how to attach to a remote process, debug a process in a Docker container, see thepipeline transportationItem configuration.

Hardware breakpoints

If specified, this explicitly controls the behavior of the hardware breakpoint for remote targets. Yeahdemandis set to true, always use hardware breakpoints. The default isINCORRECT.Shouldis an optional limit on the number of available hardware breakpoints, which applies only ifdemandit's the truthShouldis greater than 0. The default is 0. Example:"hardwareBreakpoints": {requires: true, threshold: 6}.

additional properties

process identification

The default is${command:pickProcess}This displays a list of processes available for the debugger to attach. We recommend keeping this default value, but the property can be explicitly set to a specific process ID that the debugger can attach.


Indicates if the configuration section is intended for thisto throwthe program orattachto an instance that is already running.

green architecture

disruptedThis option is no longer required as the target architecture is automatically detected.


Specifies the underlying debugger used. we should becppvsdbgwhen using the Visual Studio Windows Debugger andcppdbgwhen using GDB or LLDB. This automatically adjusts to the correct value when thelaunch.jsonthe file is created.


This allows the mapping of source compile-time paths to local source locations. It is a key/value pair object and resolves to the first path that matches the string. (Example:"sourceFileMap": { "/mnt/c": "c:\\" }Matches any path returned by the debugger that begins with/mnt/cand convert it toC:\\. You can have multiple associations for the object, but they will be discussed in the order presented.)

(Video) How to set up Visual Studio Code for Executing and Debugging C++ Programs | Tutorial for Beginners

Environment Variables Definition File

An environment variable definition file is a plain text file that contains key-value pairs in the form ofenvironment variable=valuecom#used for comments. Multi-line values ​​are not supported.

ocppvsdbgThe debugger configuration also includes aenvFileproperty that allows you to easily define variables for debugging purposes.

For example:


# project.env# Sample environment with key as "MYENVRIONMENTPATH" and value as C:\\Users\\USERNAME\\ProjectENVIRONMENT MIRUTA=C:\\user\\USERNAME\\Project# Variables with spacesSPACED_OUT_PATH="C:\\has spaces\\Project"

icon options

oicon optionsThe element allows customization of how the debugger searches for symbols. Example:

 "Icon Options": { "find ways": [ "C:\\Origen\\MeuOutroProjeto\\container\\debug", "https://my-companies-symbols-server"], "findMicrosoftSymbolServer":TRUE, "cachePfad":"%TEMPERATURE%\\token cache", "ModulFilter": { "Far":"loadAllButExcluded", "Deleted Modules": ["NoBuscarEste*.dll"]}}


search paths: Array of symbol server URLs (example: or directories (example: /build/symbols) to search for .pdb files. These directories are searched in addition to the default locations, as well as the module and path where the PDB was originally placed.

searchMicrosoftSymbolServer: SeTRUEThe Microsoft Symbol Server ( is added to the symbol search path. If not specified, this option is enabled by defaultINCORRECT.

cachePath": directory in which to cache symbols downloaded from symbol servers. If not specified, the debugger defaults to %TEMP%\SymbolCache..

modulefilter.mode: This value is"loadAllButExcluded"o"loadOnlyIncluded". em"loadAllButExcluded"mode, the debugger loads symbols for all modules unless the module is in the excluded-modules array. In"loadOnlyIncluded"mode, the debugger does not attempt to load symbols for any modules unless they are in the addedModules array or included via the includeSymbolsNextToModules setting.

properties for"loadAllButExcluded"Far

moduleFilter.excludedModule: array of modules for which the debugger should NOT load symbols. Wildcards are supported (example: MyCompany.*.dll).

properties for"loadOnlyIncluded"Far

moduleFilter.includedModule: array of modules for which the debugger should load symbols. Wildcards are supported (example: MyCompany.*.dll).

moduleFilter.includeSymbolsNextToModules: If true, for any modules NOT included in the included modules array, the debugger will still check along with the module itself and the startup executable, but will not check the paths in the symbol lookup list. This option is set to true by default.

(Video) How to debug c program in visual studio code



How do I Debug C++ code in Visual Studio? ›

Start the debugger!
  1. Press F5 (Debug > Start Debugging) or the Start Debugging button. in the Debug Toolbar. ...
  2. Stop the debugger by pressing the red stop. button (Shift + F5).
  3. In the console window, press a key and Enter to close the console window.
Aug 22, 2022

How do you Debug C code in Visual code? ›

To do that, open C++ file in VSCode and either hit F5 or go to Debug -> Start Debugging and select C++ (GDB/LLDB) then select g++.exe build and debug active file .

How do I add Debug configuration in VS Code? ›

Switch to the Run and Debug view (Ctrl+Shift+D) and select the create a launch. json file link. VS Code will let you select an "debugger" in order to create a default launch configuration.

How to configure launch json in Visual Studio Code? ›

To create a launch.json file, click the create a launch.json file link in the Run start view. If you go back to the File Explorer view (Ctrl+Shift+E), you'll see that VS Code has created a .vscode folder and added the launch.json file to your workspace.

Where is the launch JSON file in VSCode? ›

The launch. json file is located in a . vscode folder in your workspace (project root folder).

How do I enable debugging in C++? ›

It is the most basic feature in debugging. To set the breakpoint, click in the gutter to the left of the doWork function call (or select the line of code and press F9). Now press F5 (or choose Debug > Start Debugging).

What is the difference between tasks json and launch json in Vscode? ›

To use a configuration from launch. json , you select it on the Debug panel and click the run button. tasks. json is used to execute anything else you may want, be that source code formatters, bundlers or a SASS compiler.

What is debugging in C++ with example? ›

Example: sample C++ program for debugging

If one of the operators (+ - * ⁄) is read, the top two elements are popped off the stack, the operation is performed on them, and the result is pushed on the stack. The = operator writes out the value of the top element of the stack to a buffer.

How do I debug a configuration in Visual Studio? ›

To set Visual Studio debugger options, select Tools > Options, and under Debugging select or deselect the boxes next to the General options. You can restore all default settings with Tools > Import and Export Settings > Reset all settings.

How do I access launch json? ›

Select Activity Bar > Microsoft Edge Tools > click the Generate launch. json button. In Activity Bar > Explorer, double-click index. html to open it.

What is a launch json file in vscode? ›

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.

What is launch setting json? ›

What is launchSettings. json launchSettings. json, which is placed in the Properties folder of a project, describes how the application can be launched — the command to execute, whether the browser should be opened, which environment variables should be set, and so on.

How do I add a json file to Visual Studio? ›

Open the text editor, for example, Visual Studio Code, etc. Create a new file and add the data to it.
  1. Create a JSON file, add data in that JSON file.
  2. Using JavaScript fetch the created JSON file using the fetch() method.
  3. Display the data on the console or in the window.
Feb 16, 2022

Where is launchSettings json visual studio? ›

In the Properties folder in an ASP.NET Core project, you can find the launchSettings. json file, which contains settings that control how your web app is started on your development machine. For detailed information on how this file is used in ASP.NET development, see Use multiple environments in ASP.NET Core.

How do I debug a C++ file? ›

Debugging a C++ Example Application
  1. Click in between the line number and the window border on the line where we change the cursor position to set a breakpoint.
  2. Select Debug > Start Debugging > Start Debugging of Startup Project or press F5.
  3. To view information about the breakpoint, go to the Breakpoints view.

What are the debugging tools for C++? ›

Debugging tools
  • GDB: This is an open source CLI debugger.
  • Valgrind: This is an open source CLI, good for memory leaks, deadlocks, racing detection, and so on.
  • Affinic debugger: This is a commercial GUI tool for GDB.
  • GNU DDD: This is an open source graphical debugger for GDB, DBX, JDB, XDB, and so on.

What is debugging in C and C++? ›

Debugging is a methodical process of finding and reducing the number of bugs (or defects) in a computer program, thus making it behave as originally expected. There are two main types of errors that need debugging: ▶ Compile-time: These occur due to misuse of language constructs, such as syntax errors.

How do I get json tasks in VS Code? ›

5 Answers
  1. Open a folder with vscode.
  2. Hit F1.
  3. Select "Tasks: Configure Task"
  4. Hit Enter and vscode will create a sample tasks.json for you.

How do I open a large json file in VS Code? ›

  1. open a "big" json file (30000 lines in my case)
  2. Format the file with vs code (alt+shift+f)
  3. VS Code add a closing char at the end ("}" if object, "]" if list)
Mar 3, 2020

What are the steps in the debugging process? ›

The basic steps in debugging are:
  • Recognize that a bug exists.
  • Isolate the source of the bug.
  • Identify the cause of the bug.
  • Determine a fix for the bug.
  • Apply the fix and test it.

What are the different types of debugging in C? ›

There are two types of debugging techniques: reactive debugging and preemptive debugging. Most debugging is reactive—a defect is reported in the application or an error occurs, and the developer tries to find the root cause of the error to fix it.

What are debugging techniques? ›

Debugging Techniques in Embedded Systems

There are 6 debugging techniques in an embedded system. Simplify the complex data. Divide and conquer. Slow down the process. Change only one variable at a time.

What is the best way to Debug code? ›

What is Debugging? How to Debug Your Code for Beginners
  1. Pay Attention to Error Messages.
  2. Google Things.
  3. Explain Your Logic to Another Person or a Duck.
  4. Narrow Down Your Problem and Understand Where the Error is Generated.
  5. Take a Break and Think about Something Else.
  6. Look for Help.
  7. Make Sure the Bug is Dead.
  8. Write Clean Code.
Mar 16, 2022

How do I Debug an entire solution in Visual Studio? ›

To start debugging a project from Solution Explorer without making it the startup project, right-click the project and select Debug > Start new instance or Step into new instance.

What is the difference between Debug and release configuration in Visual Studio? ›

A Debug configuration supports the debugging of an app, and a Release configuration builds a version of the app that can be deployed.

How do I run a configuration in Visual Studio? ›

Open the Configuration Manager dialog box. In the Active solution configuration drop-down list, select the configuration you want. In the Project contexts pane, for every project, select the Configuration and Platform you want, and select whether to Build it and whether to Deploy it.

What is a run debug configuration? ›

IntelliJ IDEA uses run/debug configurations to run, debug, and test your code. Each configuration is a named set of startup properties that define what to execute and what parameters and environment should be used.

How do I add a config in Visual Studio? ›

To add an application configuration file to a C# project
  1. In Solution Explorer, right-click the project node, and then select Add > New Item. The Add New Item dialog box appears.
  2. Expand Installed > Visual C# Items.
  3. In the middle pane, select the Application Configuration File template.
  4. Select the Add button.
Jan 17, 2023

How do I configure json? ›

Press Ctrl + Shift + P on Windows or... Type settings. json into command palette and press Enter.

How do I edit json config? ›

You can modify the config.
Customizing the config. json file
  1. In the Project Explorer view, expand the plug-in project node.
  2. Expand the plugin folder node.
  3. Double-click the config. json file, or right-click the file and select Open with > PDK JSON Editor. ...
  4. Click the Configuration tab to update the config. json file.

How do I enable debugging in Visual Studio? ›

In the Visual Studio toolbar, make sure the configuration is set to Debug. To start debugging, select the profile name in the toolbar, such as <project profile name>, IIS Express, or <IIS profile name> in the toolbar, select Start Debugging from the Debug menu, or press F5.

How do you debug C++ errors? ›

To determine where your error occurs, run your program in debug mode (set a breakpoint by clicking next to the line number; a red stopsign will appear). This will cause your program to pause execution on the marked line. You can then step to the next line (F7) or continue to the next breakpoint (shift+F7).

How do I run C++ code in Terminal Visual Studio? ›

Simply open VS Code/VS Code Insiders, open any folder, and create any file with the extension . c for the C file and . cpp for the C++ file. After writing your code, you can run the code directly using the play button you'll find in the upper right corner.

What are the 4 steps to debugging a code? ›

Isolate the source of the bug. Identify the cause of the bug. Determine a fix for the bug. Apply the fix and test it.

What are the 5 different methods for debugging? ›

What Is Debugging?
  • Ask Yourself the Right Questions. Start the debugging process by defining the problem and asking yourself questions about it. ...
  • Pay Attention to Error Messages. ...
  • Leverage a Debugger. ...
  • Log Everything. ...
  • Localize the Problem. ...
  • Try to Replicate the Problem. ...
  • Turn to the Community. ...
  • Test, Test, and Test Again.

What are the 7 debug steps? ›

7 Steps to Debug Efficiently and Effectively
  • 1) Always Reproduce the Bug Before You Start Changing Code.
  • 2) Understand Stack Traces.
  • 3) Write a Test Case that Reproduces the Bug.
  • 4) Know Your Error Codes.
  • 5) Google! Bing! Duck! Duck! Go!
  • 6) Pair Program Your Way Out of It.
  • 7) Celebrate Your Fix.
Sep 11, 2015

Why can't I debug in Visual Studio? ›

Go to Tools->Options->Debugging->General and see if the option "Use Managed compatibility mode" is selected. If it is, uncheck it and try again.

Why is my debugger not working in VS Code? ›

Debugger not working

Look at the debugger console for any error messages displayed. Look at the Debugger Tools console output for any errors. Remember to re-start VS Code once done (this won't be necessary in a future release). Solution: Clear all expressions from the debugger Watch window and start debugging again.

What are the hardest errors to find when debugging? ›

Logic Errors

Logic errors can be the hardest to track down. Everything looks like it is working; you have just programmed the computer to do the wrong thing.

What are the three types of errors in C++? ›

In a similar way the errors are classified as below: Syntax Errors. Runtime Errors. Logical Errors.

What are the two types of errors in C++? ›

Errors in C/C++
  • Syntax Error.
  • Run-Time Error.
  • Linker Error.
  • Logical Error.
  • Semantic Error.
Dec 3, 2021

How to use terminal in Visual Studio Code? ›

To open the terminal: Use the Ctrl+` keyboard shortcut to toggle the terminal panel. Use the Ctrl+Shift+` keyboard shortcut to create a new terminal.
Copy & paste
  1. Linux: Ctrl+Shift+C and Ctrl+Shift+V; selection paste is available with Shift+Insert.
  2. macOS: Cmd+C and Cmd+V.
  3. Windows: Ctrl+C and Ctrl+V.

How do I run code directly in terminal VS Code? ›

Once your terminal is open, you can open VS Code from it by typing $ code . Then hit enter . Once you hit enter , VS Code will now open.


1. How to Debug C/C++ with Visual Studio Code 2021 | Windows
(Shubham jha)
2. Launch.json Visual Studio Code Error - How to CORRECT It
(Junior Coder)
3. How to debug c++ program in visual studio code (vscode) | gdb | g++ | c | c++ | #vscode
4. Debugging C++ on Mac with VSCode
(Practical Programmer)
5. How To Setup VS Code for Debugging C, C++, and Python
6. C++ Setup in VS Code with g++ and gdb on Windows 10
Top Articles
Latest Posts
Article information

Author: Kimberely Baumbach CPA

Last Updated: 03/23/2023

Views: 5850

Rating: 4 / 5 (41 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Kimberely Baumbach CPA

Birthday: 1996-01-14

Address: 8381 Boyce Course, Imeldachester, ND 74681

Phone: +3571286597580

Job: Product Banking Analyst

Hobby: Cosplaying, Inline skating, Amateur radio, Baton twirling, Mountaineering, Flying, Archery

Introduction: My name is Kimberely Baumbach CPA, I am a gorgeous, bright, charming, encouraging, zealous, lively, good person who loves writing and wants to share my knowledge and understanding with you.