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