Eyes Above The Waves

Robert O'Callahan. Christian. Kiwi. Software guy. All content human-authored unless otherwise noted.

robert@ocallahan.org ... Follow on X, Follow on Bluesky

Thursday 3 December 2026

Releasing rr Remix

In our work on Pernosco Kyle Huey and I extended rr to support dynamic binary instrumentation of rr replays. That means you can record an application under rr running normally on the CPU, then replay that execution while injecting extra instructions. For example you could inject code to count the frequency of certain operations, or log the addresses of all memory writes, or check the preconditions of certain functions. We call this feature “remix”. With AI agents it’s now pretty easy to replicate this functionality, so there’s no point in keeping remix private, and I’ve just merged it into rr master (minus some code that is only relevant to Pernosco). This will make it easier to maintain and let other people build on top of it.

The theory and implementation are similar to Valgrind and DynamoRio. When instrumentation is needed, instead of running the machine code normally we disassemble the code, add instrumentation instructions, compile that back to modified machine code, and run the new code. Unlike other DBI systems, doing this in the context of rr replay has some advantages. It doesn’t add any overhead during recording; your expensive instrumentation can run offline after you’ve finished running the application, for less perturbation. The instrumented replay preserves the exact memory and register values of the recording, so we can turn instrumentation on and off at any point; in particular, you can replay at full speed up to some point of interest and then enable the instrumentation for some period of time. If you want to collect multiple different kinds of data you can replay a recording multiple times with different instrumentation; combined with the previous point this lets you use parallel replays to speed up data gathering. More implementation notes here.

Our implementation uses the DynamoRio disassembler and assembler, but otherwise our DBI pipeline is fully custom. (It turns out that instrumenting replay is easier than the general DBI problem because we have information about the future, for example we know exactly which instruction executions will trigger CPU exceptions.) We optimized for efficiency; instrumentation tools have to work with DynamoRio’s x86 opcodes, not a nice IR like Valgrind’s VEX. We also optimized for fast translation at the expense of highly optimized generated code (unlike DynamoRio for example), because a lot of our use-cases are short runs of very large applications like browsers.

Remix is pretty robust — Pernosco has been using it for a long time for serious debugging of apps like Firefox and Chrome. It’s not very well tested in CI at present and that’s something I plan to improve. It fully supports self-modifying code, albeit with some performance impact when executing from writeable-executable pages. The remix DBI engine runs in the address spaces of all replayed processes, but is protected from the tracee code because we place it at addresses we know the recorded code never accesses.

Remix provides a “NullTool” which runs the code through the DBI engine without adding instrumentation. This enables some features that may be useful to rr users. Remix counts conditional branches manually instead of using the hardware PMU, so you can use remix to replay traces on machines that don’t have access to the hardware PMU (but see below for limitations). Remix supports emulating the quirks of Intel CPUs on AMD and vice versa, and also papering over XCR0 and XSAVE format differences, enabling the porting of traces across CPU families. Remix stops when encountering instructions rr doesn’t support such as RDRAND or XBEGIN, which can help diagnose those problems. These features are currently not super useful because remix replays currently don’t support debugging, e.g. with gdb (see below).

Performance is not too bad. For example, running the rustls test suite, NullTool remix slows down replay by about 3x. That number is pretty typical. By comparison, valgrind --tool=none --trace-children=yes is about 12x (238s on the graph below). Obviously if significant instrumentation is added, overhead will increase. As noted above, it is often possible to only enable remix for specific sections of the trace, to reduce overhead.

The only real instrumentation tool upstreamed at the moment is StatisticsTool. It measures some internal remix implementation metrics and a few architectural metrics such as the usage frequency of each CPU register. It’s a useful starting point for anyone wanting to build on remix.

FWIW this code was developed a while ago without the use of AI, except for the AVX512 support which was built with Claude.

Limitations

We don’t yet have a good story for supporting external instrumentation tools. For now, anyone building their own instrumentation tool will have to have their own rr branch, or (if it’s of general interest) submit it to rr upstream. If you do build something I’d like to hear about it!

For now remix only supports x86-64.

Remix doesn’t support debugging replays with gdb. This would be pretty easy to fix since it already supports singlestepping and breakpoints internally, we just need to wire things up. Support for hardware data watchpoints would be tricky, because these can cause CPU exceptions at almost any instruction which remix doesn’t support, but even that is fixable using some tricks similar to the way remix handles self-modifying code.