2

I'm at a bit of a loss here, I hadn't really expected this to be difficult. I usually work on Linux, but today I had some work that I needed to do and only had a Windows machine. I thought this would be no problem, I can install git for windows, clone my project, and get right to work. Its just been a huge mess. I'm really hoping someone can help me understand where I went wrong in setting all this up on Windows. It isn't something I plan to do frequently, but definitely something I want to be able to do on a Windows machine in a reasonable amount of time.

I'm using WSL and have set my default VSCode Windows integrated terminal to C:\WINDOWS\System32\bash.exe

I installed Windows 10 SDK to fix crtdbg.h include errors as a dependency against <iostream>

I installed gdb with MinGW - MinGW Install Configuration

I set the path environment variable

enter image description here

I created a launch.json -

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) CDLL Driver",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/driver",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
} 

My MinGW bin contains the following

MinGW Bin Contents

I launch my debug task in VSCode and I get the following error

cmd /C "c:\Users\shaun\.vscode\extensions\ms-vscode.cpptools-0.28.2\debugAdapters\bin\WindowsDebugLauncher.exe --stdin=Microsoft-MIEngine-In-4n4ohh2f.ibt --stdout=Microsoft-MIEngine-Out-1irudlfy.q5x --stderr=Microsoft-MIEngine-Error-fg20cagk.ynl --pid=Microsoft-MIEngine-Pid-kzdzn4p4.lro --dbgExe=C:\MinGW\bin\gdb.exe --interpreter=mi "

Command 'cmd' not found, but there are 16 similar ones.

I can provide more information if needed. I'm really hoping I missed something simple here that would be obvious to someone who works on Windows.. Thank you in advance, I really appreciate the help!

3
  • 1
    Command 'cmd' not found This is weird. cmd.exe is a system file. Commented Jun 5, 2020 at 20:44
  • 1
    Can you run cmd.exe? Commented Jun 5, 2020 at 21:01
  • I can launch cmd.exe no problem, either by Windows->command or Windows->Run->cmd.exe. I can even just type cmd.exe in VSCode's integrated WSL Bash terminal and it kicks me into cmd. Commented Jun 5, 2020 at 21:03

2 Answers 2

3

If you are using WSL to compile the project you should not use MinGW gdb. You need to install gdb on you Linux subsystem (using native tools like apt if you are using Ubuntu WSL), reopen your project in WSL and configure the WSL path to gdb. I was able to successfully debug using this setup on WSL.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the response! I'm curious what your path to gdb looks like? I tried pointing miDebuggerPath to my WSL gdb install at C:\\Users\\shaun\\AppData\\Local\\Packages\\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\\LocalState\\rootfs\\usr\\bin\\gdb and I got an error stating that this gdb executable is not a valid application for this OS platform.
@ShaunReed, my gdb path looks like "/usr/bin/gdb". When you are working with WSL you can consider it as full linux virtualization (especially if you are using WSL2), so the path is unix like.
No dice, unfortunately :( VSCode shows an error that says the miDebuggerPath is invalid when I use a unix path. I've been able to verify its location on WSL using which gdb and by navigating to the rootfs through windows. Also, just to give it a shot vs my particular exe, I ran the gdb debugger against my executable within WSL with no issues.
@ShaunReed it looks like you are not reopening your folder in WSL. Do you have following text in bottom left corner of VS Code screen "WSL: Ubuntu"?
Awesome! Thank you very much! I like the virtualization going on there with WSL! Very neat. It seems like I definitely have a lot to learn about how WSL works in general. This is my first time using it for much more than an SSH client, I did not know I had to click in the bottom left and 'open project in WSL'
0

Replace your launch.json file with this file

{
  "version": "0.2.0",
  "configurations": [
    {
      "args": ["1"],
      "name": "gcc.exe - Build and debug active file",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",

      "stopAtEntry": false,
      "cwd": "${fileDirname}",
      "environment": [],
      "externalConsole": true,
      "MIMode": "gdb",
      "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ],
      "preLaunchTask": "C/C++: gcc.exe build active file"
    }
  ]
}

Make Sure you have installed MinGw Compiler and gdb debugger

1 Comment

You can not use this lauch.json file unless you create first the preLaunchTask. Here is the full guide: code.visualstudio.com/docs/cpp/config-mingw

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.