vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Debugging doesn't work with Clang 11 on Windows

Open bshoshany opened this issue 5 years ago • 11 comments

Type: Debugger

Describe the bug

  • OS and Version: Windows_NT x64 10.0.19042
  • VS Code Version: 1.51.1 (also tried with Insiders, the issue still occurs)
  • C/C++ Extension Version: 1.1.2
  • Other extensions you installed (and if the issue persists after disabling them): When disabling all extensions except the C/C++ extension, the issue still occurs.
  • A clear and concise description of what the bug is: Debugging doesn't work with Clang on Windows due to the file lldb-mi.exe being missing.

To Reproduce Please include a code sample and launch.json configuration. Steps to reproduce the behavior:

  • Install LLVM 11.0.0
  • Create a new workspace folder
  • Create the following test.cpp:
#include <iostream>

int main()
{
    std::cout << "Hello, World!\n";
}
  • Create the following tasks.json:
{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "Build for debugging",
            "command": "C:/Program Files/LLVM/bin/clang++.exe",
            "args": [
                "${workspaceFolder}/test.cpp",
                "-o",
                "${workspaceFolder}/test.exe",
                "-g"
            ],
            "options": {
                "cwd": "C:/Program Files/LLVM/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Build for debugging with Clang++"
        }
    ]
}
  • Press Ctrl+Shift+B to run the build task. The program compiles successfully. Typing test in the terminal prints out "Hello, World!".
  • Press F5, choose "C++ (GDB/LLDB)", and then clang. The message "Unable to start debugging. The value of miDebuggerPath is invalid" will be displayed.

The launch.json file that was created by default is:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "clang++.exe - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "miDebuggerPath": "\\usr\\bin\\lldb-mi.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "Build for debugging"
        }
    ]
}

First of all, the default miDebuggerPath isn't even a Windows path, since /usr/bin doesn't exist on Windows. More importantly, even in the correct folder, which is C:\Program Files\LLVM\bin, the file lldb-mi.exe itself doesn't exist.

I looked it up and apparently lldb-mi has been removed from recent versions of LLVM for some reason. Obviously, I don't want to downgrade to an older version of Clang just so I can use VS Code with it.

Curiously, in C:\Program Files\LLVM\bin, there is a file named lldb-vscode.exe. However, after changing miDebuggerPath to C:/Program Files/LLVM/bin/lldb-vscode.exe and pressing F5, the debugger starts but nothing happens in the terminal - the program just freezes. Typing lldb-vscode in the terminal doesn't do anything either - it just exits without printing any output to the terminal. So I don't know what that file is actually supposed to do, but it doesn't seem to solve the problem of debugging in VS Code.

bshoshany avatar Dec 03 '20 14:12 bshoshany

We are dependent on lldb-mi and are investigating a way to ship it on our own for LLVM 10+.

We currently support lldb on macOS since we can link to XCode's version of liblldb.framework but there are many ways for Windows/Linux users to download liblldb.

lldb-vscode.exe is actually its own VS Code extension that speaks VS Code Debug Adapter Protocol and not GDB-MI. See https://github.com/llvm/llvm-project/tree/master/lldb/tools/lldb-vscode#installation-for-visual-studio-code

WardenGnaw avatar Dec 03 '20 18:12 WardenGnaw

I see, thanks for the clarification. Hope to see official support for the latest LLVM versions in VS Code soon.

Would you mind expanding on what you mean by "there are many ways for Windows/Linux users to download liblldb"? (Unfortunately I'm not very familiar with how LLVM works - I've been using GCC and MSVC until now.)

What would be the most reliable way of debugging Clang in VS Code on Windows?

  1. Using the extension you linked to?
  2. Using this extension from the Marketplace?
  3. Something else?

bshoshany avatar Dec 03 '20 20:12 bshoshany

Would you mind expanding on what you mean by "there are many ways for Windows/Linux users to download liblldb"?

lldb-mi is an additional tool that calls into liblldb which has functions which actually debugs the process. MI is machine interface which makes it easy to programmatically change the debugger state and read a well formatted structure for output. Reading console output from lldb is a bit more difficult.

At the moment, we recommend CodeLLDB to debug lldb-mi on Windows and Linux.

