xv6, line by line
.gdbinit.tmpl-riscv

.gdbinit.tmpl-riscv

GDB script · 6 lines · annotated 100% · upstream

About this file

A template for .gdbinit, the file of commands gdb (the GNU debugger) runs when it starts. It sets gdb up to debug the xv6 kernel running inside QEMU: connect to QEMU, load the kernel’s symbols, and choose settings that suit RISC-V.

You do not use this file directly. The Makefile copies it to .gdbinit, replacing the port number 1234 with your own GDBPORT (Makefile:185). The workflow is:

  1. In one terminal, make qemu-gdb (Makefile:188). This generates .gdbinit, then starts QEMU with -S (every hart paused before its first instruction) and a gdb server on your port. Nothing runs yet.
  2. In a second terminal, in the same directory, run a RISC-V gdb: ${TOOLPREFIX}gdb (TOOLPREFIX is your RISC-V toolchain’s prefix, see Tour 1: From make qemu to a disk image and a kernel), or gdb-multiarch on Debian/Ubuntu/WSL. It reads .gdbinit, connects, and stops at address 0x1000, where QEMU’s built-in boot code starts.
  3. Set breakpoints (b main, b kvminithart) and c to continue.

Recent versions of gdb refuse to run a .gdbinit found in the current directory unless you allow it; gdb prints the exact add-auto-load-safe-path line to put in your own ~/.gdbinit.

1set confirm off
2set architecture riscv:rv64
3target remote 127.0.0.1:1234
4symbol-file kernel/kernel
5set disassemble-next-line auto
6set riscv use-compressed-breakpoints yes