1 /* Cache and manage the values of registers for GDB, the GNU debugger.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
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
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 #include "reggroups.h"
31 #include <forward_list>
36 * Here is the actual register cache.
39 /* Per-architecture object describing the layout of a register cache.
40 Computed once when the architecture is created. */
42 struct gdbarch_data *regcache_descr_handle;
46 /* The architecture this descriptor belongs to. */
47 struct gdbarch *gdbarch;
49 /* The raw register cache. Each raw (or hard) register is supplied
50 by the target interface. The raw cache should not contain
51 redundant information - if the PC is constructed from two
52 registers then those registers and not the PC lives in the raw
55 long sizeof_raw_registers;
56 long sizeof_raw_register_status;
58 /* The cooked register space. Each cooked register in the range
59 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
60 register. The remaining [NR_RAW_REGISTERS
61 .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto
62 both raw registers and memory by the architecture methods
63 gdbarch_pseudo_register_read and gdbarch_pseudo_register_write. */
64 int nr_cooked_registers;
65 long sizeof_cooked_registers;
66 long sizeof_cooked_register_status;
68 /* Offset and size (in 8 bit bytes), of each register in the
69 register cache. All registers (including those in the range
70 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an
72 long *register_offset;
73 long *sizeof_register;
75 /* Cached table containing the type of each register. */
76 struct type **register_type;
80 init_regcache_descr (struct gdbarch *gdbarch)
83 struct regcache_descr *descr;
84 gdb_assert (gdbarch != NULL);
86 /* Create an initial, zero filled, table. */
87 descr = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct regcache_descr);
88 descr->gdbarch = gdbarch;
90 /* Total size of the register space. The raw registers are mapped
91 directly onto the raw register cache while the pseudo's are
92 either mapped onto raw-registers or memory. */
93 descr->nr_cooked_registers = gdbarch_num_regs (gdbarch)
94 + gdbarch_num_pseudo_regs (gdbarch);
95 descr->sizeof_cooked_register_status
96 = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
98 /* Fill in a table of register types. */
100 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers,
102 for (i = 0; i < descr->nr_cooked_registers; i++)
103 descr->register_type[i] = gdbarch_register_type (gdbarch, i);
105 /* Construct a strictly RAW register cache. Don't allow pseudo's
106 into the register cache. */
107 descr->nr_raw_registers = gdbarch_num_regs (gdbarch);
108 descr->sizeof_raw_register_status = gdbarch_num_regs (gdbarch);
110 /* Lay out the register cache.
112 NOTE: cagney/2002-05-22: Only register_type() is used when
113 constructing the register cache. It is assumed that the
114 register's raw size, virtual size and type length are all the
120 descr->sizeof_register
121 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
122 descr->register_offset
123 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
124 for (i = 0; i < descr->nr_raw_registers; i++)
126 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
127 descr->register_offset[i] = offset;
128 offset += descr->sizeof_register[i];
129 gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
131 /* Set the real size of the raw register cache buffer. */
132 descr->sizeof_raw_registers = offset;
134 for (; i < descr->nr_cooked_registers; i++)
136 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
137 descr->register_offset[i] = offset;
138 offset += descr->sizeof_register[i];
139 gdb_assert (MAX_REGISTER_SIZE >= descr->sizeof_register[i]);
141 /* Set the real size of the readonly register cache buffer. */
142 descr->sizeof_cooked_registers = offset;
148 static struct regcache_descr *
149 regcache_descr (struct gdbarch *gdbarch)
151 return (struct regcache_descr *) gdbarch_data (gdbarch,
152 regcache_descr_handle);
155 /* Utility functions returning useful register attributes stored in
156 the regcache descr. */
159 register_type (struct gdbarch *gdbarch, int regnum)
161 struct regcache_descr *descr = regcache_descr (gdbarch);
163 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
164 return descr->register_type[regnum];
167 /* Utility functions returning useful register attributes stored in
168 the regcache descr. */
171 register_size (struct gdbarch *gdbarch, int regnum)
173 struct regcache_descr *descr = regcache_descr (gdbarch);
176 gdb_assert (regnum >= 0
177 && regnum < (gdbarch_num_regs (gdbarch)
178 + gdbarch_num_pseudo_regs (gdbarch)));
179 size = descr->sizeof_register[regnum];
183 /* See common/common-regcache.h. */
186 regcache_register_size (const struct regcache *regcache, int n)
188 return register_size (get_regcache_arch (regcache), n);
191 regcache::regcache (gdbarch *gdbarch, address_space *aspace_,
193 : m_aspace (aspace_), m_readonly_p (readonly_p_)
195 gdb_assert (gdbarch != NULL);
196 m_descr = regcache_descr (gdbarch);
200 m_registers = XCNEWVEC (gdb_byte, m_descr->sizeof_cooked_registers);
201 m_register_status = XCNEWVEC (signed char,
202 m_descr->sizeof_cooked_register_status);
206 m_registers = XCNEWVEC (gdb_byte, m_descr->sizeof_raw_registers);
207 m_register_status = XCNEWVEC (signed char,
208 m_descr->sizeof_raw_register_status);
210 m_ptid = minus_one_ptid;
213 static enum register_status
214 do_cooked_read (void *src, int regnum, gdb_byte *buf)
216 struct regcache *regcache = (struct regcache *) src;
218 return regcache_cooked_read (regcache, regnum, buf);
221 regcache::regcache (readonly_t, const regcache &src)
222 : regcache (src.arch (), src.aspace (), true)
224 gdb_assert (!src.m_readonly_p);
225 save (do_cooked_read, (void *) &src);
229 regcache::arch () const
231 return m_descr->gdbarch;
234 /* See regcache.h. */
237 regcache_get_ptid (const struct regcache *regcache)
239 gdb_assert (!ptid_equal (regcache->ptid (), minus_one_ptid));
241 return regcache->ptid ();
245 regcache_xmalloc (struct gdbarch *gdbarch, struct address_space *aspace)
247 return new regcache (gdbarch, aspace);
251 regcache_xfree (struct regcache *regcache)
253 if (regcache == NULL)
260 do_regcache_xfree (void *data)
262 regcache_xfree ((struct regcache *) data);
266 make_cleanup_regcache_xfree (struct regcache *regcache)
268 return make_cleanup (do_regcache_xfree, regcache);
271 /* Cleanup routines for invalidating a register. */
273 struct register_to_invalidate
275 struct regcache *regcache;
280 do_regcache_invalidate (void *data)
282 struct register_to_invalidate *reg = (struct register_to_invalidate *) data;
284 regcache_invalidate (reg->regcache, reg->regnum);
287 static struct cleanup *
288 make_cleanup_regcache_invalidate (struct regcache *regcache, int regnum)
290 struct register_to_invalidate* reg = XNEW (struct register_to_invalidate);
292 reg->regcache = regcache;
293 reg->regnum = regnum;
294 return make_cleanup_dtor (do_regcache_invalidate, (void *) reg, xfree);
297 /* Return REGCACHE's architecture. */
300 get_regcache_arch (const struct regcache *regcache)
302 return regcache->arch ();
305 struct address_space *
306 get_regcache_aspace (const struct regcache *regcache)
308 return regcache->aspace ();
311 /* Return a pointer to register REGNUM's buffer cache. */
314 regcache::register_buffer (int regnum) const
316 return m_registers + m_descr->register_offset[regnum];
320 regcache_save (struct regcache *regcache,
321 regcache_cooked_read_ftype *cooked_read, void *src)
323 regcache->save (cooked_read, src);
327 regcache::save (regcache_cooked_read_ftype *cooked_read,
330 struct gdbarch *gdbarch = m_descr->gdbarch;
333 /* The DST should be `read-only', if it wasn't then the save would
334 end up trying to write the register values back out to the
336 gdb_assert (m_readonly_p);
337 /* Clear the dest. */
338 memset (m_registers, 0, m_descr->sizeof_cooked_registers);
339 memset (m_register_status, 0, m_descr->sizeof_cooked_register_status);
340 /* Copy over any registers (identified by their membership in the
341 save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs +
342 gdbarch_num_pseudo_regs) range is checked since some architectures need
343 to save/restore `cooked' registers that live in memory. */
344 for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
346 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
348 gdb_byte *dst_buf = register_buffer (regnum);
349 enum register_status status = cooked_read (src, regnum, dst_buf);
351 gdb_assert (status != REG_UNKNOWN);
353 if (status != REG_VALID)
354 memset (dst_buf, 0, register_size (gdbarch, regnum));
356 m_register_status[regnum] = status;
362 regcache::restore (struct regcache *src)
364 struct gdbarch *gdbarch = m_descr->gdbarch;
367 /* The dst had better not be read-only. If it is, the `restore'
368 doesn't make much sense. */
369 gdb_assert (!m_readonly_p);
370 gdb_assert (src->m_readonly_p);
371 /* Copy over any registers, being careful to only restore those that
372 were both saved and need to be restored. The full [0 .. gdbarch_num_regs
373 + gdbarch_num_pseudo_regs) range is checked since some architectures need
374 to save/restore `cooked' registers that live in memory. */
375 for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
377 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
379 if (src->m_register_status[regnum] == REG_VALID)
380 cooked_write (regnum, src->register_buffer (regnum));
386 regcache_cpy (struct regcache *dst, struct regcache *src)
388 gdb_assert (src != NULL && dst != NULL);
389 gdb_assert (src->m_descr->gdbarch == dst->m_descr->gdbarch);
390 gdb_assert (src != dst);
391 gdb_assert (src->m_readonly_p || dst->m_readonly_p);
393 if (!src->m_readonly_p)
394 regcache_save (dst, do_cooked_read, src);
395 else if (!dst->m_readonly_p)
398 dst->cpy_no_passthrough (src);
401 /* Copy/duplicate the contents of a register cache. Unlike regcache_cpy,
402 which is pass-through, this does not go through to the target.
403 Only values values already in the cache are transferred. The SRC and DST
404 buffers must not overlap. */
407 regcache::cpy_no_passthrough (struct regcache *src)
409 gdb_assert (src != NULL);
410 gdb_assert (src->m_descr->gdbarch == m_descr->gdbarch);
411 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
412 move of data into a thread's regcache. Doing this would be silly
413 - it would mean that regcache->register_status would be
414 completely invalid. */
415 gdb_assert (m_readonly_p && src->m_readonly_p);
417 memcpy (m_registers, src->m_registers,
418 m_descr->sizeof_cooked_registers);
419 memcpy (m_register_status, src->m_register_status,
420 m_descr->sizeof_cooked_register_status);
424 regcache_dup (struct regcache *src)
426 return new regcache (regcache::readonly, *src);
430 regcache_register_status (const struct regcache *regcache, int regnum)
432 gdb_assert (regcache != NULL);
433 return regcache->get_register_status (regnum);
437 regcache::get_register_status (int regnum) const
439 gdb_assert (regnum >= 0);
441 gdb_assert (regnum < m_descr->nr_cooked_registers);
443 gdb_assert (regnum < m_descr->nr_raw_registers);
445 return (enum register_status) m_register_status[regnum];
449 regcache_invalidate (struct regcache *regcache, int regnum)
451 gdb_assert (regcache != NULL);
452 regcache->invalidate (regnum);
456 regcache::invalidate (int regnum)
458 gdb_assert (regnum >= 0);
459 gdb_assert (!m_readonly_p);
460 gdb_assert (regnum < m_descr->nr_raw_registers);
461 m_register_status[regnum] = REG_UNKNOWN;
464 /* Global structure containing the current regcache. */
466 /* NOTE: this is a write-through cache. There is no "dirty" bit for
467 recording if the register values have been changed (eg. by the
468 user). Therefore all registers must be written back to the
469 target when appropriate. */
470 std::forward_list<regcache *> regcache::current_regcache;
473 get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
474 struct address_space *aspace)
476 for (const auto ®cache : regcache::current_regcache)
477 if (ptid_equal (regcache->ptid (), ptid) && regcache->arch () == gdbarch)
480 regcache *new_regcache = new regcache (gdbarch, aspace, false);
482 regcache::current_regcache.push_front (new_regcache);
483 new_regcache->set_ptid (ptid);
489 get_thread_arch_regcache (ptid_t ptid, struct gdbarch *gdbarch)
491 struct address_space *aspace;
493 /* For the benefit of "maint print registers" & co when debugging an
494 executable, allow dumping the regcache even when there is no
495 thread selected (target_thread_address_space internal-errors if
496 no address space is found). Note that normal user commands will
497 fail higher up on the call stack due to no
498 target_has_registers. */
499 aspace = (ptid_equal (null_ptid, ptid)
501 : target_thread_address_space (ptid));
503 return get_thread_arch_aspace_regcache (ptid, gdbarch, aspace);
506 static ptid_t current_thread_ptid;
507 static struct gdbarch *current_thread_arch;
510 get_thread_regcache (ptid_t ptid)
512 if (!current_thread_arch || !ptid_equal (current_thread_ptid, ptid))
514 current_thread_ptid = ptid;
515 current_thread_arch = target_thread_architecture (ptid);
518 return get_thread_arch_regcache (ptid, current_thread_arch);
522 get_current_regcache (void)
524 return get_thread_regcache (inferior_ptid);
527 /* See common/common-regcache.h. */
530 get_thread_regcache_for_ptid (ptid_t ptid)
532 return get_thread_regcache (ptid);
535 /* Observer for the target_changed event. */
538 regcache_observer_target_changed (struct target_ops *target)
540 registers_changed ();
543 /* Update global variables old ptids to hold NEW_PTID if they were
546 regcache::regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
548 for (auto ®cache : regcache::current_regcache)
550 if (ptid_equal (regcache->ptid (), old_ptid))
551 regcache->set_ptid (new_ptid);
555 /* Low level examining and depositing of registers.
557 The caller is responsible for making sure that the inferior is
558 stopped before calling the fetching routines, or it will get
559 garbage. (a change from GDB version 3, in which the caller got the
560 value from the last stop). */
562 /* REGISTERS_CHANGED ()
564 Indicate that registers may have changed, so invalidate the cache. */
567 registers_changed_ptid (ptid_t ptid)
569 for (auto oit = regcache::current_regcache.before_begin (),
570 it = std::next (oit);
571 it != regcache::current_regcache.end ();
574 if (ptid_match ((*it)->ptid (), ptid))
577 it = regcache::current_regcache.erase_after (oit);
583 if (ptid_match (current_thread_ptid, ptid))
585 current_thread_ptid = null_ptid;
586 current_thread_arch = NULL;
589 if (ptid_match (inferior_ptid, ptid))
591 /* We just deleted the regcache of the current thread. Need to
592 forget about any frames we have cached, too. */
593 reinit_frame_cache ();
598 registers_changed (void)
600 registers_changed_ptid (minus_one_ptid);
602 /* Force cleanup of any alloca areas if using C alloca instead of
603 a builtin alloca. This particular call is used to clean up
604 areas allocated by low level target code which may build up
605 during lengthy interactions between gdb and the target before
606 gdb gives control to the user (ie watchpoints). */
611 regcache_raw_update (struct regcache *regcache, int regnum)
613 gdb_assert (regcache != NULL);
615 regcache->raw_update (regnum);
619 regcache::raw_update (int regnum)
621 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
623 /* Make certain that the register cache is up-to-date with respect
624 to the current thread. This switching shouldn't be necessary
625 only there is still only one target side register cache. Sigh!
626 On the bright side, at least there is a regcache object. */
628 if (!m_readonly_p && get_register_status (regnum) == REG_UNKNOWN)
630 target_fetch_registers (this, regnum);
632 /* A number of targets can't access the whole set of raw
633 registers (because the debug API provides no means to get at
635 if (m_register_status[regnum] == REG_UNKNOWN)
636 m_register_status[regnum] = REG_UNAVAILABLE;
641 regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
643 return regcache->raw_read (regnum, buf);
647 regcache::raw_read (int regnum, gdb_byte *buf)
649 gdb_assert (buf != NULL);
652 if (m_register_status[regnum] != REG_VALID)
653 memset (buf, 0, m_descr->sizeof_register[regnum]);
655 memcpy (buf, register_buffer (regnum),
656 m_descr->sizeof_register[regnum]);
658 return (enum register_status) m_register_status[regnum];
662 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
664 gdb_assert (regcache != NULL);
665 return regcache->raw_read (regnum, val);
668 template<typename T, typename>
670 regcache::raw_read (int regnum, T *val)
673 enum register_status status;
675 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
676 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
677 status = raw_read (regnum, buf);
678 if (status == REG_VALID)
679 *val = extract_integer<T> (buf,
680 m_descr->sizeof_register[regnum],
681 gdbarch_byte_order (m_descr->gdbarch));
688 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
691 gdb_assert (regcache != NULL);
692 return regcache->raw_read (regnum, val);
696 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
698 gdb_assert (regcache != NULL);
699 regcache->raw_write (regnum, val);
702 template<typename T, typename>
704 regcache::raw_write (int regnum, T val)
708 gdb_assert (regnum >=0 && regnum < m_descr->nr_raw_registers);
709 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
710 store_integer (buf, m_descr->sizeof_register[regnum],
711 gdbarch_byte_order (m_descr->gdbarch), val);
712 raw_write (regnum, buf);
716 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
719 gdb_assert (regcache != NULL);
720 regcache->raw_write (regnum, val);
724 regcache_raw_get_signed (struct regcache *regcache, int regnum)
727 enum register_status status;
729 status = regcache_raw_read_signed (regcache, regnum, &value);
730 if (status == REG_UNAVAILABLE)
731 throw_error (NOT_AVAILABLE_ERROR,
732 _("Register %d is not available"), regnum);
737 regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
739 return regcache->cooked_read (regnum, buf);
743 regcache::cooked_read (int regnum, gdb_byte *buf)
745 gdb_assert (regnum >= 0);
746 gdb_assert (regnum < m_descr->nr_cooked_registers);
747 if (regnum < m_descr->nr_raw_registers)
748 return raw_read (regnum, buf);
749 else if (m_readonly_p
750 && m_register_status[regnum] != REG_UNKNOWN)
752 /* Read-only register cache, perhaps the cooked value was
754 if (m_register_status[regnum] == REG_VALID)
755 memcpy (buf, register_buffer (regnum),
756 m_descr->sizeof_register[regnum]);
758 memset (buf, 0, m_descr->sizeof_register[regnum]);
760 return (enum register_status) m_register_status[regnum];
762 else if (gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
764 struct value *mark, *computed;
765 enum register_status result = REG_VALID;
767 mark = value_mark ();
769 computed = gdbarch_pseudo_register_read_value (m_descr->gdbarch,
771 if (value_entirely_available (computed))
772 memcpy (buf, value_contents_raw (computed),
773 m_descr->sizeof_register[regnum]);
776 memset (buf, 0, m_descr->sizeof_register[regnum]);
777 result = REG_UNAVAILABLE;
780 value_free_to_mark (mark);
785 return gdbarch_pseudo_register_read (m_descr->gdbarch, this,
790 regcache_cooked_read_value (struct regcache *regcache, int regnum)
792 return regcache->cooked_read_value (regnum);
796 regcache::cooked_read_value (int regnum)
798 gdb_assert (regnum >= 0);
799 gdb_assert (regnum < m_descr->nr_cooked_registers);
801 if (regnum < m_descr->nr_raw_registers
802 || (m_readonly_p && m_register_status[regnum] != REG_UNKNOWN)
803 || !gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
805 struct value *result;
807 result = allocate_value (register_type (m_descr->gdbarch, regnum));
808 VALUE_LVAL (result) = lval_register;
809 VALUE_REGNUM (result) = regnum;
811 /* It is more efficient in general to do this delegation in this
812 direction than in the other one, even though the value-based
814 if (cooked_read (regnum,
815 value_contents_raw (result)) == REG_UNAVAILABLE)
816 mark_value_bytes_unavailable (result, 0,
817 TYPE_LENGTH (value_type (result)));
822 return gdbarch_pseudo_register_read_value (m_descr->gdbarch,
827 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
830 gdb_assert (regcache != NULL);
831 return regcache->cooked_read (regnum, val);
834 template<typename T, typename>
836 regcache::cooked_read (int regnum, T *val)
838 enum register_status status;
841 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
842 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
843 status = cooked_read (regnum, buf);
844 if (status == REG_VALID)
845 *val = extract_integer<T> (buf, m_descr->sizeof_register[regnum],
846 gdbarch_byte_order (m_descr->gdbarch));
853 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
856 gdb_assert (regcache != NULL);
857 return regcache->cooked_read (regnum, val);
861 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
864 gdb_assert (regcache != NULL);
865 regcache->cooked_write (regnum, val);
868 template<typename T, typename>
870 regcache::cooked_write (int regnum, T val)
874 gdb_assert (regnum >=0 && regnum < m_descr->nr_cooked_registers);
875 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
876 store_integer (buf, m_descr->sizeof_register[regnum],
877 gdbarch_byte_order (m_descr->gdbarch), val);
878 cooked_write (regnum, buf);
882 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
885 gdb_assert (regcache != NULL);
886 regcache->cooked_write (regnum, val);
889 /* See regcache.h. */
892 regcache_raw_set_cached_value (struct regcache *regcache, int regnum,
895 regcache->raw_set_cached_value (regnum, buf);
899 regcache::raw_set_cached_value (int regnum, const gdb_byte *buf)
901 memcpy (register_buffer (regnum), buf,
902 m_descr->sizeof_register[regnum]);
903 m_register_status[regnum] = REG_VALID;
907 regcache_raw_write (struct regcache *regcache, int regnum,
910 gdb_assert (regcache != NULL && buf != NULL);
911 regcache->raw_write (regnum, buf);
915 regcache::raw_write (int regnum, const gdb_byte *buf)
917 struct cleanup *old_chain;
919 gdb_assert (buf != NULL);
920 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
921 gdb_assert (!m_readonly_p);
923 /* On the sparc, writing %g0 is a no-op, so we don't even want to
924 change the registers array if something writes to this register. */
925 if (gdbarch_cannot_store_register (arch (), regnum))
928 /* If we have a valid copy of the register, and new value == old
929 value, then don't bother doing the actual store. */
930 if (get_register_status (regnum) == REG_VALID
931 && (memcmp (register_buffer (regnum), buf,
932 m_descr->sizeof_register[regnum]) == 0))
935 target_prepare_to_store (this);
936 raw_set_cached_value (regnum, buf);
938 /* Register a cleanup function for invalidating the register after it is
939 written, in case of a failure. */
940 old_chain = make_cleanup_regcache_invalidate (this, regnum);
942 target_store_registers (this, regnum);
944 /* The target did not throw an error so we can discard invalidating the
945 register and restore the cleanup chain to what it was. */
946 discard_cleanups (old_chain);
950 regcache_cooked_write (struct regcache *regcache, int regnum,
953 regcache->cooked_write (regnum, buf);
957 regcache::cooked_write (int regnum, const gdb_byte *buf)
959 gdb_assert (regnum >= 0);
960 gdb_assert (regnum < m_descr->nr_cooked_registers);
961 if (regnum < m_descr->nr_raw_registers)
962 raw_write (regnum, buf);
964 gdbarch_pseudo_register_write (m_descr->gdbarch, this,
968 /* Perform a partial register transfer using a read, modify, write
971 typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
973 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
977 regcache::xfer_part (int regnum, int offset, int len, void *in,
979 enum register_status (*read) (struct regcache *regcache,
982 void (*write) (struct regcache *regcache, int regnum,
983 const gdb_byte *buf))
985 struct gdbarch *gdbarch = arch ();
986 gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum));
988 gdb_assert (offset >= 0 && offset <= m_descr->sizeof_register[regnum]);
989 gdb_assert (len >= 0 && offset + len <= m_descr->sizeof_register[regnum]);
990 /* Something to do? */
991 if (offset + len == 0)
993 /* Read (when needed) ... */
996 || offset + len < m_descr->sizeof_register[regnum])
998 enum register_status status;
1000 gdb_assert (read != NULL);
1001 status = read (this, regnum, reg);
1002 if (status != REG_VALID)
1005 /* ... modify ... */
1007 memcpy (in, reg + offset, len);
1009 memcpy (reg + offset, out, len);
1010 /* ... write (when needed). */
1013 gdb_assert (write != NULL);
1014 write (this, regnum, reg);
1020 enum register_status
1021 regcache_raw_read_part (struct regcache *regcache, int regnum,
1022 int offset, int len, gdb_byte *buf)
1024 return regcache->raw_read_part (regnum, offset, len, buf);
1027 enum register_status
1028 regcache::raw_read_part (int regnum, int offset, int len, gdb_byte *buf)
1030 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
1031 return xfer_part (regnum, offset, len, buf, NULL,
1032 regcache_raw_read, regcache_raw_write);
1036 regcache_raw_write_part (struct regcache *regcache, int regnum,
1037 int offset, int len, const gdb_byte *buf)
1039 regcache->raw_write_part (regnum, offset, len, buf);
1043 regcache::raw_write_part (int regnum, int offset, int len,
1044 const gdb_byte *buf)
1046 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
1047 xfer_part (regnum, offset, len, NULL, buf, regcache_raw_read,
1048 regcache_raw_write);
1051 enum register_status
1052 regcache_cooked_read_part (struct regcache *regcache, int regnum,
1053 int offset, int len, gdb_byte *buf)
1055 return regcache->cooked_read_part (regnum, offset, len, buf);
1059 enum register_status
1060 regcache::cooked_read_part (int regnum, int offset, int len, gdb_byte *buf)
1062 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
1063 return xfer_part (regnum, offset, len, buf, NULL,
1064 regcache_cooked_read, regcache_cooked_write);
1068 regcache_cooked_write_part (struct regcache *regcache, int regnum,
1069 int offset, int len, const gdb_byte *buf)
1071 regcache->cooked_write_part (regnum, offset, len, buf);
1075 regcache::cooked_write_part (int regnum, int offset, int len,
1076 const gdb_byte *buf)
1078 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
1079 xfer_part (regnum, offset, len, NULL, buf,
1080 regcache_cooked_read, regcache_cooked_write);
1083 /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */
1086 regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
1088 gdb_assert (regcache != NULL);
1089 regcache->raw_supply (regnum, buf);
1093 regcache::raw_supply (int regnum, const void *buf)
1098 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
1099 gdb_assert (!m_readonly_p);
1101 regbuf = register_buffer (regnum);
1102 size = m_descr->sizeof_register[regnum];
1106 memcpy (regbuf, buf, size);
1107 m_register_status[regnum] = REG_VALID;
1111 /* This memset not strictly necessary, but better than garbage
1112 in case the register value manages to escape somewhere (due
1113 to a bug, no less). */
1114 memset (regbuf, 0, size);
1115 m_register_status[regnum] = REG_UNAVAILABLE;
1119 /* Supply register REGNUM to REGCACHE. Value to supply is an integer stored at
1120 address ADDR, in target endian, with length ADDR_LEN and sign IS_SIGNED. If
1121 the register size is greater than ADDR_LEN, then the integer will be sign or
1122 zero extended. If the register size is smaller than the integer, then the
1123 most significant bytes of the integer will be truncated. */
1126 regcache::raw_supply_integer (int regnum, const gdb_byte *addr, int addr_len,
1129 enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
1133 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
1134 gdb_assert (!m_readonly_p);
1136 regbuf = register_buffer (regnum);
1137 regsize = m_descr->sizeof_register[regnum];
1139 copy_integer_to_size (regbuf, regsize, addr, addr_len, is_signed,
1141 m_register_status[regnum] = REG_VALID;
1144 /* Supply register REGNUM with zeroed value to REGCACHE. This is not the same
1145 as calling raw_supply with NULL (which will set the state to
1149 regcache::raw_supply_zeroed (int regnum)
1154 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
1155 gdb_assert (!m_readonly_p);
1157 regbuf = register_buffer (regnum);
1158 size = m_descr->sizeof_register[regnum];
1160 memset (regbuf, 0, size);
1161 m_register_status[regnum] = REG_VALID;
1164 /* Collect register REGNUM from REGCACHE and store its contents in BUF. */
1167 regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
1169 gdb_assert (regcache != NULL && buf != NULL);
1170 regcache->raw_collect (regnum, buf);
1174 regcache::raw_collect (int regnum, void *buf) const
1179 gdb_assert (buf != NULL);
1180 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
1182 regbuf = register_buffer (regnum);
1183 size = m_descr->sizeof_register[regnum];
1184 memcpy (buf, regbuf, size);
1187 /* Transfer a single or all registers belonging to a certain register
1188 set to or from a buffer. This is the main worker function for
1189 regcache_supply_regset and regcache_collect_regset. */
1191 /* Collect register REGNUM from REGCACHE. Store collected value as an integer
1192 at address ADDR, in target endian, with length ADDR_LEN and sign IS_SIGNED.
1193 If ADDR_LEN is greater than the register size, then the integer will be sign
1194 or zero extended. If ADDR_LEN is smaller than the register size, then the
1195 most significant bytes of the integer will be truncated. */
1198 regcache::raw_collect_integer (int regnum, gdb_byte *addr, int addr_len,
1199 bool is_signed) const
1201 enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
1202 const gdb_byte *regbuf;
1205 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
1207 regbuf = register_buffer (regnum);
1208 regsize = m_descr->sizeof_register[regnum];
1210 copy_integer_to_size (addr, addr_len, regbuf, regsize, is_signed,
1215 regcache::transfer_regset (const struct regset *regset,
1216 struct regcache *out_regcache,
1217 int regnum, const void *in_buf,
1218 void *out_buf, size_t size) const
1220 const struct regcache_map_entry *map;
1221 int offs = 0, count;
1223 for (map = (const struct regcache_map_entry *) regset->regmap;
1224 (count = map->count) != 0;
1227 int regno = map->regno;
1228 int slot_size = map->size;
1230 if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
1231 slot_size = m_descr->sizeof_register[regno];
1233 if (regno == REGCACHE_MAP_SKIP
1235 && (regnum < regno || regnum >= regno + count)))
1236 offs += count * slot_size;
1238 else if (regnum == -1)
1239 for (; count--; regno++, offs += slot_size)
1241 if (offs + slot_size > size)
1245 raw_collect (regno, (gdb_byte *) out_buf + offs);
1247 out_regcache->raw_supply (regno, in_buf
1248 ? (const gdb_byte *) in_buf + offs
1253 /* Transfer a single register and return. */
1254 offs += (regnum - regno) * slot_size;
1255 if (offs + slot_size > size)
1259 raw_collect (regnum, (gdb_byte *) out_buf + offs);
1261 out_regcache->raw_supply (regnum, in_buf
1262 ? (const gdb_byte *) in_buf + offs
1269 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1270 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1271 If BUF is NULL, set the register(s) to "unavailable" status. */
1274 regcache_supply_regset (const struct regset *regset,
1275 struct regcache *regcache,
1276 int regnum, const void *buf, size_t size)
1278 regcache->supply_regset (regset, regnum, buf, size);
1282 regcache::supply_regset (const struct regset *regset,
1283 int regnum, const void *buf, size_t size)
1285 transfer_regset (regset, this, regnum, buf, NULL, size);
1288 /* Collect register REGNUM from REGCACHE to BUF, using the register
1289 map in REGSET. If REGNUM is -1, do this for all registers in
1293 regcache_collect_regset (const struct regset *regset,
1294 const struct regcache *regcache,
1295 int regnum, void *buf, size_t size)
1297 regcache->collect_regset (regset, regnum, buf, size);
1301 regcache::collect_regset (const struct regset *regset,
1302 int regnum, void *buf, size_t size) const
1304 transfer_regset (regset, NULL, regnum, NULL, buf, size);
1308 /* Special handling for register PC. */
1311 regcache_read_pc (struct regcache *regcache)
1313 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1317 if (gdbarch_read_pc_p (gdbarch))
1318 pc_val = gdbarch_read_pc (gdbarch, regcache);
1319 /* Else use per-frame method on get_current_frame. */
1320 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1324 if (regcache_cooked_read_unsigned (regcache,
1325 gdbarch_pc_regnum (gdbarch),
1326 &raw_val) == REG_UNAVAILABLE)
1327 throw_error (NOT_AVAILABLE_ERROR, _("PC register is not available"));
1329 pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val);
1332 internal_error (__FILE__, __LINE__,
1333 _("regcache_read_pc: Unable to find PC"));
1338 regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
1340 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1342 if (gdbarch_write_pc_p (gdbarch))
1343 gdbarch_write_pc (gdbarch, regcache, pc);
1344 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1345 regcache_cooked_write_unsigned (regcache,
1346 gdbarch_pc_regnum (gdbarch), pc);
1348 internal_error (__FILE__, __LINE__,
1349 _("regcache_write_pc: Unable to update PC"));
1351 /* Writing the PC (for instance, from "load") invalidates the
1353 reinit_frame_cache ();
1357 regcache::debug_print_register (const char *func, int regno)
1359 struct gdbarch *gdbarch = arch ();
1361 fprintf_unfiltered (gdb_stdlog, "%s ", func);
1362 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
1363 && gdbarch_register_name (gdbarch, regno) != NULL
1364 && gdbarch_register_name (gdbarch, regno)[0] != '\0')
1365 fprintf_unfiltered (gdb_stdlog, "(%s)",
1366 gdbarch_register_name (gdbarch, regno));
1368 fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
1369 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch))
1371 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1372 int size = register_size (gdbarch, regno);
1373 gdb_byte *buf = register_buffer (regno);
1375 fprintf_unfiltered (gdb_stdlog, " = ");
1376 for (int i = 0; i < size; i++)
1378 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
1380 if (size <= sizeof (LONGEST))
1382 ULONGEST val = extract_unsigned_integer (buf, size, byte_order);
1384 fprintf_unfiltered (gdb_stdlog, " %s %s",
1385 core_addr_to_string_nz (val), plongest (val));
1388 fprintf_unfiltered (gdb_stdlog, "\n");
1392 reg_flush_command (char *command, int from_tty)
1394 /* Force-flush the register cache. */
1395 registers_changed ();
1397 printf_filtered (_("Register cache flushed.\n"));
1401 regcache::dump (ui_file *file, enum regcache_dump_what what_to_dump)
1403 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
1404 struct gdbarch *gdbarch = m_descr->gdbarch;
1406 int footnote_nr = 0;
1407 int footnote_register_size = 0;
1408 int footnote_register_offset = 0;
1409 int footnote_register_type_name_null = 0;
1410 long register_offset = 0;
1413 fprintf_unfiltered (file, "nr_raw_registers %d\n",
1414 m_descr->nr_raw_registers);
1415 fprintf_unfiltered (file, "nr_cooked_registers %d\n",
1416 m_descr->nr_cooked_registers);
1417 fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
1418 m_descr->sizeof_raw_registers);
1419 fprintf_unfiltered (file, "sizeof_raw_register_status %ld\n",
1420 m_descr->sizeof_raw_register_status);
1421 fprintf_unfiltered (file, "gdbarch_num_regs %d\n",
1422 gdbarch_num_regs (gdbarch));
1423 fprintf_unfiltered (file, "gdbarch_num_pseudo_regs %d\n",
1424 gdbarch_num_pseudo_regs (gdbarch));
1427 gdb_assert (m_descr->nr_cooked_registers
1428 == (gdbarch_num_regs (gdbarch)
1429 + gdbarch_num_pseudo_regs (gdbarch)));
1431 for (regnum = -1; regnum < m_descr->nr_cooked_registers; regnum++)
1435 fprintf_unfiltered (file, " %-10s", "Name");
1438 const char *p = gdbarch_register_name (gdbarch, regnum);
1442 else if (p[0] == '\0')
1444 fprintf_unfiltered (file, " %-10s", p);
1449 fprintf_unfiltered (file, " %4s", "Nr");
1451 fprintf_unfiltered (file, " %4d", regnum);
1453 /* Relative number. */
1455 fprintf_unfiltered (file, " %4s", "Rel");
1456 else if (regnum < gdbarch_num_regs (gdbarch))
1457 fprintf_unfiltered (file, " %4d", regnum);
1459 fprintf_unfiltered (file, " %4d",
1460 (regnum - gdbarch_num_regs (gdbarch)));
1464 fprintf_unfiltered (file, " %6s ", "Offset");
1467 fprintf_unfiltered (file, " %6ld",
1468 m_descr->register_offset[regnum]);
1469 if (register_offset != m_descr->register_offset[regnum]
1471 && (m_descr->register_offset[regnum]
1472 != (m_descr->register_offset[regnum - 1]
1473 + m_descr->sizeof_register[regnum - 1])))
1476 if (!footnote_register_offset)
1477 footnote_register_offset = ++footnote_nr;
1478 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1481 fprintf_unfiltered (file, " ");
1482 register_offset = (m_descr->register_offset[regnum]
1483 + m_descr->sizeof_register[regnum]);
1488 fprintf_unfiltered (file, " %5s ", "Size");
1490 fprintf_unfiltered (file, " %5ld", m_descr->sizeof_register[regnum]);
1500 static const char blt[] = "builtin_type";
1502 t = TYPE_NAME (register_type (arch (), regnum));
1507 if (!footnote_register_type_name_null)
1508 footnote_register_type_name_null = ++footnote_nr;
1509 n = xstrprintf ("*%d", footnote_register_type_name_null);
1510 make_cleanup (xfree, n);
1513 /* Chop a leading builtin_type. */
1514 if (startswith (t, blt))
1517 fprintf_unfiltered (file, " %-15s", t);
1520 /* Leading space always present. */
1521 fprintf_unfiltered (file, " ");
1524 if (what_to_dump == regcache_dump_raw)
1527 fprintf_unfiltered (file, "Raw value");
1528 else if (regnum >= m_descr->nr_raw_registers)
1529 fprintf_unfiltered (file, "<cooked>");
1530 else if (get_register_status (regnum) == REG_UNKNOWN)
1531 fprintf_unfiltered (file, "<invalid>");
1532 else if (get_register_status (regnum) == REG_UNAVAILABLE)
1533 fprintf_unfiltered (file, "<unavailable>");
1536 raw_update (regnum);
1537 print_hex_chars (file, register_buffer (regnum),
1538 m_descr->sizeof_register[regnum],
1539 gdbarch_byte_order (gdbarch), true);
1543 /* Value, cooked. */
1544 if (what_to_dump == regcache_dump_cooked)
1547 fprintf_unfiltered (file, "Cooked value");
1550 const gdb_byte *buf = NULL;
1551 enum register_status status;
1552 struct value *value = NULL;
1554 if (regnum < m_descr->nr_raw_registers)
1556 raw_update (regnum);
1557 status = get_register_status (regnum);
1558 buf = register_buffer (regnum);
1562 value = cooked_read_value (regnum);
1564 if (!value_optimized_out (value)
1565 && value_entirely_available (value))
1568 buf = value_contents_all (value);
1571 status = REG_UNAVAILABLE;
1574 if (status == REG_UNKNOWN)
1575 fprintf_unfiltered (file, "<invalid>");
1576 else if (status == REG_UNAVAILABLE)
1577 fprintf_unfiltered (file, "<unavailable>");
1579 print_hex_chars (file, buf,
1580 m_descr->sizeof_register[regnum],
1581 gdbarch_byte_order (gdbarch), true);
1585 release_value (value);
1591 /* Group members. */
1592 if (what_to_dump == regcache_dump_groups)
1595 fprintf_unfiltered (file, "Groups");
1598 const char *sep = "";
1599 struct reggroup *group;
1601 for (group = reggroup_next (gdbarch, NULL);
1603 group = reggroup_next (gdbarch, group))
1605 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
1607 fprintf_unfiltered (file,
1608 "%s%s", sep, reggroup_name (group));
1615 /* Remote packet configuration. */
1616 if (what_to_dump == regcache_dump_remote)
1620 fprintf_unfiltered (file, "Rmt Nr g/G Offset");
1622 else if (regnum < m_descr->nr_raw_registers)
1626 if (remote_register_number_and_offset (arch (), regnum,
1628 fprintf_unfiltered (file, "%7d %11d", pnum, poffset);
1632 fprintf_unfiltered (file, "\n");
1635 if (footnote_register_size)
1636 fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
1637 footnote_register_size);
1638 if (footnote_register_offset)
1639 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1640 footnote_register_offset);
1641 if (footnote_register_type_name_null)
1642 fprintf_unfiltered (file,
1643 "*%d: Register type's name NULL.\n",
1644 footnote_register_type_name_null);
1645 do_cleanups (cleanups);
1649 regcache_print (char *args, enum regcache_dump_what what_to_dump)
1652 get_current_regcache ()->dump (gdb_stdout, what_to_dump);
1657 if (!file.open (args, "w"))
1658 perror_with_name (_("maintenance print architecture"));
1659 get_current_regcache ()->dump (&file, what_to_dump);
1664 maintenance_print_registers (char *args, int from_tty)
1666 regcache_print (args, regcache_dump_none);
1670 maintenance_print_raw_registers (char *args, int from_tty)
1672 regcache_print (args, regcache_dump_raw);
1676 maintenance_print_cooked_registers (char *args, int from_tty)
1678 regcache_print (args, regcache_dump_cooked);
1682 maintenance_print_register_groups (char *args, int from_tty)
1684 regcache_print (args, regcache_dump_groups);
1688 maintenance_print_remote_registers (char *args, int from_tty)
1690 regcache_print (args, regcache_dump_remote);
1694 #include "selftest.h"
1696 namespace selftests {
1698 class regcache_access : public regcache
1702 /* Return the number of elements in current_regcache. */
1705 current_regcache_size ()
1707 return std::distance (regcache::current_regcache.begin (),
1708 regcache::current_regcache.end ());
1713 current_regcache_test (void)
1715 /* It is empty at the start. */
1716 SELF_CHECK (regcache_access::current_regcache_size () == 0);
1718 ptid_t ptid1 (1), ptid2 (2), ptid3 (3);
1720 /* Get regcache from ptid1, a new regcache is added to
1721 current_regcache. */
1722 regcache *regcache = get_thread_arch_aspace_regcache (ptid1,
1726 SELF_CHECK (regcache != NULL);
1727 SELF_CHECK (regcache->ptid () == ptid1);
1728 SELF_CHECK (regcache_access::current_regcache_size () == 1);
1730 /* Get regcache from ptid2, a new regcache is added to
1731 current_regcache. */
1732 regcache = get_thread_arch_aspace_regcache (ptid2,
1735 SELF_CHECK (regcache != NULL);
1736 SELF_CHECK (regcache->ptid () == ptid2);
1737 SELF_CHECK (regcache_access::current_regcache_size () == 2);
1739 /* Get regcache from ptid3, a new regcache is added to
1740 current_regcache. */
1741 regcache = get_thread_arch_aspace_regcache (ptid3,
1744 SELF_CHECK (regcache != NULL);
1745 SELF_CHECK (regcache->ptid () == ptid3);
1746 SELF_CHECK (regcache_access::current_regcache_size () == 3);
1748 /* Get regcache from ptid2 again, nothing is added to
1749 current_regcache. */
1750 regcache = get_thread_arch_aspace_regcache (ptid2,
1753 SELF_CHECK (regcache != NULL);
1754 SELF_CHECK (regcache->ptid () == ptid2);
1755 SELF_CHECK (regcache_access::current_regcache_size () == 3);
1757 /* Mark ptid2 is changed, so regcache of ptid2 should be removed from
1758 current_regcache. */
1759 registers_changed_ptid (ptid2);
1760 SELF_CHECK (regcache_access::current_regcache_size () == 2);
1763 } // namespace selftests
1764 #endif /* GDB_SELF_TEST */
1766 extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */
1769 _initialize_regcache (void)
1771 regcache_descr_handle
1772 = gdbarch_data_register_post_init (init_regcache_descr);
1774 observer_attach_target_changed (regcache_observer_target_changed);
1775 observer_attach_thread_ptid_changed (regcache::regcache_thread_ptid_changed);
1777 add_com ("flushregs", class_maintenance, reg_flush_command,
1778 _("Force gdb to flush its register cache (maintainer command)"));
1780 add_cmd ("registers", class_maintenance, maintenance_print_registers,
1781 _("Print the internal register configuration.\n"
1782 "Takes an optional file parameter."), &maintenanceprintlist);
1783 add_cmd ("raw-registers", class_maintenance,
1784 maintenance_print_raw_registers,
1785 _("Print the internal register configuration "
1786 "including raw values.\n"
1787 "Takes an optional file parameter."), &maintenanceprintlist);
1788 add_cmd ("cooked-registers", class_maintenance,
1789 maintenance_print_cooked_registers,
1790 _("Print the internal register configuration "
1791 "including cooked values.\n"
1792 "Takes an optional file parameter."), &maintenanceprintlist);
1793 add_cmd ("register-groups", class_maintenance,
1794 maintenance_print_register_groups,
1795 _("Print the internal register configuration "
1796 "including each register's group.\n"
1797 "Takes an optional file parameter."),
1798 &maintenanceprintlist);
1799 add_cmd ("remote-registers", class_maintenance,
1800 maintenance_print_remote_registers, _("\
1801 Print the internal register configuration including each register's\n\
1802 remote register number and buffer offset in the g/G packets.\n\
1803 Takes an optional file parameter."),
1804 &maintenanceprintlist);
1806 register_self_test (selftests::current_regcache_test);