1 /* libthread_db helper functions for the remote server for GDB. 2 Copyright (C) 2002-2024 Free Software Foundation, Inc. 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 10 the Free Software Foundation; either version 3 of the License, or 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 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20 21 22 /* This file is currently tied to GNU/Linux. It should scale well to 23 another libthread_db implementation, with the appropriate gdbserver 24 hooks, but for now this means we can use GNU/Linux's target data. */ 25 26 #include "linux-low.h" 27 28 #include "gdb_proc_service.h" 29 30 typedef struct ps_prochandle *gdb_ps_prochandle_t; 31 typedef void *gdb_ps_read_buf_t; 32 typedef const void *gdb_ps_write_buf_t; 33 typedef size_t gdb_ps_size_t; 34 35 #ifdef HAVE_LINUX_REGSETS 36 #define HAVE_REGSETS 37 #endif 38 39 #ifdef HAVE_REGSETS 40 static struct regset_info * 41 gregset_info (void) 42 { 43 int i = 0; 44 const regs_info *regs_info = the_linux_target->get_regs_info (); 45 struct regsets_info *regsets_info = regs_info->regsets_info; 46 47 while (regsets_info->regsets[i].size != -1) 48 { 49 if (regsets_info->regsets[i].type == GENERAL_REGS) 50 break; 51 i++; 52 } 53 54 return ®sets_info->regsets[i]; 55 } 56 #endif 57 58 /* Search for the symbol named NAME within the object named OBJ within 59 the target process PH. If the symbol is found the address of the 60 symbol is stored in SYM_ADDR. */ 61 62 ps_err_e 63 ps_pglobal_lookup (gdb_ps_prochandle_t ph, const char *obj, 64 const char *name, psaddr_t *sym_addr) 65 { 66 CORE_ADDR addr; 67 68 if (thread_db_look_up_one_symbol (name, &addr) == 0) 69 return PS_NOSYM; 70 71 *sym_addr = (psaddr_t) (unsigned long) addr; 72 return PS_OK; 73 } 74 75 /* Read SIZE bytes from the target process PH at address ADDR and copy 76 them into BUF. */ 77 78 ps_err_e 79 ps_pdread (gdb_ps_prochandle_t ph, psaddr_t addr, 80 gdb_ps_read_buf_t buf, gdb_ps_size_t size) 81 { 82 if (read_inferior_memory ((uintptr_t) addr, (gdb_byte *) buf, size) != 0) 83 return PS_ERR; 84 return PS_OK; 85 } 86 87 /* Write SIZE bytes from BUF into the target process PH at address ADDR. */ 88 89 ps_err_e 90 ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr, 91 gdb_ps_write_buf_t buf, gdb_ps_size_t size) 92 { 93 if (target_write_memory ((uintptr_t) addr, (const gdb_byte *) buf, size) 94 != 0) 95 return PS_ERR; 96 return PS_OK; 97 } 98 99 /* Get the general registers of LWP LWPID within the target process PH 100 and store them in GREGSET. */ 101 102 ps_err_e 103 ps_lgetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prgregset_t gregset) 104 { 105 #ifdef HAVE_REGSETS 106 struct lwp_info *lwp; 107 struct regcache *regcache; 108 109 lwp = find_lwp_pid (ptid_t (lwpid)); 110 if (lwp == NULL) 111 return PS_ERR; 112 113 scoped_restore_current_thread restore_thread; 114 switch_to_thread (get_lwp_thread (lwp)); 115 regcache = get_thread_regcache (current_thread, 1); 116 gregset_info ()->fill_function (regcache, gregset); 117 118 return PS_OK; 119 #else 120 return PS_ERR; 121 #endif 122 } 123 124 /* Set the general registers of LWP LWPID within the target process PH 125 from GREGSET. */ 126 127 ps_err_e 128 ps_lsetregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prgregset_t gregset) 129 { 130 /* Unneeded. */ 131 return PS_ERR; 132 } 133 134 /* Get the floating-point registers of LWP LWPID within the target 135 process PH and store them in FPREGSET. */ 136 137 ps_err_e 138 ps_lgetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, prfpregset_t *fpregset) 139 { 140 /* Unneeded. */ 141 return PS_ERR; 142 } 143 144 /* Set the floating-point registers of LWP LWPID within the target 145 process PH from FPREGSET. */ 146 147 ps_err_e 148 ps_lsetfpregs (gdb_ps_prochandle_t ph, lwpid_t lwpid, const prfpregset_t *fpregset) 149 { 150 /* Unneeded. */ 151 return PS_ERR; 152 } 153 154 /* Return overall process id of the target PH. Special for GNU/Linux 155 -- not used on Solaris. */ 156 157 pid_t 158 ps_getpid (gdb_ps_prochandle_t ph) 159 { 160 return current_process ()->pid; 161 } 162