GDB (xrefs)
/tmp/gdb-7.10/gdb/i386obsd-nat.c
Go to the documentation of this file.
1 /* Native-dependent code for OpenBSD/i386.
2 
3  Copyright (C) 2002-2015 Free Software Foundation, Inc.
4 
5  This file is part of GDB.
6 
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 3 of the License, or
10  (at your option) any later version.
11 
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.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #include "defs.h"
21 #include "gdbcore.h"
22 #include "regcache.h"
23 #include "target.h"
24 
25 #include <sys/sysctl.h>
26 #include <machine/frame.h>
27 #include <machine/pcb.h>
28 
29 #include "i386-tdep.h"
30 #include "i386bsd-nat.h"
31 #include "obsd-nat.h"
32 #include "bsd-kvm.h"
33 
34 static int
35 i386obsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
36 {
37  struct gdbarch *gdbarch = get_regcache_arch (regcache);
38  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
39  struct switchframe sf;
40 
41  /* The following is true for OpenBSD 3.6:
42 
43  The pcb contains %esp and %ebp at the point of the context switch
44  in cpu_switch(). At that point we have a stack frame as
45  described by `struct switchframe', which for OpenBSD 3.6 has the
46  following layout:
47 
48  interrupt level
49  %edi
50  %esi
51  %ebx
52  %eip
53 
54  we reconstruct the register state as it would look when we just
55  returned from cpu_switch(). */
56 
57  /* The stack pointer shouldn't be zero. */
58  if (pcb->pcb_esp == 0)
59  return 0;
60 
61  /* Read the stack frame, and check its validity. We do this by
62  checking if the saved interrupt priority level in the stack frame
63  looks reasonable.. */
64 #ifdef PCB_SAVECTX
65  if ((pcb->pcb_flags & PCB_SAVECTX) == 0)
66  {
67  /* Yes, we have a frame that matches cpu_switch(). */
68  read_memory (pcb->pcb_esp, (gdb_byte *) &sf, sizeof sf);
69  pcb->pcb_esp += sizeof (struct switchframe);
70  regcache_raw_supply (regcache, I386_EDI_REGNUM, &sf.sf_edi);
71  regcache_raw_supply (regcache, I386_ESI_REGNUM, &sf.sf_esi);
72  regcache_raw_supply (regcache, I386_EBX_REGNUM, &sf.sf_ebx);
73  regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip);
74  }
75  else
76 #endif
77  {
78  /* No, the pcb must have been last updated by savectx(). */
79  pcb->pcb_esp = pcb->pcb_ebp;
80  pcb->pcb_ebp = read_memory_integer(pcb->pcb_esp, 4, byte_order);
81  sf.sf_eip = read_memory_integer(pcb->pcb_esp + 4, 4, byte_order);
82  regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip);
83  }
84 
85  regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp);
86  regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp);
87 
88  return 1;
89 }
90 
91 
92 /* Prevent warning from -Wmissing-prototypes. */
93 void _initialize_i386obsd_nat (void);
94 
95 void
97 {
98  /* Add some extra features to the common *BSD/i386 target. */
100 
101  /* Support debugging kernel virtual memory images. */
103 
104  /* OpenBSD provides a vm.psstrings sysctl that we can use to locate
105  the sigtramp. That way we can still recognize a sigtramp if its
106  location is changed in a new kernel. This is especially
107  important for OpenBSD, since it uses a different memory layout
108  than NetBSD, yet we cannot distinguish between the two.
109 
110  Of course this is still based on the assumption that the sigtramp
111  is placed directly under the location where the program arguments
112  and environment can be found. */
113 #ifdef VM_PSSTRINGS
114  {
115  struct _ps_strings _ps;
116  int mib[2];
117  size_t len;
118 
119  mib[0] = CTL_VM;
120  mib[1] = VM_PSSTRINGS;
121  len = sizeof (_ps);
122  if (sysctl (mib, 2, &_ps, &len, NULL, 0) == 0)
123  {
124  i386obsd_sigtramp_start_addr = (u_long) _ps.val - 128;
126  }
127  }
128 #endif
129 }
void _initialize_i386obsd_nat(void)
Definition: i386obsd-nat.c:96
struct target_ops * i386bsd_target(void)
Definition: i386bsd-nat.c:282
void obsd_add_target(struct target_ops *t)
Definition: obsd-nat.c:181
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
Definition: regcache.c:297
static int i386obsd_supply_pcb(struct regcache *regcache, struct pcb *pcb)
Definition: i386obsd-nat.c:35
LONGEST read_memory_integer(CORE_ADDR memaddr, int len, enum bfd_endian byte_order)
Definition: corefile.c:311
unsigned long u_long
Definition: ser-go32.c:130
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition: gdbarch.c:1420
void read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: corefile.c:244
CORE_ADDR i386obsd_sigtramp_start_addr
bfd_byte gdb_byte
Definition: common-types.h:38
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
Definition: regcache.c:1041
CORE_ADDR i386obsd_sigtramp_end_addr
void bsd_kvm_add_target(int(*supply_pcb)(struct regcache *, struct pcb *))
Definition: bsd-kvm.c:351
enum bfd_endian byte_order
Definition: gdbarch.c:128
const ULONGEST const LONGEST len
Definition: target.h:309