Commit | Line | Data |
---|---|---|
fb0e1ba7 | 1 | /* <proc_service.h> implementation. |
ca557f44 | 2 | |
6aba47ca | 3 | Copyright (C) 1999, 2000, 2002, 2007 Free Software Foundation, Inc. |
fb0e1ba7 MK |
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 2 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, write to the Free Software | |
197e01b6 EZ |
19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | Boston, MA 02110-1301, USA. */ | |
fb0e1ba7 MK |
21 | |
22 | #include "defs.h" | |
23 | ||
24 | #include "gdb_proc_service.h" | |
25 | #include <sys/procfs.h> | |
26 | ||
27 | #include "inferior.h" | |
28 | #include "symtab.h" | |
29 | #include "target.h" | |
7f7fe91e | 30 | #include "regcache.h" |
fb0e1ba7 MK |
31 | |
32 | /* Prototypes for supply_gregset etc. */ | |
33 | #include "gregset.h" | |
34 | \f | |
35 | ||
36 | /* Fix-up some broken systems. */ | |
37 | ||
38 | /* The prototypes in <proc_service.h> are slightly different on older | |
39 | systems. Compensate for the discrepancies. */ | |
40 | ||
41 | #ifdef PROC_SERVICE_IS_OLD | |
42 | typedef const struct ps_prochandle *gdb_ps_prochandle_t; | |
43 | typedef char *gdb_ps_read_buf_t; | |
44 | typedef char *gdb_ps_write_buf_t; | |
45 | typedef int gdb_ps_size_t; | |
46 | #else | |
47 | typedef struct ps_prochandle *gdb_ps_prochandle_t; | |
48 | typedef void *gdb_ps_read_buf_t; | |
49 | typedef const void *gdb_ps_write_buf_t; | |
50 | typedef size_t gdb_ps_size_t; | |
51 | #endif | |
52 | \f | |
53 | ||
54 | /* Building process ids. */ | |
55 | ||
c987d8c0 | 56 | #define BUILD_LWP(lwp, pid) ptid_build (pid, lwp, 0) |
fb0e1ba7 MK |
57 | \f |
58 | ||
59 | /* Helper functions. */ | |
60 | ||
fb0e1ba7 MK |
61 | /* Transfer LEN bytes of memory between BUF and address ADDR in the |
62 | process specified by PH. If WRITE, transfer them to the process, | |
63 | else transfer them from the process. Returns PS_OK for success, | |
64 | PS_ERR on failure. | |
65 | ||
66 | This is a helper function for ps_pdread, ps_pdwrite, ps_ptread and | |
67 | ps_ptwrite. */ | |
68 | ||
69 | static ps_err_e | |
70 | ps_xfer_memory (const struct ps_prochandle *ph, paddr_t addr, | |
47b667de | 71 | gdb_byte *buf, size_t len, int write) |
fb0e1ba7 | 72 | { |
39f77062 | 73 | struct cleanup *old_chain = save_inferior_ptid (); |
fb0e1ba7 MK |
74 | int ret; |
75 | ||
39f77062 | 76 | inferior_ptid = pid_to_ptid (ph->pid); |
fb0e1ba7 MK |
77 | |
78 | if (write) | |
79 | ret = target_write_memory (addr, buf, len); | |
80 | else | |
81 | ret = target_read_memory (addr, buf, len); | |
82 | ||
83 | do_cleanups (old_chain); | |
84 | ||
85 | return (ret == 0 ? PS_OK : PS_ERR); | |
86 | } | |
87 | \f | |
88 | ||
89 | /* Stop the target process PH. */ | |
90 | ||
91 | ps_err_e | |
92 | ps_pstop (gdb_ps_prochandle_t ph) | |
93 | { | |
94 | /* The process is always stopped when under control of GDB. */ | |
95 | return PS_OK; | |
96 | } | |
97 | ||
98 | /* Resume the target process PH. */ | |
99 | ||
100 | ps_err_e | |
101 | ps_pcontinue (gdb_ps_prochandle_t ph) | |
102 | { | |
103 | /* Pretend we did successfully continue the process. GDB will take | |
104 | care of it later on. */ | |
105 | return PS_OK; | |
106 | } | |
107 | ||
108 | /* Stop the lightweight process LWPID within the target process PH. */ | |
109 | ||
110 | ps_err_e | |
111 | ps_lstop (gdb_ps_prochandle_t ph, lwpid_t lwpid) | |
112 | { | |
113 | /* All lightweight processes are stopped when under control of GDB. */ | |
114 | return PS_OK; | |
115 | } | |
116 | ||
117 | /* Resume the lightweight process (LWP) LWPID within the target | |
118 | process PH. */ | |
119 | ||
120 | ps_err_e | |
121 | ps_lcontinue (gdb_ps_prochandle_t ph, lwpid_t lwpid) | |
122 | { | |
123 | /* Pretend we did successfully continue LWPID. GDB will take care | |
124 | of it later on. */ | |
125 | return PS_OK; | |
126 | } | |
127 | ||
128 | /* Get the size of the architecture-dependent extra state registers | |
129 | for LWP LWPID within the target process PH and return it in | |
130 | *XREGSIZE. */ | |
131 | ||
132 | ps_err_e | |
133 | ps_lgetxregsize (gdb_ps_prochandle_t ph, lwpid_t lwpid, int *xregsize) | |
134 | { | |
135 | /* FIXME: Not supported yet. */ | |
136 | return PS_OK; | |
137 | } | |
138 | ||
139 | /* Get the extra state registers of LWP LWPID within the target | |
140 | process PH and store them in XREGSET. */ | |
141 | ||
142 | ps_err_e | |
143 | ps_lgetxregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, caddr_t xregset) | |
144 | { | |
145 | /* FIXME: Not supported yet. */ | |
146 | return PS_OK; | |
147 | } | |
148 | ||
149 | /* Set the extra state registers of LWP LWPID within the target | |
150 | process PH from XREGSET. */ | |
151 | ||
152 | ps_err_e | |
153 | ps_lsetxregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, caddr_t xregset) | |
154 | { | |
155 | /* FIXME: Not supported yet. */ | |
156 | return PS_OK; | |
157 | } | |
158 | ||
159 | /* Log (additional) diognostic information. */ | |
160 | ||
161 | void | |
162 | ps_plog (const char *fmt, ...) | |
163 | { | |
164 | va_list args; | |
165 | ||
166 | va_start (args, fmt); | |
167 | vfprintf_filtered (gdb_stderr, fmt, args); | |
168 | } | |
169 | ||
170 | /* Search for the symbol named NAME within the object named OBJ within | |
171 | the target process PH. If the symbol is found the address of the | |
172 | symbol is stored in SYM_ADDR. */ | |
173 | ||
174 | ps_err_e | |
175 | ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj, | |
176 | const char *name, paddr_t *sym_addr) | |
177 | { | |
178 | struct minimal_symbol *ms; | |
179 | ||
180 | /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */ | |
181 | ms = lookup_minimal_symbol (name, NULL, NULL); | |
182 | if (ms == NULL) | |
183 | return PS_NOSYM; | |
184 | ||
185 | *sym_addr = SYMBOL_VALUE_ADDRESS (ms); | |
186 | return PS_OK; | |
187 | } | |
188 | ||
189 | /* Read SIZE bytes from the target process PH at address ADDR and copy | |
190 | them into BUF. */ | |
191 | ||
192 | ps_err_e | |
193 | ps_pdread (gdb_ps_prochandle_t ph, paddr_t addr, | |
194 | gdb_ps_read_buf_t buf, gdb_ps_size_t size) | |
195 | { | |
196 | return ps_xfer_memory (ph, addr, buf, size, 0); | |
197 | } | |
198 | ||
199 | /* Write SIZE bytes from BUF into the target process PH at address ADDR. */ | |
200 | ||
201 | ps_err_e | |
202 | ps_pdwrite (gdb_ps_prochandle_t ph, paddr_t addr, | |
203 | gdb_ps_write_buf_t buf, gdb_ps_size_t size) | |
204 | { | |
47b667de | 205 | return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 1); |
fb0e1ba7 MK |
206 | } |
207 | ||
208 | /* Read SIZE bytes from the target process PH at address ADDR and copy | |
209 | them into BUF. */ | |
210 | ||
211 | ps_err_e | |
212 | ps_ptread (gdb_ps_prochandle_t ph, paddr_t addr, | |
213 | gdb_ps_read_buf_t buf, gdb_ps_size_t size) | |
214 | { | |
47b667de | 215 | return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 0); |
fb0e1ba7 MK |
216 | } |
217 | ||
218 | /* Write SIZE bytes from BUF into the target process PH at address ADDR. */ | |
219 | ||
220 | ps_err_e | |
221 | ps_ptwrite (gdb_ps_prochandle_t ph, paddr_t addr, | |
222 | gdb_ps_write_buf_t buf, gdb_ps_size_t size) | |
223 | { | |
47b667de | 224 | return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 1); |
fb0e1ba7 MK |
225 | } |
226 | ||
227 | /* Get the general registers of LWP LWPID within the target process PH | |
228 | and store them in GREGSET. */ | |
229 | ||
230 | ps_err_e | |
231 | ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset) | |
232 | { | |
39f77062 | 233 | struct cleanup *old_chain = save_inferior_ptid (); |
fb0e1ba7 | 234 | |
39f77062 | 235 | inferior_ptid = BUILD_LWP (lwpid, ph->pid); |
fb0e1ba7 MK |
236 | |
237 | target_fetch_registers (-1); | |
7f7fe91e | 238 | fill_gregset (current_regcache, (gdb_gregset_t *) gregset, -1); |
fb0e1ba7 MK |
239 | |
240 | do_cleanups (old_chain); | |
241 | return PS_OK; | |
242 | } | |
243 | ||
244 | /* Set the general registers of LWP LWPID within the target process PH | |
245 | from GREGSET. */ | |
246 | ||
247 | ps_err_e | |
248 | ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset) | |
249 | { | |
39f77062 | 250 | struct cleanup *old_chain = save_inferior_ptid (); |
fb0e1ba7 | 251 | |
39f77062 | 252 | inferior_ptid = BUILD_LWP (lwpid, ph->pid); |
fb0e1ba7 | 253 | |
7f7fe91e | 254 | supply_gregset (current_regcache, (const gdb_gregset_t *) gregset); |
fb0e1ba7 MK |
255 | target_store_registers (-1); |
256 | ||
257 | do_cleanups (old_chain); | |
258 | return PS_OK; | |
259 | } | |
260 | ||
261 | /* Get the floating-point registers of LWP LWPID within the target | |
262 | process PH and store them in FPREGSET. */ | |
263 | ||
264 | ps_err_e | |
265 | ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, | |
266 | gdb_prfpregset_t *fpregset) | |
267 | { | |
39f77062 | 268 | struct cleanup *old_chain = save_inferior_ptid (); |
fb0e1ba7 | 269 | |
39f77062 | 270 | inferior_ptid = BUILD_LWP (lwpid, ph->pid); |
fb0e1ba7 MK |
271 | |
272 | target_fetch_registers (-1); | |
7f7fe91e | 273 | fill_fpregset (current_regcache, (gdb_fpregset_t *) fpregset, -1); |
fb0e1ba7 MK |
274 | |
275 | do_cleanups (old_chain); | |
276 | return PS_OK; | |
277 | } | |
278 | ||
279 | /* Set the floating-point registers of LWP LWPID within the target | |
280 | process PH from FPREGSET. */ | |
281 | ||
282 | ps_err_e | |
283 | ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, | |
284 | const gdb_prfpregset_t *fpregset) | |
285 | { | |
39f77062 | 286 | struct cleanup *old_chain = save_inferior_ptid (); |
fb0e1ba7 | 287 | |
39f77062 | 288 | inferior_ptid = BUILD_LWP (lwpid, ph->pid); |
fb0e1ba7 | 289 | |
7f7fe91e | 290 | supply_fpregset (current_regcache, (const gdb_fpregset_t *) fpregset); |
fb0e1ba7 MK |
291 | target_store_registers (-1); |
292 | ||
293 | do_cleanups (old_chain); | |
294 | return PS_OK; | |
295 | } | |
296 | ||
ca557f44 AC |
297 | /* Return overall process id of the target PH. Special for GNU/Linux |
298 | -- not used on Solaris. */ | |
fb0e1ba7 MK |
299 | |
300 | pid_t | |
301 | ps_getpid (gdb_ps_prochandle_t ph) | |
302 | { | |
303 | return ph->pid; | |
304 | } | |
305 | ||
306 | void | |
307 | _initialize_proc_service (void) | |
308 | { | |
309 | /* This function solely exists to make sure this module is linked | |
310 | into the final binary. */ | |
311 | } |