From 3152b2ae078f83145774d2dbfaf6f471b8b766e8 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Tue, 25 Mar 2025 18:00:51 -0400 Subject: more qemu opts and gdb --- Makefile | 15 +++++++++++++-- util/gdbinit | 31 +++++++++++++++++++++++++++++++ util/gdbinit.tmpl | 31 ------------------------------- 3 files changed, 44 insertions(+), 33 deletions(-) create mode 100644 util/gdbinit delete mode 100644 util/gdbinit.tmpl diff --git a/Makefile b/Makefile index 27f2133..4f4fef9 100644 --- a/Makefile +++ b/Makefile @@ -3,11 +3,22 @@ .SILENT: QEMU = qemu-system-i386 -QEMUOPTS = -drive file=bin/disk.img,index=0,media=disk,format=raw +QEMUOPTS = -drive file=bin/disk.img,index=0,media=disk,format=raw \ + -no-reboot -d cpu_reset \ + -serial mon:stdio \ + -m 4G \ + -display sdl \ + -enable-kvm \ + -name kern qemu: bin/disk.img - $(QEMU) -serial mon:stdio $(QEMUOPTS) + $(QEMU) $(QEMUOPTS) +qemu-gdb: bin/disk.img + $(QEMU) $(QEMUOPTS) -S -gdb tcp::1337 + +gdb: + gdb -q -n -x util/gdbinit clean: rm -fr .zig-cache diff --git a/util/gdbinit b/util/gdbinit new file mode 100644 index 0000000..ca2c885 --- /dev/null +++ b/util/gdbinit @@ -0,0 +1,31 @@ +# adapted from the xv6 .gdbinit.tmpl file +set $lastcs = -1 + +define hook-stop + # There doesn't seem to be a good way to detect if we're in 16- or + # 32-bit mode, but we always run with CS == 8 in 32-bit mode. + if $cs == 8 || $cs == 27 + if $lastcs != 8 && $lastcs != 27 + set architecture i386 + end + x/i $pc + else + if $lastcs == -1 || $lastcs == 8 || $lastcs == 27 + set architecture i8086 + end + # Translate the segment:offset into a physical address + printf "[%4x:%4x] ", $cs, $eip + x/i $cs*16+$eip + end + set $lastcs = $cs +end + +echo + target remote localhost:1337\n +target remote localhost:1337 + +# If this fails, it's probably because your GDB doesn't support ELF. +# Look at the tools page at +# http://pdos.csail.mit.edu/6.828/2009/tools.html +# for instructions on building GDB with ELF support. +echo + symbol-file build/kernel/kernel\n +symbol-file build/kernel/kernel diff --git a/util/gdbinit.tmpl b/util/gdbinit.tmpl deleted file mode 100644 index d9a981d..0000000 --- a/util/gdbinit.tmpl +++ /dev/null @@ -1,31 +0,0 @@ -# adapted from the xv6 .gdbinit.tmpl file -set $lastcs = -1 - -define hook-stop - # There doesn't seem to be a good way to detect if we're in 16- or - # 32-bit mode, but we always run with CS == 8 in 32-bit mode. - if $cs == 8 || $cs == 27 - if $lastcs != 8 && $lastcs != 27 - set architecture i386 - end - x/i $pc - else - if $lastcs == -1 || $lastcs == 8 || $lastcs == 27 - set architecture i8086 - end - # Translate the segment:offset into a physical address - printf "[%4x:%4x] ", $cs, $eip - x/i $cs*16+$eip - end - set $lastcs = $cs -end - -echo + target remote localhost:1234\n -target remote localhost:1234 - -# If this fails, it's probably because your GDB doesn't support ELF. -# Look at the tools page at -# http://pdos.csail.mit.edu/6.828/2009/tools.html -# for instructions on building GDB with ELF support. -echo + symbol-file build/kernel/kernel\n -symbol-file build/kernel/kernel -- cgit v1.2.3-freya