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