microsoft / microsoft/vscode-cpptools

Wrong debugging command on MSYS2 terminal

Open
#13,875 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted tasks/build/debug
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using the provided tasks.json and launch.json with MSYS2 UCRT64 as the VS Code terminal, then trace how the C/C++ extension constructs the compile and debug command. Done means the generated command works in MSYS2 bash and the cppdbg session connects to GDB without timing out.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, typescript
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.