You can pass multiple arguments in the same string, space-separated:
"args": "bla bla"
Answer from Cameron637 on Stack OverflowPass parameters to launch.json's program field
Launch.json 'args' not passing correctly
VS Code does not use launch.json arguments when I press Debug Python File
node.js - In Visual Studio Code, how to pass arguments in launch.json - Stack Overflow
Videos
I followed this page #VSCode: C++ Development and Debugging using containers, successfully setup vscode env to debug a c program running inside a docker without a problem. Below is my launch.json content inside .vscode dir.
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "./main",
"args": [],
"stopAtEntry": true,
"cwd": "/myproject",
"environment": [],
"externalConsole": true,
"sourceFileMap": { "/myproject": "${workspaceFolder}" },
"pipeTransport": {
"debuggerPath": "/usr/bin/gdb",
"pipeProgram": "/usr/bin/sshpass",
"pipeArgs": [
"-p",
"root",
"ssh",
"root@localhost",
"-p",
"2222"
],
"pipeCwd": ""
},
"MIMode": "gdb"
}
]
}The problem is the program field in the launch.json only accepts binary blob i.e. ./main without passing any parameters. My executable program needs some parameters such as `-i eth0 -c /path/to/my.conf ...`. However, if I provide the command, for instance, `./main -i eth0 -c /path/to/my.conf`. VSCode complains
Unable to start debugging. Program path `./main -i eth0 -c /path/to/my.conf` is missing or invalid. GDB failed with message: ./main -i eth0 -c /path/to/my.conf: No such file or directory. ...
How should I configure so that I can dynamically pass different parameters to the program for debugging? Thanks
As described in the documentation, you need to use the args attribute. E.g.
{
// 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": "node",
"request": "launch",
"name": "Debug App",
"program": "${workspaceFolder}/main.js",
"args": ["arg1", "arg2", "arg3"]
}
]
}
I pass arguments by this way for the python program, it may work for nodejs:
{
"type": "node",
"request": "launch",
"name": "Debug App",
"program": "${workspaceFolder}/main.js",
"args": ["--arg1", "value1", "--arg2", "value2"]
}
Setting up a .vscode/launch.json configuration for debugging is quite useful
Following are the launch configurations for different cases:
The program takes in arguments:
{
// 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": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/main.go",
"cwd": "${workspaceFolder}", // need to specify if you have a nested main.go or else it defaults to "program" folder
"args": ["arg1", "arg2", "--flag1=flag1value", "--flag2", "flag2value"]
},
{
"name": "Attach to Process",
"type": "go",
"request": "attach",
"mode": "local",
"processId": 0
}
]
}The program takes additional build flags
{
// 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": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/main.go",
"cwd": "${workspaceFolder}", // need to specify if you have a nested main.go or else it defaults to "program" folder
"buildFlags": ["--buildflag"],
},
{
"name": "Attach to Process",
"type": "go",
"request": "attach",
"mode": "local",
"processId": 0
}
]
}Or optionally you can just build and run your program from the terminal with whatever build flags and arguments and then use the "Attach to process" to debug that running program. In this case you will have to find the exact process that you started from the terminal. This is very manual, therefore I prefer the above launch configurations, but this "Attach to process" method gives more flexibility.