]> Devi Nivas Git - cs3210-lab1.git/commitdiff
qemu-gdb target and script
authorSilas Boyd-Wickizer <sbw@wether.csail.mit.edu>
Tue, 15 Sep 2009 21:15:36 +0000 (17:15 -0400)
committerSilas Boyd-Wickizer <sbw@wether.csail.mit.edu>
Tue, 15 Sep 2009 21:15:36 +0000 (17:15 -0400)
.gdbinit.tmpl [new file with mode: 0644]
Makefile

diff --git a/.gdbinit.tmpl b/.gdbinit.tmpl
new file mode 100644 (file)
index 0000000..4c4e734
--- /dev/null
@@ -0,0 +1,28 @@
+set $lastcs = -1
+
+# This fails on Darwin because the default gdb has no ELF support
+# echo + symbol-file obj/kern/kernel\n
+# symbol-file obj/kern/kernel
+
+define hook-stop
+  # There doesn't seem to be a good way to detect if we're in 16- or
+  # 32-bit mode, but in 32-bit mode we always run with CS == 8 in the
+  # kernel and CS == 35 in user space
+  if $cs == 8 || $cs == 35
+    if $lastcs != 8 && $lastcs != 35
+      set architecture i386
+    end
+    x/i $pc
+  else
+    if $lastcs == -1 || $lastcs == 8 || $lastcs == 35
+      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
index 8fe23b78d41bbbc8824890abd61818b35682d48c..52190a54a7a4139ad533b7547b0822f80d7d96a6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -138,11 +138,22 @@ bochs : fs.img xv6.img
        if [ ! -e .bochsrc ]; then ln -s dot-bochsrc .bochsrc; fi
        bochs -q
 
+# try to generate a unique GDB port
+GDBPORT = $(shell expr `id -u` % 5000 + 25000)
+QEMUOPTS = -smp 2 -hdb fs.img xv6.img
+
 qemu: fs.img xv6.img
-       qemu -parallel stdio -smp 2 -hdb fs.img xv6.img
+       qemu -parallel mon:stdio $(QEMUOPTS)
 
 qemutty: fs.img xv6.img
-       qemu -nographic -smp 2 -hdb fs.img xv6.img
+       qemu -nographic $(QEMUOPTS)
+
+.gdbinit: .gdbinit.tmpl
+       sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@
+
+qemu-gdb: fs.img xv6.img .gdbinit
+       @echo "*** Now run 'gdb'." 1>&2
+       qemu -parallel mon:stdio $(QEMUOPTS) -s -S -p $(GDBPORT)
 
 # CUT HERE
 # prepare dist for students