GDB (xrefs)
Loading...
Searching...
No Matches
proc-service.c
Go to the documentation of this file.
1/* <proc_service.h> implementation.
2
3 Copyright (C) 1999-2023 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 "gdbthread.h"
25#include "symtab.h"
26#include "target.h"
27#include "regcache.h"
28#include "objfiles.h"
29
30#include "gdb_proc_service.h"
31
32#include <sys/procfs.h>
33
34/* Prototypes for supply_gregset etc. */
35#include "gregset.h"
36
37
38/* Helper functions. */
39
40/* Convert a psaddr_t to a CORE_ADDR. */
41
42static CORE_ADDR
43ps_addr_to_core_addr (psaddr_t addr)
44{
46 && bfd_get_sign_extend_vma (current_program_space->exec_bfd ()))
47 return (intptr_t) addr;
48 else
49 return (uintptr_t) addr;
50}
51
52/* Convert a CORE_ADDR to a psaddr_t. */
53
54static psaddr_t
55core_addr_to_ps_addr (CORE_ADDR addr)
56{
58 && bfd_get_sign_extend_vma (current_program_space->exec_bfd ()))
59 return (psaddr_t) (intptr_t) addr;
60 else
61 return (psaddr_t) (uintptr_t) addr;
62}
63
64/* Transfer LEN bytes of memory between BUF and address ADDR in the
65 process specified by PH. If WRITE, transfer them to the process,
66 else transfer them from the process. Returns PS_OK for success,
67 PS_ERR on failure.
68
69 This is a helper function for ps_pdread and ps_pdwrite. */
70
71static ps_err_e
72ps_xfer_memory (const struct ps_prochandle *ph, psaddr_t addr,
73 gdb_byte *buf, size_t len, int write)
74{
75 scoped_restore_current_inferior restore_inferior;
77
78 scoped_restore_current_program_space restore_current_progspace;
80
81 scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
83
84 CORE_ADDR core_addr = ps_addr_to_core_addr (addr);
85
86 int ret;
87 if (write)
88 ret = target_write_memory (core_addr, buf, len);
89 else
90 ret = target_read_memory (core_addr, buf, len);
91 return (ret == 0 ? PS_OK : PS_ERR);
92}
93
94
95/* Search for the symbol named NAME within the object named OBJ within
96 the target process PH. If the symbol is found the address of the
97 symbol is stored in SYM_ADDR. */
98
99ps_err_e
100ps_pglobal_lookup (struct ps_prochandle *ph, const char *obj,
101 const char *name, psaddr_t *sym_addr)
102{
103 inferior *inf = ph->thread->inf;
104
106
108
109 /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */
111 if (ms.minsym == NULL)
112 return PS_NOSYM;
113
114 *sym_addr = core_addr_to_ps_addr (ms.value_address ());
115 return PS_OK;
116}
117
118/* Read SIZE bytes from the target process PH at address ADDR and copy
119 them into BUF. */
120
121ps_err_e
122ps_pdread (struct ps_prochandle *ph, psaddr_t addr, void *buf, size_t size)
123{
124 return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 0);
125}
126
127/* Write SIZE bytes from BUF into the target process PH at address ADDR. */
128
129ps_err_e
130ps_pdwrite (struct ps_prochandle *ph, psaddr_t addr,
131 const void *buf, size_t size)
132{
133 return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 1);
134}
135
136/* Get a regcache for LWPID using its inferior's "main" architecture,
137 which is the register set libthread_db expects to be using. In
138 multi-arch debugging scenarios, the thread's architecture may
139 differ from the inferior's "main" architecture. */
140
141static struct regcache *
142get_ps_regcache (struct ps_prochandle *ph, lwpid_t lwpid)
143{
144 inferior *inf = ph->thread->inf;
145 return get_thread_arch_regcache (inf->process_target (),
146 ptid_t (inf->pid, lwpid),
147 inf->gdbarch);
148}
149
150/* Get the general registers of LWP LWPID within the target process PH
151 and store them in GREGSET. */
152
153ps_err_e
154ps_lgetregs (struct ps_prochandle *ph, lwpid_t lwpid, prgregset_t gregset)
155{
156 struct regcache *regcache = get_ps_regcache (ph, lwpid);
157
159 fill_gregset (regcache, (gdb_gregset_t *) gregset, -1);
160
161 return PS_OK;
162}
163
164/* Set the general registers of LWP LWPID within the target process PH
165 from GREGSET. */
166
167ps_err_e
168ps_lsetregs (struct ps_prochandle *ph, lwpid_t lwpid, const prgregset_t gregset)
169{
170 struct regcache *regcache = get_ps_regcache (ph, lwpid);
171
172 supply_gregset (regcache, (const gdb_gregset_t *) gregset);
174
175 return PS_OK;
176}
177
178/* Get the floating-point registers of LWP LWPID within the target
179 process PH and store them in FPREGSET. */
180
181ps_err_e
182ps_lgetfpregs (struct ps_prochandle *ph, lwpid_t lwpid,
183 prfpregset_t *fpregset)
184{
185 struct regcache *regcache = get_ps_regcache (ph, lwpid);
186
188 fill_fpregset (regcache, (gdb_fpregset_t *) fpregset, -1);
189
190 return PS_OK;
191}
192
193/* Set the floating-point registers of LWP LWPID within the target
194 process PH from FPREGSET. */
195
196ps_err_e
197ps_lsetfpregs (struct ps_prochandle *ph, lwpid_t lwpid,
198 const prfpregset_t *fpregset)
199{
200 struct regcache *regcache = get_ps_regcache (ph, lwpid);
201
202 supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset);
204
205 return PS_OK;
206}
207
208/* Return overall process id of the target PH. Special for GNU/Linux
209 -- not used on Solaris. */
210
211pid_t
213{
214 return ph->thread->ptid.pid ();
215}
216
218void
220{
221 /* This function solely exists to make sure this module is linked
222 into the final binary. */
223}
void supply_gregset(struct regcache *regcache, const gdb_gregset_t *gregsetp)
void fill_gregset(const struct regcache *regcache, gdb_gregset_t *gregsetp, int regno)
void supply_fpregset(struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
void fill_fpregset(const struct regcache *regcache, gdb_fpregset_t *fpregsetp, int regno)
const char *const name
struct program_space * pspace
Definition inferior.h:547
ptid_t ptid
Definition gdbthread.h:256
struct inferior * inf
Definition gdbthread.h:298
size_t size
Definition go32-nat.c:241
GDB_FPREGSET_T gdb_fpregset_t
Definition gregset.h:35
GDB_GREGSET_T gdb_gregset_t
Definition gregset.h:34
ptid_t inferior_ptid
Definition infcmd.c:91
void set_current_inferior(struct inferior *inf)
Definition inferior.c:60
struct bound_minimal_symbol lookup_minimal_symbol(const char *name, const char *sfile, struct objfile *objf)
Definition minsyms.c:363
static ps_err_e ps_xfer_memory(const struct ps_prochandle *ph, psaddr_t addr, gdb_byte *buf, size_t len, int write)
pid_t ps_getpid(struct ps_prochandle *ph)
ps_err_e ps_lgetfpregs(struct ps_prochandle *ph, lwpid_t lwpid, prfpregset_t *fpregset)
static struct regcache * get_ps_regcache(struct ps_prochandle *ph, lwpid_t lwpid)
static CORE_ADDR ps_addr_to_core_addr(psaddr_t addr)
ps_err_e ps_lgetregs(struct ps_prochandle *ph, lwpid_t lwpid, prgregset_t gregset)
ps_err_e ps_lsetfpregs(struct ps_prochandle *ph, lwpid_t lwpid, const prfpregset_t *fpregset)
ps_err_e ps_pdread(struct ps_prochandle *ph, psaddr_t addr, void *buf, size_t size)
void _initialize_proc_service()
ps_err_e ps_pdwrite(struct ps_prochandle *ph, psaddr_t addr, const void *buf, size_t size)
static psaddr_t core_addr_to_ps_addr(CORE_ADDR addr)
ps_err_e ps_pglobal_lookup(struct ps_prochandle *ph, const char *obj, const char *name, psaddr_t *sym_addr)
ps_err_e ps_lsetregs(struct ps_prochandle *ph, lwpid_t lwpid, const prgregset_t gregset)
struct program_space * current_program_space
Definition progspace.c:39
void set_current_program_space(struct program_space *pspace)
Definition progspace.c:224
struct regcache * get_thread_arch_regcache(process_stratum_target *target, ptid_t ptid, struct gdbarch *gdbarch)
Definition regcache.c:382
CORE_ADDR value_address() const
Definition minsyms.h:41
struct minimal_symbol * minsym
Definition minsyms.h:49
Definition gnu-nat.c:154
pid_t pid
Definition gnu-nat.c:166
bfd * exec_bfd() const
Definition progspace.h:264
thread_info * thread
void target_fetch_registers(struct regcache *regcache, int regno)
Definition target.c:3921
int target_write_memory(CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
Definition target.c:1847
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition target.c:1771
void target_store_registers(struct regcache *regcache, int regno)
Definition target.c:3929