microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.51k stars 1.55k forks source link

Support "Run without debugging" #1201

Open HorstBaerbel opened 6 years ago

HorstBaerbel commented 6 years ago

I'm running VSCode 1.17.02 on Ubuntu 16.04 x64 and cpptools 0.14.

Could you please add information about how to launch an application w/o debugging (CTRL+F5) to the VSCode C++ docs and maybe post a complete tasks.json / launch.json example here? I've read a couple of issues now and can't quite make launching work... I use make to build my projects. I put

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "runtimeExecutable": "MYEXECUTABLE",
            "program": "${workspaceRoot}/MYOUTPUT.FILE",
            "preLaunchTask": "Make"
            }
    ]
}

into launch.json. My tasks.json looks like this:

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Make",
            "type": "shell",
            "command": "make",
            "args": [""],
            "group": "build",
            "presentation": {
                "reveal": "always",
                "panel": "dedicated"
            },
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": ["relative", "${workspaceRoot}"],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
}

The binary file is built successfully via CTRL+SHIFT+B, but when launching via CTRL+F5 I get the message "No executable targets are available". I guess vscode does not know what output file make generates...

agauniyal commented 6 years ago

Just create another task that runs builds and runs executable :|

HorstBaerbel commented 6 years ago

And connect that to CTRL+F5 through the key bindings? Might work, but how is it actually meant to be done?! What about my launch.json example? Should that work? Why not? The docs are lacking there imo... :/

agauniyal commented 6 years ago

No you cannot connect it to CTRL + F5 but you'd be able to run it with CTRL+SHIFT+B if you set it default build task which I've done :)

HorstBaerbel commented 6 years ago

Thanks for the workaround, but I suspect there must be an actual solution to the problem...

pieandcakes commented 6 years ago

@HorstBaerbel We haven't implemented Launch without Debugging. I'll mark this as a feature request but you may either do it as @agauniyal suggested with a batch file or from the Terminal within VSCode.

HorstBaerbel commented 6 years ago

Thanks. Will try the "build-and-run" version then for the moment...

jcrawford commented 6 years ago

I would also love to see a Launch Without Debugging feature added to vscode.

chuxubank commented 6 years ago

In some cases, you can use Code Runner an alternative.

swharden commented 6 years ago

Isn't CTRL+F5 already the default key binding for Start (without debugging) (workbench.action.debug.run)? ~It seems to work for me out of the box too: F5 launches with debugging, CTRL+F5 launches without.~

EDIT: In my case I don't think debugging is actually ever running properly, but at least CTRL+F5 is still "running without debugging". The only difference I see is that the call stack shows threads when I F5 but not when I CTRL+F5...

Visual Studio Code Default Key Bindings: https://code.visualstudio.com/docs/getstarted/keybindings#_debug

My launch.json file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/bin/main.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/data/",
            "environment": [],
            "externalConsole": true,
        }
    ]
}

My tasks.json file:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g", "${workspaceFolder}/src/main.cpp", "-o", "${workspaceFolder}/bin/main.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

My version of VS Code:

Version: 1.27.1 (system setup)
Commit: 5944e81f3c46a3938a82c701f96d7a59b074cfdc
Date: 2018-09-06T09:21:18.328Z
Electron: 2.0.7
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64
roachsinai commented 5 years ago

@pieandcakes maybe a week ago, Ctrl+F5 do the same with Start without debugging. Don't why doesn't work now.

pieandcakes commented 5 years ago

@roachsinai We haven't done work enable that scenario and we haven't shipped an extension update since 0.20.1 which shipped a few months back. Did you apply a VS Code update?

roachsinai commented 5 years ago

Yes, update it at 2019-01-09...

xgdgsc commented 5 years ago

Needing this launch feature.

polyclash commented 5 years ago

We need this to run external application and capture the stdout, with no debug attached.

pieandcakes commented 5 years ago

@polyclash @xgdgsc for now you can use the VS Code Terminal window to launch your application from the command line.

polyclash commented 5 years ago

