Chapter 7, "Software Breakpoints" of "Building a Debugger" by Sy Brand is done (in Rust)!
https://github.com/drmorr0/drbug
This chapter was reasonably straightforward. The hardest part was figuring out the right type for my breakpoint sites and convincing the borrow checker it was OK. In the C++ version of this code, Sy just returns a pointer to the breakpoint site and everything is fine.
I tried to do it this way at first but ran into a point in the code where I had to hold an immutable borrow across a mutable borrow. In the C++ code this is fine because they're clearly touching different parts of the code and won't interact, but there's no way to tell the Rust borrow checker that, and there was no way to restructure the code to make it work.
I ended up making the breakpoint sites Clone-able, and then just wrapped the "important"/"shared" bits in Rc<Cell<...>>, which works pretty well aside from a couple dumb mistakes which took me too long to debug.
I also, instead of shelling out to `readelf` in the tests, just used the `elf` crate which already exists for Rust. I expect to rip this out in Chapter 11 when we implement our own ELF support in the debugger, but for now it feels less gross than readelf regex parsing.
Next up, Chapter 8, is Memory and Disassembly! I did a quick sneak peak ahead and discovered that the book relies on an external C++ lib for disassembly; fortunately, the `iced` crate for Rust seems to provide the functionality that we need here:
https://github.com/icedland/iced