qemu xv6 使用GDB调试

安装依赖:
apt-get install git build-essential gdb-multiarch qemu-system-misc gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu
apt install gcc-riscv64-unknown-elf

安装验证:
riscv64-unknown-elf-gcc --version

gdb --configuration
一般 Ubuntu 默认的 GDB 是不支持 riscv64 的, 因此需要安装 riscv64-unknown-elf-gdb
apt-get install libncurses5-dev python python-dev texinfo libreadline-dev

克隆
git clone https://github.com/mit-pdos/xv6-riscv.git

编译
cd xv6-riscv
make

使用 qemu 运行
make qemu
make CPUS=1 qemu

使用 qemu-gdb 对 xv6进行调试
需要2个窗口(终端)
窗口1
cd xv6-riscv
make CPUS=1 qemu-gdb

窗口2
cd xv6-riscv
将xv6-riscv/.gdbinit文件所在的路径写到~/.gdbinit中
echo "add-auto-load-safe-path /home/li/xv6-riscv/.gdbinit" >> ~/.gdbinit

gdb-multiarch

出现以下信息为成功
The target architecture is assumed to be riscv:rv64
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x0000000000001000 in ?? ()
(gdb)