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