Skip to content

Wrong debugging command on MSYS2 terminal #13875

@hanzhanji1

Description

@hanzhanji1

Environment

  • OS and version: Windows 11 22H2
  • VS Code: 1.103.2
  • C/C++ extension: 1.26.3
  • GDB / LLDB version: 16.3

Bug Summary and Steps to Reproduce

Bug Summary:
After setting MSYS2 bash as the default terminal of VSCode, the command of compile and debug provided by C/C++ extension is still "cmd /c ${command}". However, in bash, "/c" is interpreted as a directory (A "c" directory in the root directory) instead of a parameter. It leads that the bash launch "cmd.exe /msys-root/c ${command}"

Steps to reproduce:

  1. Install MSYS2 on Windows
  2. Install ucrt64-binutils and ucrt64-gdb by pacman
  3. Set MSYS2 UCRT64 as the default terminal of VSCode
  4. Launch "Debug" (cppdbg) task
  5. See error...

The terminal will stop at "cmd.exe" in interactive mode, because "/c" parameter is interpreted as directory name by bash. The debug process failed for timeout.

A possible solution might be changing the command to "cmd //c ${command}" or just run "${command}", but I can't find anywhere to configure the command for compile and debug in C/C++ extension.

Debugger Configurations

tasks.json:
{
    "type": "cppbuild",
    "label": "mingw-debug",
    "command": "g++",
    "args": [
        "-fdiagnostics-color=always",
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}.exe"
    ],
    "options": {
        "cwd": "${fileDirname}"
    },
    "problemMatcher": [
        "$gcc"
    ],
    "group": {
        "kind": "build",
        "isDefault": true
    }
}

launch.json:
{
    "name": "Debug",
    "type": "cppdbg",
    "request": "launch",
    "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
    "args": [],
    "stopAtEntry": false,
    "cwd": "${fileDirname}",
    "environment": [],
    "externalConsole": false,
    "MIMode": "gdb",
    "miDebuggerPath": "gdb",
    "preLaunchTask": "mingw-debug"
}

Debugger Logs

--> R (launch-2): {"type":"response","request_seq":2,"success":false,"command":"launch","message":"Unable to start debugging. Unable to establish a connection to GDB. Debug output may contain more information.","body":{"error":{"id":1005,"format":"Unable to start debugging. Unable to establish a connection to GDB. Debug output may contain more information."}},"seq":14}

Other Extensions

No response

Additional Information

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wantedCan be fixed in the public (open source) repo.tasks/build/debugAn issue relating to tasks.json (e.g. build issues)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions