microsoft / vscode-cpptools

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

[Windows] cppdbg debugger Unable to Use Integrated Terminal with mingw #5497

Open DrVrej opened 4 years ago

DrVrej commented 4 years ago

Type: Debugger

Describe the bug I want to use the ingerated terminal inside VSC. I can only get inputs if I enable "externalConsole", which doesn't solve this issue as it requires using an external terminal.

To Reproduce Sample launch.json:

"configurations": [
    {
        "name": "g++ Build & Debug Folder",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}\\test.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${fileDirname}",
        "environment": [],
        "externalConsole": true, // Only to way get inputs currently =(
        "MIMode": "gdb",
        "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
    }
]

Sample C++ Program:

#include <iostream>
int main() {
    int input {1};
    std::cin >> input;
    std::cout << input << '\n';
    return 0;
}

Steps to reproduce the behavior:

  1. Write a simple C++ program that requires user input.
  2. Start the debugger without enabling "externalConsole".
  3. Step until you reach a line that requires user input.

Additional context The following is ran inside the integrated terminal: 'c:\Users\Vrej\.vscode\extensions\ms-vscode.cpptools-0.28.0\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-rzbbs23a.feg' '--stdout=Microsoft-MIEngine-Out-0mxge4rh.udl' '--stderr=Microsoft-MIEngine-Error-gcbm3hqx.mik' '--pid=Microsoft-MIEngine-Pid-imrtgchk.lay' '--dbgExe=C:\MinGW\bin\gdb.exe' '--interpreter=mi' Then the cursor begins blinking in the new line, but I am unable to give any inputs.

WardenGnaw commented 4 years ago

I can't reproduce this issue, there may be some delay before the integrated terminal starts to work.

Can you try inputting when "Ready for Input" shows up in the window?

#include <iostream>
int main() {
    int input {1};
        std::cout << "Ready for Input" << std::endl;
    std::cin >> input;
    std::cout << input << '\n';
    return 0;
}

If its still failing can you enable engineLogs by adding the following to your launch.json?

"logging": {
   "engineLogging": true
}
DrVrej commented 4 years ago
  1. For the first test, "Ready for Input" didn't show up in the integrated terminal, only showed up when I used the external terminal. Though "Ready for Input" did print inside the debug console in both cases: image

  2. I put the code you have sent me, it didn't make any difference. The integrated terminal still refuses to get any input.

DrVrej commented 4 years ago

What does the terminal tab look like?

image

WardenGnaw commented 4 years ago

I can repro this with mingw-get version 0.6.3-pre-20170905-1 installing gdb-7.6.1

WardenGnaw commented 4 years ago

Did you download MinGW from the link from the docs

Expected MinGW

DrVrej commented 4 years ago

Did you download MinGW from the link from the docs

Expected MinGW

I downloaded from the main MinGW website (www.mingw.org), all installed packages are up to date.

WardenGnaw commented 4 years ago

Looks like theres an issue with mingw with integrated terminal.

A workaround is to use mingw-w64 with integrated terminal on Windows.

Investigating.

TheWirv commented 4 years ago

I have the same problem using MSVC pipeline on Windows. Using the external console works just fine, but when trying to use the integrated one, it doesn't even print the first cout statement. And btw, without any cin statements, everything also works perfectly fine in the integrated console.

Versions:

Here are some files if that helps: main.cpp:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    int age;
    string zipCode;
    string promptAge = "Please enter you age: ";
    string promptZipCode = "Please enter you ZIP code: ";

    cout << promptAge;
    cin >> age;
    cout << promptZipCode;
    cin >> zipCode;
    cout << "Hi, you are " << age << " years old and your ZIP code is " << zipCode << ".\n";
    return 0;
}

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Build and debug",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}\\bin\\debug\\main.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}\\bin\\debug",
            "environment": [],
            "externalConsole": false,
            "preLaunchTask": "Build debug"
        }
    ]
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "Build debug",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/EHsc",
                "/Fe:",
                "${workspaceFolder}\\bin\\debug\\main.exe",
                "${workspaceFolder}\\src\\main.cpp"
            ],
            "options": {
                "cwd": "${workspaceFolder}\\bin\\debug"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "type": "shell",
            "label": "Build release",
            "command": "cl.exe",
            "args": [
                "/EHsc",
                "/GA",
                "/Qpar",
                "/O2",
                "/Ot",
                "/Ox",
                "/favor:blend",
                "/Fe:",
                "${workspaceFolder}\\bin\\release\\main.exe",
                "${workspaceFolder}\\src\\main.cpp"
            ],
            "options": {
                "cwd": "${workspaceFolder}\\bin\\release"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": "build",
        }
    ]
}
XiaWuSharve commented 3 years ago

I have the same problem debugging C++ programs.The terminal didn't output anything and of course can't get inputs.You say there's an issue with mingw,but I don't know the concrete steps to solve this problem.Thanks a lot.

asimard1 commented 3 years ago

I am also having this problem and cannot find a way to solve it. My program is showing up in Debug Console but I would like it in the integrated terminal like all my other languages.

XiaWuSharve commented 3 years ago

I am also having this problem and cannot find a way to solve it. My program is showing up in Debug Console but I would like it in the integrated terminal like all my other languages.

Try reinstalling MinGW through this website,https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe/download

geyan21 commented 2 years ago

mingw-64 works.

pandihong commented 2 years ago

mingw-64 works.

Could you show the link? Thanks.

EngineerHamziey commented 1 year ago

Im facing the same problem, my VScode isn't taking input, although same code works perfectly on code blocks, I'm on windows 64 bits, Any suggestions please 🙏