# Linux Kernel Module Cheat

#### 23.9.5. QEMU record and replay

QEMU runs, unlike gem5, are not deterministic by default, however it does support a record and replay mechanism that allows you to replay a previous run deterministically.

This awesome feature allows you to examine a single run as many times as you would like until you understand everything:

    # Record a run.
    ./run --eval-after './linux/rand_check.out;./linux/poweroff.out;' --record
    # Replay the run.
    ./run --eval-after './linux/rand_check.out;./linux/poweroff.out;' --replay

A convenient shortcut to do both at once to test the feature is:

    ./qemu-rr --eval-after './linux/rand_check.out;./linux/poweroff.out;'

By comparing the terminal output of both runs, we can see that they are the exact same, including things which normally differ across runs:

- timestamps of dmesg output

- rand_check.out output

The record and replay feature was revived around QEMU v3.0.0. In v5.2.0 it is quite usable, almost all peripherals and vCPUs are supported.

Documented at: https://github.com/qemu/qemu/blob/v5.2.0/docs/replay.txt

replay may be used with with network:

    ./qemu-rr --eval-after 'ifup -a;wget -S google.com;./linux/poweroff.out;'

`arm` and `aarch64` targets can also be used with rr:

    ./qemu-rr --arch aarch64 --eval-after './linux/rand_check.out;./linux/poweroff.out;'
    ./qemu-rr --arch aarch64 --eval-after 'ifup -a;wget -S google.com;./linux/poweroff.out;'

Replay also supports initrd and no disk:

    ./build-buildroot --arch aarch64 --initrd
    ./qemu-rr --arch aarch64 --eval-after './linux/rand_check.out;./linux/poweroff.out;' --initrd

- QEMU reverse debugging