[ARM] Mark USER_SPECIFIED_MACHINE_TYPE in disassemble_info.flags
[deliverable/binutils-gdb.git] / gdb / proc-service.c
CommitLineData
fb0e1ba7 1/* <proc_service.h> implementation.
ca557f44 2
61baf725 3 Copyright (C) 1999-2017 Free Software Foundation, Inc.
fb0e1ba7
MK
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
fb0e1ba7
MK
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
fb0e1ba7
MK
19
20#include "defs.h"
21
76e1ee85 22#include "gdbcore.h"
fb0e1ba7
MK
23#include "inferior.h"
24#include "symtab.h"
25#include "target.h"
7f7fe91e 26#include "regcache.h"
77e371c0 27#include "objfiles.h"
fb0e1ba7 28
76e1ee85 29#include "gdb_proc_service.h"
76e1ee85
DJ
30
31#include <sys/procfs.h>
32
fb0e1ba7
MK
33/* Prototypes for supply_gregset etc. */
34#include "gregset.h"
35\f
36
37/* Fix-up some broken systems. */
38
39/* The prototypes in <proc_service.h> are slightly different on older
40 systems. Compensate for the discrepancies. */
41
42#ifdef PROC_SERVICE_IS_OLD
43typedef const struct ps_prochandle *gdb_ps_prochandle_t;
44typedef char *gdb_ps_read_buf_t;
45typedef char *gdb_ps_write_buf_t;
46typedef int gdb_ps_size_t;
47#else
48typedef struct ps_prochandle *gdb_ps_prochandle_t;
49typedef void *gdb_ps_read_buf_t;
50typedef const void *gdb_ps_write_buf_t;
51typedef size_t gdb_ps_size_t;
52#endif
53\f
54
fb0e1ba7
MK
55/* Helper functions. */
56
76e1ee85
DJ
57/* Convert a psaddr_t to a CORE_ADDR. */
58
59static CORE_ADDR
60ps_addr_to_core_addr (psaddr_t addr)
61{
62 if (exec_bfd && bfd_get_sign_extend_vma (exec_bfd))
63 return (intptr_t) addr;
64 else
65 return (uintptr_t) addr;
66}
67
68/* Convert a CORE_ADDR to a psaddr_t. */
69
70static psaddr_t
71core_addr_to_ps_addr (CORE_ADDR addr)
72{
73 if (exec_bfd && bfd_get_sign_extend_vma (exec_bfd))
74 return (psaddr_t) (intptr_t) addr;
75 else
76 return (psaddr_t) (uintptr_t) addr;
77}
78
fb0e1ba7
MK
79/* Transfer LEN bytes of memory between BUF and address ADDR in the
80 process specified by PH. If WRITE, transfer them to the process,
81 else transfer them from the process. Returns PS_OK for success,
82 PS_ERR on failure.
83
9b11e3a7 84 This is a helper function for ps_pdread and ps_pdwrite. */
fb0e1ba7
MK
85
86static ps_err_e
76e1ee85 87ps_xfer_memory (const struct ps_prochandle *ph, psaddr_t addr,
47b667de 88 gdb_byte *buf, size_t len, int write)
fb0e1ba7 89{
39f77062 90 struct cleanup *old_chain = save_inferior_ptid ();
fb0e1ba7 91 int ret;
76e1ee85 92 CORE_ADDR core_addr = ps_addr_to_core_addr (addr);
fb0e1ba7 93
93a91755 94 inferior_ptid = ph->ptid;
fb0e1ba7
MK
95
96 if (write)
76e1ee85 97 ret = target_write_memory (core_addr, buf, len);
fb0e1ba7 98 else
76e1ee85 99 ret = target_read_memory (core_addr, buf, len);
fb0e1ba7
MK
100
101 do_cleanups (old_chain);
102
103 return (ret == 0 ? PS_OK : PS_ERR);
104}
105\f
106
fb0e1ba7
MK
107/* Search for the symbol named NAME within the object named OBJ within
108 the target process PH. If the symbol is found the address of the
109 symbol is stored in SYM_ADDR. */
110
111ps_err_e
112ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj,
76e1ee85 113 const char *name, psaddr_t *sym_addr)
fb0e1ba7 114{
c9657e70 115 struct inferior *inf = find_inferior_ptid (ph->ptid);
5ed8105e
PA
116
117 scoped_restore_current_program_space restore_pspace;
c988ad87
TT
118
119 set_current_program_space (inf->pspace);
fb0e1ba7
MK
120
121 /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */
5ed8105e 122 bound_minimal_symbol ms = lookup_minimal_symbol (name, NULL, NULL);
3b7344d5 123 if (ms.minsym == NULL)
5ed8105e 124 return PS_NOSYM;
fb0e1ba7 125
5ed8105e
PA
126 *sym_addr = core_addr_to_ps_addr (BMSYMBOL_VALUE_ADDRESS (ms));
127 return PS_OK;
fb0e1ba7
MK
128}
129
130/* Read SIZE bytes from the target process PH at address ADDR and copy
131 them into BUF. */
132
133ps_err_e
76e1ee85 134ps_pdread (gdb_ps_prochandle_t ph, psaddr_t addr,
fb0e1ba7
MK
135 gdb_ps_read_buf_t buf, gdb_ps_size_t size)
136{
49e66b4d 137 return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 0);
fb0e1ba7
MK
138}
139
140/* Write SIZE bytes from BUF into the target process PH at address ADDR. */
141
142ps_err_e
76e1ee85 143ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr,
fb0e1ba7
MK
144 gdb_ps_write_buf_t buf, gdb_ps_size_t size)
145{
47b667de 146 return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 1);
fb0e1ba7
MK
147}
148
fb0e1ba7
MK
149/* Get the general registers of LWP LWPID within the target process PH
150 and store them in GREGSET. */
151
152ps_err_e
153ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
154{
3e00d44f
SM
155 ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
156 struct regcache *regcache
157 = get_thread_arch_regcache (ptid, target_gdbarch ());
fb0e1ba7 158
594f7785
UW
159 target_fetch_registers (regcache, -1);
160 fill_gregset (regcache, (gdb_gregset_t *) gregset, -1);
fb0e1ba7 161
fb0e1ba7
MK
162 return PS_OK;
163}
164
165/* Set the general registers of LWP LWPID within the target process PH
166 from GREGSET. */
167
168ps_err_e
169ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset)
170{
3e00d44f
SM
171 ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
172 struct regcache *regcache
173 = get_thread_arch_regcache (ptid, target_gdbarch ());
fb0e1ba7 174
594f7785
UW
175 supply_gregset (regcache, (const gdb_gregset_t *) gregset);
176 target_store_registers (regcache, -1);
fb0e1ba7 177
fb0e1ba7
MK
178 return PS_OK;
179}
180
181/* Get the floating-point registers of LWP LWPID within the target
182 process PH and store them in FPREGSET. */
183
184ps_err_e
185ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid,
186 gdb_prfpregset_t *fpregset)
187{
3e00d44f
SM
188 ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
189 struct regcache *regcache
190 = get_thread_arch_regcache (ptid, target_gdbarch ());
fb0e1ba7 191
594f7785
UW
192 target_fetch_registers (regcache, -1);
193 fill_fpregset (regcache, (gdb_fpregset_t *) fpregset, -1);
fb0e1ba7 194
fb0e1ba7
MK
195 return PS_OK;
196}
197
198/* Set the floating-point registers of LWP LWPID within the target
199 process PH from FPREGSET. */
200
201ps_err_e
202ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid,
203 const gdb_prfpregset_t *fpregset)
204{
3e00d44f
SM
205 ptid_t ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
206 struct regcache *regcache
207 = get_thread_arch_regcache (ptid, target_gdbarch ());
fb0e1ba7 208
594f7785
UW
209 supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset);
210 target_store_registers (regcache, -1);
fb0e1ba7 211
fb0e1ba7
MK
212 return PS_OK;
213}
214
ca557f44
AC
215/* Return overall process id of the target PH. Special for GNU/Linux
216 -- not used on Solaris. */
fb0e1ba7
MK
217
218pid_t
219ps_getpid (gdb_ps_prochandle_t ph)
220{
93a91755 221 return ptid_get_pid (ph->ptid);
fb0e1ba7
MK
222}
223
2c0b251b
PA
224/* Provide a prototype to silence -Wmissing-prototypes. */
225extern initialize_file_ftype _initialize_proc_service;
226
fb0e1ba7
MK
227void
228_initialize_proc_service (void)
229{
230 /* This function solely exists to make sure this module is linked
231 into the final binary. */
232}
This page took 1.619628 seconds and 4 git commands to generate.