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

Alaunch.jsonThe file is used to configure theWashing machineim Visual Studio-Code.

Visual Studio Code un generationslaunch.json(sob.vscodefolder in your project) with almost all the information you need. To start debugging, you need theprogramField with the path to the executable you want to debug. This must be specified for activation and connection settings (if you intend to connect to a running instance at any time).

The generated file contains two sections, one that configures debugging to launch and a second that configures debugging to attach.

Configure VS Code debugging behavior

Set or change the following options to control VS Code's debug behavior:

program (mandatory)

Specifies the full path to the executable to launch or attach to the debugger. The debugger needs this location to load debug symbols.

símboloSearchPath

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

RequireExactSource

An optional flag that tells the Visual Studio Windows debugger that the current source code must 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. Foradd, this parameter does not change debugging behavior.

  • Window: If set to true, an external console is generated. If set to false, VS Code's built-in terminal is used.
  • Linux: If set to true, VS Code will be prompted to generate an external console. If set to false, VS Code's built-in terminal is used.
  • MacOS: If set to true, an external console is created vialldb-mi. When set to false, the output can be viewed in the VS Code debug console. Due to restrictions withinlldb-mi, built-in terminal support is not available.

Prevent Windows console redirection

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

Register

Optional flags to specify which types of messages should be logged in the debug console.

  • exceptions: Optional flag to determine whether exception messages should be logged to the debug console. The default is true.
  • ModulLaden: Optional flag to determine whether module load events should be logged in the debug console. The default is true.
  • leave the program: Optional flag to determine whether program output should be logged to the debug console. The default is true.
  • engine protocol: Optional flag to determine whether diagnostic engine logs should be logged to the debug console. The default is false.
  • path: Optional flag to determine whether the diagnostic adapter command trace should be logged in the debug console. The default is false.
  • tracking response: Optional flag to determine whether the diagnostic adapter command and response trace should be logged in the debug console. The default is false.

VisualizerFile

.NightFile to use while debugging. To seeCreate custom views of native objectsInformation on how to create Natvis files.

showDisplayString

When oneVisualizerFileis declaredshowDisplayStringactivates the display chain. Enabling this option may result in slower performance when debugging.

Example:

{ "Name":"Start C++ (Windows)", "Type":"cppvsdbg", "Command":"To start", "Program":"C:\\Application1\\debug\\app1.exe", "simboloSearchPath":"C:\\Symbol; vs:\\SymbolDir2", "external console":TRUE, "Register": { "Load module":INCORRECT, "Path":TRUE}, "File Viewer":"${workspace folder}/my.natvis", "Show display string":TRUE}

Configure the target application

You can use the following options to change the status of the target application on startup:

argument

JSON array of command line arguments passed to the program on startup. Example["arg1", "arg2"]. When you run away from characters, you have to do it twice. For example,["{\\\"arg1\\\": true}"]send to{"arg1": true}to your application.

cwd

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

Surroundings

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

Example:

{ "Name":"C++-Start", "Type":"cppdbg", "Command":"To start", "Program":"${workspace folder}/a.out", "Arguments": ["arg1","arg2"], "Surroundings": [{"Name":"Attitude","Bravura":"Debug"}], "cwd":"${workspace folder}"}

GDB or LLDB Customization

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

mode IM

Specifies the debugger that VS Code connects to. Must be configured for thisgdbÖlldb. This is preconfigured by the operating system and can be changed if needed.

miDebuggerPfadName

The path to the debugger (eg gdb). If only the executable is specified, it looks for a debugger in the OS PATH variable (GDB on Linux and Windows, LLDB on OS X).

miDebuggerArgs

Additional arguments to be passed to the debugger (e.g. gdb).

stop at the entrance

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

stopEnConnect

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

configuration commands

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

customLaunchSetupCommands

If present, replaces the default commands used to launch a target with some other commands. For example, this could be "-target-attach" to attach it 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 }].

launchCommandFull

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".

Example:

