How do you guys do debugging in Rust?

Yes I mean watchpoints on variables or values of custom Debug implementations. For complex types I usually implement a custom Debug trait. This means that when the Debug::fmt() function is called it will print values that are not necessarily part of the struct or enum that the Debug is implemented on. For example:

struct Data {
    vec: Vec<T>
}

impl std::fmt::Debug for Data {
    fn fmt(&self, f: &mut fmt::Formatter<`_> -> fmt::Result {
        write!(f, "{}", format!("Data {{ vec: {:?} }}\nlength: {}", &self.vec, self.vec.len())
    }
}

Which could yield:

Data { vec: [1, 2, 3, 4] }
length: 4

Would it be possible to make a debugger that could watch for when length >= 5 for example? This is very custom, but it could make the debugger very powerful.

Do you have a sponsor page on github? Are you still actively developing the debugger?

Interesting. I assume that they are basing their debugger on lldb in the same way as in vs code?

Can you make conditional breakpoints on variables with the Rust Rover debugger?

Yep, currently with BS you can do this (GitHub - godzie44/BugStalker: Rust debugger for Linux x86-64):

watch (~vec).len

This will set a watchpoint on the vector length and your program will stop when it changes. (~vec means using the original vector representation with capacity and length). Unfortunately, conditions are not supported now.

Yes, I'm developing the debugger in the "develop" branch. I think the new feature release will be available within 3-4 months. If you are interested in conditional breaks (and watchpoints), just create an issue. I think I will be able to implement this within a reasonable time frame.

1 Like

I guess the question was "is it possible to set a watchpoint on something exposed only through Debug implementation, ideally without breaking on each change in Debug output, but only on the relevant part?", since in the example vec is not a directly observable variable, but a private field inside one. Or privacy don't matter here?

I can't speak to this specific one, but yes, traditionally at least debuggers ignore visibility, debuggers normally need to reimplement expression evaluation anyway and they already have access to private names for being able to dump the internal structure of types via debug info.

It doesn't matter, so you can do somethink like:

watch (~my_struct.vec).len
1 Like