gdb: Make GMP a required dependency for building GDB
[binutils-gdb.git] / gdbserver / proc-service.cc
blob803c704e3f34b68f2c1fff185d9cea0d6a645fac
1 /* libthread_db helper functions for the remote server for GDB.
2 Copyright (C) 2002-2020 Free Software Foundation, Inc.
4 Contributed by MontaVista Software.
6 This file is part of GDB.
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
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "server.h"
23 /* This file is currently tied to GNU/Linux. It should scale well to
24 another libthread_db implementation, with the appropriate gdbserver
25 hooks, but for now this means we can use GNU/Linux's target data. */
27 #include "linux-low.h"
29 #include "gdb_proc_service.h"
31 typedef struct ps_prochandle *gdb_ps_prochandle_t;
32 typedef void *gdb_ps_read_buf_t;
33 typedef const void *gdb_ps_write_buf_t;
34 typedef size_t gdb_ps_size_t;
36 #ifdef HAVE_LINUX_REGSETS
37 #define HAVE_REGSETS
38 #endif
40 #ifdef HAVE_REGSETS
41 static struct regset_info *
42 gregset_info (void)
44 int i = 0;
45 const regs_info *regs_info = the_linux_target->get_regs_info ();
46 struct regsets_info *regsets_info = regs_info->regsets_info;
48 while (regsets_info->regsets[i].size != -1)
50 if (regsets_info->regsets[i].type == GENERAL_REGS)
51 break;
52 i++;
55 return &regsets_info->regsets[i];
57 #endif
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. */
63 ps_err_e
64 ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj,
65 const char *name, psaddr_t *sym_addr)
67 CORE_ADDR addr;
69 if (thread_db_look_up_one_symbol (name, &addr) == 0)
70 return PS_NOSYM;
72 *sym_addr = (psaddr_t) (unsigned long) addr;
73 return PS_OK;
76 /* Read SIZE bytes from the target process PH at address ADDR and copy
77 them into BUF. */
79 ps_err_e
80 ps_pdread (gdb_ps_prochandle_t ph, psaddr_t addr,
81 gdb_ps_read_buf_t buf, gdb_ps_size_t size)
83 if (read_inferior_memory ((uintptr_t) addr, (gdb_byte *) buf, size) != 0)
84 return PS_ERR;
85 return PS_OK;
88 /* Write SIZE bytes from BUF into the target process PH at address ADDR. */
90 ps_err_e
91 ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr,
92 gdb_ps_write_buf_t buf, gdb_ps_size_t size)
94 if (target_write_memory ((uintptr_t) addr, (const gdb_byte *) buf, size)
95 != 0)
96 return PS_ERR;
97 return PS_OK;
100 /* Get the general registers of LWP LWPID within the target process PH
101 and store them in GREGSET. */
103 ps_err_e
104 ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset)
106 #ifdef HAVE_REGSETS
107 struct lwp_info *lwp;
108 struct thread_info *reg_thread, *saved_thread;
109 struct regcache *regcache;
111 lwp = find_lwp_pid (ptid_t (lwpid));
112 if (lwp == NULL)
113 return PS_ERR;
115 reg_thread = get_lwp_thread (lwp);
116 saved_thread = current_thread;
117 current_thread = reg_thread;
118 regcache = get_thread_regcache (current_thread, 1);
119 gregset_info ()->fill_function (regcache, gregset);
121 current_thread = saved_thread;
122 return PS_OK;
123 #else
124 return PS_ERR;
125 #endif
128 /* Set the general registers of LWP LWPID within the target process PH
129 from GREGSET. */
131 ps_err_e
132 ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset)
134 /* Unneeded. */
135 return PS_ERR;
138 /* Get the floating-point registers of LWP LWPID within the target
139 process PH and store them in FPREGSET. */
141 ps_err_e
142 ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prfpregset_t *fpregset)
144 /* Unneeded. */
145 return PS_ERR;
148 /* Set the floating-point registers of LWP LWPID within the target
149 process PH from FPREGSET. */
151 ps_err_e
152 ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prfpregset_t *fpregset)
154 /* Unneeded. */
155 return PS_ERR;
158 /* Return overall process id of the target PH. Special for GNU/Linux
159 -- not used on Solaris. */
161 pid_t
162 ps_getpid (gdb_ps_prochandle_t ph)
164 return pid_of (current_thread);