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