This guide covers debugging Milo in QEMU and GDB, interpreting faults and panics, following repository commit and licensing rules, and adding new syscalls, drivers, or host unit tests.
Makefile, arch/aarch64-linux-gnu/boot.s, arch/aarch64-linux-gnu/trap_aarch64.cpp)Start QEMU paused at the entry point with GDB stub listening on TCP port 1234:
make debug
This invokes $(QEMU) $(QEMUFLAGS) -s -S (qemu-system-aarch64 -M virt -cpu cortex-a57 -m 256M -nographic -kernel build/kernel.bin ... -s -S). Note that debug does not list $(DISK_IMG) as a prerequisite, so run make disk beforehand if you need disk.img mounted.
In a second terminal, launch gdb-multiarch against the symbol-rich ELF binary:
make gdb
This runs $(GDB) build/kernel.elf -ex "target remote localhost:1234" -ex "layout split".
Useful breakpoints and register checks during bring-up or fault triage:
_start (0x40080000) or kmain to inspect pre-MMU state (x0 = DTB physical address, vbar_el1, cpacr_el1).ttbr0_el1 / ttbr1_el1 (p/x $TTBR0_EL1, p/x $TTBR1_EL1) or dumping g_ttbr0_l0 / g_ttbr1_l0 (x/8gx &g_ttbr0_l0, x/8gx &g_ttbr1_l0) and walking 64-bit descriptors ((desc & 0x000FFFFFFFFFF000)).aarch64_handle_sync_exception or aarch64_handle_irq_exception (arch/aarch64-linux-gnu/trap_aarch64.cpp) to inspect esr_el1, far_el1, elr_el1, spsr_el1, and the saved AArch64CpuContext frame.Kernel::Scheduler::schedule (kernel/process/scheduler.cpp) or Kernel::Syscalls::SyscallDispatcher::handle_trap (kernel/syscalls/SyscallDispatcher.cpp) to trace task switches and svc #0 calls.kernel/core/log.{hpp,cpp}, arch/aarch64-linux-gnu/trap_aarch64.cpp, kernel/mm/heap.cpp)aarch64_handle_sync_exception prints [TRAP] Data/Instruction Abort Trap Captured!, FAR_EL1, and ESR_EL1 for unrecovered faults; if ENABLE_REGISTER_DUMP in trap_aarch64.cpp is set to true (default false), dump_registers also prints X0–X30, SP_EL0, ELR_EL1, and SPSR_EL1. Unhandled exception classes print [PANIC] Unhandled Synchronous Exception! EC=... ESR_EL1=... FAR_EL1=....aarch64_handle_invalid_exception prints [PANIC] Invalid/Async Trap Captured: ... (decoding entries 0..15 such as Current EL SPx SError or Lower EL AArch64 SError).Scheduler::schedule() panics with [PANIC] Scheduler::schedule() entered with IRQs enabled! or [PANIC] Recursive Scheduler::schedule() re-entry!.KernelHeap (kernel/mm/heap.cpp) and kernel/runtime/cxx_abi.cpp report slab corruption, invalid/double kfree(), OOM, or std::terminate to the console.Kernel::Log in kernel/core/log.{hpp,cpp}): Kernel::Log::set_level(Level) and Kernel::Log::get_level() control Level (Trace = 0, Debug = 1, Info = 2, Warn = 3, Error = 4, Off = 5), defaulting to Level::Trace at startup and formatting messages via SinkWriter to HAL::get_console().Makefile): Run make -j"$(nproc)" test-host to execute build/host-tests/kernel_host_tests with ASan and UBSan (-fsanitize=address,undefined -fno-omit-frame-pointer) and generate gcovr reports in build/reports/ (coverage_report.html, cobertura.xml, jacoco.xml, test_report.xml)..githooks/pre-commit, scripts/check_license_headers.py, Makefile)make commit (which runs quality and sets MILO_MAKE_COMMIT=1 for git commit); .githooks/pre-commit rejects direct git commit invocations unless MILO_MAKE_COMMIT=1 is set.make license-check or python3 scripts/check_license_headers.py --apply to verify or apply the required SPDX (GPL-3.0-only) and copyright header (Copyright (c) 2026 Marco Buschini <marco.buschini@gmail.com>).kernel/uapi/*.hpp): Use extern "C" standard-layout, trivial structs with static_asserts on sizeof and offsetof (and #undef colliding macros under #ifdef HOST_TEST).kernel/syscalls/SyscallInternal.hpp and FileSyscalls.cpp / MemorySyscalls.cpp / ProcessSyscalls.cpp / SignalSyscalls.cpp / SocketSyscalls.cpp / TimeSyscalls.cpp): Validate user pointers/ranges (copy_from_user, copy_to_user, validate_user_read_range, validate_user_write_range, copy_user_cstring) and return negative ERR_* codes on failure.kernel/syscalls/SyscallDispatcher.cpp: Add constexpr uint64_t SYS_<NAME> = ...; and its case arm in SyscallDispatcher::handle_trap.compile_commands.json: Add a snitch test in tests/host/ (and/or an EL0 test in arch/aarch64-linux-gnu/user_test.s + kernel/shell/tests/), run make compile_commands.json, and run make quality.kernel/drivers/... or kernel/input/): Follow freestanding C++20 rules (no exceptions/RTTI, IrqGuard around shared/IRQ state, phys_to_virt / virt_to_phys for MMIO and PFA DMA frames, flush_dcache_range around DMA buffers, and GicV2::register_spi_handler / unregister_spi_handler for SPIs).kernel/hal/targets/qemu_virt/platform_*.cpp, kernel/fs/devfs/devfs.cpp, kernel/main.cpp): Bind via VirtioMmioBus::instance().bind_device / bind_all (or FDT helpers in kernel/boot/fdt.cpp), expose VFS/devfs interfaces where appropriate, and call initialization during kmain bring-up..cpp files to KERNEL_CORE_SRCS in kernel/kernel.mk if the driver runs in HOST_TEST (automatically mirrored into HOST_KERNEL_SRCS), or to KERNEL_TARGET_SRCS if it is bare-metal/target-only.docs/adr/0001-unit-testing-framework.md, Makefile)tests/host/<feature>_test.cpp: Include <snitch/snitch.hpp> (linked against the pre-installed -L/usr/local/lib -lsnitch library with -DSNITCH_WITH_EXCEPTIONS=0), use HostTest::reset_host_hal() to reset simulated RAM/roots/mappings/console, and assert that pfa_free_pages_count() and heap stats return to baseline after teardown.Makefile automatically discovers tests/host/*.cpp (and tests/host/mocks/*.cpp) via HOST_TEST_CASE_SRCS / HOST_ONLY_TEST_SRCS, wiring new tests into $(HOST_TEST_BIN), $(HOST_COV_BIN), TEST_FORMAT_SRCS, and compile_commands.json without manual edits.make quality: Run make compile_commands.json, make format, and make -j"$(nproc)" quality.