Git Bisect定位问题

Posted by Fei Wu on March 7, 2024

复现问题

发现rva22s64出现hang,复现脚本

1
2
3
4
$QEMU -machine virt -nographic -m 2G -smp 2 \
    -cpu rva22s64 \
    -bios $d/fw_jump.elf \
    -kernel $d/kernel-latest &> log &

只要看到最后停在哪里就可以知道有没有问题

bisect脚本

稍微改造一下上面的测试用例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$ cat check-qemu
#!/bin/bash

QEMU_SRC=~/qemu
QEMU=$QEMU_SRC/install/bin/qemu-system-riscv64

pushd $QEMU_SRC
make -j 64 install
popd

$d=~/wufei/rvsp
tm=$(date +%s)
log=$d/log-$tm

$QEMU -machine virt -nographic -m 2G -smp 2 \
    -cpu rva22s64 \
    -bios $d/fw_jump.elf \
    -kernel $d/kernel-latest &> log &

pid=$!
sleep 5
kill -9 $pid

if tail -1 $log | grep MEDELEG; then
    exit 1
else
    exit 0
fi

执行bisect

1
2
3
4
5
6
7
8
9
$ git bisect start master dfa3c4c57e
$ git bisect run check-qemu

d06f28db60c536b9d7f159adedca397979f6e5ca is the first bad commit
commit d06f28db60c536b9d7f159adedca397979f6e5ca
Author: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Date: Fri Jan 5 20:05:33 2024 -0300

    target/riscv: move 'mmu' to riscv_cpu_properties[]

bisect特别适合这类任务,总共不到一小时内定位问题,直接上去调试代码肯定需要更多时间。