Visual Studio Code

Is anyone using Visual Code Studio or Clion to develop LLVM and MLIR?

I’m wondering if there is some simple setup and ways to debug programs in either of these.

My preference is Visual Code Studio, but I have Clion also.

TIA.

Reed

I am using VS Code for LLVM development. I compile Clang + LLVM with -DCMAKE_BUILD_TYPE=Debug. Then, the created libraries and executables already contain debug information. Hence, GDB startup is reasonably fast since it does not have to create a symbol table each time it starts up.

I use a normal C++ debug configuration, the only major thing I have added is the following entry:

"setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Enable LLVM pretty printing",
                    "text": "source ${env:SPU_LLVM_INSTALL_DIR}/../llvm/utils/gdb-scripts/prettyprinters.py",
                    "ignoreFailures": true
                },
                {
                    "description": "Skip standard library files",
                    "text": "skip -gfi /usr/include/c++/11/bits/*.h",
                    "ignoreFailures": true
                },
            ]

The “Enable LLVM pretty printing” command uses referenced script in llvm/utils, leading to some LLVM-specific data types being displayed more nicely than would be the case without that.

When I want to debug into Clang compiling a binary, I use clang++ as the to-be-debugged program and add any command line arguments to it via "args": [] in the debug configuration.

I hope this helps!

You may find clangd (vscode extension) to give better results than Microsoft’s C++ VSCode plugin (which it will prompt you to install by default).

It relies on compile_commands.json describing your project. CMake will produce this, if your cmake build directory is llvm-project/build then clangd will be able to find it automatically. (It provides completion/diagnostics/navigation etc, but you’ll need some other adapter for debugging: there are plugins available for LLDB and GDB).

1 Like

+1 for clangd because it enables use of http://clangd-index.llvm.org/, the clangd remote index for LLVM, which saves a lot of CPU time spent on indexing when navigating this huge monorepo.

1 Like