# SchOS kernel debugging.
#
# gdb refuses to auto-load this unless the directory is trusted. Once, in
# ~/.gdbinit:
#
#   add-auto-load-safe-path /home/nexoniarz/Dokumenty/Projects/SchOS
#
# Then:  make qemu-gdb        (one terminal)
#        gdb build/kernel/kernel   (another)

set confirm off
set architecture i386:x86-64
target remote 127.0.0.1:26000

# You are stopped at the reset vector, 0xfff0, with the firmware not yet run.
#
# A breakpoint on a kernel symbol will NOT take here, and the error is
# confusing rather than wrong:
#
#   Cannot insert breakpoint 1. Cannot access memory at 0xffff800000104fc2
#
# The kernel links at 0xffff8000_00000000 and nothing is mapped there until it
# turns paging on. Symbols resolve -- gdb knows kmain is main.c:32 -- but the
# address is not addressable yet.
#
# So: `continue`, let the firmware and the loader run, and interrupt with ^C
# once SchOS is up. Every kernel symbol works from then on, because the high
# half is mapped and stays mapped.
#
#   (gdb) continue
#   ... SchOS boots ...
#   ^C
#   (gdb) break vt_switch
#   (gdb) continue
#
# For the early boot itself -- entry.S, the long-mode switch, the handoff from
# the loader -- break on the *physical* address instead: the kernel is loaded
# at 1 MB, so `break *0x100000` catches the entry point before paging.
echo \n=== SchOS: stopped at reset. `continue`, then ^C once it boots. ===\n\n
