Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing arguments to C++ programme for debugging in VSCode

I want to debug a C++ project in VSCode (on a Mac, using either GDB or LLDB). The program itself takes command line arguments like

./prog -input cf file_x.txt

This works fine when starting a debugging session in GDB on the command line.

In VSCode, I tried to adapt launch.json to read like this (only relevant lines shown):

"program": "${workspaceRoot}/build/prog",
            "args": [
              "-input cf",
               "path_to/file_x.txt"
            ]

With this, I get @"Unknown option: \"-input cf\"\r\n" in the output and the process is not debugged; alternatively, I tried only one argument like so:

"program": "${workspaceRoot}/build/prog",
            "args": [
              "-input cf path_to/file_x.txt"
            ]

resulting in the same message. Have I missed something important?

like image 386
cszang Avatar asked Aug 08 '16 11:08

cszang


People also ask

How do you pass arguments in Visual Studio debugging?

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.

Can you Debug C in VS Code?

To do that, open C++ file in VSCode and either hit F5 or go to Debug -> Start Debugging and select C++ (GDB/LLDB) then select g++.exe build and debug active file .

How do you use C on VS Code?

Download & Install the C/C++ Extension We need to click on the extension button that displays a sidebar for downloading and installing the C/C++ extension in the visual studio code. In the sidebar, type C Extension. In this image, click on the Install button to install the C/C++ extension.

How do I debug C++ code in VSCode?

Run and Debug C/C++ Code You’ll notice that there is also a .vscodefolder in your sample project. To configure debug configuration, 2 files are required launch.jsonand tasks.jsoninside .vscodefolder. VSCode can create and auto-configure these files if we try to debug for the first time.

How to start debugging or launch a code file by passing arguments?

And how we can start debugging or launch a code file by passing command line arguments. For this, you would need launch.json. If you have, just edit it as I will discuss in this post. To create a new launch.json, click on Run -> Open Configuratio or Run -> Add Configuration

How do I run a program in VS Code without debugging?

In addition to debugging a program, VS Code supports running the program. The Debug: Run (Start Without Debugging) action is triggered with Ctrl+F5 and uses the currently selected launch configuration. Many of the launch configuration attributes are supported in 'Run' mode.

Does VSCode support gdb debugging on the command line?

The program itself takes command line arguments like This works fine when starting a debugging session in GDB on the command line. In VSCode, I tried to adapt launch.json to read like this (only relevant lines shown):


1 Answers

Try it like this

"program": "${workspaceRoot}/build/prog",
            "args": [
              "-input",
              "cf",
              "path_to/file_x.txt"
            ]
like image 53
DAXaholic Avatar answered Oct 08 '22 13:10

DAXaholic