{ "Name":"C++-Start", "Type":"cppdbg", "Command":"To start", "Program":"${workspace folder}/a.out", "Stop at the entrance":INCORRECT, "Custom Boot Configuration Commands": [{"Text":"end run","Description":"goal run","ignore errors":INCORRECT}], "LaunchCommandFull":"executive-executive", "Linux": { "Modo IM":"gdb", "miDebuggerPfad":"/usr/bin/gdb"}, "osx": { "Modo IM":"lldb"}, "Window": { "Modo IM":"gdb", "miDebuggerPfad":"C:\\MinGw\\paper basket\\gdb.exe"}}

SymbolLoadInfo

  • load all: If true, symbols for all libraries are loaded; otherwise Solib symbols will not be loaded. Modified from the list of exceptions. The default is true.
  • list of exceptions: List of filenames (wildcards allowed), separated by semicolons;. Changes the behavior of LoadAll. If LoadAll is true, no symbols are loaded for libraries matching any name in the list. Otherwise, only load symbols for matching libraries. Example:"foo.so;bar.so"

Debug dump files

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

DumpPath

If you want to debug a Windows dump file, set this to the dump file path to start debugging onTo startAttitude.

coreDumpPath

Full path to a main dump file for debugging the given program. Set it to the path of the main dump file to start debugging onTo startAttitude.Note: MinGw does not support core dump debugging.

Remote debugging or debugging with a local debugger server

miDebuggerServerAddress

Network address of the debugger server (e.g. gdbserver) to connect to for remote debugging (example:Local server: 1234).

debugServerPfad

Full path to debug the server to start.

debugServerArgs

Arguments to the debugger server.

server started

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

filtrorStdout

If set to true, look fordefault connectionPass the server-initiated pattern and record stdout to debug output. The default isTRUE.

filtrorStderr

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

serverLaunchTimeout

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

PipelineTransport

Learn how to connect to a remote process, such as B. To debug a process in a Docker container, see thepipe transportConfiguration element.

hardware breakpoints

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

additional properties

process identification

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

command

Indicates whether the configuration section is intendedTo startthe program oraddto an already running instance.

green architecture

out of dateThis option is no longer needed as the target architecture is automatically detected.

Type

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

sourceFileMap

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

Environment variable definition file

An environment variable definition file is a plain text file containing key-value pairs in the form ofenvironment variable=value, swindler#used for comments. Multiline values ​​are not supported.

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

For example:

project.env-Datei:

# project.env# Example environment with key as "MYENVRIONMENTPATH" and value as C:\\Users\\USERNAME\\ProjectMIRUTA ENVIRONMENT=C:\\from the user\\USER NAME\\Project# Variables with spacesSPACED_OUT_PATH="C:\\that has spaces\\Project"

icon options

ANDicon optionsThe item allows customization of how the debugger looks for symbols. Example:

 "Icon Options": { "Search Routes": [ "C:\\Origin\\MeuOutroProjeto\\paper basket\\debug", "https://my-companies-symbols-server"], "findMicrosoftSymbolServer":TRUE, "cachePfad":"%TEMPERATURE%\\simcache", "Modulfilter": { "Absent":"loadAllButExcluded", "deleted modules": ["NoBuscarEste*.dll"]}}

Characteristics

search paths: Array of symbol server URLs (example: https://msdl.microsoft.com/download/symbols) or directories (example: /build/symbols) to search for .pdb files. These directories are searched in addition to the default locations along with the module and path where the PDB was originally placed.

searchMicrosoftSymbolServer: ETRUEMicrosoft Symbol Server (https://msdl.microsoft.com/download/symbols) is added to the symbol search path. If not specified, this is the default option.INCORRECT.

hidden broken": 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"Ö"loadOnlyIncluded". Em"loadAllButExcluded"mode, the debugger loads symbols for all modules unless the module is in the excludeModules array. In"loadOnlyIncluded"mode, the debugger does not attempt to load symbols for any module unless it is in the includedModules array or included via the includeSymbolsNextToModules setting.

properties for"loadAllButExcluded"Absent

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

properties for"loadOnlyIncluded"Absent

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

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

10.06.2021

Top Articles
Latest Posts
Article information

Author: The Hon. Margery Christiansen

Last Updated: 02/10/2023

Views: 6584

Rating: 5 / 5 (70 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: The Hon. Margery Christiansen

Birthday: 2000-07-07

Address: 5050 Breitenberg Knoll, New Robert, MI 45409

Phone: +2556892639372

Job: Investor Mining Engineer

Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.