We hope to provide a better experience for debugging with LLDB in the future in the C/C++ extension.

WardenGnaw avatar Dec 04 '20 01:12 WardenGnaw

Thank you for the explanation. Hoping to see improved official LLDB debugging support soon!

bshoshany avatar Dec 04 '20 04:12 bshoshany

I have compiled llvm (13.0.0) and lldb-mi for windows myself, and it still doesn't work properly with lldb-mi in the right place

The terminal says

& 'c:\Users\username\.vscode\extensions\ms-vscode.cpptools-1.6.0\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-kujkbtpw.1hc' '--stdout=Microsoft-MIEngine-Out-kaec0x1i.ft3' '--stderr=Microsoft-MIEngine-Error-3ptfrd1g.eph' '--pid=Microsoft-MIEngine-Pid-bt5nkgyl.erv' '--dbgExe=C:\Program Files\LLVM\bin\lldb-mi.exe' '--interpreter=mi'

The debug console says

Warning: Debuggee TargetArchitecture not detected, assuming x86_64.

but it doesn't look like it ever actually starts executing the exe to be debugged. Something must be going wrong with the MI protocol communication or something?

Edit: updating to 1.7.0-insiders2 doesn't fix it

Edit: should I create a new issue for this? If so, here or at the MIEngine github?

justinkb avatar Oct 01 '21 08:10 justinkb

2022 Feb 25 -- It seems I have the same issue...

...\VC\Tools\Llvm\x64\bin\lldb-mi.exe

is missing?

DBJDBJ avatar Feb 25 '22 17:02 DBJDBJ

Having same issue on Linux Mint (clang 10).

AeroBliss avatar Mar 20 '22 02:03 AeroBliss

Install lldb-mi from MSYS2 by

pacman -S mingw-w64-x86_64-lldb-mi

and you will get lldb-mi.exe in

<your_MSYS2_installation_directory>\mingw64\bin\

Furthermore, the command above also installs lldb, clang and gcc since they are required dependency packages. Therefore, you perhaps don't even need to install LLVM by its official .exe installer.

By the way, the default target of Clang from MSYS2 is x86_64-w64-windows-gnu rather than MSVC, which may helps.

Roger-WIN avatar Jul 07 '22 16:07 Roger-WIN

2023 and still doesn't work...

alnovikoff avatar Apr 16 '23 11:04 alnovikoff

Hello, I built lldb-mi for Windows and you can get it here. Currently the package is under moderation of chocolatey but it works.

sucicf1 avatar Mar 26 '24 18:03 sucicf1

Install lldb-mi from MSYS2 by

pacman -S mingw-w64-x86_64-lldb-mi

and you will get lldb-mi.exe in

<your_MSYS2_installation_directory>\mingw64\bin\

Furthermore, the command above also installs lldb, clang and gcc since they are required dependency packages. Therefore, you perhaps don't even need to install LLVM by its official .exe installer.

By the way, the default target of Clang from MSYS2 is x86_64-w64-windows-gnu rather than MSVC, which may helps.

Hi, I tried the msys2 version but it just doesn't start at all. It stucks at the beginning. I am using the following config:

{
  "name": "test",
  "type": "cppdbg",
  "request": "launch",
  "program": "${workspaceFolder}/debug/bin/a.exe",
  "args": [ ],
  "stopAtEntry": false,
  "cwd": "${workspaceFolder}",
  "environment": [ ],
  "externalConsole": false,
  "MIMode": "lldb",
  "miDebuggerPath": "lldb-mi",
},

I also tried build lldb-mi from https://github.com/lldb-tools/lldb-mi.git , it still doesn't work. However if I manually start lldb-mi from command line, it works flawlessly. So I am guessing there's something wrong with vscode-cpptools?

RichardLuo0 avatar Mar 28 '24 08:03 RichardLuo0

So it's been almost 4 years since I opened this issue, and CodeLLDB is still the only way to debug Clang in VS Code on Windows. This extension seems to work just fine, but I would rather use the official VS Code C/C++ extension than a 3rd party one, and more importantly, that extension has not been updated in a year, so there's a risk that it may become broken at any point, which means I won't be able to debug my projects with Clang anymore. Any progress with the official LLDB debugging support?

bshoshany avatar Sep 10 '24 04:09 bshoshany