CodeLLDB extension
Learn how to install and configure the CodeLLDB extension in VS Code to debug Rust programs with breakpoints, variable inspection, and step-by-step execution.
CodeLLDB brings debugging into VS Code for Rust and other native languages. While rust-analyzer gives you code completion, navigation, and error squiggles, it cannot pause your program mid-run, inspect the values stored in variables, or let you execute code one line at a time. That is exactly what CodeLLDB does. This page explains what CodeLLDB is, why you need it for Rust development, how to install it, and how to use it to debug a simple Rust program.
What is a debugger?:
A debugger is a tool that lets you run your program in slow motion. You can tell the program to stop at a certain line (a breakpoint), then look at the current values of all variables, and decide whether to continue running normally or step line by line. Without a debugger, you would have to add temporary println! statements everywhere just to see what is happening inside your code.
The problem CodeLLDB solves
When you write Rust code, the compiler produces a binary file that the computer executes. That binary is made of low-level machine instructions, not the readable Rust source you typed. When something goes wrong at runtime - a wrong value, a panic, an infinite loop - you need a way to connect the running binary back to the original source code.
That connection is provided by debugging information. When you compile with debug symbols enabled, the binary contains a map that says, "this machine instruction came from line 47 of main.rs" and "this memory location holds the variable named count". A debugger reads that map and shows you the source code while the program is frozen at a chosen point.
VS Code has a built-in debugging interface, but it does not know how to speak to native compiled languages like Rust or C++ by itself. CodeLLDB is an extension that plugs into VS Code's debugger and understands the format used by LLDB, a popular debugger engine. LLDB itself knows how to talk to the operating system, read debug symbols, and control the running process.
For a beginner, the chain looks like this:
VS Code Debug UI -> CodeLLDB extension -> LLDB -> your running Rust program
You interact only with the leftmost part. The rest happens automatically.
Do you need CodeLLDB to run Rust?:
No. You can compile and run Rust programs without any debugger. Many developers use println! to investigate problems. But once a program grows beyond a few functions, stopping execution and inspecting live state becomes dramatically faster and less error-prone than sprinkling prints and recompiling.
Installing the CodeLLDB extension
Installation happens through the VS Code marketplace, just like any other extension.
Step 1: Open the Extensions view
In VS Code, click the square Extensions icon in the left sidebar, or press Ctrl+Shift+X (Windows/Linux) or Cmd+Shift+X (macOS). A search bar appears at the top of the panel.
Step 2: Search for CodeLLDB
Type CodeLLDB into the search bar. Look for the extension named CodeLLDB with the publisher vadimcn. The official marketplace ID is vadimcn.vscode-lldb. Avoid similarly named extensions that are not from this publisher.
Step 3: Install the extension
Click the blue Install button. After a few seconds, the button changes to Uninstall, which means the extension is active. No separate LLDB installation is needed - CodeLLDB bundles its own copy of the debugger engine, so it works out of the box on Windows, macOS, and Linux. (The current release is v1.12.3, which bundles LLDB v22.1.8.)
Step 4: Verify the installation
Open the Extensions view again (Ctrl+Shift+X / Cmd+Shift+X) and confirm CodeLLDB is listed and enabled - the Install button should now read Uninstall. Then open the Run and Debug view (Ctrl+Shift+D / Cmd+Shift+D); with a Rust project open, the debug configuration dropdown should offer a CodeLLDB ("lldb") launch type once you create a launch.json file, which is the next step on this page.
Note that there is no lldb command on your terminal's PATH - CodeLLDB keeps its bundled copy of LLDB inside the extension and manages it internally, so running lldb --version in a terminal will fail even when the extension is working perfectly. That is expected, not a problem.
Installation successful:
If you see the CodeLLDB extension listed in your Extensions panel and no error notifications appeared, you are ready to configure a debug session. The next step creates a launch.json file that tells VS Code how to start your Rust program under the debugger.
Creating a Rust project to debug
Before you can debug, you need a Rust program that compiles and runs. For this example, create a new binary project:
cargo new debug-demo
cd debug-demo
Replace the contents of src/main.rs with the following small program. It contains a function that adds two numbers and a loop that accumulates a total. This gives us several places where pausing execution will be useful.
fn add_numbers(a: i32, b: i32) -> i32 {
a + b
}
fn main() {
let mut total = 0;
for i in 1..=5 {
total = add_numbers(total, i);
println!("Current total: {}", total);
}
println!("Final total: {}", total);
}
The program runs fine on its own, but suppose you were confused about how total changes across iterations. Instead of printing more lines, you will use a debugger to stop at the line inside the loop and inspect total before and after the call to add_numbers.
Compile the project once to make sure it builds:
cargo build
Debug symbols must be present:
By default, cargo build generates a binary with debug symbols enabled, so the debugger can map machine code back to Rust source. If you ever compile with cargo build --release, the release profile does not include debug symbols by default (debug = false) - the binary is heavily optimized, and optimization can reorder instructions and make variables appear "optimized away" in the debugger. For the best beginner experience, use a debug build (cargo build or cargo run) while learning to debug. If you must debug a release build, add [profile.release] debug = true to your Cargo.toml.
Creating a launch configuration
VS Code needs a small JSON file that describes how to launch your program for debugging. This file is named launch.json and lives in a .vscode folder in your project root. You can create it manually or let VS Code generate a template.
Generating the file automatically
Open the Run and Debug view by clicking the play icon with a bug in the left sidebar (or press Ctrl+Shift+D / Cmd+Shift+D). If no launch configuration exists, VS Code shows a button labeled "create a launch.json file". Click it, choose CodeLLDB from the list, and then pick Rust if prompted. VS Code creates a .vscode/launch.json file with sensible defaults for your project.
That generated file will look similar to the one below, though the exact paths may differ.
Writing the file manually
Create a folder named .vscode in the project root, then create a file named launch.json inside it. Paste the following:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable",
"program": "${workspaceFolder}/target/debug/debug-demo",
"args": [],
"cwd": "${workspaceFolder}",
"sourceMap": {
"/rustc/*": "${env:HOME}/.rustup/toolchains/*/lib/rustlib/src/rust/*"
}
}
]
}
Let's break down each part of this configuration:
"version"is the format version of the file;0.2.0is the standard value."type"tells VS Code which debug adapter to use."lldb"is the type registered by CodeLLDB (older configurations might use"codelldb", but"lldb"is preferred)."request"set to"launch"means VS Code should start your program from scratch."name"is the label shown in the debug dropdown; you can change it to anything."program"is the absolute path to the compiled binary.${workspaceFolder}is a placeholder that VS Code replaces with the path to the folder you opened in VS Code. The binary name matches your project name (debug-demo)."args"is a list of command-line arguments passed to your program; it is empty here."cwd"sets the working directory when the program starts; the project root is typical."sourceMap"helps the debugger locate Rust standard library source code when you step into a standard library function. The value shown is a common pattern for Unix-like systems; Windows paths may differ. If stepping into the standard library is not something you need yet, you can omit this field entirely.
The sourceMap line can cause confusion because it uses a glob pattern. It maps compiler-internal paths (like /rustc/abc123.../library/std/src/...) to your local Rust toolchain source. If you are on Windows, the value might look like "C:/Users/YourName/.rustup/toolchains/*/lib/rustlib/src/rust/*". If you do not plan to step into std functions, leave it out.
Binary name must match your project:
In the "program" field, the last part after /target/debug/ must be exactly the name of your binary. For a project named debug-demo, the binary is debug-demo. If you rename the project, update this field. If you see an error like "file not found" when starting the debug session, check this path first.
Starting your first debug session
Now that the configuration exists, you can begin debugging.
Step 1: Set a breakpoint
Open src/main.rs in the editor. Click in the narrow gutter to the left of the line numbers, next to the line total = add_numbers(total, i);. A red dot appears. That dot is a breakpoint - the debugger will pause execution every time the program reaches that line.
Step 2: Start debugging
Open the Run and Debug view (Ctrl+Shift+D / Cmd+Shift+D). At the top, ensure "Debug executable" is selected in the dropdown. Click the green play button. The bottom of the window changes to show a Debug Console and a set of debug controls.
Step 3: Observe the pause
The program starts, enters main, and begins the loop. The first time it reaches the breakpoint line, execution stops. The line in the editor is highlighted. The Variables panel on the left shows total with value 0 and i with value 1.
Step 4: Continue and repeat
Press the Continue button (the blue triangle) in the debug toolbar. The program resumes, prints Current total: 1, and immediately hits the breakpoint again on the next loop iteration. Now total is 1 and i is 2. Continue through all five iterations and watch total grow.
Breakpoint hit = debugging works:
If you see the program pause at the line with the red dot and the Variables panel updates with live values, your CodeLLDB setup is working correctly. You have successfully connected VS Code to your running Rust program through LLDB.
Controlling execution with step actions
Breakpoints are only one tool. The debug toolbar has several step buttons that give you fine-grained control.
- Continue (F5): Run until the next breakpoint or the program ends.
- Step Over (F10): Execute the current line and pause on the next line in the same function.
- Step Into (F11): If the current line calls a function, jump inside that function and pause at its first line.
- Step Out (Shift+F11): Run until the current function returns and pause at the call site.
- Restart (Ctrl+Shift+F5): Stop the current debug session and start it again from the beginning.
- Stop (Shift+F5): End the debug session and stop the program.
Let's practice these with the example. Set a breakpoint on the line total = add_numbers(total, i);. When execution pauses there:
- Press Step Into. The debugger jumps to the first line of
add_numbers, which isa + b. The Variables panel now showsaandbwith their current values. - Press Step Over. The function computes
a + band is about to return. Press Step Out to return tomainand see the result assigned tototal. - Now press Step Over again. The debugger moves to the
println!line. Press Step Over once more to execute the print and move to the next iteration.
This slow-motion walk gives you a mental model of how Rust moves through your code - when functions are entered, what values they receive, and what they return.
Step Over vs Step Into:
If the line does not contain a function call, Step Over and Step Into behave the same. The difference matters only on lines with function calls. Use Step Over when you trust the function and just want to see its result; use Step Into when you suspect the bug is inside that function.
Inspecting variables and the call stack
While paused, the left side of VS Code shows two panels: Variables and Call Stack.
The Variables panel lists all variables currently in scope, their types, and their values. For primitive types like i32, the value appears directly. For String, Vec, and other complex types, CodeLLDB uses Rust-aware visualizers to show the contents in a readable way - for example, a Vec<i32> appears as a list of numbers, not raw memory bytes.
The Call Stack panel shows the chain of function calls that led to the current line. When you are paused inside add_numbers, the call stack shows two entries: add_numbers at the top and main below it. Clicking on main jumps the editor to the call site, and the Variables panel updates to show main's local variables. This is extremely useful when you have nested calls and need to understand "how did I get here?"
You can also hover over any variable in the editor while paused to see its value in a popup. Right-clicking a variable gives options to Add to Watch, which pins that variable to a dedicated Watch panel so you can monitor it across multiple pauses.
Conditional breakpoints and logpoints
Plain breakpoints stop every time the line is reached. That can be noisy in loops with thousands of iterations. Suppose you only care about the state when i equals 3. Right-click on the red breakpoint dot and choose Edit Breakpoint. In the condition field, type:
i == 3
Now the program will only pause when i is exactly 3. The breakpoint dot becomes a red diamond instead of a circle to indicate a condition.
A logpoint is similar but instead of pausing, it prints a message to the Debug Console and keeps running. Right-click a breakpoint and choose Edit Breakpoint, then select Logpoint instead of Breakpoint. In the expression field, type a message with variables inside curly braces:
i={i}, total={total}
Each time execution reaches that line, the debugger prints i=1, total=0, then i=2, total=1, and so on, without stopping. Logpoints are a middle ground between temporary println! statements and full breakpoints - they work only during a debug session and do not require modifying your source code.
Logpoints need a running debug session:
Logpoints only produce output when you start the program through the debugger. If you run cargo run normally, the logpoint messages will not appear. They are not part of your Rust code; they are instructions for the debugger.
Launching the debugger in an external terminal
Sometimes your program expects to read from the keyboard or interact with the terminal in ways the internal Debug Console cannot handle. CodeLLDB can launch your program in an external terminal window instead. Modify your launch.json configuration by adding the following field:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug in external terminal",
"program": "${workspaceFolder}/target/debug/debug-demo",
"args": [],
"cwd": "${workspaceFolder}",
"terminal": "external"
}
]
}
When you start this configuration, a separate terminal window opens and your program runs there. The debugger still pauses execution, but all input and output goes to that external window. The Debug Console remains available for debugger commands and logpoint output.
The default behavior without the "terminal" field is "integrated", which uses VS Code's internal terminal for the program's stdin/stdout. If your program does not need terminal interaction, the integrated terminal is more convenient.
Program stops but terminal disappears:
When debugging in an external terminal, the terminal may close immediately when the debug session ends. If your program finishes normally, you may not see the final output. To prevent this, add a temporary read_line or infinite loop at the end of main while debugging, or set a breakpoint on the last line so the program pauses before exiting.
Attaching to a running process
In some scenarios, your program is already running and you want to start debugging it without restarting it. This is called attaching. For example, a web server like an Axum application might be serving requests, and you want to inspect what happens when a particular request arrives.
Create a second configuration in launch.json with "request": "attach" and a process ID:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable",
"program": "${workspaceFolder}/target/debug/debug-demo",
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "attach",
"name": "Attach to process",
"pid": "${command:pickMyProcess}"
}
]
}
The "pid" field with "${command:pickMyProcess}" tells CodeLLDB to show a list of running processes when you start this configuration. You pick the one you want, and the debugger attaches to it. The program freezes at whatever point it was at, and you can set breakpoints before pressing Continue.
For this to work, the running program must have been compiled with debug symbols, and you may need elevated permissions on some operating systems to attach to processes you do not own. Attaching is an advanced feature - if you are just starting out, stick with the launch configuration.
Attach vs Launch:
Launch starts the program fresh under the debugger. Attach connects to an already-running program. For most beginner debugging sessions, launch is simpler. Attach becomes useful when reproducing a bug requires a specific environment or when the program is started by another tool.
Rust-specific data visualization
CodeLLDB includes built-in visualizers for common Rust standard library types. When you look at a variable of type String, you see the actual text. A Vec<i32> appears as a list of numbers with its length. A HashMap<String, i32> shows key-value pairs. This is not automatic for all debuggers - LLDB normally shows raw memory addresses. CodeLLDB ships with Python scripts that tell LLDB how to interpret Rust's layout.
This means you can often debug Rust code without manually expanding raw bytes. If you ever see a variable displayed as a memory address or a blob of bytes, the type is probably not one of the built-in visualizers, but most common types are covered.
The sourceMap field in launch.json also allows you to step into Rust standard library source code if you need to understand exactly what a standard function does. That is a more advanced use case and not necessary for everyday debugging.
Troubleshooting common beginner issues
Even with a correct setup, you may run into a few predictable problems.
"File not found" when starting the debugger
This means the path in "program" does not point to an existing binary. Common causes:
- You have not built the project yet. Run
cargo buildfirst. - The binary name in
"program"does not match your project name. CheckCargo.tomlfor the package name. - You opened VS Code in a different folder than the project root.
${workspaceFolder}points to the folder you opened, not necessarily the folder containingCargo.toml.
Breakpoints are gray and never hit
If the breakpoint appears as a hollow circle instead of a filled red dot, the debugger could not bind it to the running code. This usually means the debug symbols do not match the source file. Rebuild with cargo build and restart the debug session. Also check that you are editing the same file that was compiled.
"Unable to start debugging" with no other details
This can happen on Windows if the extension cannot find its bundled LLDB. Reinstall CodeLLDB and restart VS Code. Ensure no antivirus software is blocking the extension's native components.
Variables show as "optimized away"
This happens in release builds or when Rust's optimizer removes a variable because it is not needed. Switch to a debug build (cargo build) and the problem usually disappears. If you must debug a release build, consider adding [profile.release] debug = true to Cargo.toml.
Do not debug without a breakpoint:
If you start a debug session with no breakpoints and the program runs to completion, you will not see any debugging information. The program will just finish, and the debugger will stop. Always set at least one breakpoint before starting the debugger. If you want the debugger to pause as soon as the program starts, add "stopOnEntry": true to the launch configuration - the debugger then stops on the first line of main before running anything. You can also press the Pause button in the debug toolbar right after starting; it freezes the program wherever it happens to be.
Summary
CodeLLDB closes the loop between editing Rust and understanding how it runs. With rust-analyzer handling code intelligence and CodeLLDB handling execution inspection, VS Code becomes a complete Rust development environment. The ability to pause a program, inspect every variable, and step through code line by line is one of the most effective ways to understand both your own logic and Rust's behavior.
The workflow you now know - set a breakpoint, start the debugger, step through code, inspect variables - transfers directly to larger Rust projects, including Axum web applications. When you encounter a handler that returns the wrong response or a state update that behaves unexpectedly, you will be able to attach the debugger, freeze the request mid-flight, and see exactly what the application sees.
If you want to explore further, the CodeLLDB extension supports remote debugging, hardware watchpoints that trigger when a memory address changes, and even Python scripting for custom debugger behavior. None of those are needed for a beginner, but they show the depth available as your debugging skills grow.