I'm using VSCode
on Linux and I've came up with a the following launch configuration in my attempt to fire the VSCode
debugger, which, in turn, would rely on gdb
:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": ["a", "b", "c", "d", "e"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "make project"
}]
}
Here, using the args
attribute I'd like to pass 5 arguments to the process I'm debugging, namely: "a", "b", "c", "d", "e".
However, when I run the debugger, the argc
value is correctly set to 6, but the values themselves, stored by argv
are not present.
To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line. They will be passed to the program via the argv array.
In Visual Studio 2010, right click the project, choose Properties, click the configuring properties section on the left pane, then click Debugging, then on the right pane there is a box for command arguments. In that enter the command line arguments. You are good to go. Now debug and see the result.
Run to a breakpoint in code You can also select the line and then select F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert Breakpoint. The breakpoint appears as a red dot in the left margin next to the line of code. The debugger suspends execution just before the line runs.
To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.
The first argument is always the executable. This is expected behaviour.
That's cause the type of argv is char**. The debugger doesn't know if it's pointing at a single element or an array.
In VS you can use format specifiers. With gdb you should be able to use something like this in the Watch view:
(char*[6])argv
https://github.com/Microsoft/vscode-cpptools/issues/688#issuecomment-685956825
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With