-
Notifications
You must be signed in to change notification settings - Fork 0
CodeLLDB
In contrast to Microsoft's C/C++ extension, clangd does not come with a debugging feature. Instead, we will use the CodeLLDB extension together with the lldb debugger.
To install/enable the extension, follow the same steps as in the previous sections.
To use the debugger in VS Code, we have to provide a launch.json
file.
Fortunately, CodeLLDB makes it fairly easy to generate a basic template:
- Click on
Run and Debug
in the activity bar - Choose
create a launch.json file
- Select
LLDB
This creates a launch.json
in our project settings folder .vscode
:
Before using the debugger, it is probably a good idea to compile our code in debug mode. If you haven't done so,
- Run
>CMake: Select a Variant
and selectDebug
- Run
>Cmake: Build
This creates a new build directory (build.Clang-19.1.2-Debug
in our case).
Now open again the launch.json
file and apply the following changes:
To set a breakpoint,
- Open the source file
./examples/ex2.cpp
- Click next to the line number 9
The red dot indicates that a breakpoint has been set on this specific line.
- Click on
Run and Debug
in the activity bar - Click the green play icon next to
Debug ex2
- Start debugging
We can now examine variables, step into functions, etc.
It is also possible to use the usual commands in the Debug Console:
If we want to debug a different executable or run the same executable with different input arguments, we can simply add a new configuration to the launch.json
file and select the configuration from the drop down menu next to the green play icon in the Run and Debug
window: