blog.dbrgn.ch

Breakpoints Not Working With VS Code + Rust + LLDB

written on Sunday, December 20, 2020 by

(Note: This blogpost does not include any instructions on how to actually set up a launch config for debugging Rust code. There are plenty of tutorials for that already.)

When you debug a Rust binary in VS Code with LLDB, and the breakpoints don't seem to work, try the following steps:

1. Settings: Allow breakpoints everywhere

In the VS Code settings, ensure that "Allow Breakpoints Everywhere" is checked.

2. Ensure that LLDB is working

Next, ensure that LLDB is working properly by adding a manual breakpoint on a symbol that's sure to exist. In the left toolbar, click the "Run/Debug" icon (or press Ctrl+Shift+D). In the lower left corner you should now see a section called "Breakpoints". Click on the "+" icon and add a breakpoint on "main".

If you now start the debugger with F5, it should first stop at some assembly instructions. Press F5 again to continue, now you should be in Rust's main function. If this works, then you can be sure that LLDB itself is set up correctly. (If not, you should try to fix that.)

3. Check for symlinks

This one is the problem that bit me: VS Code does not hit breakpoints when source path contains symlinks. The reason is that the Rust compiler normalizes file paths before writing the paths into the debug symbols.

There are two ways to solve this: Either open the project at the non-symlinked location, or add a source map to your launch config:

{
  "type": "lldb",
  ...
  "sourceMap": {
    "<original-path>": "<symlinked-path>"
  }
}

(Of course, replace the two <original-path> and <symlinked-path> placeholders with your actual paths.)

With this, setting breakpoints should work. Happy debugging!

This entry was tagged debugging, lldb, rust and vscode