@pieandcakes yes, I use a task, the internal terminal is configured with bash(mingw64), but the terminal don't receive the stdout from the application.

xgdgsc commented 5 years ago

But then I have to set environment variables again in the terminal, I already set those in launch configurations.

duanyongli commented 4 years ago

Looking forward to this feature.

voltflake commented 4 years ago

Also waiting for this feature.

kaidokert commented 4 years ago

One more vote. Setting all environment vars, launch arguments with unit test filters etc again separately is quite annoying. Debuggers start really slowly in larger projects, due to big symbol tables, being able to make minor edits to code and hit Ctrl+F5 to trigger rebuild and run would really speed iterations.

jfostier commented 4 years ago

Another vote. I am writing performance-critical code and I often want to benchmark runtime in release mode. The command line arguments I specify in launch.json are not passed to the command.

rido-min commented 4 years ago

+1, I want to reuse args from launch.json. Also enable to start from the terminal.

fufjvnvnf commented 4 years ago

Is this implemented yet?

qalisander commented 4 years ago

+1

sean-mcmanus commented 4 years ago

@fufjvnvnf No.

jan-runkel-zeitgleich commented 4 years ago

+1

AVSurfer123 commented 3 years ago

Has there been any progress on this? This is a very nice feature to have.

dwilliamson commented 3 years ago

My scenario is that I use compounds to launch client and server executables and debug them both at the same time. Command-line arguments are sometimes long and verbose for configuring various debug environments. For most cases this is great.

However, they both share a lot of the same library code and sometimes I need breakpoints to only trigger for one process and the other process interferes, making debugging slow.

Support for run without debugging with be perfect here.

Meanwhile, I'm using the fact that VSCode currently doesn't debug child processes, creating a forwarding executable that launches the target and exits immediately:


#include <Shlwapi.h>
#include <stdio.h>
#include <windows.h>

#pragma comment(lib, "shlwapi.lib")

int main(int argc, const char* argv[])
{
    // Header
    printf("Forwarder.exe Running...\n\n");
    if (argc < 2)
    {
        printf("ERROR: Not enough arguments provided\n");
        return 1;
    }

    // Get target executable
    const char* executable = argv[1];
    printf("Executable to Launch  : %s\n", executable);
    if (!PathFileExists(executable))
    {
        printf("ERROR: Executable path doesn't exist\n");
        return 1;
    }

    // Parse command line for forwarding
    const char* command_line = GetCommandLine();
    printf("Command Line          : %s\n", command_line);
    const char* arguments = PathGetArgs(command_line);
    printf("Forwarder Arguments   : %s\n", arguments);
    const char* forward_arguments = PathGetArgs(arguments);
    printf("Arguments to forward  : %s\n\n", forward_arguments);

    // Launch and forward, exiting immediately
    STARTUPINFO si{};
    si.cb = sizeof(si);
    PROCESS_INFORMATION pi{};
    if (CreateProcess(executable, (char*)forward_arguments, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi) == FALSE)
    {
        printf("ERROR: Failed to create process\n");
        return 1;
    }

    printf("Success\n");

    return 0;
}

I would love to be able to delete this :)

ant6n commented 3 years ago

I don't get it. VSCode seems so complicated, with these json configurations to launch. Isn't it possible to tell vscode to run some executable when hitting ctrl+f5, without an attached debugger? I can't even figure out how to set up two launch configurations, and tell VSCode to run one for ctrl+f5 and the other for f5.

The makefile tools extension sets up a play and a debug button, but there doesn't seem to be an obvious way to configure these, and to connect them to the f5 and ctrl-f5 shortcuts.

kamleshwebtech commented 3 years ago

"Run without debugging" not working and also devices are not being listed in VS code while if we write and run command in command line then flutter application is compiled. Its weird with VSCode now, it was working well earlier. any suggestion will be welcomed. Thanks.

lake2 commented 2 years ago

same need + 1

BrainSlugs83 commented 2 years ago

I don't get it. VSCode seems so complicated, with these json configurations to launch. Isn't it possible to tell vscode to run some executable when hitting ctrl+f5, without an attached debugger? I can't even figure out how to set up two launch configurations, and tell VSCode to run one for ctrl+f5 and the other for f5.

