-An alternative to interactive debug mode is to attach using gdb. When invoked
-with '--gdb-port <port>' spike will listen on the given TCP port. It's
-possible to attach with gdb (that has riscv support compiled in) by entering
-`target remote localhost:<port>` in gdb. For example, in one shell run:
+An alternative to interactive debug mode is to attach using gdb. Because spike
+tries to be like real hardware, you also need OpenOCD to do that. OpenOCD
+doesn't currently know about address translation, so it's not possible to
+easily debug programs that are run under `pk`. We'll use the following test
+program:
+```
+$ cat rot13.c
+char text[] = "Vafgehpgvba frgf jnag gb or serr!";
+
+// Don't use the stack, because sp isn't set up.
+volatile int wait = 1;
+
+int main()
+{
+ while (wait)
+ ;
+
+ // Doesn't actually go on the stack, because there are lots of GPRs.
+ int i = 0;
+ while (text[i]) {
+ char lower = text[i] | 32;
+ if (lower >= 'a' && lower <= 'm')
+ text[i] += 13;
+ else if (lower > 'm' && lower <= 'z')
+ text[i] -= 13;
+ i++;
+ }
+
+ while (!wait)
+ ;
+}
+$ cat spike.lds
+OUTPUT_ARCH( "riscv" )
+
+SECTIONS
+{
+ . = 0x10010000;
+ .text : { *(.text) }
+ .data : { *(.data) }
+}
+$ riscv64-unknown-elf-gcc -g -Og -o rot13-64.o -c rot13.c
+$ riscv64-unknown-elf-gcc -g -Og -T spike.lds -nostartfiles -o rot13-64 rot13-64.o
+```
+
+To debug this program, first run spike telling it to listen for OpenOCD: