Commit | Line | Data |
---|---|---|
32178cab | 1 | /* Cache and manage the values of registers for GDB, the GNU debugger. |
3fadccb3 | 2 | |
61baf725 | 3 | Copyright (C) 1986-2017 Free Software Foundation, Inc. |
32178cab MS |
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 |
32178cab MS |
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/>. */ |
32178cab MS |
19 | |
20 | #include "defs.h" | |
32178cab MS |
21 | #include "inferior.h" |
22 | #include "target.h" | |
23 | #include "gdbarch.h" | |
705152c5 | 24 | #include "gdbcmd.h" |
4e052eda | 25 | #include "regcache.h" |
b59ff9d5 | 26 | #include "reggroups.h" |
f4c5303c | 27 | #include "observer.h" |
c21236dc | 28 | #include "remote.h" |
d3eaaf66 | 29 | #include "valprint.h" |
0b309272 | 30 | #include "regset.h" |
32178cab MS |
31 | |
32 | /* | |
33 | * DATA STRUCTURE | |
34 | * | |
35 | * Here is the actual register cache. | |
36 | */ | |
37 | ||
3fadccb3 | 38 | /* Per-architecture object describing the layout of a register cache. |
0df8b418 | 39 | Computed once when the architecture is created. */ |
3fadccb3 AC |
40 | |
41 | struct gdbarch_data *regcache_descr_handle; | |
42 | ||
43 | struct regcache_descr | |
44 | { | |
45 | /* The architecture this descriptor belongs to. */ | |
46 | struct gdbarch *gdbarch; | |
47 | ||
bb1db049 AC |
48 | /* The raw register cache. Each raw (or hard) register is supplied |
49 | by the target interface. The raw cache should not contain | |
50 | redundant information - if the PC is constructed from two | |
d2f0b918 | 51 | registers then those registers and not the PC lives in the raw |
bb1db049 | 52 | cache. */ |
3fadccb3 AC |
53 | int nr_raw_registers; |
54 | long sizeof_raw_registers; | |
ee99023e | 55 | long sizeof_raw_register_status; |
3fadccb3 | 56 | |
d138e37a AC |
57 | /* The cooked register space. Each cooked register in the range |
58 | [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw | |
59 | register. The remaining [NR_RAW_REGISTERS | |
02f60eae | 60 | .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto |
d138e37a | 61 | both raw registers and memory by the architecture methods |
02f60eae | 62 | gdbarch_pseudo_register_read and gdbarch_pseudo_register_write. */ |
d138e37a | 63 | int nr_cooked_registers; |
067df2e5 | 64 | long sizeof_cooked_registers; |
ee99023e | 65 | long sizeof_cooked_register_status; |
d138e37a | 66 | |
86d31898 | 67 | /* Offset and size (in 8 bit bytes), of each register in the |
d138e37a | 68 | register cache. All registers (including those in the range |
99e42fd8 PA |
69 | [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an |
70 | offset. */ | |
3fadccb3 | 71 | long *register_offset; |
3fadccb3 | 72 | long *sizeof_register; |
3fadccb3 | 73 | |
bb425013 AC |
74 | /* Cached table containing the type of each register. */ |
75 | struct type **register_type; | |
3fadccb3 AC |
76 | }; |
77 | ||
3fadccb3 AC |
78 | static void * |
79 | init_regcache_descr (struct gdbarch *gdbarch) | |
80 | { | |
81 | int i; | |
82 | struct regcache_descr *descr; | |
83 | gdb_assert (gdbarch != NULL); | |
84 | ||
bb425013 | 85 | /* Create an initial, zero filled, table. */ |
116f06ea | 86 | descr = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct regcache_descr); |
3fadccb3 | 87 | descr->gdbarch = gdbarch; |
3fadccb3 | 88 | |
d138e37a AC |
89 | /* Total size of the register space. The raw registers are mapped |
90 | directly onto the raw register cache while the pseudo's are | |
3fadccb3 | 91 | either mapped onto raw-registers or memory. */ |
214e098a UW |
92 | descr->nr_cooked_registers = gdbarch_num_regs (gdbarch) |
93 | + gdbarch_num_pseudo_regs (gdbarch); | |
ee99023e PA |
94 | descr->sizeof_cooked_register_status |
95 | = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch); | |
3fadccb3 | 96 | |
bb425013 | 97 | /* Fill in a table of register types. */ |
116f06ea | 98 | descr->register_type |
3e43a32a MS |
99 | = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, |
100 | struct type *); | |
bb425013 | 101 | for (i = 0; i < descr->nr_cooked_registers; i++) |
336a3131 | 102 | descr->register_type[i] = gdbarch_register_type (gdbarch, i); |
bb425013 | 103 | |
bb1db049 AC |
104 | /* Construct a strictly RAW register cache. Don't allow pseudo's |
105 | into the register cache. */ | |
214e098a | 106 | descr->nr_raw_registers = gdbarch_num_regs (gdbarch); |
ee99023e | 107 | descr->sizeof_raw_register_status = gdbarch_num_regs (gdbarch); |
bb1db049 | 108 | |
067df2e5 | 109 | /* Lay out the register cache. |
3fadccb3 | 110 | |
bb425013 AC |
111 | NOTE: cagney/2002-05-22: Only register_type() is used when |
112 | constructing the register cache. It is assumed that the | |
113 | register's raw size, virtual size and type length are all the | |
114 | same. */ | |
3fadccb3 AC |
115 | |
116 | { | |
117 | long offset = 0; | |
123f5f96 | 118 | |
116f06ea AC |
119 | descr->sizeof_register |
120 | = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long); | |
121 | descr->register_offset | |
122 | = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long); | |
99e42fd8 PA |
123 | for (i = 0; i < descr->nr_raw_registers; i++) |
124 | { | |
125 | descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]); | |
126 | descr->register_offset[i] = offset; | |
127 | offset += descr->sizeof_register[i]; | |
128 | gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]); | |
129 | } | |
130 | /* Set the real size of the raw register cache buffer. */ | |
131 | descr->sizeof_raw_registers = offset; | |
132 | ||
133 | for (; i < descr->nr_cooked_registers; i++) | |
3fadccb3 | 134 | { |
bb425013 | 135 | descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]); |
3fadccb3 AC |
136 | descr->register_offset[i] = offset; |
137 | offset += descr->sizeof_register[i]; | |
123a958e | 138 | gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]); |
3fadccb3 | 139 | } |
99e42fd8 | 140 | /* Set the real size of the readonly register cache buffer. */ |
067df2e5 | 141 | descr->sizeof_cooked_registers = offset; |
3fadccb3 AC |
142 | } |
143 | ||
3fadccb3 AC |
144 | return descr; |
145 | } | |
146 | ||
147 | static struct regcache_descr * | |
148 | regcache_descr (struct gdbarch *gdbarch) | |
149 | { | |
19ba03f4 SM |
150 | return (struct regcache_descr *) gdbarch_data (gdbarch, |
151 | regcache_descr_handle); | |
3fadccb3 AC |
152 | } |
153 | ||
bb425013 AC |
154 | /* Utility functions returning useful register attributes stored in |
155 | the regcache descr. */ | |
156 | ||
157 | struct type * | |
158 | register_type (struct gdbarch *gdbarch, int regnum) | |
159 | { | |
160 | struct regcache_descr *descr = regcache_descr (gdbarch); | |
123f5f96 | 161 | |
bb425013 AC |
162 | gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); |
163 | return descr->register_type[regnum]; | |
164 | } | |
165 | ||
0ed04cce AC |
166 | /* Utility functions returning useful register attributes stored in |
167 | the regcache descr. */ | |
168 | ||
08a617da AC |
169 | int |
170 | register_size (struct gdbarch *gdbarch, int regnum) | |
171 | { | |
172 | struct regcache_descr *descr = regcache_descr (gdbarch); | |
173 | int size; | |
123f5f96 | 174 | |
f57d151a | 175 | gdb_assert (regnum >= 0 |
214e098a UW |
176 | && regnum < (gdbarch_num_regs (gdbarch) |
177 | + gdbarch_num_pseudo_regs (gdbarch))); | |
08a617da | 178 | size = descr->sizeof_register[regnum]; |
08a617da AC |
179 | return size; |
180 | } | |
181 | ||
8d689ee5 YQ |
182 | /* See common/common-regcache.h. */ |
183 | ||
184 | int | |
185 | regcache_register_size (const struct regcache *regcache, int n) | |
186 | { | |
187 | return register_size (get_regcache_arch (regcache), n); | |
188 | } | |
189 | ||
3fadccb3 AC |
190 | /* The register cache for storing raw register values. */ |
191 | ||
192 | struct regcache | |
193 | { | |
194 | struct regcache_descr *descr; | |
6c95b8df PA |
195 | |
196 | /* The address space of this register cache (for registers where it | |
197 | makes sense, like PC or SP). */ | |
198 | struct address_space *aspace; | |
199 | ||
51b1fe4e | 200 | /* The register buffers. A read-only register cache can hold the |
f57d151a UW |
201 | full [0 .. gdbarch_num_regs + gdbarch_num_pseudo_regs) while a read/write |
202 | register cache can only hold [0 .. gdbarch_num_regs). */ | |
2d522557 | 203 | gdb_byte *registers; |
ee99023e PA |
204 | /* Register cache status. */ |
205 | signed char *register_status; | |
2d28509a AC |
206 | /* Is this a read-only cache? A read-only cache is used for saving |
207 | the target's register state (e.g, across an inferior function | |
208 | call or just before forcing a function return). A read-only | |
209 | cache can only be updated via the methods regcache_dup() and | |
210 | regcache_cpy(). The actual contents are determined by the | |
211 | reggroup_save and reggroup_restore methods. */ | |
212 | int readonly_p; | |
594f7785 UW |
213 | /* If this is a read-write cache, which thread's registers is |
214 | it connected to? */ | |
215 | ptid_t ptid; | |
3fadccb3 AC |
216 | }; |
217 | ||
ddaaf0fb SM |
218 | /* See regcache.h. */ |
219 | ||
220 | ptid_t | |
221 | regcache_get_ptid (const struct regcache *regcache) | |
222 | { | |
223 | gdb_assert (!ptid_equal (regcache->ptid, minus_one_ptid)); | |
224 | ||
225 | return regcache->ptid; | |
226 | } | |
227 | ||
99e42fd8 PA |
228 | static struct regcache * |
229 | regcache_xmalloc_1 (struct gdbarch *gdbarch, struct address_space *aspace, | |
230 | int readonly_p) | |
3fadccb3 AC |
231 | { |
232 | struct regcache_descr *descr; | |
233 | struct regcache *regcache; | |
123f5f96 | 234 | |
3fadccb3 AC |
235 | gdb_assert (gdbarch != NULL); |
236 | descr = regcache_descr (gdbarch); | |
70ba0933 | 237 | regcache = XNEW (struct regcache); |
3fadccb3 | 238 | regcache->descr = descr; |
99e42fd8 PA |
239 | regcache->readonly_p = readonly_p; |
240 | if (readonly_p) | |
241 | { | |
242 | regcache->registers | |
fc270c35 | 243 | = XCNEWVEC (gdb_byte, descr->sizeof_cooked_registers); |
ee99023e | 244 | regcache->register_status |
fc270c35 | 245 | = XCNEWVEC (signed char, descr->sizeof_cooked_register_status); |
99e42fd8 PA |
246 | } |
247 | else | |
248 | { | |
249 | regcache->registers | |
fc270c35 | 250 | = XCNEWVEC (gdb_byte, descr->sizeof_raw_registers); |
ee99023e | 251 | regcache->register_status |
fc270c35 | 252 | = XCNEWVEC (signed char, descr->sizeof_raw_register_status); |
99e42fd8 | 253 | } |
d37346f0 | 254 | regcache->aspace = aspace; |
594f7785 | 255 | regcache->ptid = minus_one_ptid; |
3fadccb3 AC |
256 | return regcache; |
257 | } | |
258 | ||
99e42fd8 PA |
259 | struct regcache * |
260 | regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace) | |
261 | { | |
262 | return regcache_xmalloc_1 (gdbarch, aspace, 1); | |
263 | } | |
264 | ||
3fadccb3 AC |
265 | void |
266 | regcache_xfree (struct regcache *regcache) | |
267 | { | |
268 | if (regcache == NULL) | |
269 | return; | |
51b1fe4e | 270 | xfree (regcache->registers); |
ee99023e | 271 | xfree (regcache->register_status); |
3fadccb3 AC |
272 | xfree (regcache); |
273 | } | |
274 | ||
b9362cc7 | 275 | static void |
36160dc4 AC |
276 | do_regcache_xfree (void *data) |
277 | { | |
19ba03f4 | 278 | regcache_xfree ((struct regcache *) data); |
36160dc4 AC |
279 | } |
280 | ||
281 | struct cleanup * | |
282 | make_cleanup_regcache_xfree (struct regcache *regcache) | |
283 | { | |
284 | return make_cleanup (do_regcache_xfree, regcache); | |
285 | } | |
286 | ||
b94ade42 PL |
287 | /* Cleanup routines for invalidating a register. */ |
288 | ||
289 | struct register_to_invalidate | |
290 | { | |
291 | struct regcache *regcache; | |
292 | int regnum; | |
293 | }; | |
294 | ||
295 | static void | |
296 | do_regcache_invalidate (void *data) | |
297 | { | |
19ba03f4 | 298 | struct register_to_invalidate *reg = (struct register_to_invalidate *) data; |
b94ade42 PL |
299 | |
300 | regcache_invalidate (reg->regcache, reg->regnum); | |
301 | } | |
302 | ||
303 | static struct cleanup * | |
304 | make_cleanup_regcache_invalidate (struct regcache *regcache, int regnum) | |
305 | { | |
306 | struct register_to_invalidate* reg = XNEW (struct register_to_invalidate); | |
307 | ||
308 | reg->regcache = regcache; | |
309 | reg->regnum = regnum; | |
310 | return make_cleanup_dtor (do_regcache_invalidate, (void *) reg, xfree); | |
311 | } | |
312 | ||
41d35cb0 MK |
313 | /* Return REGCACHE's architecture. */ |
314 | ||
315 | struct gdbarch * | |
316 | get_regcache_arch (const struct regcache *regcache) | |
317 | { | |
318 | return regcache->descr->gdbarch; | |
319 | } | |
320 | ||
6c95b8df PA |
321 | struct address_space * |
322 | get_regcache_aspace (const struct regcache *regcache) | |
323 | { | |
324 | return regcache->aspace; | |
325 | } | |
326 | ||
51b1fe4e AC |
327 | /* Return a pointer to register REGNUM's buffer cache. */ |
328 | ||
2d522557 | 329 | static gdb_byte * |
9a661b68 | 330 | register_buffer (const struct regcache *regcache, int regnum) |
51b1fe4e AC |
331 | { |
332 | return regcache->registers + regcache->descr->register_offset[regnum]; | |
333 | } | |
334 | ||
2d28509a | 335 | void |
5602984a AC |
336 | regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read, |
337 | void *src) | |
2d28509a AC |
338 | { |
339 | struct gdbarch *gdbarch = dst->descr->gdbarch; | |
2d522557 | 340 | gdb_byte buf[MAX_REGISTER_SIZE]; |
2d28509a | 341 | int regnum; |
123f5f96 | 342 | |
2d28509a | 343 | /* The DST should be `read-only', if it wasn't then the save would |
5602984a | 344 | end up trying to write the register values back out to the |
2d28509a | 345 | target. */ |
2d28509a AC |
346 | gdb_assert (dst->readonly_p); |
347 | /* Clear the dest. */ | |
348 | memset (dst->registers, 0, dst->descr->sizeof_cooked_registers); | |
ee99023e PA |
349 | memset (dst->register_status, 0, |
350 | dst->descr->sizeof_cooked_register_status); | |
2d28509a | 351 | /* Copy over any registers (identified by their membership in the |
f57d151a UW |
352 | save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs + |
353 | gdbarch_num_pseudo_regs) range is checked since some architectures need | |
5602984a | 354 | to save/restore `cooked' registers that live in memory. */ |
2d28509a AC |
355 | for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++) |
356 | { | |
357 | if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup)) | |
358 | { | |
05d1431c | 359 | enum register_status status = cooked_read (src, regnum, buf); |
123f5f96 | 360 | |
05d1431c PA |
361 | if (status == REG_VALID) |
362 | memcpy (register_buffer (dst, regnum), buf, | |
363 | register_size (gdbarch, regnum)); | |
364 | else | |
5602984a | 365 | { |
05d1431c PA |
366 | gdb_assert (status != REG_UNKNOWN); |
367 | ||
368 | memset (register_buffer (dst, regnum), 0, | |
5602984a | 369 | register_size (gdbarch, regnum)); |
5602984a | 370 | } |
05d1431c | 371 | dst->register_status[regnum] = status; |
2d28509a AC |
372 | } |
373 | } | |
374 | } | |
375 | ||
349d1385 | 376 | static void |
5602984a AC |
377 | regcache_restore (struct regcache *dst, |
378 | regcache_cooked_read_ftype *cooked_read, | |
2d522557 | 379 | void *cooked_read_context) |
2d28509a AC |
380 | { |
381 | struct gdbarch *gdbarch = dst->descr->gdbarch; | |
2d522557 | 382 | gdb_byte buf[MAX_REGISTER_SIZE]; |
2d28509a | 383 | int regnum; |
123f5f96 | 384 | |
5602984a AC |
385 | /* The dst had better not be read-only. If it is, the `restore' |
386 | doesn't make much sense. */ | |
2d28509a | 387 | gdb_assert (!dst->readonly_p); |
2d28509a | 388 | /* Copy over any registers, being careful to only restore those that |
f57d151a UW |
389 | were both saved and need to be restored. The full [0 .. gdbarch_num_regs |
390 | + gdbarch_num_pseudo_regs) range is checked since some architectures need | |
5602984a AC |
391 | to save/restore `cooked' registers that live in memory. */ |
392 | for (regnum = 0; regnum < dst->descr->nr_cooked_registers; regnum++) | |
2d28509a | 393 | { |
5602984a | 394 | if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup)) |
2d28509a | 395 | { |
349d1385 | 396 | enum register_status status; |
123f5f96 | 397 | |
349d1385 DM |
398 | status = cooked_read (cooked_read_context, regnum, buf); |
399 | if (status == REG_VALID) | |
5602984a | 400 | regcache_cooked_write (dst, regnum, buf); |
2d28509a AC |
401 | } |
402 | } | |
403 | } | |
404 | ||
05d1431c | 405 | static enum register_status |
2d522557 | 406 | do_cooked_read (void *src, int regnum, gdb_byte *buf) |
5602984a | 407 | { |
19ba03f4 | 408 | struct regcache *regcache = (struct regcache *) src; |
123f5f96 | 409 | |
05d1431c | 410 | return regcache_cooked_read (regcache, regnum, buf); |
5602984a AC |
411 | } |
412 | ||
bd49952b JK |
413 | static void regcache_cpy_no_passthrough (struct regcache *dst, |
414 | struct regcache *src); | |
415 | ||
3fadccb3 AC |
416 | void |
417 | regcache_cpy (struct regcache *dst, struct regcache *src) | |
418 | { | |
3fadccb3 AC |
419 | gdb_assert (src != NULL && dst != NULL); |
420 | gdb_assert (src->descr->gdbarch == dst->descr->gdbarch); | |
421 | gdb_assert (src != dst); | |
2d28509a | 422 | gdb_assert (src->readonly_p || dst->readonly_p); |
6c95b8df | 423 | |
2d28509a | 424 | if (!src->readonly_p) |
5602984a | 425 | regcache_save (dst, do_cooked_read, src); |
2d28509a | 426 | else if (!dst->readonly_p) |
5602984a | 427 | regcache_restore (dst, do_cooked_read, src); |
2d28509a AC |
428 | else |
429 | regcache_cpy_no_passthrough (dst, src); | |
3fadccb3 AC |
430 | } |
431 | ||
bd49952b JK |
432 | /* Copy/duplicate the contents of a register cache. Unlike regcache_cpy, |
433 | which is pass-through, this does not go through to the target. | |
434 | Only values values already in the cache are transferred. The SRC and DST | |
435 | buffers must not overlap. */ | |
436 | ||
437 | static void | |
3fadccb3 AC |
438 | regcache_cpy_no_passthrough (struct regcache *dst, struct regcache *src) |
439 | { | |
3fadccb3 AC |
440 | gdb_assert (src != NULL && dst != NULL); |
441 | gdb_assert (src->descr->gdbarch == dst->descr->gdbarch); | |
442 | /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough | |
ee99023e PA |
443 | move of data into a thread's regcache. Doing this would be silly |
444 | - it would mean that regcache->register_status would be | |
445 | completely invalid. */ | |
99e42fd8 | 446 | gdb_assert (dst->readonly_p && src->readonly_p); |
6c95b8df | 447 | |
99e42fd8 PA |
448 | memcpy (dst->registers, src->registers, |
449 | dst->descr->sizeof_cooked_registers); | |
ee99023e PA |
450 | memcpy (dst->register_status, src->register_status, |
451 | dst->descr->sizeof_cooked_register_status); | |
3fadccb3 AC |
452 | } |
453 | ||
454 | struct regcache * | |
455 | regcache_dup (struct regcache *src) | |
456 | { | |
457 | struct regcache *newbuf; | |
123f5f96 | 458 | |
d37346f0 | 459 | newbuf = regcache_xmalloc (src->descr->gdbarch, get_regcache_aspace (src)); |
3fadccb3 AC |
460 | regcache_cpy (newbuf, src); |
461 | return newbuf; | |
462 | } | |
463 | ||
39181896 | 464 | enum register_status |
ee99023e | 465 | regcache_register_status (const struct regcache *regcache, int regnum) |
3fadccb3 AC |
466 | { |
467 | gdb_assert (regcache != NULL); | |
6ed7ea50 UW |
468 | gdb_assert (regnum >= 0); |
469 | if (regcache->readonly_p) | |
470 | gdb_assert (regnum < regcache->descr->nr_cooked_registers); | |
471 | else | |
472 | gdb_assert (regnum < regcache->descr->nr_raw_registers); | |
473 | ||
aead7601 | 474 | return (enum register_status) regcache->register_status[regnum]; |
3fadccb3 AC |
475 | } |
476 | ||
9c5ea4d9 UW |
477 | void |
478 | regcache_invalidate (struct regcache *regcache, int regnum) | |
479 | { | |
480 | gdb_assert (regcache != NULL); | |
481 | gdb_assert (regnum >= 0); | |
482 | gdb_assert (!regcache->readonly_p); | |
483 | gdb_assert (regnum < regcache->descr->nr_raw_registers); | |
ee99023e | 484 | regcache->register_status[regnum] = REG_UNKNOWN; |
9c5ea4d9 UW |
485 | } |
486 | ||
487 | ||
3fadccb3 | 488 | /* Global structure containing the current regcache. */ |
3fadccb3 | 489 | |
5ebd2499 | 490 | /* NOTE: this is a write-through cache. There is no "dirty" bit for |
32178cab MS |
491 | recording if the register values have been changed (eg. by the |
492 | user). Therefore all registers must be written back to the | |
493 | target when appropriate. */ | |
494 | ||
c2250ad1 | 495 | struct regcache_list |
594f7785 | 496 | { |
c2250ad1 UW |
497 | struct regcache *regcache; |
498 | struct regcache_list *next; | |
499 | }; | |
500 | ||
501 | static struct regcache_list *current_regcache; | |
502 | ||
503 | struct regcache * | |
e2d96639 YQ |
504 | get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch, |
505 | struct address_space *aspace) | |
c2250ad1 UW |
506 | { |
507 | struct regcache_list *list; | |
508 | struct regcache *new_regcache; | |
594f7785 | 509 | |
c2250ad1 UW |
510 | for (list = current_regcache; list; list = list->next) |
511 | if (ptid_equal (list->regcache->ptid, ptid) | |
512 | && get_regcache_arch (list->regcache) == gdbarch) | |
513 | return list->regcache; | |
594f7785 | 514 | |
e2d96639 YQ |
515 | new_regcache = regcache_xmalloc_1 (gdbarch, aspace, 0); |
516 | new_regcache->ptid = ptid; | |
517 | ||
8d749320 | 518 | list = XNEW (struct regcache_list); |
e2d96639 YQ |
519 | list->regcache = new_regcache; |
520 | list->next = current_regcache; | |
521 | current_regcache = list; | |
522 | ||
523 | return new_regcache; | |
524 | } | |
525 | ||
526 | struct regcache * | |
527 | get_thread_arch_regcache (ptid_t ptid, struct gdbarch *gdbarch) | |
528 | { | |
529 | struct address_space *aspace; | |
530 | ||
b78974c3 PA |
531 | /* For the benefit of "maint print registers" & co when debugging an |
532 | executable, allow dumping the regcache even when there is no | |
533 | thread selected (target_thread_address_space internal-errors if | |
534 | no address space is found). Note that normal user commands will | |
535 | fail higher up on the call stack due to no | |
536 | target_has_registers. */ | |
537 | aspace = (ptid_equal (null_ptid, ptid) | |
538 | ? NULL | |
539 | : target_thread_address_space (ptid)); | |
540 | ||
e2d96639 | 541 | return get_thread_arch_aspace_regcache (ptid, gdbarch, aspace); |
594f7785 UW |
542 | } |
543 | ||
c2250ad1 UW |
544 | static ptid_t current_thread_ptid; |
545 | static struct gdbarch *current_thread_arch; | |
546 | ||
547 | struct regcache * | |
548 | get_thread_regcache (ptid_t ptid) | |
549 | { | |
550 | if (!current_thread_arch || !ptid_equal (current_thread_ptid, ptid)) | |
551 | { | |
552 | current_thread_ptid = ptid; | |
553 | current_thread_arch = target_thread_architecture (ptid); | |
554 | } | |
555 | ||
556 | return get_thread_arch_regcache (ptid, current_thread_arch); | |
557 | } | |
558 | ||
559 | struct regcache * | |
560 | get_current_regcache (void) | |
594f7785 UW |
561 | { |
562 | return get_thread_regcache (inferior_ptid); | |
563 | } | |
32178cab | 564 | |
361c8ade GB |
565 | /* See common/common-regcache.h. */ |
566 | ||
567 | struct regcache * | |
568 | get_thread_regcache_for_ptid (ptid_t ptid) | |
569 | { | |
570 | return get_thread_regcache (ptid); | |
571 | } | |
32178cab | 572 | |
f4c5303c OF |
573 | /* Observer for the target_changed event. */ |
574 | ||
2c0b251b | 575 | static void |
f4c5303c OF |
576 | regcache_observer_target_changed (struct target_ops *target) |
577 | { | |
578 | registers_changed (); | |
579 | } | |
580 | ||
5231c1fd PA |
581 | /* Update global variables old ptids to hold NEW_PTID if they were |
582 | holding OLD_PTID. */ | |
583 | static void | |
584 | regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) | |
585 | { | |
c2250ad1 UW |
586 | struct regcache_list *list; |
587 | ||
588 | for (list = current_regcache; list; list = list->next) | |
589 | if (ptid_equal (list->regcache->ptid, old_ptid)) | |
590 | list->regcache->ptid = new_ptid; | |
5231c1fd PA |
591 | } |
592 | ||
32178cab MS |
593 | /* Low level examining and depositing of registers. |
594 | ||
595 | The caller is responsible for making sure that the inferior is | |
596 | stopped before calling the fetching routines, or it will get | |
597 | garbage. (a change from GDB version 3, in which the caller got the | |
598 | value from the last stop). */ | |
599 | ||
600 | /* REGISTERS_CHANGED () | |
601 | ||
602 | Indicate that registers may have changed, so invalidate the cache. */ | |
603 | ||
604 | void | |
e66408ed | 605 | registers_changed_ptid (ptid_t ptid) |
32178cab | 606 | { |
e66408ed | 607 | struct regcache_list *list, **list_link; |
c2250ad1 | 608 | |
e66408ed PA |
609 | list = current_regcache; |
610 | list_link = ¤t_regcache; | |
611 | while (list) | |
c2250ad1 | 612 | { |
e66408ed PA |
613 | if (ptid_match (list->regcache->ptid, ptid)) |
614 | { | |
615 | struct regcache_list *dead = list; | |
616 | ||
617 | *list_link = list->next; | |
618 | regcache_xfree (list->regcache); | |
619 | list = *list_link; | |
620 | xfree (dead); | |
621 | continue; | |
622 | } | |
623 | ||
624 | list_link = &list->next; | |
625 | list = *list_link; | |
c2250ad1 | 626 | } |
32178cab | 627 | |
c34fd852 | 628 | if (ptid_match (current_thread_ptid, ptid)) |
041274d8 PA |
629 | { |
630 | current_thread_ptid = null_ptid; | |
631 | current_thread_arch = NULL; | |
632 | } | |
32178cab | 633 | |
c34fd852 | 634 | if (ptid_match (inferior_ptid, ptid)) |
041274d8 PA |
635 | { |
636 | /* We just deleted the regcache of the current thread. Need to | |
637 | forget about any frames we have cached, too. */ | |
638 | reinit_frame_cache (); | |
639 | } | |
640 | } | |
c2250ad1 | 641 | |
041274d8 PA |
642 | void |
643 | registers_changed (void) | |
644 | { | |
645 | registers_changed_ptid (minus_one_ptid); | |
a5d9d57d | 646 | |
32178cab MS |
647 | /* Force cleanup of any alloca areas if using C alloca instead of |
648 | a builtin alloca. This particular call is used to clean up | |
649 | areas allocated by low level target code which may build up | |
650 | during lengthy interactions between gdb and the target before | |
651 | gdb gives control to the user (ie watchpoints). */ | |
652 | alloca (0); | |
32178cab MS |
653 | } |
654 | ||
8e368124 AH |
655 | void |
656 | regcache_raw_update (struct regcache *regcache, int regnum) | |
61a0eb5b | 657 | { |
8e368124 | 658 | gdb_assert (regcache != NULL); |
3fadccb3 | 659 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); |
8e368124 | 660 | |
3fadccb3 AC |
661 | /* Make certain that the register cache is up-to-date with respect |
662 | to the current thread. This switching shouldn't be necessary | |
663 | only there is still only one target side register cache. Sigh! | |
664 | On the bright side, at least there is a regcache object. */ | |
8e368124 | 665 | |
788c8b10 PA |
666 | if (!regcache->readonly_p |
667 | && regcache_register_status (regcache, regnum) == REG_UNKNOWN) | |
3fadccb3 | 668 | { |
788c8b10 | 669 | target_fetch_registers (regcache, regnum); |
788c8b10 PA |
670 | |
671 | /* A number of targets can't access the whole set of raw | |
672 | registers (because the debug API provides no means to get at | |
673 | them). */ | |
674 | if (regcache->register_status[regnum] == REG_UNKNOWN) | |
675 | regcache->register_status[regnum] = REG_UNAVAILABLE; | |
3fadccb3 | 676 | } |
8e368124 AH |
677 | } |
678 | ||
679 | enum register_status | |
680 | regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf) | |
681 | { | |
682 | gdb_assert (buf != NULL); | |
683 | regcache_raw_update (regcache, regnum); | |
05d1431c PA |
684 | |
685 | if (regcache->register_status[regnum] != REG_VALID) | |
686 | memset (buf, 0, regcache->descr->sizeof_register[regnum]); | |
687 | else | |
688 | memcpy (buf, register_buffer (regcache, regnum), | |
689 | regcache->descr->sizeof_register[regnum]); | |
690 | ||
aead7601 | 691 | return (enum register_status) regcache->register_status[regnum]; |
61a0eb5b AC |
692 | } |
693 | ||
05d1431c | 694 | enum register_status |
28fc6740 AC |
695 | regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val) |
696 | { | |
2d522557 | 697 | gdb_byte *buf; |
05d1431c | 698 | enum register_status status; |
123f5f96 | 699 | |
28fc6740 AC |
700 | gdb_assert (regcache != NULL); |
701 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
224c3ddb | 702 | buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]); |
05d1431c PA |
703 | status = regcache_raw_read (regcache, regnum, buf); |
704 | if (status == REG_VALID) | |
705 | *val = extract_signed_integer | |
706 | (buf, regcache->descr->sizeof_register[regnum], | |
707 | gdbarch_byte_order (regcache->descr->gdbarch)); | |
708 | else | |
709 | *val = 0; | |
710 | return status; | |
28fc6740 AC |
711 | } |
712 | ||
05d1431c | 713 | enum register_status |
28fc6740 AC |
714 | regcache_raw_read_unsigned (struct regcache *regcache, int regnum, |
715 | ULONGEST *val) | |
716 | { | |
2d522557 | 717 | gdb_byte *buf; |
05d1431c | 718 | enum register_status status; |
123f5f96 | 719 | |
28fc6740 AC |
720 | gdb_assert (regcache != NULL); |
721 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
224c3ddb | 722 | buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]); |
05d1431c PA |
723 | status = regcache_raw_read (regcache, regnum, buf); |
724 | if (status == REG_VALID) | |
725 | *val = extract_unsigned_integer | |
726 | (buf, regcache->descr->sizeof_register[regnum], | |
727 | gdbarch_byte_order (regcache->descr->gdbarch)); | |
728 | else | |
729 | *val = 0; | |
730 | return status; | |
28fc6740 AC |
731 | } |
732 | ||
c00dcbe9 MK |
733 | void |
734 | regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val) | |
735 | { | |
7c543f7b | 736 | gdb_byte *buf; |
123f5f96 | 737 | |
c00dcbe9 MK |
738 | gdb_assert (regcache != NULL); |
739 | gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers); | |
7c543f7b | 740 | buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]); |
e17a4113 UW |
741 | store_signed_integer (buf, regcache->descr->sizeof_register[regnum], |
742 | gdbarch_byte_order (regcache->descr->gdbarch), val); | |
c00dcbe9 MK |
743 | regcache_raw_write (regcache, regnum, buf); |
744 | } | |
745 | ||
746 | void | |
747 | regcache_raw_write_unsigned (struct regcache *regcache, int regnum, | |
748 | ULONGEST val) | |
749 | { | |
7c543f7b | 750 | gdb_byte *buf; |
123f5f96 | 751 | |
c00dcbe9 MK |
752 | gdb_assert (regcache != NULL); |
753 | gdb_assert (regnum >=0 && regnum < regcache->descr->nr_raw_registers); | |
7c543f7b | 754 | buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]); |
e17a4113 UW |
755 | store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], |
756 | gdbarch_byte_order (regcache->descr->gdbarch), val); | |
c00dcbe9 MK |
757 | regcache_raw_write (regcache, regnum, buf); |
758 | } | |
759 | ||
9fd15b2e YQ |
760 | LONGEST |
761 | regcache_raw_get_signed (struct regcache *regcache, int regnum) | |
762 | { | |
763 | LONGEST value; | |
764 | enum register_status status; | |
765 | ||
766 | status = regcache_raw_read_signed (regcache, regnum, &value); | |
767 | if (status == REG_UNAVAILABLE) | |
768 | throw_error (NOT_AVAILABLE_ERROR, | |
769 | _("Register %d is not available"), regnum); | |
770 | return value; | |
771 | } | |
772 | ||
05d1431c | 773 | enum register_status |
2d522557 | 774 | regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf) |
68365089 | 775 | { |
d138e37a | 776 | gdb_assert (regnum >= 0); |
68365089 AC |
777 | gdb_assert (regnum < regcache->descr->nr_cooked_registers); |
778 | if (regnum < regcache->descr->nr_raw_registers) | |
05d1431c | 779 | return regcache_raw_read (regcache, regnum, buf); |
2d28509a | 780 | else if (regcache->readonly_p |
05d1431c PA |
781 | && regcache->register_status[regnum] != REG_UNKNOWN) |
782 | { | |
783 | /* Read-only register cache, perhaps the cooked value was | |
784 | cached? */ | |
05d1431c PA |
785 | if (regcache->register_status[regnum] == REG_VALID) |
786 | memcpy (buf, register_buffer (regcache, regnum), | |
787 | regcache->descr->sizeof_register[regnum]); | |
788 | else | |
789 | memset (buf, 0, regcache->descr->sizeof_register[regnum]); | |
790 | ||
aead7601 | 791 | return (enum register_status) regcache->register_status[regnum]; |
05d1431c | 792 | } |
3543a589 TT |
793 | else if (gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch)) |
794 | { | |
795 | struct value *mark, *computed; | |
796 | enum register_status result = REG_VALID; | |
797 | ||
798 | mark = value_mark (); | |
799 | ||
800 | computed = gdbarch_pseudo_register_read_value (regcache->descr->gdbarch, | |
801 | regcache, regnum); | |
802 | if (value_entirely_available (computed)) | |
803 | memcpy (buf, value_contents_raw (computed), | |
804 | regcache->descr->sizeof_register[regnum]); | |
805 | else | |
806 | { | |
807 | memset (buf, 0, regcache->descr->sizeof_register[regnum]); | |
808 | result = REG_UNAVAILABLE; | |
809 | } | |
810 | ||
811 | value_free_to_mark (mark); | |
812 | ||
813 | return result; | |
814 | } | |
d138e37a | 815 | else |
05d1431c PA |
816 | return gdbarch_pseudo_register_read (regcache->descr->gdbarch, regcache, |
817 | regnum, buf); | |
61a0eb5b AC |
818 | } |
819 | ||
3543a589 TT |
820 | struct value * |
821 | regcache_cooked_read_value (struct regcache *regcache, int regnum) | |
822 | { | |
823 | gdb_assert (regnum >= 0); | |
824 | gdb_assert (regnum < regcache->descr->nr_cooked_registers); | |
825 | ||
826 | if (regnum < regcache->descr->nr_raw_registers | |
827 | || (regcache->readonly_p | |
828 | && regcache->register_status[regnum] != REG_UNKNOWN) | |
829 | || !gdbarch_pseudo_register_read_value_p (regcache->descr->gdbarch)) | |
830 | { | |
831 | struct value *result; | |
832 | ||
833 | result = allocate_value (register_type (regcache->descr->gdbarch, | |
834 | regnum)); | |
835 | VALUE_LVAL (result) = lval_register; | |
836 | VALUE_REGNUM (result) = regnum; | |
837 | ||
838 | /* It is more efficient in general to do this delegation in this | |
839 | direction than in the other one, even though the value-based | |
840 | API is preferred. */ | |
841 | if (regcache_cooked_read (regcache, regnum, | |
842 | value_contents_raw (result)) == REG_UNAVAILABLE) | |
843 | mark_value_bytes_unavailable (result, 0, | |
844 | TYPE_LENGTH (value_type (result))); | |
845 | ||
846 | return result; | |
847 | } | |
848 | else | |
849 | return gdbarch_pseudo_register_read_value (regcache->descr->gdbarch, | |
850 | regcache, regnum); | |
851 | } | |
852 | ||
05d1431c | 853 | enum register_status |
a378f419 AC |
854 | regcache_cooked_read_signed (struct regcache *regcache, int regnum, |
855 | LONGEST *val) | |
856 | { | |
05d1431c | 857 | enum register_status status; |
2d522557 | 858 | gdb_byte *buf; |
123f5f96 | 859 | |
a378f419 | 860 | gdb_assert (regcache != NULL); |
a66a9c23 | 861 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers); |
224c3ddb | 862 | buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]); |
05d1431c PA |
863 | status = regcache_cooked_read (regcache, regnum, buf); |
864 | if (status == REG_VALID) | |
865 | *val = extract_signed_integer | |
866 | (buf, regcache->descr->sizeof_register[regnum], | |
867 | gdbarch_byte_order (regcache->descr->gdbarch)); | |
868 | else | |
869 | *val = 0; | |
870 | return status; | |
a378f419 AC |
871 | } |
872 | ||
05d1431c | 873 | enum register_status |
a378f419 AC |
874 | regcache_cooked_read_unsigned (struct regcache *regcache, int regnum, |
875 | ULONGEST *val) | |
876 | { | |
05d1431c | 877 | enum register_status status; |
2d522557 | 878 | gdb_byte *buf; |
123f5f96 | 879 | |
a378f419 | 880 | gdb_assert (regcache != NULL); |
a66a9c23 | 881 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_cooked_registers); |
224c3ddb | 882 | buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]); |
05d1431c PA |
883 | status = regcache_cooked_read (regcache, regnum, buf); |
884 | if (status == REG_VALID) | |
885 | *val = extract_unsigned_integer | |
886 | (buf, regcache->descr->sizeof_register[regnum], | |
887 | gdbarch_byte_order (regcache->descr->gdbarch)); | |
888 | else | |
889 | *val = 0; | |
890 | return status; | |
a378f419 AC |
891 | } |
892 | ||
a66a9c23 AC |
893 | void |
894 | regcache_cooked_write_signed (struct regcache *regcache, int regnum, | |
895 | LONGEST val) | |
896 | { | |
7c543f7b | 897 | gdb_byte *buf; |
123f5f96 | 898 | |
a66a9c23 AC |
899 | gdb_assert (regcache != NULL); |
900 | gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers); | |
7c543f7b | 901 | buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]); |
e17a4113 UW |
902 | store_signed_integer (buf, regcache->descr->sizeof_register[regnum], |
903 | gdbarch_byte_order (regcache->descr->gdbarch), val); | |
a66a9c23 AC |
904 | regcache_cooked_write (regcache, regnum, buf); |
905 | } | |
906 | ||
907 | void | |
908 | regcache_cooked_write_unsigned (struct regcache *regcache, int regnum, | |
909 | ULONGEST val) | |
910 | { | |
7c543f7b | 911 | gdb_byte *buf; |
123f5f96 | 912 | |
a66a9c23 AC |
913 | gdb_assert (regcache != NULL); |
914 | gdb_assert (regnum >=0 && regnum < regcache->descr->nr_cooked_registers); | |
7c543f7b | 915 | buf = (gdb_byte *) alloca (regcache->descr->sizeof_register[regnum]); |
e17a4113 UW |
916 | store_unsigned_integer (buf, regcache->descr->sizeof_register[regnum], |
917 | gdbarch_byte_order (regcache->descr->gdbarch), val); | |
a66a9c23 AC |
918 | regcache_cooked_write (regcache, regnum, buf); |
919 | } | |
920 | ||
20aa2c60 PA |
921 | /* See regcache.h. */ |
922 | ||
923 | void | |
924 | regcache_raw_set_cached_value (struct regcache *regcache, int regnum, | |
925 | const gdb_byte *buf) | |
926 | { | |
927 | memcpy (register_buffer (regcache, regnum), buf, | |
928 | regcache->descr->sizeof_register[regnum]); | |
929 | regcache->register_status[regnum] = REG_VALID; | |
930 | } | |
931 | ||
61a0eb5b | 932 | void |
2d522557 AC |
933 | regcache_raw_write (struct regcache *regcache, int regnum, |
934 | const gdb_byte *buf) | |
61a0eb5b | 935 | { |
3e00d44f | 936 | struct cleanup *old_chain; |
594f7785 | 937 | |
3fadccb3 AC |
938 | gdb_assert (regcache != NULL && buf != NULL); |
939 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
2d28509a | 940 | gdb_assert (!regcache->readonly_p); |
3fadccb3 | 941 | |
3fadccb3 AC |
942 | /* On the sparc, writing %g0 is a no-op, so we don't even want to |
943 | change the registers array if something writes to this register. */ | |
214e098a | 944 | if (gdbarch_cannot_store_register (get_regcache_arch (regcache), regnum)) |
3fadccb3 AC |
945 | return; |
946 | ||
3fadccb3 | 947 | /* If we have a valid copy of the register, and new value == old |
0df8b418 | 948 | value, then don't bother doing the actual store. */ |
ee99023e | 949 | if (regcache_register_status (regcache, regnum) == REG_VALID |
3fadccb3 AC |
950 | && (memcmp (register_buffer (regcache, regnum), buf, |
951 | regcache->descr->sizeof_register[regnum]) == 0)) | |
952 | return; | |
953 | ||
316f2060 | 954 | target_prepare_to_store (regcache); |
20aa2c60 | 955 | regcache_raw_set_cached_value (regcache, regnum, buf); |
b94ade42 PL |
956 | |
957 | /* Register a cleanup function for invalidating the register after it is | |
958 | written, in case of a failure. */ | |
3e00d44f | 959 | old_chain = make_cleanup_regcache_invalidate (regcache, regnum); |
b94ade42 | 960 | |
56be3814 | 961 | target_store_registers (regcache, regnum); |
594f7785 | 962 | |
b94ade42 PL |
963 | /* The target did not throw an error so we can discard invalidating the |
964 | register and restore the cleanup chain to what it was. */ | |
3e00d44f | 965 | discard_cleanups (old_chain); |
61a0eb5b AC |
966 | } |
967 | ||
68365089 | 968 | void |
2d522557 AC |
969 | regcache_cooked_write (struct regcache *regcache, int regnum, |
970 | const gdb_byte *buf) | |
68365089 | 971 | { |
d138e37a | 972 | gdb_assert (regnum >= 0); |
68365089 AC |
973 | gdb_assert (regnum < regcache->descr->nr_cooked_registers); |
974 | if (regnum < regcache->descr->nr_raw_registers) | |
975 | regcache_raw_write (regcache, regnum, buf); | |
d138e37a | 976 | else |
68365089 | 977 | gdbarch_pseudo_register_write (regcache->descr->gdbarch, regcache, |
d8124050 | 978 | regnum, buf); |
61a0eb5b AC |
979 | } |
980 | ||
06c0b04e AC |
981 | /* Perform a partial register transfer using a read, modify, write |
982 | operation. */ | |
983 | ||
984 | typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum, | |
985 | void *buf); | |
986 | typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum, | |
987 | const void *buf); | |
988 | ||
05d1431c | 989 | static enum register_status |
06c0b04e AC |
990 | regcache_xfer_part (struct regcache *regcache, int regnum, |
991 | int offset, int len, void *in, const void *out, | |
05d1431c PA |
992 | enum register_status (*read) (struct regcache *regcache, |
993 | int regnum, | |
994 | gdb_byte *buf), | |
2d522557 AC |
995 | void (*write) (struct regcache *regcache, int regnum, |
996 | const gdb_byte *buf)) | |
06c0b04e AC |
997 | { |
998 | struct regcache_descr *descr = regcache->descr; | |
9890e433 AH |
999 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
1000 | gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum)); | |
123f5f96 | 1001 | |
06c0b04e AC |
1002 | gdb_assert (offset >= 0 && offset <= descr->sizeof_register[regnum]); |
1003 | gdb_assert (len >= 0 && offset + len <= descr->sizeof_register[regnum]); | |
1004 | /* Something to do? */ | |
1005 | if (offset + len == 0) | |
05d1431c | 1006 | return REG_VALID; |
0df8b418 | 1007 | /* Read (when needed) ... */ |
06c0b04e AC |
1008 | if (in != NULL |
1009 | || offset > 0 | |
1010 | || offset + len < descr->sizeof_register[regnum]) | |
1011 | { | |
05d1431c PA |
1012 | enum register_status status; |
1013 | ||
06c0b04e | 1014 | gdb_assert (read != NULL); |
05d1431c PA |
1015 | status = read (regcache, regnum, reg); |
1016 | if (status != REG_VALID) | |
1017 | return status; | |
06c0b04e | 1018 | } |
0df8b418 | 1019 | /* ... modify ... */ |
06c0b04e AC |
1020 | if (in != NULL) |
1021 | memcpy (in, reg + offset, len); | |
1022 | if (out != NULL) | |
1023 | memcpy (reg + offset, out, len); | |
1024 | /* ... write (when needed). */ | |
1025 | if (out != NULL) | |
1026 | { | |
1027 | gdb_assert (write != NULL); | |
1028 | write (regcache, regnum, reg); | |
1029 | } | |
05d1431c PA |
1030 | |
1031 | return REG_VALID; | |
06c0b04e AC |
1032 | } |
1033 | ||
05d1431c | 1034 | enum register_status |
06c0b04e | 1035 | regcache_raw_read_part (struct regcache *regcache, int regnum, |
2d522557 | 1036 | int offset, int len, gdb_byte *buf) |
06c0b04e AC |
1037 | { |
1038 | struct regcache_descr *descr = regcache->descr; | |
123f5f96 | 1039 | |
06c0b04e | 1040 | gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers); |
05d1431c PA |
1041 | return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL, |
1042 | regcache_raw_read, regcache_raw_write); | |
06c0b04e AC |
1043 | } |
1044 | ||
1045 | void | |
1046 | regcache_raw_write_part (struct regcache *regcache, int regnum, | |
2d522557 | 1047 | int offset, int len, const gdb_byte *buf) |
06c0b04e AC |
1048 | { |
1049 | struct regcache_descr *descr = regcache->descr; | |
123f5f96 | 1050 | |
06c0b04e AC |
1051 | gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers); |
1052 | regcache_xfer_part (regcache, regnum, offset, len, NULL, buf, | |
1053 | regcache_raw_read, regcache_raw_write); | |
1054 | } | |
1055 | ||
05d1431c | 1056 | enum register_status |
06c0b04e | 1057 | regcache_cooked_read_part (struct regcache *regcache, int regnum, |
2d522557 | 1058 | int offset, int len, gdb_byte *buf) |
06c0b04e AC |
1059 | { |
1060 | struct regcache_descr *descr = regcache->descr; | |
123f5f96 | 1061 | |
06c0b04e | 1062 | gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); |
05d1431c PA |
1063 | return regcache_xfer_part (regcache, regnum, offset, len, buf, NULL, |
1064 | regcache_cooked_read, regcache_cooked_write); | |
06c0b04e AC |
1065 | } |
1066 | ||
1067 | void | |
1068 | regcache_cooked_write_part (struct regcache *regcache, int regnum, | |
2d522557 | 1069 | int offset, int len, const gdb_byte *buf) |
06c0b04e AC |
1070 | { |
1071 | struct regcache_descr *descr = regcache->descr; | |
123f5f96 | 1072 | |
06c0b04e AC |
1073 | gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers); |
1074 | regcache_xfer_part (regcache, regnum, offset, len, NULL, buf, | |
1075 | regcache_cooked_read, regcache_cooked_write); | |
1076 | } | |
32178cab | 1077 | |
a16d75cc | 1078 | /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */ |
9a661b68 MK |
1079 | |
1080 | void | |
6618125d | 1081 | regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf) |
9a661b68 MK |
1082 | { |
1083 | void *regbuf; | |
1084 | size_t size; | |
1085 | ||
a16d75cc | 1086 | gdb_assert (regcache != NULL); |
9a661b68 MK |
1087 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); |
1088 | gdb_assert (!regcache->readonly_p); | |
1089 | ||
9a661b68 MK |
1090 | regbuf = register_buffer (regcache, regnum); |
1091 | size = regcache->descr->sizeof_register[regnum]; | |
1092 | ||
1093 | if (buf) | |
ee99023e PA |
1094 | { |
1095 | memcpy (regbuf, buf, size); | |
1096 | regcache->register_status[regnum] = REG_VALID; | |
1097 | } | |
9a661b68 | 1098 | else |
ee99023e PA |
1099 | { |
1100 | /* This memset not strictly necessary, but better than garbage | |
1101 | in case the register value manages to escape somewhere (due | |
1102 | to a bug, no less). */ | |
1103 | memset (regbuf, 0, size); | |
1104 | regcache->register_status[regnum] = REG_UNAVAILABLE; | |
1105 | } | |
9a661b68 MK |
1106 | } |
1107 | ||
1108 | /* Collect register REGNUM from REGCACHE and store its contents in BUF. */ | |
1109 | ||
1110 | void | |
6618125d | 1111 | regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf) |
9a661b68 MK |
1112 | { |
1113 | const void *regbuf; | |
1114 | size_t size; | |
1115 | ||
1116 | gdb_assert (regcache != NULL && buf != NULL); | |
1117 | gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); | |
1118 | ||
1119 | regbuf = register_buffer (regcache, regnum); | |
1120 | size = regcache->descr->sizeof_register[regnum]; | |
1121 | memcpy (buf, regbuf, size); | |
1122 | } | |
1123 | ||
0b309272 AA |
1124 | /* Transfer a single or all registers belonging to a certain register |
1125 | set to or from a buffer. This is the main worker function for | |
1126 | regcache_supply_regset and regcache_collect_regset. */ | |
1127 | ||
1128 | static void | |
1129 | regcache_transfer_regset (const struct regset *regset, | |
1130 | const struct regcache *regcache, | |
1131 | struct regcache *out_regcache, | |
1132 | int regnum, const void *in_buf, | |
1133 | void *out_buf, size_t size) | |
1134 | { | |
1135 | const struct regcache_map_entry *map; | |
1136 | int offs = 0, count; | |
1137 | ||
19ba03f4 SM |
1138 | for (map = (const struct regcache_map_entry *) regset->regmap; |
1139 | (count = map->count) != 0; | |
1140 | map++) | |
0b309272 AA |
1141 | { |
1142 | int regno = map->regno; | |
1143 | int slot_size = map->size; | |
1144 | ||
1145 | if (slot_size == 0 && regno != REGCACHE_MAP_SKIP) | |
1146 | slot_size = regcache->descr->sizeof_register[regno]; | |
1147 | ||
1148 | if (regno == REGCACHE_MAP_SKIP | |
1149 | || (regnum != -1 | |
1150 | && (regnum < regno || regnum >= regno + count))) | |
1151 | offs += count * slot_size; | |
1152 | ||
1153 | else if (regnum == -1) | |
1154 | for (; count--; regno++, offs += slot_size) | |
1155 | { | |
1156 | if (offs + slot_size > size) | |
1157 | break; | |
1158 | ||
1159 | if (out_buf) | |
1160 | regcache_raw_collect (regcache, regno, | |
1161 | (gdb_byte *) out_buf + offs); | |
1162 | else | |
1163 | regcache_raw_supply (out_regcache, regno, in_buf | |
1164 | ? (const gdb_byte *) in_buf + offs | |
1165 | : NULL); | |
1166 | } | |
1167 | else | |
1168 | { | |
1169 | /* Transfer a single register and return. */ | |
1170 | offs += (regnum - regno) * slot_size; | |
1171 | if (offs + slot_size > size) | |
1172 | return; | |
1173 | ||
1174 | if (out_buf) | |
1175 | regcache_raw_collect (regcache, regnum, | |
1176 | (gdb_byte *) out_buf + offs); | |
1177 | else | |
1178 | regcache_raw_supply (out_regcache, regnum, in_buf | |
1179 | ? (const gdb_byte *) in_buf + offs | |
1180 | : NULL); | |
1181 | return; | |
1182 | } | |
1183 | } | |
1184 | } | |
1185 | ||
1186 | /* Supply register REGNUM from BUF to REGCACHE, using the register map | |
1187 | in REGSET. If REGNUM is -1, do this for all registers in REGSET. | |
1188 | If BUF is NULL, set the register(s) to "unavailable" status. */ | |
1189 | ||
1190 | void | |
1191 | regcache_supply_regset (const struct regset *regset, | |
1192 | struct regcache *regcache, | |
1193 | int regnum, const void *buf, size_t size) | |
1194 | { | |
1195 | regcache_transfer_regset (regset, regcache, regcache, regnum, | |
1196 | buf, NULL, size); | |
1197 | } | |
1198 | ||
1199 | /* Collect register REGNUM from REGCACHE to BUF, using the register | |
1200 | map in REGSET. If REGNUM is -1, do this for all registers in | |
1201 | REGSET. */ | |
1202 | ||
1203 | void | |
1204 | regcache_collect_regset (const struct regset *regset, | |
1205 | const struct regcache *regcache, | |
1206 | int regnum, void *buf, size_t size) | |
1207 | { | |
1208 | regcache_transfer_regset (regset, regcache, NULL, regnum, | |
1209 | NULL, buf, size); | |
1210 | } | |
1211 | ||
193cb69f | 1212 | |
515630c5 | 1213 | /* Special handling for register PC. */ |
32178cab MS |
1214 | |
1215 | CORE_ADDR | |
515630c5 | 1216 | regcache_read_pc (struct regcache *regcache) |
32178cab | 1217 | { |
61a1198a UW |
1218 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
1219 | ||
32178cab MS |
1220 | CORE_ADDR pc_val; |
1221 | ||
61a1198a UW |
1222 | if (gdbarch_read_pc_p (gdbarch)) |
1223 | pc_val = gdbarch_read_pc (gdbarch, regcache); | |
cde9ea48 | 1224 | /* Else use per-frame method on get_current_frame. */ |
214e098a | 1225 | else if (gdbarch_pc_regnum (gdbarch) >= 0) |
cde9ea48 | 1226 | { |
61a1198a | 1227 | ULONGEST raw_val; |
123f5f96 | 1228 | |
05d1431c PA |
1229 | if (regcache_cooked_read_unsigned (regcache, |
1230 | gdbarch_pc_regnum (gdbarch), | |
1231 | &raw_val) == REG_UNAVAILABLE) | |
1232 | throw_error (NOT_AVAILABLE_ERROR, _("PC register is not available")); | |
1233 | ||
214e098a | 1234 | pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val); |
cde9ea48 AC |
1235 | } |
1236 | else | |
515630c5 UW |
1237 | internal_error (__FILE__, __LINE__, |
1238 | _("regcache_read_pc: Unable to find PC")); | |
32178cab MS |
1239 | return pc_val; |
1240 | } | |
1241 | ||
32178cab | 1242 | void |
515630c5 | 1243 | regcache_write_pc (struct regcache *regcache, CORE_ADDR pc) |
32178cab | 1244 | { |
61a1198a UW |
1245 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
1246 | ||
61a1198a UW |
1247 | if (gdbarch_write_pc_p (gdbarch)) |
1248 | gdbarch_write_pc (gdbarch, regcache, pc); | |
214e098a | 1249 | else if (gdbarch_pc_regnum (gdbarch) >= 0) |
3e8c568d | 1250 | regcache_cooked_write_unsigned (regcache, |
214e098a | 1251 | gdbarch_pc_regnum (gdbarch), pc); |
61a1198a UW |
1252 | else |
1253 | internal_error (__FILE__, __LINE__, | |
515630c5 | 1254 | _("regcache_write_pc: Unable to update PC")); |
edb3359d DJ |
1255 | |
1256 | /* Writing the PC (for instance, from "load") invalidates the | |
1257 | current frame. */ | |
1258 | reinit_frame_cache (); | |
32178cab MS |
1259 | } |
1260 | ||
ed771251 AH |
1261 | void |
1262 | regcache_debug_print_register (const char *func, struct regcache *regcache, | |
1263 | int regno) | |
1264 | { | |
1265 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
1266 | ||
1267 | fprintf_unfiltered (gdb_stdlog, "%s ", func); | |
1268 | if (regno >= 0 && regno < gdbarch_num_regs (gdbarch) | |
1269 | && gdbarch_register_name (gdbarch, regno) != NULL | |
1270 | && gdbarch_register_name (gdbarch, regno)[0] != '\0') | |
1271 | fprintf_unfiltered (gdb_stdlog, "(%s)", | |
1272 | gdbarch_register_name (gdbarch, regno)); | |
1273 | else | |
1274 | fprintf_unfiltered (gdb_stdlog, "(%d)", regno); | |
1275 | if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)) | |
1276 | { | |
1277 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
1278 | int size = register_size (gdbarch, regno); | |
1279 | gdb_byte *buf = register_buffer (regcache, regno); | |
1280 | ||
1281 | fprintf_unfiltered (gdb_stdlog, " = "); | |
1282 | for (int i = 0; i < size; i++) | |
1283 | { | |
1284 | fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]); | |
1285 | } | |
1286 | if (size <= sizeof (LONGEST)) | |
1287 | { | |
1288 | ULONGEST val = extract_unsigned_integer (buf, size, byte_order); | |
1289 | ||
1290 | fprintf_unfiltered (gdb_stdlog, " %s %s", | |
1291 | core_addr_to_string_nz (val), plongest (val)); | |
1292 | } | |
1293 | } | |
1294 | fprintf_unfiltered (gdb_stdlog, "\n"); | |
1295 | } | |
32178cab | 1296 | |
705152c5 MS |
1297 | static void |
1298 | reg_flush_command (char *command, int from_tty) | |
1299 | { | |
1300 | /* Force-flush the register cache. */ | |
1301 | registers_changed (); | |
1302 | if (from_tty) | |
a3f17187 | 1303 | printf_filtered (_("Register cache flushed.\n")); |
705152c5 MS |
1304 | } |
1305 | ||
af030b9a AC |
1306 | enum regcache_dump_what |
1307 | { | |
3e43a32a | 1308 | regcache_dump_none, regcache_dump_raw, |
c21236dc PA |
1309 | regcache_dump_cooked, regcache_dump_groups, |
1310 | regcache_dump_remote | |
af030b9a AC |
1311 | }; |
1312 | ||
1313 | static void | |
1314 | regcache_dump (struct regcache *regcache, struct ui_file *file, | |
1315 | enum regcache_dump_what what_to_dump) | |
1316 | { | |
1317 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); | |
b59ff9d5 | 1318 | struct gdbarch *gdbarch = regcache->descr->gdbarch; |
af030b9a AC |
1319 | int regnum; |
1320 | int footnote_nr = 0; | |
1321 | int footnote_register_size = 0; | |
1322 | int footnote_register_offset = 0; | |
1323 | int footnote_register_type_name_null = 0; | |
1324 | long register_offset = 0; | |
e362b510 | 1325 | gdb_byte buf[MAX_REGISTER_SIZE]; |
af030b9a AC |
1326 | |
1327 | #if 0 | |
af030b9a AC |
1328 | fprintf_unfiltered (file, "nr_raw_registers %d\n", |
1329 | regcache->descr->nr_raw_registers); | |
1330 | fprintf_unfiltered (file, "nr_cooked_registers %d\n", | |
1331 | regcache->descr->nr_cooked_registers); | |
1332 | fprintf_unfiltered (file, "sizeof_raw_registers %ld\n", | |
1333 | regcache->descr->sizeof_raw_registers); | |
ee99023e PA |
1334 | fprintf_unfiltered (file, "sizeof_raw_register_status %ld\n", |
1335 | regcache->descr->sizeof_raw_register_status); | |
f57d151a | 1336 | fprintf_unfiltered (file, "gdbarch_num_regs %d\n", |
214e098a | 1337 | gdbarch_num_regs (gdbarch)); |
f57d151a | 1338 | fprintf_unfiltered (file, "gdbarch_num_pseudo_regs %d\n", |
214e098a | 1339 | gdbarch_num_pseudo_regs (gdbarch)); |
af030b9a AC |
1340 | #endif |
1341 | ||
1342 | gdb_assert (regcache->descr->nr_cooked_registers | |
214e098a UW |
1343 | == (gdbarch_num_regs (gdbarch) |
1344 | + gdbarch_num_pseudo_regs (gdbarch))); | |
af030b9a AC |
1345 | |
1346 | for (regnum = -1; regnum < regcache->descr->nr_cooked_registers; regnum++) | |
1347 | { | |
1348 | /* Name. */ | |
1349 | if (regnum < 0) | |
1350 | fprintf_unfiltered (file, " %-10s", "Name"); | |
1351 | else | |
1352 | { | |
214e098a | 1353 | const char *p = gdbarch_register_name (gdbarch, regnum); |
123f5f96 | 1354 | |
af030b9a AC |
1355 | if (p == NULL) |
1356 | p = ""; | |
1357 | else if (p[0] == '\0') | |
1358 | p = "''"; | |
1359 | fprintf_unfiltered (file, " %-10s", p); | |
1360 | } | |
1361 | ||
1362 | /* Number. */ | |
1363 | if (regnum < 0) | |
1364 | fprintf_unfiltered (file, " %4s", "Nr"); | |
1365 | else | |
1366 | fprintf_unfiltered (file, " %4d", regnum); | |
1367 | ||
1368 | /* Relative number. */ | |
1369 | if (regnum < 0) | |
1370 | fprintf_unfiltered (file, " %4s", "Rel"); | |
214e098a | 1371 | else if (regnum < gdbarch_num_regs (gdbarch)) |
af030b9a AC |
1372 | fprintf_unfiltered (file, " %4d", regnum); |
1373 | else | |
f57d151a | 1374 | fprintf_unfiltered (file, " %4d", |
214e098a | 1375 | (regnum - gdbarch_num_regs (gdbarch))); |
af030b9a AC |
1376 | |
1377 | /* Offset. */ | |
1378 | if (regnum < 0) | |
1379 | fprintf_unfiltered (file, " %6s ", "Offset"); | |
1380 | else | |
1381 | { | |
1382 | fprintf_unfiltered (file, " %6ld", | |
1383 | regcache->descr->register_offset[regnum]); | |
a7e3c2ad | 1384 | if (register_offset != regcache->descr->register_offset[regnum] |
d3b22ed5 AC |
1385 | || (regnum > 0 |
1386 | && (regcache->descr->register_offset[regnum] | |
1387 | != (regcache->descr->register_offset[regnum - 1] | |
1388 | + regcache->descr->sizeof_register[regnum - 1]))) | |
1389 | ) | |
af030b9a AC |
1390 | { |
1391 | if (!footnote_register_offset) | |
1392 | footnote_register_offset = ++footnote_nr; | |
1393 | fprintf_unfiltered (file, "*%d", footnote_register_offset); | |
1394 | } | |
1395 | else | |
1396 | fprintf_unfiltered (file, " "); | |
1397 | register_offset = (regcache->descr->register_offset[regnum] | |
1398 | + regcache->descr->sizeof_register[regnum]); | |
1399 | } | |
1400 | ||
1401 | /* Size. */ | |
1402 | if (regnum < 0) | |
1403 | fprintf_unfiltered (file, " %5s ", "Size"); | |
1404 | else | |
01e1877c AC |
1405 | fprintf_unfiltered (file, " %5ld", |
1406 | regcache->descr->sizeof_register[regnum]); | |
af030b9a AC |
1407 | |
1408 | /* Type. */ | |
b59ff9d5 AC |
1409 | { |
1410 | const char *t; | |
123f5f96 | 1411 | |
b59ff9d5 AC |
1412 | if (regnum < 0) |
1413 | t = "Type"; | |
1414 | else | |
1415 | { | |
1416 | static const char blt[] = "builtin_type"; | |
123f5f96 | 1417 | |
b59ff9d5 AC |
1418 | t = TYPE_NAME (register_type (regcache->descr->gdbarch, regnum)); |
1419 | if (t == NULL) | |
1420 | { | |
1421 | char *n; | |
123f5f96 | 1422 | |
b59ff9d5 AC |
1423 | if (!footnote_register_type_name_null) |
1424 | footnote_register_type_name_null = ++footnote_nr; | |
b435e160 | 1425 | n = xstrprintf ("*%d", footnote_register_type_name_null); |
b59ff9d5 AC |
1426 | make_cleanup (xfree, n); |
1427 | t = n; | |
1428 | } | |
1429 | /* Chop a leading builtin_type. */ | |
61012eef | 1430 | if (startswith (t, blt)) |
b59ff9d5 AC |
1431 | t += strlen (blt); |
1432 | } | |
1433 | fprintf_unfiltered (file, " %-15s", t); | |
1434 | } | |
1435 | ||
1436 | /* Leading space always present. */ | |
1437 | fprintf_unfiltered (file, " "); | |
af030b9a AC |
1438 | |
1439 | /* Value, raw. */ | |
1440 | if (what_to_dump == regcache_dump_raw) | |
1441 | { | |
1442 | if (regnum < 0) | |
1443 | fprintf_unfiltered (file, "Raw value"); | |
1444 | else if (regnum >= regcache->descr->nr_raw_registers) | |
1445 | fprintf_unfiltered (file, "<cooked>"); | |
ee99023e | 1446 | else if (regcache_register_status (regcache, regnum) == REG_UNKNOWN) |
af030b9a | 1447 | fprintf_unfiltered (file, "<invalid>"); |
ee99023e PA |
1448 | else if (regcache_register_status (regcache, regnum) == REG_UNAVAILABLE) |
1449 | fprintf_unfiltered (file, "<unavailable>"); | |
af030b9a AC |
1450 | else |
1451 | { | |
1452 | regcache_raw_read (regcache, regnum, buf); | |
d3eaaf66 AB |
1453 | print_hex_chars (file, buf, |
1454 | regcache->descr->sizeof_register[regnum], | |
1455 | gdbarch_byte_order (gdbarch)); | |
af030b9a AC |
1456 | } |
1457 | } | |
1458 | ||
1459 | /* Value, cooked. */ | |
1460 | if (what_to_dump == regcache_dump_cooked) | |
1461 | { | |
1462 | if (regnum < 0) | |
1463 | fprintf_unfiltered (file, "Cooked value"); | |
1464 | else | |
1465 | { | |
05d1431c PA |
1466 | enum register_status status; |
1467 | ||
1468 | status = regcache_cooked_read (regcache, regnum, buf); | |
1469 | if (status == REG_UNKNOWN) | |
1470 | fprintf_unfiltered (file, "<invalid>"); | |
1471 | else if (status == REG_UNAVAILABLE) | |
1472 | fprintf_unfiltered (file, "<unavailable>"); | |
1473 | else | |
d3eaaf66 AB |
1474 | print_hex_chars (file, buf, |
1475 | regcache->descr->sizeof_register[regnum], | |
1476 | gdbarch_byte_order (gdbarch)); | |
af030b9a AC |
1477 | } |
1478 | } | |
1479 | ||
b59ff9d5 AC |
1480 | /* Group members. */ |
1481 | if (what_to_dump == regcache_dump_groups) | |
1482 | { | |
1483 | if (regnum < 0) | |
1484 | fprintf_unfiltered (file, "Groups"); | |
1485 | else | |
1486 | { | |
b59ff9d5 | 1487 | const char *sep = ""; |
6c7d17ba | 1488 | struct reggroup *group; |
123f5f96 | 1489 | |
6c7d17ba AC |
1490 | for (group = reggroup_next (gdbarch, NULL); |
1491 | group != NULL; | |
1492 | group = reggroup_next (gdbarch, group)) | |
b59ff9d5 | 1493 | { |
6c7d17ba | 1494 | if (gdbarch_register_reggroup_p (gdbarch, regnum, group)) |
b59ff9d5 | 1495 | { |
3e43a32a MS |
1496 | fprintf_unfiltered (file, |
1497 | "%s%s", sep, reggroup_name (group)); | |
b59ff9d5 AC |
1498 | sep = ","; |
1499 | } | |
1500 | } | |
1501 | } | |
1502 | } | |
1503 | ||
c21236dc PA |
1504 | /* Remote packet configuration. */ |
1505 | if (what_to_dump == regcache_dump_remote) | |
1506 | { | |
1507 | if (regnum < 0) | |
1508 | { | |
1509 | fprintf_unfiltered (file, "Rmt Nr g/G Offset"); | |
1510 | } | |
1511 | else if (regnum < regcache->descr->nr_raw_registers) | |
1512 | { | |
1513 | int pnum, poffset; | |
1514 | ||
1515 | if (remote_register_number_and_offset (get_regcache_arch (regcache), regnum, | |
1516 | &pnum, &poffset)) | |
1517 | fprintf_unfiltered (file, "%7d %11d", pnum, poffset); | |
1518 | } | |
1519 | } | |
1520 | ||
af030b9a AC |
1521 | fprintf_unfiltered (file, "\n"); |
1522 | } | |
1523 | ||
1524 | if (footnote_register_size) | |
1525 | fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n", | |
1526 | footnote_register_size); | |
1527 | if (footnote_register_offset) | |
1528 | fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n", | |
1529 | footnote_register_offset); | |
1530 | if (footnote_register_type_name_null) | |
1531 | fprintf_unfiltered (file, | |
1532 | "*%d: Register type's name NULL.\n", | |
1533 | footnote_register_type_name_null); | |
1534 | do_cleanups (cleanups); | |
1535 | } | |
1536 | ||
1537 | static void | |
1538 | regcache_print (char *args, enum regcache_dump_what what_to_dump) | |
1539 | { | |
1540 | if (args == NULL) | |
28c38f10 | 1541 | regcache_dump (get_current_regcache (), gdb_stdout, what_to_dump); |
af030b9a AC |
1542 | else |
1543 | { | |
d7e74731 | 1544 | stdio_file file; |
123f5f96 | 1545 | |
d7e74731 | 1546 | if (!file.open (args, "w")) |
e2e0b3e5 | 1547 | perror_with_name (_("maintenance print architecture")); |
d7e74731 | 1548 | regcache_dump (get_current_regcache (), &file, what_to_dump); |
af030b9a AC |
1549 | } |
1550 | } | |
1551 | ||
1552 | static void | |
1553 | maintenance_print_registers (char *args, int from_tty) | |
1554 | { | |
1555 | regcache_print (args, regcache_dump_none); | |
1556 | } | |
1557 | ||
1558 | static void | |
1559 | maintenance_print_raw_registers (char *args, int from_tty) | |
1560 | { | |
1561 | regcache_print (args, regcache_dump_raw); | |
1562 | } | |
1563 | ||
1564 | static void | |
1565 | maintenance_print_cooked_registers (char *args, int from_tty) | |
1566 | { | |
1567 | regcache_print (args, regcache_dump_cooked); | |
1568 | } | |
1569 | ||
b59ff9d5 AC |
1570 | static void |
1571 | maintenance_print_register_groups (char *args, int from_tty) | |
1572 | { | |
1573 | regcache_print (args, regcache_dump_groups); | |
1574 | } | |
1575 | ||
c21236dc PA |
1576 | static void |
1577 | maintenance_print_remote_registers (char *args, int from_tty) | |
1578 | { | |
1579 | regcache_print (args, regcache_dump_remote); | |
1580 | } | |
1581 | ||
b9362cc7 AC |
1582 | extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */ |
1583 | ||
32178cab MS |
1584 | void |
1585 | _initialize_regcache (void) | |
1586 | { | |
3e43a32a MS |
1587 | regcache_descr_handle |
1588 | = gdbarch_data_register_post_init (init_regcache_descr); | |
705152c5 | 1589 | |
f4c5303c | 1590 | observer_attach_target_changed (regcache_observer_target_changed); |
5231c1fd | 1591 | observer_attach_thread_ptid_changed (regcache_thread_ptid_changed); |
f4c5303c | 1592 | |
705152c5 | 1593 | add_com ("flushregs", class_maintenance, reg_flush_command, |
1bedd215 | 1594 | _("Force gdb to flush its register cache (maintainer command)")); |
39f77062 | 1595 | |
3e43a32a MS |
1596 | add_cmd ("registers", class_maintenance, maintenance_print_registers, |
1597 | _("Print the internal register configuration.\n" | |
1598 | "Takes an optional file parameter."), &maintenanceprintlist); | |
af030b9a | 1599 | add_cmd ("raw-registers", class_maintenance, |
3e43a32a MS |
1600 | maintenance_print_raw_registers, |
1601 | _("Print the internal register configuration " | |
1602 | "including raw values.\n" | |
1603 | "Takes an optional file parameter."), &maintenanceprintlist); | |
af030b9a | 1604 | add_cmd ("cooked-registers", class_maintenance, |
3e43a32a MS |
1605 | maintenance_print_cooked_registers, |
1606 | _("Print the internal register configuration " | |
1607 | "including cooked values.\n" | |
1608 | "Takes an optional file parameter."), &maintenanceprintlist); | |
b59ff9d5 | 1609 | add_cmd ("register-groups", class_maintenance, |
3e43a32a MS |
1610 | maintenance_print_register_groups, |
1611 | _("Print the internal register configuration " | |
1612 | "including each register's group.\n" | |
1613 | "Takes an optional file parameter."), | |
af030b9a | 1614 | &maintenanceprintlist); |
c21236dc PA |
1615 | add_cmd ("remote-registers", class_maintenance, |
1616 | maintenance_print_remote_registers, _("\ | |
1617 | Print the internal register configuration including each register's\n\ | |
1618 | remote register number and buffer offset in the g/G packets.\n\ | |
1619 | Takes an optional file parameter."), | |
1620 | &maintenanceprintlist); | |
af030b9a | 1621 | |
32178cab | 1622 | } |