The makefile tools extension sets up a play and a debug button, but there doesn't seem to be an obvious way to configure these, and to connect them to the f5 and ctrl-f5 shortcuts.

Same boat. -- VS Code has built-in support for F5 = Run with Debugging, and CTRL+F5 for Run without Debugging -- it's kind of an industry standard. -- Why can't it be supported?

Why can't we tie a configuration option to each one? -- I don't get it. -- Why does launch.json have to be only for debugging, and not just used for all launch configurations, like it's supposed to be?

Why can't we just add a type? (i.e. cpp instead of cppdbg?) -- and then just infer the correct item to run based on whether or not we wanted to be running in debug mode.

dipeshbindlish commented 2 years ago

@HorstBaerbel We haven't implemented Launch without Debugging. I'll mark this as a feature request but you may either do it as @agauniyal suggested with a batch file or from the Terminal within VSCode.

@pieandcakes & @agauniyal Can you explain how set default build task CTRL+SHIFT+B.

kevinarch commented 2 years ago

still waiting for this in 2022

moritzgerl commented 2 years ago

want it too

rastna12 commented 1 year ago

bump

eduarddejong commented 1 year ago

In my situation the main issue is that clicking via the menu ("Run Without Debugging Ctrl+F5") works, and often also using the via Ctrl+P using "Tasks: Run Task" followed by choosing the specific task to run, but the hotkey Ctrl+F5 seems completely dead. I am on Linux now, I am not sure about the situation on Windows right now. Currently trying it with a Rust project, but I know that with C# .NET projects and C/C++ I am having the same issues, Ctrl+F5 does nothing.

mzient commented 1 year ago

Bumping up - again - in 2023!

emielsteerneman commented 1 year ago

Bumping up again - half a year + 5 days later.

submarines-and commented 1 year ago

Here is my workaround. Might seem unnecessary, but the goal for me was just to be able to use the "run without debugging" keybinding for my c++ projects as well.

Basically, set up a debug task that exists immediately, but runs a task afterwards. The task (tasks.json) can run arbitrary commands, so here you place your actual build + run code, in my case make.

launch.json

{
    "version": "2.0.0",
    "configurations": [
        {
            "name": "start",
            "request": "launch",
            "type": "node-terminal",
            "command": "exit",
            "postDebugTask": "build"
        },
    ]
}

tasks.json

 {
    "version": "2.0.0",
    "command": "bash",
    "options": {
        "cwd": "${workspaceRoot}"
    },
    "args": [
        "-c"
    ],
    "tasks": [
        {
            "label": "build",
            "args": [
                "make start"
            ]
        }
    ]
}

If you want to play with "when" conditions for keybindings, you can skip the first step and just have the task file. Then you would need a keybinding like below, that only runs on c++ files (and then you set the debug keybinding to activate on non cpp-files). I didn't like this approach, however, because I still want to use the launch.json when I am actually debugging (for which I switch the active task in the UI), but it is up to you.

    {
        "key": "cmd+b",
        "command": "workbench.action.tasks.runTask",
        "args": "build",
        "when": "editorLangId == 'cpp'"
    },
rinzwind5 commented 8 months ago

So no one knows how this is supposed to work? Great editor... a default key binding and function that isn't workable.

rastna12 commented 8 months ago

While maybe not exactly what we have in mind, I've made analogous configuration options in task.json that I have in launch.json. The configured task.json options run without the debugger but still has the configurability and ease of use as the launch.json options. With a name like "launch.json" I figured it would have the option to execute without a debugger, but it seems like launch.json is only intended for debugging? If so, that seems like a bit of a misnomer to call it that?

tt-cricut commented 7 months ago

Please fix this! +1

antoniocaruso commented 7 months ago

[moderated] They never care about C/C++ good stuff. It is 5 years that we are asking for this STUPID feature. It is clear that there is a political reason to NOT support it. Maybe they want us all to download 25 GB of Visual Studio, to compile hello world.

