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