Sync usage with man page.
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / i386nbsd-nat.c
blobf89f82df1440f78e8e2d4c24ae9b33eef4e28d4f
1 /* Native-dependent code for NetBSD/i386.
3 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 #include "defs.h"
23 #include "gdbcore.h"
24 #include "regcache.h"
25 #include "target.h"
27 #include "i386-tdep.h"
28 #include "i386bsd-nat.h"
30 /* Support for debugging kernel virtual memory images. */
32 #include <sys/types.h>
33 #include <machine/frame.h>
34 #include <machine/pcb.h>
36 #include "nbsd-nat.h"
37 #include "bsd-kvm.h"
39 static int
40 i386nbsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
42 struct switchframe sf;
44 /* The following is true for NetBSD 1.6.2 and after:
46 The pcb contains %esp and %ebp at the point of the context switch
47 in cpu_switch()/cpu_switchto(). At that point we have a stack frame as
48 described by `struct switchframe', which for NetBSD (2.0 and later) has
49 the following layout:
51 %edi
52 %esi
53 %ebx
54 return address
56 we reconstruct the register state as it would look when we just
57 returned from cpu_switch()/cpu_switchto().
59 For core dumps the pcb is saved by savectx()/dumpsys() and contains the
60 stack pointer and frame pointer. A new dumpsys() fakes a switchframe
61 whereas older code isn't reliable so use an iffy heuristic to detect this
62 and use the frame pointer to recover enough state. */
64 /* The stack pointer shouldn't be zero. */
65 if (pcb->pcb_esp == 0)
66 return 0;
68 read_memory (pcb->pcb_esp, (gdb_byte *) &sf, sizeof sf);
70 if ( (unsigned long)sf.sf_eip >= (unsigned long)0xc0100000 )
72 /* Yes, we have a switchframe that matches cpu_switchto() or
73 the new dumpsys(). */
75 pcb->pcb_esp += sizeof (struct switchframe);
76 regcache_raw_supply (regcache, I386_EDI_REGNUM, &sf.sf_edi);
77 regcache_raw_supply (regcache, I386_ESI_REGNUM, &sf.sf_esi);
78 regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp);
79 regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp);
80 regcache_raw_supply (regcache, I386_EBX_REGNUM, &sf.sf_ebx);
81 regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip);
83 else
85 CORE_ADDR pc, fp;
87 /* No, the pcb must have been last updated by savectx() in old
88 dumpsys(). Use the frame pointer to recover enough state. */
90 read_memory (pcb->pcb_ebp, (gdb_byte *) &fp, sizeof(fp));
91 read_memory (pcb->pcb_ebp + 4, (gdb_byte *) &pc, sizeof(pc));
93 regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_ebp);
94 regcache_raw_supply (regcache, I386_EBP_REGNUM, &fp);
95 regcache_raw_supply (regcache, I386_EIP_REGNUM, &pc);
98 return 1;
102 /* Provide a prototype to silence -Wmissing-prototypes. */
103 void _initialize_i386nbsd_nat (void);
105 void
106 _initialize_i386nbsd_nat (void)
108 struct target_ops *t;
110 /* Add some extra features to the common *BSD/i386 target. */
111 t = i386bsd_target ();
112 t->to_pid_to_exec_file = nbsd_pid_to_exec_file;
113 add_target (t);
115 /* Support debugging kernel virtual memory images. */
116 bsd_kvm_add_target (i386nbsd_supply_pcb);