Skip to content

Commit 02e294c

Browse files
committed
qemurr: create
qemu: start documenting unmerged replay reverse debugging while testing it
1 parent 19f4d00 commit 02e294c

File tree

5 files changed

+84
-25
lines changed

5 files changed

+84
-25
lines changed

README.adoc

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,13 @@ And then search for a line of type:
16651665

16661666
=== GDB step debug early boot
16671667

1668-
TODO: why can't we break at early startup stuff such as:
1668+
Break at the very first instruction executed by QEMU:
1669+
1670+
....
1671+
./rungdb -C
1672+
....
1673+
1674+
TODO why can't we break at early startup stuff such as:
16691675

16701676
....
16711677
./rungdb extract_kernel
@@ -6096,11 +6102,17 @@ Only tested in x86.
60966102

60976103
PCI driver for our minimal `pci_min.c` QEMU fork device:
60986104

6105+
....
6106+
./run -- -device lkmc_pci_min
6107+
....
6108+
6109+
then:
6110+
60996111
....
61006112
insmod /pci_min.ko
61016113
....
61026114

6103-
Source:
6115+
Sources:
61046116

61056117
* Kernel module: link:kernel_module/pci_min.c[].
61066118
* QEMU device: https://github.com/cirosantilli/qemu/blob/lkmc/hw/misc/lkmc_pci_min.c
@@ -6124,11 +6136,7 @@ What happened:
61246136

61256137
Kernel messages and printks from inside QEMU are shown all together, to see that more clearly, run in <<graphic-mode>> instead.
61266138

6127-
Works because we add to our default QEMU CLI:
6128-
6129-
....
6130-
-device lkmc_pci_min
6131-
....
6139+
We don't enable the device by default because it does not work for vanilla QEMU, which we often want to test with this repository.
61326140

61336141
Probe already does a MMIO write, which generates an IRQ and tests everything.
61346142

@@ -7022,6 +7030,12 @@ This awesome feature allows you to examine a single run as many times as you wou
70227030
./run -F '/rand_check.out;/poweroff.out;' -R
70237031
....
70247032

7033+
A convenient shortcut to do both at once to test the feature is:
7034+
7035+
....
7036+
./qemurr -F '/rand_check.out;/poweroff.out;'
7037+
....
7038+
70257039
By comparing the terminal output of both runs, we can see that they are the exact same, including things which normally differ across runs:
70267040

70277041
* timestamps of dmesg output
@@ -7046,8 +7060,7 @@ EXT4-fs (sda): re-mounted. Opts: block_validity,barrier,user_xattr
70467060
TODO replay with network gets stuck:
70477061

70487062
....
7049-
./run -F '/sbin/ifup -a;wget -S google.com;/poweroff.out;' -r
7050-
./run -F '/sbin/ifup -a;wget -S google.com;/poweroff.out;' -R
7063+
./qemurr -F '/sbin/ifup -a;wget -S google.com;/poweroff.out;'
70517064
....
70527065

70537066
after the message:
@@ -7058,14 +7071,15 @@ adding dns 10.0.2.3
70587071

70597072
There is explicit network support on the QEMU patches, but either it is buggy or we are not using the correct magic options.
70607073

7074+
Solved on unmerged c42634d8e3428cfa60672c3ba89cabefc720cde9 from https://github.com/ispras/qemu/tree/rr-180725
7075+
70617076
TODO `arm` and `aarch64` only seem to work with initrd since I cannot plug a working IDE disk device? See also: https://lists.gnu.org/archive/html/qemu-devel/2018-02/msg05245.html
70627077

70637078
Then, when I tried with <<initrd>> and no disk:
70647079

70657080
....
70667081
./build -aA -i
7067-
./run -aA -F '/rand_check.out;/poweroff.out;' -i -r
7068-
./run -aA -F '/rand_check.out;/poweroff.out;' -i -R
7082+
./qemurr -aA -F '/rand_check.out;/poweroff.out;' -i
70697083
....
70707084

