Search code examples
rustlldbvscode-debugger

Can't create a conditional breakpoint in VSCode-LLDB with Rust


I'm debugging a Rust program in VS-Code with LLDB.

The documentation on expressions says there's a Python projection of program's vars and structures.

So I check what it is like in the debugger, and set a breakpoint, but the expression does not work.

In Variables section, there's ooo, which is a list, with 0th element that has id and it's 0th element has a value I'm looking for. However expression /se ooo[0]['id'][0] == 135654667 raises IndexError in the Python debugger: IndexError: Index '0' is out of range.

The irony is that when you type that in the debug console, it works and suggests an expression!

enter image description here

I've tried a native Rust expression:

/nat ooo.id().inner_id() == 135654667

The output was

Stopped due to an error evaluating condition of breakpoint 1.1: "ooo.id().inner_id() == 135654667"
Couldn't execute expression:
error: no field named id

...although in the real app the expression does work:

let x = ooo.id().inner_id() == 135654667;
println!("{}", x);

This compiles and prints the id's.

What am I doing wrong?

enter image description here


Solution

  • The support for Rust in the main-line lldb is incomplete. In particular, the expression parser is just the clang expression parser (which doesn't know about Rust). So it will only work on expressions that also parse as C expressions (and use the same calling conventions). And breakpoint conditions are just expressions evaluated when you stop.

    There was an lldb fork with more full Rust support, but it doesn't seem to be actively maintained at present. There's a little more info here:

    https://github.com/rust-lang/lldb/wiki