Commit | Line | Data |
---|---|---|
fb0e1ba7 | 1 | /* <proc_service.h> implementation. |
ca557f44 | 2 | |
28e7fd62 | 3 | Copyright (C) 1999-2013 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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
fb0e1ba7 MK |
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 | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
fb0e1ba7 MK |
19 | |
20 | #include "defs.h" | |
21 | ||
76e1ee85 | 22 | #include "gdbcore.h" |
fb0e1ba7 MK |
23 | #include "inferior.h" |
24 | #include "symtab.h" | |
25 | #include "target.h" | |
7f7fe91e | 26 | #include "regcache.h" |
fb0e1ba7 | 27 | |
76e1ee85 | 28 | #include "gdb_proc_service.h" |
76e1ee85 DJ |
29 | |
30 | #include <sys/procfs.h> | |
31 | ||
fb0e1ba7 MK |
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 | ||
fb0e1ba7 MK |
54 | /* Helper functions. */ |
55 | ||
76e1ee85 DJ |
56 | /* Convert a psaddr_t to a CORE_ADDR. */ |
57 | ||
58 | static CORE_ADDR | |
59 | ps_addr_to_core_addr (psaddr_t addr) | |
60 | { | |
61 | if (exec_bfd && bfd_get_sign_extend_vma (exec_bfd)) | |
62 | return (intptr_t) addr; | |
63 | else | |
64 | return (uintptr_t) addr; | |
65 | } | |
66 | ||
67 | /* Convert a CORE_ADDR to a psaddr_t. */ | |
68 | ||
69 | static psaddr_t | |
70 | core_addr_to_ps_addr (CORE_ADDR addr) | |
71 | { | |
72 | if (exec_bfd && bfd_get_sign_extend_vma (exec_bfd)) | |
73 | return (psaddr_t) (intptr_t) addr; | |
74 | else | |
75 | return (psaddr_t) (uintptr_t) addr; | |
76 | } | |
77 | ||
fb0e1ba7 MK |
78 | /* Transfer LEN bytes of memory between BUF and address ADDR in the |
79 | process specified by PH. If WRITE, transfer them to the process, | |
80 | else transfer them from the process. Returns PS_OK for success, | |
81 | PS_ERR on failure. | |
82 | ||
83 | This is a helper function for ps_pdread, ps_pdwrite, ps_ptread and | |
84 | ps_ptwrite. */ | |
85 | ||
86 | static ps_err_e | |
76e1ee85 | 87 | ps_xfer_memory (const struct ps_prochandle *ph, psaddr_t addr, |
47b667de | 88 | gdb_byte *buf, size_t len, int write) |
fb0e1ba7 | 89 | { |
39f77062 | 90 | struct cleanup *old_chain = save_inferior_ptid (); |
fb0e1ba7 | 91 | int ret; |
76e1ee85 | 92 | CORE_ADDR core_addr = ps_addr_to_core_addr (addr); |
fb0e1ba7 | 93 | |
93a91755 | 94 | inferior_ptid = ph->ptid; |
fb0e1ba7 MK |
95 | |
96 | if (write) | |
76e1ee85 | 97 | ret = target_write_memory (core_addr, buf, len); |
fb0e1ba7 | 98 | else |
76e1ee85 | 99 | ret = target_read_memory (core_addr, buf, len); |
fb0e1ba7 MK |
100 | |
101 | do_cleanups (old_chain); | |
102 | ||
103 | return (ret == 0 ? PS_OK : PS_ERR); | |
104 | } | |
105 | \f | |
106 | ||
107 | /* Stop the target process PH. */ | |
108 | ||
109 | ps_err_e | |
110 | ps_pstop (gdb_ps_prochandle_t ph) | |
111 | { | |
112 | /* The process is always stopped when under control of GDB. */ | |
113 | return PS_OK; | |
114 | } | |
115 | ||
116 | /* Resume the target process PH. */ | |
117 | ||
118 | ps_err_e | |
119 | ps_pcontinue (gdb_ps_prochandle_t ph) | |
120 | { | |
121 | /* Pretend we did successfully continue the process. GDB will take | |
122 | care of it later on. */ | |
123 | return PS_OK; | |
124 | } | |
125 | ||
126 | /* Stop the lightweight process LWPID within the target process PH. */ | |
127 | ||
128 | ps_err_e | |
129 | ps_lstop (gdb_ps_prochandle_t ph, lwpid_t lwpid) | |
130 | { | |
131 | /* All lightweight processes are stopped when under control of GDB. */ | |
132 | return PS_OK; | |
133 | } | |
134 | ||
135 | /* Resume the lightweight process (LWP) LWPID within the target | |
136 | process PH. */ | |
137 | ||
138 | ps_err_e | |
139 | ps_lcontinue (gdb_ps_prochandle_t ph, lwpid_t lwpid) | |
140 | { | |
141 | /* Pretend we did successfully continue LWPID. GDB will take care | |
142 | of it later on. */ | |
143 | return PS_OK; | |
144 | } | |
145 | ||
146 | /* Get the size of the architecture-dependent extra state registers | |
147 | for LWP LWPID within the target process PH and return it in | |
148 | *XREGSIZE. */ | |
149 | ||
150 | ps_err_e | |
151 | ps_lgetxregsize (gdb_ps_prochandle_t ph, lwpid_t lwpid, int *xregsize) | |
152 | { | |
153 | /* FIXME: Not supported yet. */ | |
154 | return PS_OK; | |
155 | } | |
156 | ||
157 | /* Get the extra state registers of LWP LWPID within the target | |
158 | process PH and store them in XREGSET. */ | |
159 | ||
160 | ps_err_e | |
161 | ps_lgetxregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, caddr_t xregset) | |
162 | { | |
163 | /* FIXME: Not supported yet. */ | |
164 | return PS_OK; | |
165 | } | |
166 | ||
167 | /* Set the extra state registers of LWP LWPID within the target | |
168 | process PH from XREGSET. */ | |
169 | ||
170 | ps_err_e | |
171 | ps_lsetxregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, caddr_t xregset) | |
172 | { | |
173 | /* FIXME: Not supported yet. */ | |
174 | return PS_OK; | |
175 | } | |
176 | ||
177 | /* Log (additional) diognostic information. */ | |
178 | ||
179 | void | |
180 | ps_plog (const char *fmt, ...) | |
181 | { | |
182 | va_list args; | |
183 | ||
184 | va_start (args, fmt); | |
185 | vfprintf_filtered (gdb_stderr, fmt, args); | |
0480cefa | 186 | va_end (args); |
fb0e1ba7 MK |
187 | } |
188 | ||
189 | /* Search for the symbol named NAME within the object named OBJ within | |
190 | the target process PH. If the symbol is found the address of the | |
191 | symbol is stored in SYM_ADDR. */ | |
192 | ||
193 | ps_err_e | |
194 | ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj, | |
76e1ee85 | 195 | const char *name, psaddr_t *sym_addr) |
fb0e1ba7 MK |
196 | { |
197 | struct minimal_symbol *ms; | |
c988ad87 TT |
198 | struct cleanup *old_chain = save_current_program_space (); |
199 | struct inferior *inf = find_inferior_pid (ptid_get_pid (ph->ptid)); | |
200 | ps_err_e result; | |
201 | ||
202 | set_current_program_space (inf->pspace); | |
fb0e1ba7 MK |
203 | |
204 | /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */ | |
205 | ms = lookup_minimal_symbol (name, NULL, NULL); | |
206 | if (ms == NULL) | |
c988ad87 TT |
207 | result = PS_NOSYM; |
208 | else | |
209 | { | |
210 | *sym_addr = core_addr_to_ps_addr (SYMBOL_VALUE_ADDRESS (ms)); | |
211 | result = PS_OK; | |
212 | } | |
fb0e1ba7 | 213 | |
c988ad87 TT |
214 | do_cleanups (old_chain); |
215 | return result; | |
fb0e1ba7 MK |
216 | } |
217 | ||
218 | /* Read SIZE bytes from the target process PH at address ADDR and copy | |
219 | them into BUF. */ | |
220 | ||
221 | ps_err_e | |
76e1ee85 | 222 | ps_pdread (gdb_ps_prochandle_t ph, psaddr_t addr, |
fb0e1ba7 MK |
223 | gdb_ps_read_buf_t buf, gdb_ps_size_t size) |
224 | { | |
225 | return ps_xfer_memory (ph, addr, buf, size, 0); | |
226 | } | |
227 | ||
228 | /* Write SIZE bytes from BUF into the target process PH at address ADDR. */ | |
229 | ||
230 | ps_err_e | |
76e1ee85 | 231 | ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr, |
fb0e1ba7 MK |
232 | gdb_ps_write_buf_t buf, gdb_ps_size_t size) |
233 | { | |
47b667de | 234 | return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 1); |
fb0e1ba7 MK |
235 | } |
236 | ||
237 | /* Read SIZE bytes from the target process PH at address ADDR and copy | |
238 | them into BUF. */ | |
239 | ||
240 | ps_err_e | |
76e1ee85 | 241 | ps_ptread (gdb_ps_prochandle_t ph, psaddr_t addr, |
fb0e1ba7 MK |
242 | gdb_ps_read_buf_t buf, gdb_ps_size_t size) |
243 | { | |
47b667de | 244 | return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 0); |
fb0e1ba7 MK |
245 | } |
246 | ||
247 | /* Write SIZE bytes from BUF into the target process PH at address ADDR. */ | |
248 | ||
249 | ps_err_e | |
76e1ee85 | 250 | ps_ptwrite (gdb_ps_prochandle_t ph, psaddr_t addr, |
fb0e1ba7 MK |
251 | gdb_ps_write_buf_t buf, gdb_ps_size_t size) |
252 | { | |
47b667de | 253 | return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 1); |
fb0e1ba7 MK |
254 | } |
255 | ||
256 | /* Get the general registers of LWP LWPID within the target process PH | |
257 | and store them in GREGSET. */ | |
258 | ||
259 | ps_err_e | |
260 | ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset) | |
261 | { | |
39f77062 | 262 | struct cleanup *old_chain = save_inferior_ptid (); |
594f7785 | 263 | struct regcache *regcache; |
fb0e1ba7 | 264 | |
dfd4cc63 | 265 | inferior_ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0); |
f5656ead | 266 | regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ()); |
fb0e1ba7 | 267 | |
594f7785 UW |
268 | target_fetch_registers (regcache, -1); |
269 | fill_gregset (regcache, (gdb_gregset_t *) gregset, -1); | |
fb0e1ba7 MK |
270 | |
271 | do_cleanups (old_chain); | |
272 | return PS_OK; | |
273 | } | |
274 | ||
275 | /* Set the general registers of LWP LWPID within the target process PH | |
276 | from GREGSET. */ | |
277 | ||
278 | ps_err_e | |
279 | ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset) | |
280 | { | |
39f77062 | 281 | struct cleanup *old_chain = save_inferior_ptid (); |
594f7785 | 282 | struct regcache *regcache; |
fb0e1ba7 | 283 | |
dfd4cc63 | 284 | inferior_ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0); |
f5656ead | 285 | regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ()); |
fb0e1ba7 | 286 | |
594f7785 UW |
287 | supply_gregset (regcache, (const gdb_gregset_t *) gregset); |
288 | target_store_registers (regcache, -1); | |
fb0e1ba7 MK |
289 | |
290 | do_cleanups (old_chain); | |
291 | return PS_OK; | |
292 | } | |
293 | ||
294 | /* Get the floating-point registers of LWP LWPID within the target | |
295 | process PH and store them in FPREGSET. */ | |
296 | ||
297 | ps_err_e | |
298 | ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, | |
299 | gdb_prfpregset_t *fpregset) | |
300 | { | |
39f77062 | 301 | struct cleanup *old_chain = save_inferior_ptid (); |
594f7785 | 302 | struct regcache *regcache; |
fb0e1ba7 | 303 | |
dfd4cc63 | 304 | inferior_ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0); |
f5656ead | 305 | regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ()); |
fb0e1ba7 | 306 | |
594f7785 UW |
307 | target_fetch_registers (regcache, -1); |
308 | fill_fpregset (regcache, (gdb_fpregset_t *) fpregset, -1); | |
fb0e1ba7 MK |
309 | |
310 | do_cleanups (old_chain); | |
311 | return PS_OK; | |
312 | } | |
313 | ||
314 | /* Set the floating-point registers of LWP LWPID within the target | |
315 | process PH from FPREGSET. */ | |
316 | ||
317 | ps_err_e | |
318 | ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, | |
319 | const gdb_prfpregset_t *fpregset) | |
320 | { | |
39f77062 | 321 | struct cleanup *old_chain = save_inferior_ptid (); |
594f7785 | 322 | struct regcache *regcache; |
fb0e1ba7 | 323 | |
dfd4cc63 | 324 | inferior_ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0); |
f5656ead | 325 | regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ()); |
fb0e1ba7 | 326 | |
594f7785 UW |
327 | supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset); |
328 | target_store_registers (regcache, -1); | |
fb0e1ba7 MK |
329 | |
330 | do_cleanups (old_chain); | |
331 | return PS_OK; | |
332 | } | |
333 | ||
ca557f44 AC |
334 | /* Return overall process id of the target PH. Special for GNU/Linux |
335 | -- not used on Solaris. */ | |
fb0e1ba7 MK |
336 | |
337 | pid_t | |
338 | ps_getpid (gdb_ps_prochandle_t ph) | |
339 | { | |
93a91755 | 340 | return ptid_get_pid (ph->ptid); |
fb0e1ba7 MK |
341 | } |
342 | ||
2c0b251b PA |
343 | /* Provide a prototype to silence -Wmissing-prototypes. */ |
344 | extern initialize_file_ftype _initialize_proc_service; | |
345 | ||
fb0e1ba7 MK |
346 | void |
347 | _initialize_proc_service (void) | |
348 | { | |
349 | /* This function solely exists to make sure this module is linked | |
350 | into the final binary. */ | |
351 | } |