]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/gdbserver/proc-service.c
Add/adjust casts in gdbserver's proc-service
[thirdparty/binutils-gdb.git] / gdb / gdbserver / proc-service.c
CommitLineData
0d62e5e8 1/* libthread_db helper functions for the remote server for GDB.
32d0add0 2 Copyright (C) 2002-2015 Free Software Foundation, Inc.
0d62e5e8
DJ
3
4 Contributed by MontaVista Software.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
0d62e5e8
DJ
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
0d62e5e8
DJ
20
21#include "server.h"
22
23/* This file is currently tied to GNU/Linux. It should scale well to
24 another libthread_db implementation, with the approriate gdbserver
25 hooks, but for now this means we can use GNU/Linux's target data. */
26
27#include "linux-low.h"
28
0050a760 29#include "gdb_proc_service.h"
0d62e5e8
DJ
30
31typedef struct ps_prochandle *gdb_ps_prochandle_t;
32typedef void *gdb_ps_read_buf_t;
33typedef const void *gdb_ps_write_buf_t;
34typedef size_t gdb_ps_size_t;
35
fd500816
DJ
36#ifdef HAVE_LINUX_REGSETS
37#define HAVE_REGSETS
38#endif
39
40#ifdef HAVE_REGSETS
0d62e5e8 41static struct regset_info *
3aee8918 42gregset_info (void)
0d62e5e8
DJ
43{
44 int i = 0;
3aee8918
PA
45 const struct regs_info *regs_info = (*the_low_target.regs_info) ();
46 struct regsets_info *regsets_info = regs_info->regsets_info;
0d62e5e8 47
3aee8918 48 while (regsets_info->regsets[i].size != -1)
0d62e5e8 49 {
3aee8918 50 if (regsets_info->regsets[i].type == GENERAL_REGS)
0d62e5e8
DJ
51 break;
52 i++;
53 }
54
3aee8918 55 return &regsets_info->regsets[i];
0d62e5e8 56}
0d62e5e8
DJ
57#endif
58
59/* Search for the symbol named NAME within the object named OBJ within
60 the target process PH. If the symbol is found the address of the
61 symbol is stored in SYM_ADDR. */
62
63ps_err_e
64ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj,
0050a760 65 const char *name, psaddr_t *sym_addr)
0d62e5e8
DJ
66{
67 CORE_ADDR addr;
68
9836d6ea 69 if (thread_db_look_up_one_symbol (name, &addr) == 0)
0d62e5e8
DJ
70 return PS_NOSYM;
71
0050a760 72 *sym_addr = (psaddr_t) (unsigned long) addr;
0d62e5e8
DJ
73 return PS_OK;
74}
75
76/* Read SIZE bytes from the target process PH at address ADDR and copy
77 them into BUF. */
78
79ps_err_e
0050a760 80ps_pdread (gdb_ps_prochandle_t ph, psaddr_t addr,
0d62e5e8
DJ
81 gdb_ps_read_buf_t buf, gdb_ps_size_t size)
82{
b42945fd 83 read_inferior_memory ((CORE_ADDR) addr, (gdb_byte *) buf, size);
0d62e5e8
DJ
84 return PS_OK;
85}
86
87/* Write SIZE bytes from BUF into the target process PH at address ADDR. */
88
89ps_err_e
0050a760 90ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr,
0d62e5e8
DJ
91 gdb_ps_write_buf_t buf, gdb_ps_size_t size)
92{
b42945fd
SM
93 if (write_inferior_memory ((CORE_ADDR) addr, (const gdb_byte *) buf, size)
94 != 0)
ab290430
PA
95 return PS_ERR;
96 return PS_OK;
0d62e5e8
DJ
97}
98
99/* Get the general registers of LWP LWPID within the target process PH
100 and store them in GREGSET. */
101
102ps_err_e
103ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
104{
fd500816 105#ifdef HAVE_REGSETS
54a0b537 106 struct lwp_info *lwp;
0bfdf32f 107 struct thread_info *reg_thread, *saved_thread;
442ea881 108 struct regcache *regcache;
0d62e5e8 109
95954743 110 lwp = find_lwp_pid (pid_to_ptid (lwpid));
54a0b537 111 if (lwp == NULL)
0d62e5e8
DJ
112 return PS_ERR;
113
0bfdf32f
GB
114 reg_thread = get_lwp_thread (lwp);
115 saved_thread = current_thread;
116 current_thread = reg_thread;
117 regcache = get_thread_regcache (current_thread, 1);
442ea881 118 gregset_info ()->fill_function (regcache, gregset);
0d62e5e8 119
0bfdf32f 120 current_thread = saved_thread;
0d62e5e8 121 return PS_OK;
fd500816 122#else
0d62e5e8 123 return PS_ERR;
fd500816 124#endif
0d62e5e8
DJ
125}
126
127/* Set the general registers of LWP LWPID within the target process PH
128 from GREGSET. */
129
130ps_err_e
131ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset)
132{
fd500816 133 /* Unneeded. */
0d62e5e8
DJ
134 return PS_ERR;
135}
136
137/* Get the floating-point registers of LWP LWPID within the target
138 process PH and store them in FPREGSET. */
139
140ps_err_e
749bab01 141ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prfpregset_t *fpregset)
0d62e5e8 142{
fd500816 143 /* Unneeded. */
0d62e5e8
DJ
144 return PS_ERR;
145}
146
147/* Set the floating-point registers of LWP LWPID within the target
148 process PH from FPREGSET. */
149
150ps_err_e
749bab01 151ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prfpregset_t *fpregset)
0d62e5e8 152{
fd500816 153 /* Unneeded. */
0d62e5e8
DJ
154 return PS_ERR;
155}
156
157/* Return overall process id of the target PH. Special for GNU/Linux
158 -- not used on Solaris. */
159
160pid_t
161ps_getpid (gdb_ps_prochandle_t ph)
162{
0bfdf32f 163 return pid_of (current_thread);
0d62e5e8 164}