21

I mostly use gdb for debugging c++ single files in vscode but now want to try lldb but i am facing issues while setting it up for vscode.

I first create default launch.json form debug tab selecting cpp gdb/lldb then clang++ for configuration.

When the debugging starts.. it shows following error:

When the debugging starts.. it shows following error:

then in launch.json I changed miDebuggerPath path form /usr/bin/lldb-mi to /usr/bin/lldb.

Then when I launch the debugger it does NOTHING just debug controls up top and following lines in terminal:

warning: ignoring unknown option: --interpreter=mi
warning: ignoring unknown option: --tty=/dev/pts/1

anything I am missing here?

My whole launch.json is:

{
    // 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"
        }
    ]
}
1

3 Answers 3

10

lldb-mi is not part of the LLDB project. see lists.llvm.org

you can still build it yourself from the project's github repo. you will need to build LLDB/Clang/LLVM first, since lldb-micompilation requires headers and compiled libraries for the build to work as per information stated in the README.

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

Comments

10

As mentioned in this answer, and discussed here, using lldb-mi may not be the best option.

lldb-vscode (https://github.com/llvm/llvm-project/tree/main/lldb/tools/lldb-vscode) works well to enable debugging with lldb in vscode on linux, and is part of the LLDB project. Here are the steps I used (taken from the readme) to set it up on a remote-ssh vscode server (assumes llvm installation exists):

  1. Create the vscode extension
    # Create directory for a new VSCode extension
    $ mkdir -p  ~/.vscode-server/extensions/llvm-org.lldb-vscode-0.1.0/bin
    # Copy the extension package.json from GitHub
    $ wget -P ~/.vscode-server/extensions/llvm-org.lldb-vscode-0.1.0/ 
    https://raw.githubusercontent.com/llvm/llvm-project/main/lldb/tools/lldb-vscode/package.json
    # Copy the lldb-vscode binary to the bin directory
    $ cp $(which lldb-vscode) ~/.vscode-server/extensions/llvm-org.lldb-vscode-0.1.0/bin/
    # Copy the lldb-server binary to the bin directory
    $ cp $(which lldb-server) ~/.vscode-server/extensions/llvm-org.lldb-vscode-0.1.0/bin/
    # also make sure all libraries are found by ldd for the copied binaries,
    # e.g. liblldb.so.13
    
    Now under the extensions tab in vscode on my remote host, "LLDB native Debug stub" is shown
  2. Create a launch.json, for example
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch lldb-vscode",
                "type": "lldb-vscode",
                "request": "launch",
                "program": "${command:cmake.launchTargetPath}",
                "args": [],
                "env": [],
                "cwd": "${workspaceFolder}",
                "stopOnEntry": false,
                "sourceMap": [["/path/a/", "/path/b"]]
            }
        ]
    }
    

Notes for Ubuntu:

In a Ubuntu distro, llvm can be installed from the package manager, e.g. apt install lldb-13. In this case, lldb-server and lldb-vscode are not on the path so the commands above will not work. Taking a look at the installed package:

$ dpkg --search lldb-vscode
lldb-13: /usr/bin/lldb-vscode-13
lldb-13: /usr/lib/llvm-13/bin/lldb-vscode
$ ls -l /usr/bin/lldb-vscode-13
/usr/bin/lldb-vscode-13 -> ../lib/llvm-13/bin/lldb-vscode

$ dpkg --search lldb-server
lldb-13: /usr/lib/llvm-13/bin/lldb-server
lldb-13: /usr/lib/llvm-13/bin/lldb-server-13
lldb-13: /usr/bin/lldb-server-13
lldb-13: /usr/lib/llvm-13/bin/lldb-server-13.0.0
$ ls -l /usr/bin/lldb-server-13
/usr/bin/lldb-server-13 -> ../lib/llvm-13/bin/lldb-server
$ ls -l /usr/lib/llvm-13/bin/lldb-server*
/usr/lib/llvm-13/bin/lldb-server
/usr/lib/llvm-13/bin/lldb-server-13 -> lldb-server
/usr/lib/llvm-13/bin/lldb-server-13.0.0 -> lldb-server

Therefore, for Ubuntu, for example, cd ~/.vscode-server/extensions/llvm-org.lldb-vscode-0.1.0/bin and do:

$ cp /usr/lib/llvm-13/bin/lldb-vscode .
$ cp /usr/lib/llvm-13/bin/lldb-server .
# make the same symlinks as in the package
$ ln -s lldb-server lldb-server-13
$ ln -s lldb-server lldb-server-13.0.0

4 Comments

I got unable to locate lldb-server-14.0.0 error, and it suggests to Open 'launch.json'. What option do I need to add? ps. I've added symlink to lldb-server-14 with the name lldb-server-14.0.0, no effect.
@amordo try $ cp $(which lldb-server) ~/.vscode-server/extensions/llvm-org.lldb-vscode-0.1.0/bin/. If that works I'll edit the answer to add that
stranger things, it works in the extension bin directory if the name exactly matches the name in error. So in my case I have ~/.vscode-server/extensions/llvm-org.lldb-vscode-0.1.0/bin/lldb-server-14.0.0, not lldb-server, nor lldb-server-14. ty!
Heads up to anyone reading this, lldb-vscode has been renamed to lldb-dap.
5

CodeLLDB extension works perfectly in Ubuntu docker container launched in Windows 10. It suggests some predefined configs.
I had troubles with gdb that threw out core-dump on multithreaded application; lldb-vscode also required some efforts as discussed in comments of Joe's answer.
PS: Container has gcc clang lldb installed by apt, maybe they are necessary for the plugin to work (maybe not)🙂 enter image description here

Comments

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.