Open PhilParisot opened 4 years ago
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?
Oh I think it's a bug on Ubuntu's side https://bugs.launchpad.net/ubuntu/+source/llvm-toolchain-10/+bug/1872387
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:
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:
apt
sudo apt install clang-10 llvm-10-dev liblldb-10-dev
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
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.
@iamWing, thanks for the instructions.
I've also had to install liblldb-dev
in addition to liblldb-11-dev
on Debian testing (bullseye).
After following the above steps, I see the following errors when trying to use lldb
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
ERROR: Unable to start debugging. Unexpected LLDB output from command "-exec-run". process launch failed: unable to locate lldb-server-10.0.1
The program '/home/arpit/assign/dirt-arpit15/build-Debug/00_dirt_tutorial' has exited with code 42 (0x0000002a).
Any hints as to why this might be the case.
created a symbolic link using the following command.
sudo ln -s /usr/bin/lldb-server-10 /usr/bin/lldb-server-10.0.1
I got the same 'unable to locate lldb-server-XX.X.X' message. In my case it was "process launch failed: unable to locate lldb-server-12.0.0"
I had previously been obliged to build lldb-mi from source, and the resulting executable wound up in /usr/local/bin. On a hunch, I made a link in /usr/local/bin for lldb-server-12.0.0 that pointed back to the system lldb-server-12. After a restart, the 'unable to locate' error went away.
After spending all day tearing my hair out, @iamWing's solution above worked for me, with minor adjustments for llvm 12. Similar to @kevinpowell, my lldb-server-XX.X.X wasn't found, but I was told it expected version 12.0.1. So after switching the version in the symbolic link name I was good to go.
Curiously, I do not see any output from my Hello World application, so I guess that's my next hurdle.
I hope this issue in VSCode gets sorted out soon. It shouldn't be this hard to get the Clang/LLVM toolchain to work with VSCode.
Okay, so I've tested once again and I've got it working on Ubuntu 18.04.
Here's how:
- Install the following packages via
apt
sudo apt install clang-10 llvm-10-dev liblldb-10-dev
- 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
- Build the
lldb-mi
executable from sourcegit 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 fromclang++
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.
Thanks. Also work well on Ubuntu 20.04
Work on WSL2: Ubuntu-18.04 using @iamWing Solution. LLDB could be launched successfully. But still struggling in std::cin debugging using LLDB (providing input to the program on stdin). Related open issue: #6715
This is what I had to do in an Ubuntu 21.04 container (mcr.microsoft.com/vscode/devcontainers/cpp:0-ubuntu-21.04):
sudo apt update
sudo apt install liblldb-12-dev
sudo ln -s /usr/bin/lldb-server-12 /usr/bin/lldb-server-12.0.0
sudo rm /usr/bin/lldb-mi
git clone https://github.com/lldb-tools/lldb-mi.git
cd lldb-mi
cmake .
cmake --build .
sudo cp src/lldb-mi /usr/bin/
I added these commands to the Dockerfile in the .devcontainer folder, this way they are executed automatically and the result is cached, so subsequent container rebuilds are quick:
RUN sudo apt update && sudo apt install liblldb-12-dev && sudo ln -s /usr/bin/lldb-server-12 /usr/bin/lldb-server-12.0.0 && sudo rm /usr/bin/lldb-mi && git clone https://github.com/lldb-tools/lldb-mi.git && cd lldb-mi && cmake . && cmake --build . && sudo cp src/lldb-mi /usr/bin/ && cd .. && rm -r lldb-mi && sudo apt remove -y liblldb-12-dev && sudo apt clean
For lldb debug, please remove the dependency for lldb-mi. Since Llvm guys has removed lldb-mi from llvm main project, lldb-mi started to pop out various issues.
Latest lldb-mi cannot even build on Ubuntu20 LTS, which is the most popular Linux distro. Check https://github.com/lldb-tools/lldb-mi/issues/90
Even it can build, it does not even have an installation package. So the people has to build/install the package, which is so frustrating process.
I once asked if llvm guy can move lldb-mi back to their project. So it at least can be released with llvm and has a installation package. But my suggestion got rejected, https://github.com/llvm/llvm-project/issues/54453
So please remove the dependency on lldb-mi and call lldb api directly. I also filed the request here: https://github.com/microsoft/vscode-cpptools/issues/9062#issuecomment-1075458878
Thanks.,
@WardenGnaw , you mentioned "For macOS, we build LLDB-MI and ship". As a workaround for removing dependencies on lldb-mi, can you do the similar thing for Linux? Latest lldb-mi code cannot even compile on Linux and there is no active maintenance for it..... very frustrating.
Even it can build, it does not even have an installation package.
Something that does get installed is their own debug adapter: https://github.com/llvm/llvm-project/tree/main/lldb/tools/lldb-vscode#introduction https://packages.ubuntu.com/impish/amd64/lldb-13/filelist But oddly they never uploaded it as an extension package to the marketplace.
@WardenGnaw , you mentioned "For macOS, we build LLDB-MI and ship". As a workaround for removing dependencies on lldb-mi, can you do the similar thing for Linux?
That would probably be the best solution for this extension.
I know it's not ideal, but I just use Clang on MacOS, Linux and Windows, and I use a different debugger for all the different platforms, GDB on Linux, the VS debugger one on Windows and LLDB on MacOS, it all works fine with Clang for my purposes.
Having this extension work with LLDB (lldb-mi) on all platforms would still be ideal however
To make it work, it's not necessarily to depends on lldb-mi. vscode-lldb does not depend on lldb-mi, https://github.com/vadimcn/vscode-lldb. It works pretty well.
Can hardly believe VSCode still ships with lldb
not working out-of-the-box. Should be using vscode-lldb
which is llvm
's "official" extension. (I'm interested in Linux support first, then Windows.)
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.