]>
Commit | Line | Data |
---|---|---|
fb0e1ba7 | 1 | /* <proc_service.h> implementation. |
ca557f44 | 2 | |
1d506c26 | 3 | Copyright (C) 1999-2024 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 | 19 | |
fb0e1ba7 | 20 | |
76e1ee85 | 21 | #include "gdbcore.h" |
fb0e1ba7 | 22 | #include "inferior.h" |
00431a78 | 23 | #include "gdbthread.h" |
fb0e1ba7 MK |
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 | ||
fb0e1ba7 MK |
37 | /* Helper functions. */ |
38 | ||
76e1ee85 DJ |
39 | /* Convert a psaddr_t to a CORE_ADDR. */ |
40 | ||
41 | static CORE_ADDR | |
42 | ps_addr_to_core_addr (psaddr_t addr) | |
43 | { | |
7e10abd1 TT |
44 | if (current_program_space->exec_bfd () |
45 | && bfd_get_sign_extend_vma (current_program_space->exec_bfd ())) | |
76e1ee85 DJ |
46 | return (intptr_t) addr; |
47 | else | |
48 | return (uintptr_t) addr; | |
49 | } | |
50 | ||
51 | /* Convert a CORE_ADDR to a psaddr_t. */ | |
52 | ||
53 | static psaddr_t | |
54 | core_addr_to_ps_addr (CORE_ADDR addr) | |
55 | { | |
7e10abd1 TT |
56 | if (current_program_space->exec_bfd () |
57 | && bfd_get_sign_extend_vma (current_program_space->exec_bfd ())) | |
76e1ee85 DJ |
58 | return (psaddr_t) (intptr_t) addr; |
59 | else | |
60 | return (psaddr_t) (uintptr_t) addr; | |
61 | } | |
62 | ||
fb0e1ba7 MK |
63 | /* Transfer LEN bytes of memory between BUF and address ADDR in the |
64 | process specified by PH. If WRITE, transfer them to the process, | |
65 | else transfer them from the process. Returns PS_OK for success, | |
66 | PS_ERR on failure. | |
67 | ||
9b11e3a7 | 68 | This is a helper function for ps_pdread and ps_pdwrite. */ |
fb0e1ba7 MK |
69 | |
70 | static ps_err_e | |
76e1ee85 | 71 | ps_xfer_memory (const struct ps_prochandle *ph, psaddr_t addr, |
47b667de | 72 | gdb_byte *buf, size_t len, int write) |
fb0e1ba7 | 73 | { |
6d30ada8 | 74 | scoped_restore_current_inferior_for_memory save_inferior (ph->thread->inf); |
fb0e1ba7 | 75 | |
5b6d1e4f PA |
76 | CORE_ADDR core_addr = ps_addr_to_core_addr (addr); |
77 | ||
78 | int ret; | |
fb0e1ba7 | 79 | if (write) |
76e1ee85 | 80 | ret = target_write_memory (core_addr, buf, len); |
fb0e1ba7 | 81 | else |
76e1ee85 | 82 | ret = target_read_memory (core_addr, buf, len); |
fb0e1ba7 MK |
83 | return (ret == 0 ? PS_OK : PS_ERR); |
84 | } | |
85 | \f | |
86 | ||
fb0e1ba7 MK |
87 | /* Search for the symbol named NAME within the object named OBJ within |
88 | the target process PH. If the symbol is found the address of the | |
89 | symbol is stored in SYM_ADDR. */ | |
90 | ||
91 | ps_err_e | |
281c4447 | 92 | ps_pglobal_lookup (struct ps_prochandle *ph, const char *obj, |
76e1ee85 | 93 | const char *name, psaddr_t *sym_addr) |
fb0e1ba7 | 94 | { |
00431a78 | 95 | inferior *inf = ph->thread->inf; |
5ed8105e PA |
96 | |
97 | scoped_restore_current_program_space restore_pspace; | |
c988ad87 TT |
98 | |
99 | set_current_program_space (inf->pspace); | |
fb0e1ba7 MK |
100 | |
101 | /* FIXME: kettenis/2000-09-03: What should we do with OBJ? */ | |
5ed8105e | 102 | bound_minimal_symbol ms = lookup_minimal_symbol (name, NULL, NULL); |
3b7344d5 | 103 | if (ms.minsym == NULL) |
5ed8105e | 104 | return PS_NOSYM; |
fb0e1ba7 | 105 | |
4aeddc50 | 106 | *sym_addr = core_addr_to_ps_addr (ms.value_address ()); |
5ed8105e | 107 | return PS_OK; |
fb0e1ba7 MK |
108 | } |
109 | ||
110 | /* Read SIZE bytes from the target process PH at address ADDR and copy | |
111 | them into BUF. */ | |
112 | ||
113 | ps_err_e | |
281c4447 | 114 | ps_pdread (struct ps_prochandle *ph, psaddr_t addr, void *buf, size_t size) |
fb0e1ba7 | 115 | { |
49e66b4d | 116 | return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 0); |
fb0e1ba7 MK |
117 | } |
118 | ||
119 | /* Write SIZE bytes from BUF into the target process PH at address ADDR. */ | |
120 | ||
121 | ps_err_e | |
281c4447 RO |
122 | ps_pdwrite (struct ps_prochandle *ph, psaddr_t addr, |
123 | const void *buf, size_t size) | |
fb0e1ba7 | 124 | { |
47b667de | 125 | return ps_xfer_memory (ph, addr, (gdb_byte *) buf, size, 1); |
fb0e1ba7 MK |
126 | } |
127 | ||
4c4e7ad4 PA |
128 | /* Get a regcache for LWPID using its inferior's "main" architecture, |
129 | which is the register set libthread_db expects to be using. In | |
130 | multi-arch debugging scenarios, the thread's architecture may | |
8133c7dc | 131 | differ from the inferior's "main" architecture. */ |
4c4e7ad4 PA |
132 | |
133 | static struct regcache * | |
134 | get_ps_regcache (struct ps_prochandle *ph, lwpid_t lwpid) | |
135 | { | |
136 | inferior *inf = ph->thread->inf; | |
74387712 | 137 | return get_thread_arch_regcache (inf, ptid_t (inf->pid, lwpid), |
27b1f19f | 138 | inf->arch ()); |
4c4e7ad4 PA |
139 | } |
140 | ||
fb0e1ba7 MK |
141 | /* Get the general registers of LWP LWPID within the target process PH |
142 | and store them in GREGSET. */ | |
143 | ||
144 | ps_err_e | |
281c4447 | 145 | ps_lgetregs (struct ps_prochandle *ph, lwpid_t lwpid, prgregset_t gregset) |
fb0e1ba7 | 146 | { |
4c4e7ad4 | 147 | struct regcache *regcache = get_ps_regcache (ph, lwpid); |
fb0e1ba7 | 148 | |
594f7785 UW |
149 | target_fetch_registers (regcache, -1); |
150 | fill_gregset (regcache, (gdb_gregset_t *) gregset, -1); | |
fb0e1ba7 | 151 | |
fb0e1ba7 MK |
152 | return PS_OK; |
153 | } | |
154 | ||
155 | /* Set the general registers of LWP LWPID within the target process PH | |
156 | from GREGSET. */ | |
157 | ||
158 | ps_err_e | |
281c4447 | 159 | ps_lsetregs (struct ps_prochandle *ph, lwpid_t lwpid, const prgregset_t gregset) |
fb0e1ba7 | 160 | { |
4c4e7ad4 | 161 | struct regcache *regcache = get_ps_regcache (ph, lwpid); |
fb0e1ba7 | 162 | |
594f7785 UW |
163 | supply_gregset (regcache, (const gdb_gregset_t *) gregset); |
164 | target_store_registers (regcache, -1); | |
fb0e1ba7 | 165 | |
fb0e1ba7 MK |
166 | return PS_OK; |
167 | } | |
168 | ||
169 | /* Get the floating-point registers of LWP LWPID within the target | |
170 | process PH and store them in FPREGSET. */ | |
171 | ||
172 | ps_err_e | |
12b164e9 GB |
173 | ps_lgetfpregs (struct ps_prochandle *ph, lwpid_t lwpid, |
174 | prfpregset_t *fpregset) | |
fb0e1ba7 | 175 | { |
4c4e7ad4 | 176 | struct regcache *regcache = get_ps_regcache (ph, lwpid); |
fb0e1ba7 | 177 | |
594f7785 UW |
178 | target_fetch_registers (regcache, -1); |
179 | fill_fpregset (regcache, (gdb_fpregset_t *) fpregset, -1); | |
fb0e1ba7 | 180 | |
fb0e1ba7 MK |
181 | return PS_OK; |
182 | } | |
183 | ||
184 | /* Set the floating-point registers of LWP LWPID within the target | |
185 | process PH from FPREGSET. */ | |
186 | ||
187 | ps_err_e | |
281c4447 | 188 | ps_lsetfpregs (struct ps_prochandle *ph, lwpid_t lwpid, |
12b164e9 | 189 | const prfpregset_t *fpregset) |
fb0e1ba7 | 190 | { |
4c4e7ad4 | 191 | struct regcache *regcache = get_ps_regcache (ph, lwpid); |
fb0e1ba7 | 192 | |
594f7785 UW |
193 | supply_fpregset (regcache, (const gdb_fpregset_t *) fpregset); |
194 | target_store_registers (regcache, -1); | |
fb0e1ba7 | 195 | |
fb0e1ba7 MK |
196 | return PS_OK; |
197 | } | |
198 | ||
ca557f44 AC |
199 | /* Return overall process id of the target PH. Special for GNU/Linux |
200 | -- not used on Solaris. */ | |
fb0e1ba7 MK |
201 | |
202 | pid_t | |
281c4447 | 203 | ps_getpid (struct ps_prochandle *ph) |
fb0e1ba7 | 204 | { |
e99b03dc | 205 | return ph->thread->ptid.pid (); |
fb0e1ba7 MK |
206 | } |
207 | ||
6c265988 | 208 | void _initialize_proc_service (); |
fb0e1ba7 | 209 | void |
6c265988 | 210 | _initialize_proc_service () |
fb0e1ba7 MK |
211 | { |
212 | /* This function solely exists to make sure this module is linked | |
213 | into the final binary. */ | |
214 | } |