Vscode-cpptools: Official support for Clang and LLDB on Linux

Created on 6 May 2020  ·  13Comments  ·  Source: microsoft/vscode-cpptools

Currently LLDB support on Linux for VS Code is lacking. It plainly doesn't work.

There is no official documentation on how to get started with Clang on Linux using the vscode-cpptools either.

Adding official support for Clang/LLDB on Linux would be absolutely awesome. Extending that to Windows would be great too thanks to LLVM's cross-platform nature.

Feature Request debugger docs

Most helpful comment

Okay, so I've tested once again and I've got it working on Ubuntu 18.04.

Here's how:

  1. Install the following packages via apt
sudo apt install clang-10 llvm-10-dev liblldb-10-dev
  1. Create soft links for executable files so things can work as expected
sudo ln -s /usr/bin/clang-10 /usr/bin/clang
sudo ln -s /usr/bin/clang++-10 /usr/bin/clang++
sudo ln -s /usr/bin/lldb-10 /usr/bin/lldb
# This one is a bit strange but VSCode only looks for the name `lldb-server-10.0.0` but not `lldb-server-10`
sudo ln -s /usr/bin/lldb-server-10 /usr/bin/lldb-server-10.0.0
  1. Build the lldb-mi executable from source
git clone https://github.com/lldb-tools/lldb-mi.git
cd lldb-mi
cmake .
cmake --build .
sudo cp src/lldb-mi /usr/bin/

These should be it. And here's my launch.json. Basically just the default one from clang++ preset and changed nothing if I remember it correctly.

{
    // 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": "clang++ - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: clang++ build active file",
            "miDebuggerPath": "/usr/bin/lldb-mi"
        }
    ]
}

@WardenGnaw You may want to give it a try.

All 13 comments

Yeah, it would sort of being a combo of https://code.visualstudio.com/docs/cpp/config-clang-mac (with Mac references change to Linux) and https://code.visualstudio.com/docs/cpp/config-linux (with gcc references changed to clang). The language service should work with clang on Linux, and I've used gdb to debug clang-compiled programs on Linux, but I'm not sure if LLDB debugging is supported on Linux like it is on Mac (@WardenGnaw would know).

Getting LLDB debugging to work on linux would require obtaining the lldb-mi executable.

Once you have that, then you will need to modify the launch.json configuration with:

{
...
"miDebuggerPath": "path/to/lldb-mi".
"miMode": ''lldb"
}

Thanks @sean-mcmanus.

Hey @WardenGnaw, I noticed you mentioned that on a an older closed ticket. But I never managed to make that work on my machine.

I've found lldb-mi file in /usr/bin/ but was unable to make it work when I target it using "miDebuggerPath": "usr/bin/lldb-mi". Something about not being able to find lldb-mi-10?

Does that ring a bell?

Since Ubuntu 20.04 seems to have forgotten to package lldb-mi-10 with lldb I tried using "miDebuggerPath": "usr/bin/lldb-mi-9" after installing lldb-9, but to no avail.

@WardenGnaw can you confirm if "miDebuggerPath": "usr/bin/lldb-mi-9" works for you? Does it have to be specifically "miDebuggerPath": "usr/bin/lldb-mi" in order for debugging to work?

It does not have to be specifically "usr/bin/lldb-mi", it just has to point to a valid debugger that uses the mi interface.

One way to test is to run the binary and see if it responds to -interpreter-exec console "version"

@WardenGnaw it doesn't look like lldb-mi is going to be supported anymore on Ubuntu:

https://bugs.launchpad.net/ubuntu/+source/llvm-toolchain-10/+bug/1872387

Are there any solutions for this? It would be really appreciated if we could use lldb with VS Code.

As it stands we're confined to using older versions of lldb with VS Code, and to be clear I was not even able to get lldb-mi-9 to work properly on Ubuntu 20.04 with VS Code.

For macOS, we build LLDB-MI and ship our own copy for the extension. However, we use the lldb.framework from XCode to not have to worry about updating lldb every time there's a new version.

One workaround will be to build your own copy and point your launch configuration to it with miDebuggerPath. I'll investigate if building a copy on linux works with an installed lldb with the extension.

Update: I just got around getting a build of lldb-mi for Ubuntu 20.04 but running into a bunch of runtime issues.

This build may have to ship liblldb.so and lldb-server.
Requirements on the machile will have to have:

  • clang
  • libpython2.7
  • libncurses5

_Still investigating_

I also met a similar situation when I tried to use clang in vscode on Linux(Ubuntu 20.04) And it tells me miDebuggerPath is a invalid path. So is it actually a bug?

@zbhxlj The llvm group has decided not to ship lldb-mi starting with llvm-toolchain-10.

In order to use clang and lldb, users will need to build lldb-mi from its source and point miDebuggerPath to the built lldb-mi binary.

@WardenGnaw you can compile with no python and no curses and see if that meets the minimum set of requirements.

As for clang, I don't think its unreasonable to assume that clang exists for use with LLDB-MI

Okay, so I've tested once again and I've got it working on Ubuntu 18.04.

Here's how:

  1. Install the following packages via apt
sudo apt install clang-10 llvm-10-dev liblldb-10-dev
  1. Create soft links for executable files so things can work as expected
sudo ln -s /usr/bin/clang-10 /usr/bin/clang
sudo ln -s /usr/bin/clang++-10 /usr/bin/clang++
sudo ln -s /usr/bin/lldb-10 /usr/bin/lldb
# This one is a bit strange but VSCode only looks for the name `lldb-server-10.0.0` but not `lldb-server-10`
sudo ln -s /usr/bin/lldb-server-10 /usr/bin/lldb-server-10.0.0
  1. Build the lldb-mi executable from source
git clone https://github.com/lldb-tools/lldb-mi.git
cd lldb-mi
cmake .
cmake --build .
sudo cp src/lldb-mi /usr/bin/

These should be it. And here's my launch.json. Basically just the default one from clang++ preset and changed nothing if I remember it correctly.

{
    // 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": "clang++ - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: clang++ build active file",
            "miDebuggerPath": "/usr/bin/lldb-mi"
        }
    ]
}

@WardenGnaw You may want to give it a try.

Was this page helpful?
0 / 5 - 0 ratings