Skip to content

Latest commit

 

History

History
151 lines (91 loc) · 4.44 KB

File metadata and controls

151 lines (91 loc) · 4.44 KB

CodeLLDB

To debug a Rust application or C++ application, you can use the CodeLLDB DAP server.

Rust Application

Let's debug the following main.rs Rust file:

fn main() {
  let name = "world";
  println!("Hello, {}!", name);
}

Set Breakpoint

You will need to install cargo, which is used to create a Rust application with cargo init and to build an executable with cargo build.
The executable is required for debugging.

Initialize Rust Application

cargo init

This command generates a Rust application with a src/main.rs file. Update this file with the following content:

fn main() {
  let name = "world";
  println!("Hello, {}!", name);
}

To debug the Rust application, you first need to build the executable that will be used by the debugger. In the project directory, run:

cargo build

This will generate an executable in the target/debug folder.

Target executable

Configure DAP server

  1. Create a DAP Run/Debug configuration:

    DAP Configuration Type

  2. In the Server tab, click on create a new server:

    Create a new server

  3. A new dialog will open to create a DAP server. Select the CodeLLDB template:

    Select Template

  4. After clicking the OK button, the new server will be selected and the configuration automatically pre-filled:

Select New server

  1. Enable DAP server traces

If you wish to show DAP request/response traces when you will debug:

Show DAP traces

you need to select Trace with verbose.

Set verbose traces

Configure file mappings

To allows settings breakpoints to Rust files, you need configure mappings in the Mappings tab. As you have selected CodeLLDB server, it will automatically populate the file mappings like this:

File mappings

Configure the executable to run/debug

Since you selected the CodeLLDB server, the Launch configuration will be automatically populated like this:

  1. Launch as Debug mode should be selected.
  2. The DAP parameters of the launch should look like this:
{
  "type": "lldb",
  "name": "Launch Rust file",
  "request": "launch",
  "program": "${file}",
  "cwd": "${workspaceFolder}"
}

You also need to select the executable in the File field:

DAP Configuration/Configuration

Set Breakpoint

After applying the run configuration, set breakpoints in files that match the file mappings. For example, set a breakpoint in the main.rs file:

Set Breakpoint

Debugging

You can start the run configuration in either Run or Debug mode.

The first time you run it, CodeLLDB, the DAP server, will be downloaded and installed:

Debugging / Installing

If you encounter an error during installation, go to the Installer tab, update the Installer Descriptor , and run Run Installation again:

Installer

Once started, you should see DAP traces in the console:

Debugging / Console

You will also see Threads and Variables:

Debugging / Threads

You can open the Disassembly view to debug step-by-step instructions at the assembly level:

Debugging / Disassembly

Language Support

If you need language support for Rust (completion, validation, etc.), you can configure the Rust Language Server.

Rust demo

C++ Application

TODO

Language Support

If you need language support for C++ files (completion, validation, etc.), you can configure the Clangd Language Server.