Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preLaunchTask fails (non zero exit code) but launch proceeds #141654

Closed
devzeb opened this issue Jan 27, 2022 · 5 comments
Closed

preLaunchTask fails (non zero exit code) but launch proceeds #141654

devzeb opened this issue Jan 27, 2022 · 5 comments
Assignees
Labels
*caused-by-extension Issue identified to be caused by an extension debug Debug viewlet, configurations, breakpoints, adapter issues info-needed Issue requires more information from poster

Comments

@devzeb
Copy link

devzeb commented Jan 27, 2022

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.64.0-insider, 1.63.2
  • OS Version: Windows 10 Pro 20H2
  • MinGW x64 environment (from MSYS2)

Steps to Reproduce:

  1. Follow the example of https://code.visualstudio.com/docs/cpp/config-mingw until "Step through the code"
  2. Open launch.json and change "stopAtEntry" to true. This way you can better see whats happening
  3. Make sure that you at least have built the application once, so that helloworld.exe can be found in the working directory
  4. Open helloworld.cpp and type gibberish at any line.
  5. Build the project using Ctrl+Shift+B. You can see that the build now fails.
  6. Press F5 (while helloworld.cpp is the active file). Watch the terminal output, it now says that the build fails but after that the launch just proceeds and the application stops at the entry point. vscode is in debugging perspective.

I can't understand why this most basic workflow just doesn't work.
Debugging an outdated executable is just a pain to deal with.

If you run the build command in powershell (which is displayed when pressing Ctrl+Shift+B) and run $? directly after, you see that powershell returns False, so it recognises that the build fails.
cpp_test_project.zip

That means the issue has to be VSCode.

I attached a workspace which contains a minimal example.

@weinand
Copy link
Contributor

weinand commented Jan 27, 2022

@devzeb By using a "fake build task" that always returns the exit code 1, I can prove that VS Code honours the exit code correctly:

CleanShot 2022-01-27 at 18 33 53@2x

What does this mean for your case? There are two possibilities:

  • you told VS Code previously to ignore the errors and debug anyway. In this case you might want to remove the setting: "debug.onTaskErrors": "debugAnyway" or
  • there is a problem in the build task you are using.

@weinand weinand added debug Debug viewlet, configurations, breakpoints, adapter issues info-needed Issue requires more information from poster labels Jan 27, 2022
@devzeb
Copy link
Author

devzeb commented Jan 27, 2022

Having the fake build task as you showed in your example makes my launch fail as well.
So the problem seems to be something different.

I added "debug.onTaskErrors": "abort" to check if that was a problem.
Unfortunately this didn't change anything, I still get the same behaviour for the example workspace folder I provided.

The build task I'm using is the exact task of this official tutorial: https://code.visualstudio.com/docs/cpp/config-mingw

It looks like this:

tasks.json

"tasks": [
        {
            "type": "cppbuild",
            "label": "buildapp",
            "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
           "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Vom Debugger generierte Aufgabe."
        }]

launch.json

"configurations": [
        {
            "name": "g++.exe - Aktive Datei erstellen und debuggen",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Automatische Strukturierung und Einrückung für \"gdb\" aktivieren",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "buildapp"
        }
    ]

@weinand
Copy link
Contributor

weinand commented Jan 27, 2022

@devzeb you said:

If you run the build command in powershell (which is displayed when pressing Ctrl+Shift+B) and run $? directly after, you see that powershell returns False, so it recognises that the build fails.

Since I'm using macOS I don't know whether a non-zero exit code should really result in "False".

And if this is not the problem then maybe there is an issue with the "$gcc" problem matcher.

I suggest to file an issue against the C/C++ extension (which defines the build task and the problem matcher).

@weinand
Copy link
Contributor

weinand commented Jan 27, 2022

/extCpp

@github-actions github-actions bot locked and limited conversation to collaborators Mar 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*caused-by-extension Issue identified to be caused by an extension debug Debug viewlet, configurations, breakpoints, adapter issues info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants
@weinand @devzeb and others