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