diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2007-10-03 07:54:12 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2007-10-03 07:54:12 +0000 |
commit | cb2d00af29bc5a63365adc72564f0c9e7304ef5c (patch) | |
tree | 73be36c109fecde1eb52120c0504273b24b1aba4 /gnu | |
parent | 742b13cb3dd8afd4e04cf22c3faaceb16ff28c58 (diff) |
On i386, use PCB_SAVECTX flags to distinguish between state saved by a normal
context switch, and state saved by savectx(). This makes backtraces from
kernel crash dumps work much better.
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/usr.bin/binutils/gdb/config/i386/obsd.mh | 2 | ||||
-rw-r--r-- | gnu/usr.bin/binutils/gdb/i386obsd-nat.c | 73 |
2 files changed, 73 insertions, 2 deletions
diff --git a/gnu/usr.bin/binutils/gdb/config/i386/obsd.mh b/gnu/usr.bin/binutils/gdb/config/i386/obsd.mh index f5b4b2dffc7..3bdd4c12a9b 100644 --- a/gnu/usr.bin/binutils/gdb/config/i386/obsd.mh +++ b/gnu/usr.bin/binutils/gdb/config/i386/obsd.mh @@ -1,6 +1,6 @@ # Host: OpenBSD/i386 ELF NATDEPFILES= fork-child.o inf-ptrace.o \ - i386bsd-nat.o i386obsd-nat.o i386nbsd-nat.o bsd-kvm.o + i386bsd-nat.o i386obsd-nat.o bsd-kvm.o NAT_FILE= nm-obsd.h LOADLIBES= -lkvm diff --git a/gnu/usr.bin/binutils/gdb/i386obsd-nat.c b/gnu/usr.bin/binutils/gdb/i386obsd-nat.c index 68cc79044ec..892b17b71eb 100644 --- a/gnu/usr.bin/binutils/gdb/i386obsd-nat.c +++ b/gnu/usr.bin/binutils/gdb/i386obsd-nat.c @@ -20,11 +20,76 @@ Boston, MA 02111-1307, USA. */ #include "defs.h" +#include "gdbcore.h" +#include "regcache.h" +#include "target.h" + +#include "i386-tdep.h" +#include "i386bsd-nat.h" #include <sys/param.h> #include <sys/sysctl.h> -#include "i386-tdep.h" +/* Support for debugging kernel virtual memory images. */ + +#include <machine/frame.h> +#include <machine/pcb.h> + +#include "bsd-kvm.h" + +static int +i386obsd_supply_pcb (struct regcache *regcache, struct pcb *pcb) +{ + struct switchframe sf; + + /* The following is true for OpenBSD 4.3: + + The pcb contains %esp and %ebp at the point of the context switch + in cpu_switchto(). At that point we have a stack frame as + described by `struct switchframe', which for OpenBSD 4.3 has the + following layout: + + %edi + %esi + %ebx + %eip + + we reconstruct the register state as it would look when we just + returned from cpu_switchto(). + + For crash dumps, the state is saved by savectx(). In that case + we just reconstruct the register state as if we just returned + from dumsys(). */ + + /* The stack pointer shouldn't be zero. */ + if (pcb->pcb_esp == 0) + return 0; + + if ((pcb->pcb_flags & PCB_SAVECTX) == 0) + { + /* Yes, we have a frame that matches cpu_switchto(). */ + read_memory (pcb->pcb_esp, (char *) &sf, sizeof sf); + pcb->pcb_esp += sizeof (struct switchframe); + regcache_raw_supply (regcache, I386_EDI_REGNUM, &sf.sf_edi); + regcache_raw_supply (regcache, I386_ESI_REGNUM, &sf.sf_esi); + regcache_raw_supply (regcache, I386_EBX_REGNUM, &sf.sf_ebx); + regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip); + } + else + { + /* No, the pcb must have been last updated by savectx(). */ + pcb->pcb_esp = pcb->pcb_ebp; + pcb->pcb_ebp = read_memory_integer(pcb->pcb_esp, 4); + sf.sf_eip = read_memory_integer(pcb->pcb_esp + 4, 4); + regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip); + } + + regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp); + regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp); + + return 1; +} + /* Prevent warning from -Wmissing-prototypes. */ void _initialize_i386obsd_nat (void); @@ -57,4 +122,10 @@ _initialize_i386obsd_nat (void) } } #endif + + /* We've got nothing to add to the common *BSD/i386 target. */ + add_target (i386bsd_target ()); + + /* Support debugging kernel virtual memory images. */ + bsd_kvm_add_target (i386obsd_supply_pcb); } |