Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging doesn't work with Clang 11 on Windows #6617

Open
bshoshany opened this issue Dec 3, 2020 · 13 comments
Open

Debugging doesn't work with Clang 11 on Windows #6617

bshoshany opened this issue Dec 3, 2020 · 13 comments
Labels
debugger Feature Request help wanted Can be fixed in the public (open source) repo.

Comments

@bshoshany
Copy link

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.

@WardenGnaw
Copy link
Member

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

@bshoshany
Copy link
Author

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?

@WardenGnaw
Copy link
Member

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.

@bshoshany
Copy link
Author

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

@justinkb
Copy link

justinkb commented Oct 1, 2021

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?

@DBJDBJ
Copy link

DBJDBJ commented Feb 25, 2022

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

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

is missing?

@AeroBliss
Copy link

AeroBliss commented Mar 20, 2022

Having same issue on Linux Mint (clang 10).

@Roger-WIN
Copy link

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.

@alnovikoff
Copy link

2023 and still doesn't work...

@sucicf1
Copy link

sucicf1 commented Mar 26, 2024

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

@RichardLuo0
Copy link

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?

@bshoshany
Copy link
Author

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?

@sean-mcmanus sean-mcmanus added the help wanted Can be fixed in the public (open source) repo. label Sep 10, 2024
@Joymaker
Copy link

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

Unfortunately, it will not install on Windows on an ARM architecture. Which is really sad because that is where gdb falls down and lldb-mi would be really, really helpful. See my report in the Chocolatey discussion for this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debugger Feature Request help wanted Can be fixed in the public (open source) repo.
Projects
None yet
Development

No branches or pull requests