hoechenberger commented 7 months ago

@antoniocaruso Please watch your language, this behavior of yours is disrespectful.

xgdgsc commented 7 months ago

That language is much less disrespectful than https://github.com/microsoft/vscode/issues/204270 https://github.com/microsoft/vscode/issues/204728 https://github.com/microsoft/vscode/issues/203967. .

antoniocaruso commented 7 months ago

I can ask to my 250 Engineering student to espress their opinion in how easy and smart is trying to use this extension, to learn C/C++, so maybe they will be less harsh, but ..maybe not. I'm just trying to convey a simple messages to developers:

what is your target?

is this a "community editor"? or it is a "professional developer" editor? DECIDE. At this moment I cannot suggest it, too cumbersome to just do SIMPLE EASY stuff, and I'm harsh because there is large community in Colleges that really like to use ONE EDITOR for all platforms (like this) for teaching, without spending hours to explain to students how to install different development environments.

But if they have to write builds.json, and endless configuration variables, just to setup the path for the compiler and cannot just "build" please, and "run" please, without a debugger, that they never ever know about. Maybe this is 'no way'.

And, this is not the first comment, in several bug reports that raise this problem, but you seems really ..not interested. So, maybe I'll ask the students to install emacs, and solve the problem like in the '80.

bobbrow commented 7 months ago

There are two different Microsoft teams that contribute to the C++ extension - the C++ language team and the debugger team. The C++ language team (my team) remains very active developing language services for the C++ extension but the debugger team has been focused on other priorities within the company. I know that this isn't what anyone wants to hear as this is one of our top voted feature requests, but we do continue to let them know that this is a priority for us.

antoniocaruso commented 7 months ago

Dear bibbrow, thanks for your replay, at least we know that we are not wrong. Just priorities on the other side do not match.

But please, let me say to all of you:

The C++ language team, need to think about a simple issue:

Do you want to have support for Visual Studio for NEW programmers that are actually learning to code, and learning for the first time to install an editor, understand the differences between editors and IDE, use a compiler, etc etc with this language and with C, so we have developers that work in C/C++ in the next 10 years or not?

If you care about THE LANGUAGES (and if you are in a team called 'C++ extension - C++ language' maybe you must care, then, I think that 'language service' like intellisense are USELESS if people are unable to do: 1) Install Visual Studio 2) Unzip mingw 3) Open Visual Studio 4) Install your extension for C/C++ support 5) Create a .c or .cpp file with hello world.

and thaaaa daaaam, the editor ask you 'where is the compiler please?' (no intelligence, just ask), people provide a directory path for all mingw64 and you can just see everything working.

I don't want to iterate on this, and I accept your explanations, it is a big company, but, I hope that if you as Microsoft spent 10 years to figure out how to provide a real terminal to users, and now a good system like WSL, please do not spent 4 years to understand that you have a good product in Visual Studio Code, and you can do something really 'sensible' to a community in school and university by providing them a good simple editor with a good simple build system.

Debugging is not my problem. Compiling with just "gcc name.c -o name" and runnning with "./name" is better, I fixed it with another extension, but still....json to changes, and so on. Maybe people in microsoft do not know about it, but emacs, is able to compile and run a program in .c, with just a keyboard shortcut. and it is 30 year old. It is surprising to me, that you have that increadible beast under your fingers, with typescript, and cannot do something that in lisp has been done 30 years ago.

bobbrow commented 7 months ago

Hi @antoniocaruso, I'd be happy to chat about priorities and such if you'd like to open a Discussion. This issue probably isn't the right place for that unless it concerns the Run without debugging feature.

I'll address the compilers issue briefly though... as much as we'd like to bundle a compiler with the extension, logistically it doesn't make sense for us:

Instead, we provide installation instructions in our C++ Walkthrough and on linux/macOS we can run the installation commands directly for you. Run the "C/C++: Select IntelliSense Configuration..." command, then pick "Install a compiler". On Windows the option is "Help me install a compiler" which will take you back to the Walkthrough -- perhaps this should be its own command though...