1 /* <proc_service.h> implementation.
3 Copyright 1999, 2000, 2002 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., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "gdb_proc_service.h"
25 #include <sys/procfs.h>
31 /* Prototypes for supply_gregset etc. */
35 /* Fix-up some broken systems. */
37 /* The prototypes in <proc_service.h> are slightly different on older
38 systems. Compensate for the discrepancies. */
40 #ifdef PROC_SERVICE_IS_OLD
41 typedef const struct ps_prochandle
*gdb_ps_prochandle_t
;
42 typedef char *gdb_ps_read_buf_t
;
43 typedef char *gdb_ps_write_buf_t
;
44 typedef int gdb_ps_size_t
;
46 typedef struct ps_prochandle
*gdb_ps_prochandle_t
;
47 typedef void *gdb_ps_read_buf_t
;
48 typedef const void *gdb_ps_write_buf_t
;
49 typedef size_t gdb_ps_size_t
;
53 /* Building process ids. */
55 #define BUILD_LWP(lwp, pid) ptid_build (pid, lwp, 0)
58 /* Helper functions. */
60 /* Transfer LEN bytes of memory between BUF and address ADDR in the
61 process specified by PH. If WRITE, transfer them to the process,
62 else transfer them from the process. Returns PS_OK for success,
65 This is a helper function for ps_pdread, ps_pdwrite, ps_ptread and
69 ps_xfer_memory (const struct ps_prochandle
*ph
, paddr_t addr
,
70 char *buf
, size_t len
, int write
)
72 struct cleanup
*old_chain
= save_inferior_ptid ();
75 inferior_ptid
= pid_to_ptid (ph
->pid
);
78 ret
= target_write_memory (addr
, buf
, len
);
80 ret
= target_read_memory (addr
, buf
, len
);
82 do_cleanups (old_chain
);
84 return (ret
== 0 ? PS_OK
: PS_ERR
);
88 /* Stop the target process PH. */
91 ps_pstop (gdb_ps_prochandle_t ph
)
93 /* The process is always stopped when under control of GDB. */
97 /* Resume the target process PH. */
100 ps_pcontinue (gdb_ps_prochandle_t ph
)
102 /* Pretend we did successfully continue the process. GDB will take
103 care of it later on. */
107 /* Stop the lightweight process LWPID within the target process PH. */
110 ps_lstop (gdb_ps_prochandle_t ph
, lwpid_t lwpid
)
112 /* All lightweight processes are stopped when under control of GDB. */
116 /* Resume the lightweight process (LWP) LWPID within the target
120 ps_lcontinue (gdb_ps_prochandle_t ph
, lwpid_t lwpid
)
122 /* Pretend we did successfully continue LWPID. GDB will take care
127 /* Get the size of the architecture-dependent extra state registers
128 for LWP LWPID within the target process PH and return it in
132 ps_lgetxregsize (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, int *xregsize
)
134 /* FIXME: Not supported yet. */
138 /* Get the extra state registers of LWP LWPID within the target
139 process PH and store them in XREGSET. */
142 ps_lgetxregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, caddr_t xregset
)
144 /* FIXME: Not supported yet. */
148 /* Set the extra state registers of LWP LWPID within the target
149 process PH from XREGSET. */
152 ps_lsetxregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, caddr_t xregset
)
154 /* FIXME: Not supported yet. */
158 /* Log (additional) diognostic information. */
161 ps_plog (const char *fmt
, ...)
165 va_start (args
, fmt
);
166 vfprintf_filtered (gdb_stderr
, fmt
, args
);
169 /* Search for the symbol named NAME within the object named OBJ within
170 the target process PH. If the symbol is found the address of the
171 symbol is stored in SYM_ADDR. */
174 ps_pglobal_lookup (gdb_ps_prochandle_t ph
, const char *obj
,
175 const char *name
, paddr_t
*sym_addr
)
177 struct minimal_symbol
*ms
;
179 /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */
180 ms
= lookup_minimal_symbol (name
, NULL
, NULL
);
184 *sym_addr
= SYMBOL_VALUE_ADDRESS (ms
);
188 /* Read SIZE bytes from the target process PH at address ADDR and copy
192 ps_pdread (gdb_ps_prochandle_t ph
, paddr_t addr
,
193 gdb_ps_read_buf_t buf
, gdb_ps_size_t size
)
195 return ps_xfer_memory (ph
, addr
, buf
, size
, 0);
198 /* Write SIZE bytes from BUF into the target process PH at address ADDR. */
201 ps_pdwrite (gdb_ps_prochandle_t ph
, paddr_t addr
,
202 gdb_ps_write_buf_t buf
, gdb_ps_size_t size
)
204 return ps_xfer_memory (ph
, addr
, (char *) buf
, size
, 1);
207 /* Read SIZE bytes from the target process PH at address ADDR and copy
211 ps_ptread (gdb_ps_prochandle_t ph
, paddr_t addr
,
212 gdb_ps_read_buf_t buf
, gdb_ps_size_t size
)
214 return ps_xfer_memory (ph
, addr
, buf
, size
, 0);
217 /* Write SIZE bytes from BUF into the target process PH at address ADDR. */
220 ps_ptwrite (gdb_ps_prochandle_t ph
, paddr_t addr
,
221 gdb_ps_write_buf_t buf
, gdb_ps_size_t size
)
223 return ps_xfer_memory (ph
, addr
, (char *) buf
, size
, 1);
226 /* Get the general registers of LWP LWPID within the target process PH
227 and store them in GREGSET. */
230 ps_lgetregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, prgregset_t gregset
)
232 struct cleanup
*old_chain
= save_inferior_ptid ();
234 inferior_ptid
= BUILD_LWP (lwpid
, ph
->pid
);
236 target_fetch_registers (-1);
237 fill_gregset ((gdb_gregset_t
*) gregset
, -1);
239 do_cleanups (old_chain
);
243 /* Set the general registers of LWP LWPID within the target process PH
247 ps_lsetregs (gdb_ps_prochandle_t ph
, lwpid_t lwpid
, const prgregset_t gregset
)
249 struct cleanup
*old_chain
= save_inferior_ptid ();
251 inferior_ptid
= BUILD_LWP (lwpid
, ph
->pid
);
253 /* FIXME: We should really make supply_gregset const-correct. */
254 supply_gregset ((gdb_gregset_t
*) gregset
);
255 target_store_registers (-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 (-1);
273 fill_fpregset ((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 /* FIXME: We should really make supply_fpregset const-correct. */
291 supply_fpregset ((gdb_fpregset_t
*) fpregset
);
292 target_store_registers (-1);
294 do_cleanups (old_chain
);
298 /* Return overall process id of the target PH. Special for GNU/Linux
299 -- not used on Solaris. */
302 ps_getpid (gdb_ps_prochandle_t ph
)
308 _initialize_proc_service (void)
310 /* This function solely exists to make sure this module is linked
311 into the final binary. */
This page took 0.036899 seconds and 4 git commands to generate.