0

I am trying to pass command line arguments to the gdb in vscode. Here is my launch.js config.

{
"configurations": [
{
    "name": "(gdb) Launch",
    "type": "cppdbg",
    "request": "launch",
    "program": "${workspaceFolder}/main",
    "args": ["1"],
    "stopAtEntry": false,
    "cwd": "${fileDirname}",
    "environment": [],
    "externalConsole": false,
    "MIMode": "gdb",
    "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
        }
    ]
}
]

}

Here is the file and folder structure.

Folder structure for dummy project

Here is the simple sanity check code

#include<stdio.h>


int main(int argc, char* argv[])
{
   printf("argc == %d\n", argc);
   return 0;
}

Its output is

argc == 1

I am not able to capture argument. Please help.

denisssj
  • 79
  • 5
  • My apology, I have added that. As for output, I was expecting argc val to be number of args I pass, that is argc value should be 2 instead of 1. – denisssj Jun 30 '23 at 07:20

1 Answers1

0

It appears that when the click on the button of at the upper right corner provided in vscode, it does not run as per config provided in launch.json config. To run it, go the right hand toolbar and click on debug button. Then make choose option of (gdb) lauch.json and run it. Then your code will run as per launch.json.

denisssj
  • 79
  • 5