Understanding the rust-lldb for making conditional breakpoints

Hello,

I am debugging in Rust using the lldb-rust debugger (As I understand it, simply lldb with a python script to format Rust types into something readable).

I have an issue when I want to make condition breakpoints, where what is displayed is not the same as what I am actually accessing under all the formatting rules.

Below I have a variable which looks fine:

(lldb) var technician->__1.skill_hours
(std::collections::hash::map::HashMap<shared_types::scheduling_environment::worker_environment::resources::Resources, shared_types::scheduling_environment::work_order::operation::Work, std::hash::random::RandomState>) technician->__1.skill_hours = size=3 {
  [0] = {
    0 = MtnMech
    1 = {
      0 = {
        flags = 65536
        hi = 0
        lo = 6318
        mid = 0
      }
    }
  }
}

Now I want to make a breakpoint saying:

breakpoint <relevant file and line in source code> --condition 'technician->__1.skill_hours.<WHAT TO WRITE HERE?>

The only available field that I can find is the .base which will yield:

(lldb) var technician->__1.skill_hours.base
(hashbrown::map::HashMap<shared_types::scheduling_environment::worker_environment::resources::Resources, shared_types::scheduling_environment::work_order::operation::Work, std::hash::random::RandomState, alloc::alloc::Global>) technician->__1.skill_hours.base = {
  hash_builder = {
    k0 = 12774794751665827137
    k1 = 1019342888363619915
  }
  table = {
    table = {
      bucket_mask = 3
      ctrl = {
        pointer = 0x00007fffe80227d0
      }
      growth_left = 0
      items = 3
    }
    alloc =
    marker =
  }
}

This is completely different and I assume is related to lower level details of how Rust handles a HashMap.

Does this mean that you cannot readily make conditional breakpoint on many of the Rust types?

Without going in too much on you specific example, and speaking very generally: There are known issues with the rust-lldb integration. There are some mentions about these issues on these forums if you search for rust-lldb, and you can find a few github issues related to it as well.

I wouldn't trust rust-lldb much beyond very trivial use-cases in its current state.

1 Like

What a shame! It feels like debugging complex algorithms in rust is significantly more tedious than in the C++ equivalent then.

Do you know if there is a strong IDE for this?

Unfortunately I tend to work with a pretty spartan setup myself, so I'm probably not the right person to ask. However, some of the best debugging experiences I've had with Rust is - brace yourself - using Visual Studio, using remote debugging, no less. In fact, Microsoft employees have, on these forums even, mentioned that they have done work to improve Rust debugging, and are looking for feedback if one finds problems.

If you're not opposed to working on Windows, I would suggest you try using Visual Studio for debugging and see if it scratches your specific itch.

Though with that said, improving the rust-lldb situation is on my todo list (I have a few pathological debugging cases that reliably trigger problems in rust-lldb), but there's unfortunately a lot of other things with higher priority.

Thank you, I will try opening it in the visual studio debugger.

My problem is that I work with multi-threaded randomized algorithms and this means that without conditional breakpoints and watchpoints it is often unlikely that I will find what I am debugging for by simply stepping through the code and inspecting the state.

My current workflow consists of huge helper modules (~1000-3000 LOC per algorithm module) where I call functions in the source code to inspect the state of the program. This is a little tedious in the long run but maybe this is just the best approach with Rust. I am just afraid that I am wasting a lot of time.

My understanding is that debuggers are not used as often in Rust as they are in other languages like C++. See this older thread for a discussion on the topic:


Edit: Sorry, I missed that you were already discussing this on a separate topic. I'll leave the link here for posterity.

My understanding is that rust-gdb is a bit better than rust-lldb. Though I have only used the former, so I can't say for sure.

That is on Linux x86-64 at least. I believe gdb doesn't work well on MacOS X. Again, based on hearsay.

Debugging rust is often not needed, but when it is, the tooling isn't great.

And for this specific issue I don't know that gdb would help. In fact, pretty printed types from C++ standard library tend to also have this issue as far as I know.