Set DF_STATIC_TLS for PIEs
[deliverable/binutils-gdb.git] / gdb / proc-service.c
CommitLineData
fb0e1ba7 1/* <proc_service.h> implementation.
ca557f44 2
ecd75fc8 3 Copyright (C) 1999-2014 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
84 This is a helper function for ps_pdread, ps_pdwrite, ps_ptread and
85 ps_ptwrite. */
86
87static ps_err_e
76e1ee85 88ps_xfer_memory (const struct ps_prochandle *ph, psaddr_t addr,
47b667de 89 gdb_byte *buf, size_t len, int write)
fb0e1ba7 90{
39f77062 91 struct cleanup *old_chain = save_inferior_ptid ();
fb0e1ba7 92 int ret;
76e1ee85 93 CORE_ADDR core_addr = ps_addr_to_core_addr (addr);
fb0e1ba7 94
93a91755 95 inferior_ptid = ph->ptid;
fb0e1ba7
MK
96
97 if (write)
76e1ee85 98 ret = target_write_memory (core_addr, buf, len);
fb0e1ba7 99 else
76e1ee85 100 ret = target_read_memory (core_addr, buf, len);
fb0e1ba7
MK
101
102 do_cleanups (old_chain);
103
104 return (ret == 0 ? PS_OK : PS_ERR);
105}
106\f
107
108/* Stop the target process PH. */
109
110ps_err_e
111ps_pstop (gdb_ps_prochandle_t ph)
112{
113 /* The process is always stopped when under control of GDB. */
114 return PS_OK;
115}
116
117/* Resume the target process PH. */
118
119ps_err_e
120ps_pcontinue (gdb_ps_prochandle_t ph)
121{
122 /* Pretend we did successfully continue the process. GDB will take
123 care of it later on. */
124 return PS_OK;
125}
126
127/* Stop the lightweight process LWPID within the target process PH. */
128
129ps_err_e
130ps_lstop (gdb_ps_prochandle_t ph, lwpid_t lwpid)
131{
132 /* All lightweight processes are stopped when under control of GDB. */
133 return PS_OK;
134}
135
136/* Resume the lightweight process (LWP) LWPID within the target
137 process PH. */
138
139ps_err_e
140ps_lcontinue (gdb_ps_prochandle_t ph, lwpid_t lwpid)
141{
142 /* Pretend we did successfully continue LWPID. GDB will take care
143 of it later on. */
144 return PS_OK;
145}
146
147/* Get the size of the architecture-dependent extra state registers
148 for LWP LWPID within the target process PH and return it in
149 *XREGSIZE. */
150
151ps_err_e
152ps_lgetxregsize (gdb_ps_prochandle_t ph, lwpid_t lwpid, int *xregsize)
153{
154 /* FIXME: Not supported yet. */
155 return PS_OK;
156}
157
158/* Get the extra state registers of LWP LWPID within the target
159 process PH and store them in XREGSET. */
160
161ps_err_e
162ps_lgetxregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, caddr_t xregset)
163{
164 /* FIXME: Not supported yet. */
165 return PS_OK;
166}
167
168/* Set the extra state registers of LWP LWPID within the target
169 process PH from XREGSET. */
170
171ps_err_e
172ps_lsetxregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, caddr_t xregset)
173{
174 /* FIXME: Not supported yet. */
175 return PS_OK;
176}
177
178/* Log (additional) diognostic information. */
179
180void
181ps_plog (const char *fmt, ...)
182{
183 va_list args;
184
185 va_start (args, fmt);
186 vfprintf_filtered (gdb_stderr, fmt, args);
0480cefa 187 va_end (args);
fb0e1ba7
MK
188}
189
190/* Search for the symbol named NAME within the object named OBJ within
191 the target process PH. If the symbol is found the address of the
192 symbol is stored in SYM_ADDR. */
193
194ps_err_e
195ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj,
76e1ee85 196 const char *name, psaddr_t *sym_addr)
fb0e1ba7 197{
3b7344d5 198 struct bound_minimal_symbol ms;
c988ad87
TT
199 struct cleanup *old_chain = save_current_program_space ();
200 struct inferior *inf = find_inferior_pid (ptid_get_pid (ph->ptid));
201 ps_err_e result;
202
203 set_current_program_space (inf->pspace);
fb0e1ba7
MK
204
205 /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */
206 ms = lookup_minimal_symbol (name, NULL, NULL);
3b7344d5 207 if (ms.minsym == NULL)
c988ad87
TT
208 result = PS_NOSYM;
209 else
210 {
77e371c0 211 *sym_addr = core_addr_to_ps_addr (BMSYMBOL_VALUE_ADDRESS (ms));
c988ad87
TT
212 result = PS_OK;
213 }
fb0e1ba7 214
c988ad87
TT
215 do_cleanups (old_chain);
216 return result;
fb0e1ba7
MK
217}
218
219/* Read SIZE bytes from the target process PH at address ADDR and copy
220 them into BUF. */
221
222ps_err_e
76e1ee85 223ps_pdread (gdb_ps_prochandle_t ph, psaddr_t addr,
fb0e1ba7
MK
224 gdb_ps_read_buf_t buf, gdb_ps_size_t size)
225{
226 return ps_xfer_memory (ph, addr, buf, size, 0);
227}
228
229/* Write SIZE bytes from BUF into the target process PH at address ADDR. */
230
231ps_err_e
76e1ee85 232ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr,
fb0e1ba7
MK
233 gdb_ps_write_buf_t buf, gdb_ps_size_t size)
234{
47b667de 235 return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 1);
fb0e1ba7
MK
236}
237
238/* Read SIZE bytes from the target process PH at address ADDR and copy
239 them into BUF. */
240
241ps_err_e
76e1ee85 242ps_ptread (gdb_ps_prochandle_t ph, psaddr_t addr,
fb0e1ba7
MK
243 gdb_ps_read_buf_t buf, gdb_ps_size_t size)
244{
47b667de 245 return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 0);
fb0e1ba7
MK
246}
247
248/* Write SIZE bytes from BUF into the target process PH at address ADDR. */
249
250ps_err_e
76e1ee85 251ps_ptwrite (gdb_ps_prochandle_t ph, psaddr_t addr,
fb0e1ba7
MK
252 gdb_ps_write_buf_t buf, gdb_ps_size_t size)
253{
47b667de 254 return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 1);
fb0e1ba7
MK
255}
256
257/* Get the general registers of LWP LWPID within the target process PH
258 and store them in GREGSET. */
259
260ps_err_e
261ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
262{
39f77062 263 struct cleanup *old_chain = save_inferior_ptid ();
594f7785 264 struct regcache *regcache;
fb0e1ba7 265
dfd4cc63 266 inferior_ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
f5656ead 267 regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ());
fb0e1ba7 268
594f7785
UW
269 target_fetch_registers (regcache, -1);
270 fill_gregset (regcache, (gdb_gregset_t *) gregset, -1);
fb0e1ba7
MK
271
272 do_cleanups (old_chain);
273 return PS_OK;
274}
275
276/* Set the general registers of LWP LWPID within the target process PH
277 from GREGSET. */
278
279ps_err_e
280ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset)
281{
39f77062 282 struct cleanup *old_chain = save_inferior_ptid ();
594f7785 283 struct regcache *regcache;
fb0e1ba7 284
dfd4cc63 285 inferior_ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
f5656ead 286 regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ());
fb0e1ba7 287
594f7785
UW
288 supply_gregset (regcache, (const gdb_gregset_t *) gregset);
289 target_store_registers (regcache, -1);
fb0e1ba7
MK
290
291 do_cleanups (old_chain);
292 return PS_OK;
293}
294
295/* Get the floating-point registers of LWP LWPID within the target
296 process PH and store them in FPREGSET. */
297
298ps_err_e
299ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid,
300 gdb_prfpregset_t *fpregset)
301{
39f77062 302 struct cleanup *old_chain = save_inferior_ptid ();
594f7785 303 struct regcache *regcache;
fb0e1ba7 304
dfd4cc63 305 inferior_ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
f5656ead 306 regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ());
fb0e1ba7 307
594f7785
UW
308 target_fetch_registers (regcache, -1);
309 fill_fpregset (regcache, (gdb_fpregset_t *) fpregset, -1);
fb0e1ba7
MK
310
311 do_cleanups (old_chain);
312 return PS_OK;
313}
314
315/* Set the floating-point registers of LWP LWPID within the target
316 process PH from FPREGSET. */
317
318ps_err_e
319ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid,
320 const gdb_prfpregset_t *fpregset)
321{
39f77062 322 struct cleanup *old_chain = save_inferior_ptid ();
594f7785 323 struct regcache *regcache;
fb0e1ba7 324
dfd4cc63 325 inferior_ptid = ptid_build (ptid_get_pid (ph->ptid), lwpid, 0);
f5656ead 326 regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch ());
fb0e1ba7 327
594f7785
UW
328 supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset);
329 target_store_registers (regcache, -1);
fb0e1ba7
MK
330
331 do_cleanups (old_chain);
332 return PS_OK;
333}
334
ca557f44
AC
335/* Return overall process id of the target PH. Special for GNU/Linux
336 -- not used on Solaris. */
fb0e1ba7
MK
337
338pid_t
339ps_getpid (gdb_ps_prochandle_t ph)
340{
93a91755 341 return ptid_get_pid (ph->ptid);
fb0e1ba7
MK
342}
343
2c0b251b
PA
344/* Provide a prototype to silence -Wmissing-prototypes. */
345extern initialize_file_ftype _initialize_proc_service;
346
fb0e1ba7
MK
347void
348_initialize_proc_service (void)
349{
350 /* This function solely exists to make sure this module is linked
351 into the final binary. */
352}
This page took 1.262621 seconds and 4 git commands to generate.