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. */
24 #include "gdb_proc_service.h"
25 #include <sys/procfs.h>
32 /* Prototypes for supply_gregset etc. */
36 /* Fix-up some broken systems. */
38 /* The prototypes in <proc_service.h> are slightly different on older
39 systems. Compensate for the discrepancies. */
41 #ifdef PROC_SERVICE_IS_OLD
42 typedef const struct ps_prochandle
*gdb_ps_prochandle_t
;
43 typedef char *gdb_ps_read_buf_t
;
44 typedef char *gdb_ps_write_buf_t
;
45 typedef int gdb_ps_size_t
;
47 typedef struct ps_prochandle
*gdb_ps_prochandle_t
;
48 typedef void *gdb_ps_read_buf_t
;
49 typedef const void *gdb_ps_write_buf_t
;
50 typedef size_t gdb_ps_size_t
;
54 /* Building process ids. */
56 #define BUILD_LWP(lwp, pid) ptid_build (pid, lwp, 0)
59 /* Helper functions. */
61 /* Transfer LEN bytes of memory between BUF and address ADDR in the
62 process specified by PH. If WRITE, transfer them to the process,
63 else transfer them from the process. Returns PS_OK for success,
66 This is a helper function for ps_pdread, ps_pdwrite, ps_ptread and
70 ps_xfer_memory (const struct ps_prochandle
*ph
, paddr_t addr
,
71 gdb_byte
*buf
, size_t len
, int write
)
73 struct cleanup
*old_chain
= save_inferior_ptid ();
76 inferior_ptid
= pid_to_ptid (ph
->pid
);
79 ret
= target_write_memory (addr
, buf
, len
);
81 ret
= target_read_memory (addr
, buf
, len
);
83 do_cleanups (old_chain
);
85 return (ret
== 0 ? PS_OK
: PS_ERR
);
89 /* Stop the target process PH. */
92 ps_pstop (gdb_ps_prochandle_t ph
)
94 /* The process is always stopped when under control of GDB. */
98 /* Resume the target process PH. */
101 ps_pcontinue (gdb_ps_prochandle_t ph
)
103 /* Pretend we did successfully continue the process. GDB will take
104 care of it later on. */
108 /* Stop the lightweight process LWPID within the target process PH. */
111 ps_lstop (gdb_ps_prochandle_t ph
, lwpid_t lwpid
)
113 /* All lightweight processes are stopped when under control of GDB. */
117 /* Resume the lightweight process (LWP) LWPID within the target
121 ps_lcontinue (gdb_ps_prochandle_t ph
, lwpid_t lwpid
)
123 /* Pretend we did successfully continue LWPID. GDB will take care
128 /* Get the size of the architecture-dependent extra state registers
129 for LWP LWPID within the target process PH and return it in
133 ps_lgetxregsize (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, int *xregsize
)
135 /* FIXME: Not supported yet. */
139 /* Get the extra state registers of LWP LWPID within the target
140 process PH and store them in XREGSET. */
143 ps_lgetxregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, caddr_t xregset
)
145 /* FIXME: Not supported yet. */
149 /* Set the extra state registers of LWP LWPID within the target
150 process PH from XREGSET. */
153 ps_lsetxregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, caddr_t xregset
)
155 /* FIXME: Not supported yet. */
159 /* Log (additional) diognostic information. */
162 ps_plog (const char *fmt
, ...)
166 va_start (args
, fmt
);
167 vfprintf_filtered (gdb_stderr
, fmt
, args
);
170 /* Search for the symbol named NAME within the object named OBJ within
171 the target process PH. If the symbol is found the address of the
172 symbol is stored in SYM_ADDR. */
175 ps_pglobal_lookup (gdb_ps_prochandle_t ph
, const char *obj
,
176 const char *name
, paddr_t
*sym_addr
)
178 struct minimal_symbol
*ms
;
180 /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */
181 ms
= lookup_minimal_symbol (name
, NULL
, NULL
);
185 *sym_addr
= SYMBOL_VALUE_ADDRESS (ms
);
189 /* Read SIZE bytes from the target process PH at address ADDR and copy
193 ps_pdread (gdb_ps_prochandle_t ph
, paddr_t addr
,
194 gdb_ps_read_buf_t buf
, gdb_ps_size_t size
)
196 return ps_xfer_memory (ph
, addr
, buf
, size
, 0);
199 /* Write SIZE bytes from BUF into the target process PH at address ADDR. */
202 ps_pdwrite (gdb_ps_prochandle_t ph
, paddr_t addr
,
203 gdb_ps_write_buf_t buf
, gdb_ps_size_t size
)
205 return ps_xfer_memory (ph
, addr
, (gdb_byte
*) buf
, size
, 1);
208 /* Read SIZE bytes from the target process PH at address ADDR and copy
212 ps_ptread (gdb_ps_prochandle_t ph
, paddr_t addr
,
213 gdb_ps_read_buf_t buf
, gdb_ps_size_t size
)
215 return ps_xfer_memory (ph
, addr
, (gdb_byte
*) buf
, size
, 0);
218 /* Write SIZE bytes from BUF into the target process PH at address ADDR. */
221 ps_ptwrite (gdb_ps_prochandle_t ph
, paddr_t addr
,
222 gdb_ps_write_buf_t buf
, gdb_ps_size_t size
)
224 return ps_xfer_memory (ph
, addr
, (gdb_byte
*) buf
, size
, 1);
227 /* Get the general registers of LWP LWPID within the target process PH
228 and store them in GREGSET. */
231 ps_lgetregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, prgregset_t gregset
)
233 struct cleanup
*old_chain
= save_inferior_ptid ();
235 inferior_ptid
= BUILD_LWP (lwpid
, ph
->pid
);
237 target_fetch_registers (current_regcache
, -1);
238 fill_gregset (current_regcache
, (gdb_gregset_t
*) gregset
, -1);
240 do_cleanups (old_chain
);
244 /* Set the general registers of LWP LWPID within the target process PH
248 ps_lsetregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, const prgregset_t gregset
)
250 struct cleanup
*old_chain
= save_inferior_ptid ();
252 inferior_ptid
= BUILD_LWP (lwpid
, ph
->pid
);
254 supply_gregset (current_regcache
, (const gdb_gregset_t
*) gregset
);
255 target_store_registers (current_regcache
, -1);
257 do_cleanups (old_chain
);
261 /* Get the floating-point registers of LWP LWPID within the target
262 process PH and store them in FPREGSET. */
265 ps_lgetfpregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
,
266 gdb_prfpregset_t
*fpregset
)
268 struct cleanup
*old_chain
= save_inferior_ptid ();
270 inferior_ptid
= BUILD_LWP (lwpid
, ph
->pid
);
272 target_fetch_registers (current_regcache
, -1);
273 fill_fpregset (current_regcache
, (gdb_fpregset_t
*) fpregset
, -1);
275 do_cleanups (old_chain
);
279 /* Set the floating-point registers of LWP LWPID within the target
280 process PH from FPREGSET. */
283 ps_lsetfpregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
,
284 const gdb_prfpregset_t
*fpregset
)
286 struct cleanup
*old_chain
= save_inferior_ptid ();
288 inferior_ptid
= BUILD_LWP (lwpid
, ph
->pid
);
290 supply_fpregset (current_regcache
, (const gdb_fpregset_t
*) fpregset
);
291 target_store_registers (current_regcache
, -1);
293 do_cleanups (old_chain
);
297 /* Return overall process id of the target PH. Special for GNU/Linux
298 -- not used on Solaris. */
301 ps_getpid (gdb_ps_prochandle_t ph
)
307 _initialize_proc_service (void)
309 /* This function solely exists to make sure this module is linked
310 into the final binary. */
This page took 0.048451 seconds and 4 git commands to generate.