VS Code Debugger
Debugger configurations for Visual Studio Code
The launch.json file defines debug configurations for Visual Studio Code. This page includes examples demonstrating common launch.json setups.
Visual Studio Code Documentation
Procedure
- Open the workspace directory in VS Code.
- In the workspace root, create a
.vscodedirectory if it does not already exist. - Inside
.vscode, create a file namedlaunch.json.
Python Example
Example Python Program
#_______________________________________________________________
# This file is named arg_test.py
#_______________________________________________________________
import argparse
if __name__ == '__main__':
parser: argparse.ArgumentParser = argparse.ArgumentParser()
parser.add_argument('--in0', '-i0', help='Input 0', action='store')
parser.add_argument('--in1', '-i1', help='Input 1', action='store')
args: argparse.Namespace = parser.parse_args()
print(str(
f'\nInput argument 0: {args.in0}'
f'\nInput argument 1: {args.in1}'
)
)
Sample launch.json
This launch.json file contains two Python debug configurations with alternative inputs.
{ "version": "0.2.0"
, "configurations":
[ { "name" : "sample py debug"
, "type" : "debugpy"
, "request" : "launch"
, "program" : "${workspaceFolder}/arg_test.py"
, "console" : "integratedTerminal"
, "args" :
[ "--in0", "42"
, "-i1" , "3.14"
]
}
, { "name" : "alternate input sample py"
, "type" : "debugpy"
, "request" : "launch"
, "program" : "${workspaceFolder}/arg_test.py"
, "console" : "integratedTerminal"
, "args" :
[ "--in0", "64"
, "--in1", "4096"
]
}
]
}
Select the icon for Run and Debug from the activity bar. Click the drop down menu and select a configuration in launch.json. 
Key Descriptions
| Key | Description |
|---|---|
label |
Name of configuration. |
type |
Type of debugger. Common values are debugpy for python, gdb for cpp. |
program |
Path to program to execute. |
args |
Arguments passed to the program. |
console |
Use integratedTerminal to use the VS Code terminal for program execution. |
Example C++ Program
#include <stdio.h>
int main()
{
int i = 0;
i++;
printf("\ni: %d", i);
return 0;
}