1 /* <proc_service.h> implementation.
3 Copyright (C) 1999, 2000, 2002, 2007 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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
19 Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
30 #include "gdb_proc_service.h"
31 #include "gdb_stdint.h"
33 #include <sys/procfs.h>
35 /* Prototypes for supply_gregset etc. */
39 /* Fix-up some broken systems. */
41 /* The prototypes in <proc_service.h> are slightly different on older
42 systems. Compensate for the discrepancies. */
44 #ifdef PROC_SERVICE_IS_OLD
45 typedef const struct ps_prochandle
*gdb_ps_prochandle_t
;
46 typedef char *gdb_ps_read_buf_t
;
47 typedef char *gdb_ps_write_buf_t
;
48 typedef int gdb_ps_size_t
;
50 typedef struct ps_prochandle
*gdb_ps_prochandle_t
;
51 typedef void *gdb_ps_read_buf_t
;
52 typedef const void *gdb_ps_write_buf_t
;
53 typedef size_t gdb_ps_size_t
;
57 /* Building process ids. */
59 #define BUILD_LWP(lwp, pid) ptid_build (pid, lwp, 0)
62 /* Helper functions. */
64 /* Convert a psaddr_t to a CORE_ADDR. */
67 ps_addr_to_core_addr (psaddr_t addr
)
69 if (exec_bfd
&& bfd_get_sign_extend_vma (exec_bfd
))
70 return (intptr_t) addr
;
72 return (uintptr_t) addr
;
75 /* Convert a CORE_ADDR to a psaddr_t. */
78 core_addr_to_ps_addr (CORE_ADDR addr
)
80 if (exec_bfd
&& bfd_get_sign_extend_vma (exec_bfd
))
81 return (psaddr_t
) (intptr_t) addr
;
83 return (psaddr_t
) (uintptr_t) addr
;
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,
91 This is a helper function for ps_pdread, ps_pdwrite, ps_ptread and
95 ps_xfer_memory (const struct ps_prochandle
*ph
, psaddr_t addr
,
96 gdb_byte
*buf
, size_t len
, int write
)
98 struct cleanup
*old_chain
= save_inferior_ptid ();
100 CORE_ADDR core_addr
= ps_addr_to_core_addr (addr
);
102 inferior_ptid
= pid_to_ptid (ph
->pid
);
105 ret
= target_write_memory (core_addr
, buf
, len
);
107 ret
= target_read_memory (core_addr
, buf
, len
);
109 do_cleanups (old_chain
);
111 return (ret
== 0 ? PS_OK
: PS_ERR
);
115 /* Stop the target process PH. */
118 ps_pstop (gdb_ps_prochandle_t ph
)
120 /* The process is always stopped when under control of GDB. */
124 /* Resume the target process PH. */
127 ps_pcontinue (gdb_ps_prochandle_t ph
)
129 /* Pretend we did successfully continue the process. GDB will take
130 care of it later on. */
134 /* Stop the lightweight process LWPID within the target process PH. */
137 ps_lstop (gdb_ps_prochandle_t ph
, lwpid_t lwpid
)
139 /* All lightweight processes are stopped when under control of GDB. */
143 /* Resume the lightweight process (LWP) LWPID within the target
147 ps_lcontinue (gdb_ps_prochandle_t ph
, lwpid_t lwpid
)
149 /* Pretend we did successfully continue LWPID. GDB will take care
154 /* Get the size of the architecture-dependent extra state registers
155 for LWP LWPID within the target process PH and return it in
159 ps_lgetxregsize (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, int *xregsize
)
161 /* FIXME: Not supported yet. */
165 /* Get the extra state registers of LWP LWPID within the target
166 process PH and store them in XREGSET. */
169 ps_lgetxregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, caddr_t xregset
)
171 /* FIXME: Not supported yet. */
175 /* Set the extra state registers of LWP LWPID within the target
176 process PH from XREGSET. */
179 ps_lsetxregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, caddr_t xregset
)
181 /* FIXME: Not supported yet. */
185 /* Log (additional) diognostic information. */
188 ps_plog (const char *fmt
, ...)
192 va_start (args
, fmt
);
193 vfprintf_filtered (gdb_stderr
, fmt
, args
);
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. */
201 ps_pglobal_lookup (gdb_ps_prochandle_t ph
, const char *obj
,
202 const char *name
, psaddr_t
*sym_addr
)
204 struct minimal_symbol
*ms
;
206 /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */
207 ms
= lookup_minimal_symbol (name
, NULL
, NULL
);
211 *sym_addr
= core_addr_to_ps_addr (SYMBOL_VALUE_ADDRESS (ms
));
215 /* Read SIZE bytes from the target process PH at address ADDR and copy
219 ps_pdread (gdb_ps_prochandle_t ph
, psaddr_t addr
,
220 gdb_ps_read_buf_t buf
, gdb_ps_size_t size
)
222 return ps_xfer_memory (ph
, addr
, buf
, size
, 0);
225 /* Write SIZE bytes from BUF into the target process PH at address ADDR. */
228 ps_pdwrite (gdb_ps_prochandle_t ph
, psaddr_t addr
,
229 gdb_ps_write_buf_t buf
, gdb_ps_size_t size
)
231 return ps_xfer_memory (ph
, addr
, (gdb_byte
*) buf
, size
, 1);
234 /* Read SIZE bytes from the target process PH at address ADDR and copy
238 ps_ptread (gdb_ps_prochandle_t ph
, psaddr_t addr
,
239 gdb_ps_read_buf_t buf
, gdb_ps_size_t size
)
241 return ps_xfer_memory (ph
, addr
, (gdb_byte
*) buf
, size
, 0);
244 /* Write SIZE bytes from BUF into the target process PH at address ADDR. */
247 ps_ptwrite (gdb_ps_prochandle_t ph
, psaddr_t addr
,
248 gdb_ps_write_buf_t buf
, gdb_ps_size_t size
)
250 return ps_xfer_memory (ph
, addr
, (gdb_byte
*) buf
, size
, 1);
253 /* Get the general registers of LWP LWPID within the target process PH
254 and store them in GREGSET. */
257 ps_lgetregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, prgregset_t gregset
)
259 struct cleanup
*old_chain
= save_inferior_ptid ();
261 inferior_ptid
= BUILD_LWP (lwpid
, ph
->pid
);
263 target_fetch_registers (current_regcache
, -1);
264 fill_gregset (current_regcache
, (gdb_gregset_t
*) gregset
, -1);
266 do_cleanups (old_chain
);
270 /* Set the general registers of LWP LWPID within the target process PH
274 ps_lsetregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, const prgregset_t gregset
)
276 struct cleanup
*old_chain
= save_inferior_ptid ();
278 inferior_ptid
= BUILD_LWP (lwpid
, ph
->pid
);
280 supply_gregset (current_regcache
, (const gdb_gregset_t
*) gregset
);
281 target_store_registers (current_regcache
, -1);
283 do_cleanups (old_chain
);
287 /* Get the floating-point registers of LWP LWPID within the target
288 process PH and store them in FPREGSET. */
291 ps_lgetfpregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
,
292 gdb_prfpregset_t
*fpregset
)
294 struct cleanup
*old_chain
= save_inferior_ptid ();
296 inferior_ptid
= BUILD_LWP (lwpid
, ph
->pid
);
298 target_fetch_registers (current_regcache
, -1);
299 fill_fpregset (current_regcache
, (gdb_fpregset_t
*) fpregset
, -1);
301 do_cleanups (old_chain
);
305 /* Set the floating-point registers of LWP LWPID within the target
306 process PH from FPREGSET. */
309 ps_lsetfpregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
,
310 const gdb_prfpregset_t
*fpregset
)
312 struct cleanup
*old_chain
= save_inferior_ptid ();
314 inferior_ptid
= BUILD_LWP (lwpid
, ph
->pid
);
316 supply_fpregset (current_regcache
, (const gdb_fpregset_t
*) fpregset
);
317 target_store_registers (current_regcache
, -1);
319 do_cleanups (old_chain
);
323 /* Return overall process id of the target PH. Special for GNU/Linux
324 -- not used on Solaris. */
327 ps_getpid (gdb_ps_prochandle_t ph
)
333 _initialize_proc_service (void)
335 /* This function solely exists to make sure this module is linked
336 into the final binary. */
This page took 0.037499 seconds and 4 git commands to generate.