70717085
QEMU crashes with:
@@ -7076,6 +7090,37 @@ ERROR:replay/replay-time.c:49:replay_read_clock: assertion failed: (replay_file
70767090

70777091
I had the same error previously on x86-64, but it was fixed: https://bugs.launchpad.net/qemu/+bug/1762179 so maybe the forgot to fix it for `aarch64`?
70787092

7093+
Solved on unmerged c42634d8e3428cfa60672c3ba89cabefc720cde9 from https://github.com/ispras/qemu/tree/rr-180725
7094+
7095+
===== QEMU reverse debugging
7096+
7097+
TODO get working.
7098+
7099+
QEMU replays support checkpointing, and this allows for a simplistic "reverse debugging" implementation proposed at https://lists.gnu.org/archive/html/qemu-devel/2018-06/msg00478.html on the unmerged link:https://github.com/ispras/qemu/tree/rr-180725[]:
7100+
7101+
....
7102+
./run -F '/rand_check.out;/poweroff.out;' -r
7103+
./run -F '/rand_check.out;/poweroff.out;' -R -d
7104+
....
7105+
7106+
On another shell:
7107+
7108+
....
7109+
./rungdb start_kernel
7110+
....
7111+
7112+
In GDB:
7113+
7114+
....
7115+
n
7116+
n
7117+
n
7118+
n
7119+
reverse-continue
7120+
....
7121+
7122+
and we are back at `start_kernel`
7123+
70797124
==== QEMU trace multicore
70807125

70817126
TODO: is there any way to distinguish which instruction runs on each core? Doing:

br2/default

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ BR2_PACKAGE_FILE=y
2828
BR2_PACKAGE_OVERRIDE_FILE="../buildroot_override"
2929
BR2_PACKAGE_PCIUTILS=y
3030
# For qemu-ga on guest. TODO: do something with it, and document it.
31+
# Maybe: https://superuser.com/questions/930588/how-to-pass-commands-noninteractively-to-running-qemu-from-the-guest-qmp-via-te
3132
BR2_PACKAGE_QEMU=y
3233
BR2_PACKAGE_STRACE=y
3334
BR2_ROOTFS_OVERLAY="../rootfs_overlay"

qemurr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -eu
3+
./run -r "$@"
4+
./run -R "$@"

run

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ else
270270
common_mkdir
271271
qemu_executable="qemu-system-${arch}"
272272
else
273-
qemu_executable="${buildroot_out_dir}/host/usr/bin/qemu-system-${arch}"
273+
qemu_executable="${common_qemu_variant_dir}/${arch}-softmmu/qemu-system-${arch}"
274274
fi
275275
extra_flags="${extra_flags_qemu} ${extra_flags}"
276276
qemu_common="\
@@ -303,12 +303,14 @@ ${vnc}"
303303
driveif=none
304304
rrid=',id=img-direct'
305305
root='root=/dev/sda'
306+
snapshot=
306307
else
307308
driveif=virtio
308309
root='root=/dev/vda'
309310
rrid=
311+
snapshot=,snapshot
310312
fi
311-
extra_flags="${extra_flags} -drive 'file=${common_images_dir}/rootfs.ext2.qcow2,format=qcow2,if=${driveif},snapshot${rrid}' \\
313+
extra_flags="${extra_flags} -drive 'file=${common_images_dir}/rootfs.ext2.qcow2,format=qcow2,if=${driveif}${snapshot}${rrid}' \\
312314
"
313315
if [ -n "$rr" ]; then
314316
extra_flags="${extra_flags} \\
@@ -323,25 +325,22 @@ ${vnc}"
323325
extra_flags="${extra_flags} \
324326
-object filter-replay,id=replay,netdev=net0 \\
325327
-icount 'shift=7,rr=${rr},rrfile=${common_qemu_rrfile}' \\
328+
"
329+
virtio_gpu_pci=
330+
else
331+
virtio_gpu_pci="-device virtio-gpu-pci \\
326332
"
327333
fi
328334
case "$arch" in
329335
x86_64)
330336
if "$kgdb"; then
331337
extra_append="${extra_append} kgdboc=ttyS0,115200"
332338
fi
333-
if "$prebuilt"; then
334-
custom_devices=
335-
else
336-
custom_devices="-device lkmc_pci_min \\
337-
"
338-
fi
339339
cmd="\
340340
${qemu_common} \
341341
-M pc \\
342342
-append '${root} nopat ${extra_append}' \\
343343
-device edu \\
344-
${custom_devices} \\
345344
${extra_flags} \
346345
"
347346
;;
@@ -354,7 +353,7 @@ ${qemu_common} \
354353
-M virt \\
355354
-append '${root} ${extra_append}' \\
356355
-cpu cortex-a15 \\
357-
-device virtio-gpu-pci \\
356+
${virtio_gpu_pci} \
358357
${extra_flags} \
359358
"
360359
;;
@@ -367,7 +366,7 @@ ${qemu_common} \
367366
-M virt \\
368367
-append '${root} ${extra_append}' \\
369368
-cpu cortex-a57 \\
370-
-device virtio-gpu-pci \\
369+
${virtio_gpu_pci} \
371370
-kernel '${common_images_dir}/Image' \\
372371
${extra_flags} \
373372
"
@@ -376,7 +375,7 @@ ${extra_flags} \
376375
if ! "$ramfs"; then
377376
root='root=/dev/hda'
378377
extra_flags="${extra_flags} \
379-
-drive 'file=${common_images_dir}/rootfs.ext2.qcow2,format=qcow2,snapshot' \\
378+
-drive 'file=${common_images_dir}/rootfs.ext2.qcow2,format=qcow2${snapshot}' \\
380379
"
381380
fi
382381
cmd="\

rungdb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ before=
77
lx_symbols="-ex 'lx-symbols ../kernel_module-1.0/' \\
88
"
99
kgdb=false
10-
while getopts A:a:b:gkL:n:X OPT; do
10+
docontinue=true
11+
while getopts A:a:b:CgkL:n:X OPT; do
1112
case "$OPT" in
1213
A)
1314
after="$OPTARG"
@@ -18,6 +19,10 @@ while getopts A:a:b:gkL:n:X OPT; do
1819
b)
1920
before="$OPTARG"
2021
;;
22+
C)
23+
# No Continue.
24+
docontinue=false
25+
;;
2126
g)
2227
gem5=true
2328
;;
@@ -84,7 +89,12 @@ ${gdb} \
8489
-ex 'file vmlinux' \\
8590
-ex 'target remote localhost:${common_gdb_port}' \\
8691
${brk} \
87-
-ex 'continue' \\
92+
"
93+
fi
94+
if "$docontinue"; then
95+
echo asdf
96+
cmd="${cmd} \
97+
-ex continue \\
8898
${lx_symbols} \
8999
"
90100
fi

0 commit comments

Comments
 (0)