1 |
227 |
jeremybenn |
/* Native-dependent code for OpenBSD/i386.
|
2 |
|
|
|
3 |
|
|
Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010
|
4 |
|
|
Free Software Foundation, Inc.
|
5 |
|
|
|
6 |
|
|
This file is part of GDB.
|
7 |
|
|
|
8 |
|
|
This program is free software; you can redistribute it and/or modify
|
9 |
|
|
it under the terms of the GNU General Public License as published by
|
10 |
|
|
the Free Software Foundation; either version 3 of the License, or
|
11 |
|
|
(at your option) any later version.
|
12 |
|
|
|
13 |
|
|
This program is distributed in the hope that it will be useful,
|
14 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
|
|
GNU General Public License for more details.
|
17 |
|
|
|
18 |
|
|
You should have received a copy of the GNU General Public License
|
19 |
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
20 |
|
|
|
21 |
|
|
#include "defs.h"
|
22 |
|
|
#include "gdbcore.h"
|
23 |
|
|
#include "regcache.h"
|
24 |
|
|
#include "target.h"
|
25 |
|
|
|
26 |
|
|
#include <sys/param.h>
|
27 |
|
|
#include <sys/sysctl.h>
|
28 |
|
|
#include <machine/frame.h>
|
29 |
|
|
#include <machine/pcb.h>
|
30 |
|
|
|
31 |
|
|
#include "i386-tdep.h"
|
32 |
|
|
#include "i386bsd-nat.h"
|
33 |
|
|
#include "bsd-kvm.h"
|
34 |
|
|
|
35 |
|
|
static int
|
36 |
|
|
i386obsd_supply_pcb (struct regcache *regcache, struct pcb *pcb)
|
37 |
|
|
{
|
38 |
|
|
struct gdbarch *gdbarch = get_regcache_arch (regcache);
|
39 |
|
|
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
|
40 |
|
|
struct switchframe sf;
|
41 |
|
|
|
42 |
|
|
/* The following is true for OpenBSD 3.6:
|
43 |
|
|
|
44 |
|
|
The pcb contains %esp and %ebp at the point of the context switch
|
45 |
|
|
in cpu_switch(). At that point we have a stack frame as
|
46 |
|
|
described by `struct switchframe', which for OpenBSD 3.6 has the
|
47 |
|
|
following layout:
|
48 |
|
|
|
49 |
|
|
interrupt level
|
50 |
|
|
%edi
|
51 |
|
|
%esi
|
52 |
|
|
%ebx
|
53 |
|
|
%eip
|
54 |
|
|
|
55 |
|
|
we reconstruct the register state as it would look when we just
|
56 |
|
|
returned from cpu_switch(). */
|
57 |
|
|
|
58 |
|
|
/* The stack pointer shouldn't be zero. */
|
59 |
|
|
if (pcb->pcb_esp == 0)
|
60 |
|
|
return 0;
|
61 |
|
|
|
62 |
|
|
/* Read the stack frame, and check its validity. We do this by
|
63 |
|
|
checking if the saved interrupt priority level in the stack frame
|
64 |
|
|
looks reasonable.. */
|
65 |
|
|
#ifdef PCB_SAVECTX
|
66 |
|
|
if ((pcb->pcb_flags & PCB_SAVECTX) == 0)
|
67 |
|
|
{
|
68 |
|
|
/* Yes, we have a frame that matches cpu_switch(). */
|
69 |
|
|
read_memory (pcb->pcb_esp, (char *) &sf, sizeof sf);
|
70 |
|
|
pcb->pcb_esp += sizeof (struct switchframe);
|
71 |
|
|
regcache_raw_supply (regcache, I386_EDI_REGNUM, &sf.sf_edi);
|
72 |
|
|
regcache_raw_supply (regcache, I386_ESI_REGNUM, &sf.sf_esi);
|
73 |
|
|
regcache_raw_supply (regcache, I386_EBX_REGNUM, &sf.sf_ebx);
|
74 |
|
|
regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip);
|
75 |
|
|
}
|
76 |
|
|
else
|
77 |
|
|
#endif
|
78 |
|
|
{
|
79 |
|
|
/* No, the pcb must have been last updated by savectx(). */
|
80 |
|
|
pcb->pcb_esp = pcb->pcb_ebp;
|
81 |
|
|
pcb->pcb_ebp = read_memory_integer(pcb->pcb_esp, 4, byte_order);
|
82 |
|
|
sf.sf_eip = read_memory_integer(pcb->pcb_esp + 4, 4, byte_order);
|
83 |
|
|
regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip);
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp);
|
87 |
|
|
regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp);
|
88 |
|
|
|
89 |
|
|
return 1;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
/* Prevent warning from -Wmissing-prototypes. */
|
94 |
|
|
void _initialize_i386obsd_nat (void);
|
95 |
|
|
|
96 |
|
|
void
|
97 |
|
|
_initialize_i386obsd_nat (void)
|
98 |
|
|
{
|
99 |
|
|
/* We've got nothing to add to the common *BSD/i386 target. */
|
100 |
|
|
add_target (i386bsd_target ());
|
101 |
|
|
|
102 |
|
|
/* Support debugging kernel virtual memory images. */
|
103 |
|
|
bsd_kvm_add_target (i386obsd_supply_pcb);
|
104 |
|
|
|
105 |
|
|
/* OpenBSD provides a vm.psstrings sysctl that we can use to locate
|
106 |
|
|
the sigtramp. That way we can still recognize a sigtramp if its
|
107 |
|
|
location is changed in a new kernel. This is especially
|
108 |
|
|
important for OpenBSD, since it uses a different memory layout
|
109 |
|
|
than NetBSD, yet we cannot distinguish between the two.
|
110 |
|
|
|
111 |
|
|
Of course this is still based on the assumption that the sigtramp
|
112 |
|
|
is placed directly under the location where the program arguments
|
113 |
|
|
and environment can be found. */
|
114 |
|
|
#ifdef VM_PSSTRINGS
|
115 |
|
|
{
|
116 |
|
|
struct _ps_strings _ps;
|
117 |
|
|
int mib[2];
|
118 |
|
|
size_t len;
|
119 |
|
|
|
120 |
|
|
mib[0] = CTL_VM;
|
121 |
|
|
mib[1] = VM_PSSTRINGS;
|
122 |
|
|
len = sizeof (_ps);
|
123 |
|
|
if (sysctl (mib, 2, &_ps, &len, NULL, 0) == 0)
|
124 |
|
|
{
|
125 |
|
|
i386obsd_sigtramp_start_addr = (u_long) _ps.val - 128;
|
126 |
|
|
i386obsd_sigtramp_end_addr = (u_long) _ps.val;
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
#endif
|
130 |
|
|
}
|