Debugging RISCV-64 bootloader in QEMU | Haiku Project

Debugging early bootloader code can be extremely difficult. The lack of printf and other classical black-box debugging tools means you’re limited to one of the following methods of debugging lockups:


This is a companion discussion topic for the original entry at https://www.haiku-os.org/blog/kallisti5/2021-01-17_debugging_riscv-64_bootloader_in_qemu/
3 Likes

When debugging UEFI loader for ARM (UEFI Haiku boot loader for ARM), I used UEFI text output protocol to write checkpoints like (1), (2), (2.1). Also UEFI display crash report with IP register value that can be converted to source code position by llvm-addr2line.

I used serial for ARM as well. However I found out printf was broken on ARM and in some very important info print 0 instead of the correct numerical values. So I think using both methods is important. (Turned out packages used by bootlloader was compiled with hardfloat, while UEFI in ARM arn’t allowed to use float).

I made RISC-V port without any external debuggers, only serial, screen output and disassemblers. There are no actual GDB version in HaikuPorts and I am not sure that current version will work with Qemu on Haiku host.

Functions like WriteInt(), WriteHex() can be used on early steps, see my sample code for qemu-aarch64.

1 Like

Good advice. And for others: remember that var-args and how arguments are passed, calculations, mmap and so on might not report the correct values when you are bringing up a new arch.