GDB (xrefs)
/tmp/gdb-8.1/gdb/proc-service.c
Go to the documentation of this file.
1 /* <proc_service.h> implementation.
2 
3  Copyright (C) 1999-2018 Free Software Foundation, Inc.
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
9  the Free Software Foundation; either version 3 of the License, or
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
18  along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #include "defs.h"
21 
22 #include "gdbcore.h"
23 #include "inferior.h"
24 #include "symtab.h"
25 #include "target.h"
26 #include "regcache.h"
27 #include "objfiles.h"
28 
29 #include "gdb_proc_service.h"
30 
31 #include <sys/procfs.h>
32 
33 /* Prototypes for supply_gregset etc. */
34 #include "gregset.h"
35 
36 
37 /* Helper functions. */
38 
39 /* Convert a psaddr_t to a CORE_ADDR. */
40 
41 static CORE_ADDR
43 {
44  if (exec_bfd && bfd_get_sign_extend_vma (exec_bfd))
45  return (intptr_t) addr;
46  else
47  return (uintptr_t) addr;
48 }
49 
50 /* Convert a CORE_ADDR to a psaddr_t. */
51 
52 static psaddr_t
54 {
55  if (exec_bfd && bfd_get_sign_extend_vma (exec_bfd))
56  return (psaddr_t) (intptr_t) addr;
57  else
58  return (psaddr_t) (uintptr_t) addr;
59 }
60 
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,
64  PS_ERR on failure.
65 
66  This is a helper function for ps_pdread and ps_pdwrite. */
67 
68 static ps_err_e
69 ps_xfer_memory (const struct ps_prochandle *ph, psaddr_t addr,
70  gdb_byte *buf, size_t len, int write)
71 {
72  scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
73  int ret;
74  CORE_ADDR core_addr = ps_addr_to_core_addr (addr);
75 
76  inferior_ptid = ph->ptid;
77 
78  if (write)
79  ret = target_write_memory (core_addr, buf, len);
80  else
81  ret = target_read_memory (core_addr, buf, len);
82 
83  return (ret == 0 ? PS_OK : PS_ERR);
84 }
85 
86 
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. */
90 
92 ps_pglobal_lookup (struct ps_prochandle *ph, const char *obj,
93  const char *name, psaddr_t *sym_addr)
94 {
95  struct inferior *inf = find_inferior_ptid (ph->ptid);
96 
98 
100 
101  /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */
103  if (ms.minsym == NULL)
104  return PS_NOSYM;
105 
106  *sym_addr = core_addr_to_ps_addr (BMSYMBOL_VALUE_ADDRESS (ms));
107  return PS_OK;
108 }
109 
110 /* Read SIZE bytes from the target process PH at address ADDR and copy
111  them into BUF. */
112 
113 ps_err_e
114 ps_pdread (struct ps_prochandle *ph, psaddr_t addr, void *buf, size_t size)
115 {
116  return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 0);
117 }
118 
119 /* Write SIZE bytes from BUF into the target process PH at address ADDR. */
120 
121 ps_err_e
123  const void *buf, size_t size)
124 {
125  return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 1);
126 }
127 
128 /* Get the general registers of LWP LWPID within the target process PH
129  and store them in GREGSET. */
130 
131 ps_err_e
132 ps_lgetregs (struct ps_prochandle *ph, lwpid_t lwpid, prgregset_t gregset)
133 {
134  ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
135  struct regcache *regcache
137 
139  fill_gregset (regcache, (gdb_gregset_t *) gregset, -1);
140 
141  return PS_OK;
142 }
143 
144 /* Set the general registers of LWP LWPID within the target process PH
145  from GREGSET. */
146 
147 ps_err_e
148 ps_lsetregs (struct ps_prochandle *ph, lwpid_t lwpid, const prgregset_t gregset)
149 {
150  ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
151  struct regcache *regcache
153 
154  supply_gregset (regcache, (const gdb_gregset_t *) gregset);
156 
157  return PS_OK;
158 }
159 
160 /* Get the floating-point registers of LWP LWPID within the target
161  process PH and store them in FPREGSET. */
162 
163 ps_err_e
164 ps_lgetfpregs (struct ps_prochandle *ph, lwpid_t lwpid, gdb_prfpregset_t *fpregset)
165 {
166  ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
167  struct regcache *regcache
169 
171  fill_fpregset (regcache, (gdb_fpregset_t *) fpregset, -1);
172 
173  return PS_OK;
174 }
175 
176 /* Set the floating-point registers of LWP LWPID within the target
177  process PH from FPREGSET. */
178 
179 ps_err_e
181  const gdb_prfpregset_t *fpregset)
182 {
183  ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
184  struct regcache *regcache
186 
187  supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset);
189 
190  return PS_OK;
191 }
192 
193 /* Return overall process id of the target PH. Special for GNU/Linux
194  -- not used on Solaris. */
195 
196 pid_t
198 {
199  return ptid_get_pid (ph->ptid);
200 }
201 
202 void
204 {
205  /* This function solely exists to make sure this module is linked
206  into the final binary. */
207 }
unsigned int lwpid_t
struct gdbarch * target_gdbarch(void)
Definition: gdbarch.c:5467
ps_err_e ps_lgetregs(struct ps_prochandle *ph, lwpid_t lwpid, prgregset_t gregset)
Definition: proc-service.c:132
bfd_vma CORE_ADDR
Definition: common-types.h:41
int target_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
Definition: target.c:1451
int ptid_get_pid(const ptid_t &ptid)
Definition: ptid.c:47
void fill_gregset(const struct regcache *regcache, gdb_gregset_t *gregsetp, int regno)
ps_err_e ps_lgetfpregs(struct ps_prochandle *ph, lwpid_t lwpid, gdb_prfpregset_t *fpregset)
Definition: proc-service.c:164
EXTERN_C_POP typedef prfpregset_t gdb_prfpregset_t
#define BMSYMBOL_VALUE_ADDRESS(symbol)
Definition: symtab.h:691
ps_err_e ps_lsetfpregs(struct ps_prochandle *ph, lwpid_t lwpid, const gdb_prfpregset_t *fpregset)
Definition: proc-service.c:180
ps_err_e ps_pglobal_lookup(struct ps_prochandle *ph, const char *obj, const char *name, psaddr_t *sym_addr)
Definition: proc-service.c:92
ps_err_e ps_pdwrite(struct ps_prochandle *ph, psaddr_t addr, const void *buf, size_t size)
Definition: proc-service.c:122
ps_err_e
struct inferior * find_inferior_ptid(ptid_t ptid)
Definition: inferior.c:321
void target_fetch_registers(struct regcache *regcache, int regno)
Definition: target.c:3437
ps_err_e ps_lsetregs(struct ps_prochandle *ph, lwpid_t lwpid, const prgregset_t gregset)
Definition: proc-service.c:148
void fill_fpregset(const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regno)
ptid_t ptid_build(int pid, long lwp, long tid)
Definition: ptid.c:31
void set_current_program_space(struct program_space *pspace)
Definition: progspace.c:190
scoped_restore_tmpl< T > make_scoped_restore(T *var)
const char *const name
Definition: aarch64-tdep.c:76
#define exec_bfd
Definition: exec.h:33
GDB_GREGSET_T gdb_gregset_t
Definition: gregset.h:34
Definition: ptid.h:35
GDB_FPREGSET_T gdb_fpregset_t
Definition: gregset.h:35
void supply_gregset(struct regcache *regcache, const gdb_gregset_t *gregsetp)
Definition: gnu-nat.c:174
ps_err_e ps_pdread(struct ps_prochandle *ph, psaddr_t addr, void *buf, size_t size)
Definition: proc-service.c:114
void * psaddr_t
static psaddr_t core_addr_to_ps_addr(CORE_ADDR addr)
Definition: proc-service.c:53
gdb_gregset_t prgregset_t
bfd_byte gdb_byte
Definition: common-types.h:38
void _initialize_proc_service(void)
Definition: proc-service.c:203
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition: target.c:1370
ptid_t inferior_ptid
Definition: infcmd.c:94
struct minimal_symbol * minsym
Definition: minsyms.h:34
static ps_err_e ps_xfer_memory(const struct ps_prochandle *ph, psaddr_t addr, gdb_byte *buf, size_t len, int write)
Definition: proc-service.c:69
pid_t ps_getpid(struct ps_prochandle *ph)
Definition: proc-service.c:197
static CORE_ADDR ps_addr_to_core_addr(psaddr_t addr)
Definition: proc-service.c:42
void target_store_registers(struct regcache *regcache, int regno)
Definition: target.c:3445
ptid_t ptid() const
Definition: regcache.h:325
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition: minsyms.c:311
size_t size
Definition: go32-nat.c:242
struct regcache * get_thread_arch_regcache(ptid_t ptid, struct gdbarch *gdbarch)
Definition: regcache.c:423
void supply_fpregset(struct regcache *regcache, const gdb_fpregset_t *fpregsetp)