1 /* <proc_service.h> implementation.
3 Copyright (C) 1999-2018 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 3 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, see <http://www.gnu.org/licenses/>. */
29 #include "gdb_proc_service.h"
31 #include <sys/procfs.h>
33 /* Prototypes for supply_gregset etc. */
37 /* Helper functions. */
39 /* Convert a psaddr_t to a CORE_ADDR. */
42 ps_addr_to_core_addr (psaddr_t addr)
44 if (exec_bfd && bfd_get_sign_extend_vma (exec_bfd))
45 return (intptr_t) addr;
47 return (uintptr_t) addr;
50 /* Convert a CORE_ADDR to a psaddr_t. */
53 core_addr_to_ps_addr (CORE_ADDR addr)
55 if (exec_bfd && bfd_get_sign_extend_vma (exec_bfd))
56 return (psaddr_t) (intptr_t) addr;
58 return (psaddr_t) (uintptr_t) addr;
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 and ps_pdwrite. */
69 ps_xfer_memory (const struct ps_prochandle *ph, psaddr_t addr,
70 gdb_byte *buf, size_t len, int write)
72 scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
74 CORE_ADDR core_addr = ps_addr_to_core_addr (addr);
76 inferior_ptid = ph->ptid;
79 ret = target_write_memory (core_addr, buf, len);
81 ret = target_read_memory (core_addr, buf, len);
83 return (ret == 0 ? PS_OK : PS_ERR);
87 /* Search for the symbol named NAME within the object named OBJ within
88 the target process PH. If the symbol is found the address of the
89 symbol is stored in SYM_ADDR. */
92 ps_pglobal_lookup (struct ps_prochandle *ph, const char *obj,
93 const char *name, psaddr_t *sym_addr)
95 struct inferior *inf = find_inferior_ptid (ph->ptid);
97 scoped_restore_current_program_space restore_pspace;
99 set_current_program_space (inf->pspace);
101 /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */
102 bound_minimal_symbol ms = lookup_minimal_symbol (name, NULL, NULL);
103 if (ms.minsym == NULL)
106 *sym_addr = core_addr_to_ps_addr (BMSYMBOL_VALUE_ADDRESS (ms));
110 /* Read SIZE bytes from the target process PH at address ADDR and copy
114 ps_pdread (struct ps_prochandle *ph, psaddr_t addr, void *buf, size_t size)
116 return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 0);
119 /* Write SIZE bytes from BUF into the target process PH at address ADDR. */
122 ps_pdwrite (struct ps_prochandle *ph, psaddr_t addr,
123 const void *buf, size_t size)
125 return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 1);
128 /* Get the general registers of LWP LWPID within the target process PH
129 and store them in GREGSET. */
132 ps_lgetregs (struct ps_prochandle *ph, lwpid_t lwpid, prgregset_t gregset)
134 ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
135 struct regcache *regcache
136 = get_thread_arch_regcache (ptid, target_gdbarch ());
138 target_fetch_registers (regcache, -1);
139 fill_gregset (regcache, (gdb_gregset_t *) gregset, -1);
144 /* Set the general registers of LWP LWPID within the target process PH
148 ps_lsetregs (struct ps_prochandle *ph, lwpid_t lwpid, const prgregset_t gregset)
150 ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
151 struct regcache *regcache
152 = get_thread_arch_regcache (ptid, target_gdbarch ());
154 supply_gregset (regcache, (const gdb_gregset_t *) gregset);
155 target_store_registers (regcache, -1);
160 /* Get the floating-point registers of LWP LWPID within the target
161 process PH and store them in FPREGSET. */
164 ps_lgetfpregs (struct ps_prochandle *ph, lwpid_t lwpid, gdb_prfpregset_t *fpregset)
166 ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
167 struct regcache *regcache
168 = get_thread_arch_regcache (ptid, target_gdbarch ());
170 target_fetch_registers (regcache, -1);
171 fill_fpregset (regcache, (gdb_fpregset_t *) fpregset, -1);
176 /* Set the floating-point registers of LWP LWPID within the target
177 process PH from FPREGSET. */
180 ps_lsetfpregs (struct ps_prochandle *ph, lwpid_t lwpid,
181 const gdb_prfpregset_t *fpregset)
183 ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
184 struct regcache *regcache
185 = get_thread_arch_regcache (ptid, target_gdbarch ());
187 supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset);
188 target_store_registers (regcache, -1);
193 /* Return overall process id of the target PH. Special for GNU/Linux
194 -- not used on Solaris. */
197 ps_getpid (struct ps_prochandle *ph)
199 return ptid_get_pid (ph->ptid);
203 _initialize_proc_service (void)
205 /* This function solely exists to make sure this module is linked
206 into the final binary. */