Commit | Line | Data |
---|---|---|
baadce09 | 1 | /* Native-dependent code for OpenBSD/i386. |
5d93ae8c | 2 | |
0fb0cc75 | 3 | Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008, 2009 |
9b254dd1 | 4 | Free Software Foundation, Inc. |
baadce09 MK |
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 | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
baadce09 MK |
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 | |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
baadce09 MK |
20 | |
21 | #include "defs.h" | |
5d0fc17b MK |
22 | #include "gdbcore.h" |
23 | #include "regcache.h" | |
24 | #include "target.h" | |
baadce09 MK |
25 | |
26 | #include <sys/param.h> | |
27 | #include <sys/sysctl.h> | |
5d0fc17b MK |
28 | #include <machine/frame.h> |
29 | #include <machine/pcb.h> | |
baadce09 | 30 | |
e2dbbd2d | 31 | #include "i386-tdep.h" |
5d0fc17b MK |
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 switchframe sf; | |
39 | ||
40 | /* The following is true for OpenBSD 3.6: | |
41 | ||
42 | The pcb contains %esp and %ebp at the point of the context switch | |
43 | in cpu_switch(). At that point we have a stack frame as | |
44 | described by `struct switchframe', which for OpenBSD 3.6 has the | |
45 | following layout: | |
46 | ||
47 | interrupt level | |
48 | %edi | |
49 | %esi | |
50 | %ebx | |
51 | %eip | |
52 | ||
53 | we reconstruct the register state as it would look when we just | |
54 | returned from cpu_switch(). */ | |
55 | ||
56 | /* The stack pointer shouldn't be zero. */ | |
57 | if (pcb->pcb_esp == 0) | |
58 | return 0; | |
59 | ||
60 | /* Read the stack frame, and check its validity. We do this by | |
61 | checking if the saved interrupt priority level in the stack frame | |
62 | looks reasonable.. */ | |
f73a15e4 MK |
63 | #ifdef PCB_SAVECTX |
64 | if ((pcb->pcb_flags & PCB_SAVECTX) == 0) | |
5d0fc17b MK |
65 | { |
66 | /* Yes, we have a frame that matches cpu_switch(). */ | |
f73a15e4 | 67 | read_memory (pcb->pcb_esp, (char *) &sf, sizeof sf); |
5d0fc17b MK |
68 | pcb->pcb_esp += sizeof (struct switchframe); |
69 | regcache_raw_supply (regcache, I386_EDI_REGNUM, &sf.sf_edi); | |
70 | regcache_raw_supply (regcache, I386_ESI_REGNUM, &sf.sf_esi); | |
71 | regcache_raw_supply (regcache, I386_EBX_REGNUM, &sf.sf_ebx); | |
72 | regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip); | |
73 | } | |
74 | else | |
f73a15e4 | 75 | #endif |
5d0fc17b MK |
76 | { |
77 | /* No, the pcb must have been last updated by savectx(). */ | |
f73a15e4 MK |
78 | pcb->pcb_esp = pcb->pcb_ebp; |
79 | pcb->pcb_ebp = read_memory_integer(pcb->pcb_esp, 4); | |
80 | sf.sf_eip = read_memory_integer(pcb->pcb_esp + 4, 4); | |
3979a37f | 81 | regcache_raw_supply (regcache, I386_EIP_REGNUM, &sf.sf_eip); |
5d0fc17b MK |
82 | } |
83 | ||
84 | regcache_raw_supply (regcache, I386_EBP_REGNUM, &pcb->pcb_ebp); | |
85 | regcache_raw_supply (regcache, I386_ESP_REGNUM, &pcb->pcb_esp); | |
86 | ||
87 | return 1; | |
88 | } | |
89 | \f | |
e2dbbd2d | 90 | |
baadce09 | 91 | /* Prevent warning from -Wmissing-prototypes. */ |
e5e4acad | 92 | void _initialize_i386obsd_nat (void); |
baadce09 MK |
93 | |
94 | void | |
95 | _initialize_i386obsd_nat (void) | |
96 | { | |
5d0fc17b MK |
97 | /* We've got nothing to add to the common *BSD/i386 target. */ |
98 | add_target (i386bsd_target ()); | |
99 | ||
100 | /* Support debugging kernel virtual memory images. */ | |
101 | bsd_kvm_add_target (i386obsd_supply_pcb); | |
102 | ||
baadce09 MK |
103 | /* OpenBSD provides a vm.psstrings sysctl that we can use to locate |
104 | the sigtramp. That way we can still recognize a sigtramp if its | |
105 | location is changed in a new kernel. This is especially | |
106 | important for OpenBSD, since it uses a different memory layout | |
107 | than NetBSD, yet we cannot distinguish between the two. | |
108 | ||
109 | Of course this is still based on the assumption that the sigtramp | |
110 | is placed directly under the location where the program arguments | |
111 | and environment can be found. */ | |
112 | #ifdef VM_PSSTRINGS | |
113 | { | |
114 | struct _ps_strings _ps; | |
115 | int mib[2]; | |
116 | size_t len; | |
117 | ||
baadce09 MK |
118 | mib[0] = CTL_VM; |
119 | mib[1] = VM_PSSTRINGS; | |
120 | len = sizeof (_ps); | |
121 | if (sysctl (mib, 2, &_ps, &len, NULL, 0) == 0) | |
122 | { | |
57ac95b8 MK |
123 | i386obsd_sigtramp_start_addr = (u_long) _ps.val - 128; |
124 | i386obsd_sigtramp_end_addr = (u_long) _ps.val; | |
baadce09 MK |
125 | } |
126 | } | |
127 | #endif | |
128 | } |