1 /* Cache and manage the values of registers for GDB, the GNU debugger.
3 Copyright (C) 1986-2018 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"
27 #include "observable.h"
29 #include <forward_list>
34 * Here is the actual register cache.
37 /* Per-architecture object describing the layout of a register cache.
38 Computed once when the architecture is created. */
40 struct gdbarch_data *regcache_descr_handle;
44 /* The architecture this descriptor belongs to. */
45 struct gdbarch *gdbarch;
47 /* The raw register cache. Each raw (or hard) register is supplied
48 by the target interface. The raw cache should not contain
49 redundant information - if the PC is constructed from two
50 registers then those registers and not the PC lives in the raw
52 long sizeof_raw_registers;
54 /* The cooked register space. Each cooked register in the range
55 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
56 register. The remaining [NR_RAW_REGISTERS
57 .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto
58 both raw registers and memory by the architecture methods
59 gdbarch_pseudo_register_read and gdbarch_pseudo_register_write. */
60 int nr_cooked_registers;
61 long sizeof_cooked_registers;
63 /* Offset and size (in 8 bit bytes), of each register in the
64 register cache. All registers (including those in the range
65 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an
67 long *register_offset;
68 long *sizeof_register;
70 /* Cached table containing the type of each register. */
71 struct type **register_type;
75 init_regcache_descr (struct gdbarch *gdbarch)
78 struct regcache_descr *descr;
79 gdb_assert (gdbarch != NULL);
81 /* Create an initial, zero filled, table. */
82 descr = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct regcache_descr);
83 descr->gdbarch = gdbarch;
85 /* Total size of the register space. The raw registers are mapped
86 directly onto the raw register cache while the pseudo's are
87 either mapped onto raw-registers or memory. */
88 descr->nr_cooked_registers = gdbarch_num_regs (gdbarch)
89 + gdbarch_num_pseudo_regs (gdbarch);
91 /* Fill in a table of register types. */
93 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers,
95 for (i = 0; i < descr->nr_cooked_registers; i++)
96 descr->register_type[i] = gdbarch_register_type (gdbarch, i);
98 /* Construct a strictly RAW register cache. Don't allow pseudo's
99 into the register cache. */
101 /* Lay out the register cache.
103 NOTE: cagney/2002-05-22: Only register_type() is used when
104 constructing the register cache. It is assumed that the
105 register's raw size, virtual size and type length are all the
111 descr->sizeof_register
112 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
113 descr->register_offset
114 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
115 for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
117 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
118 descr->register_offset[i] = offset;
119 offset += descr->sizeof_register[i];
121 /* Set the real size of the raw register cache buffer. */
122 descr->sizeof_raw_registers = offset;
124 for (; i < descr->nr_cooked_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];
130 /* Set the real size of the readonly register cache buffer. */
131 descr->sizeof_cooked_registers = offset;
137 static struct regcache_descr *
138 regcache_descr (struct gdbarch *gdbarch)
140 return (struct regcache_descr *) gdbarch_data (gdbarch,
141 regcache_descr_handle);
144 /* Utility functions returning useful register attributes stored in
145 the regcache descr. */
148 register_type (struct gdbarch *gdbarch, int regnum)
150 struct regcache_descr *descr = regcache_descr (gdbarch);
152 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
153 return descr->register_type[regnum];
156 /* Utility functions returning useful register attributes stored in
157 the regcache descr. */
160 register_size (struct gdbarch *gdbarch, int regnum)
162 struct regcache_descr *descr = regcache_descr (gdbarch);
165 gdb_assert (regnum >= 0
166 && regnum < (gdbarch_num_regs (gdbarch)
167 + gdbarch_num_pseudo_regs (gdbarch)));
168 size = descr->sizeof_register[regnum];
172 /* See common/common-regcache.h. */
175 regcache_register_size (const struct regcache *regcache, int n)
177 return register_size (regcache->arch (), n);
180 reg_buffer::reg_buffer (gdbarch *gdbarch, bool has_pseudo)
181 : m_has_pseudo (has_pseudo)
183 gdb_assert (gdbarch != NULL);
184 m_descr = regcache_descr (gdbarch);
188 m_registers.reset (new gdb_byte[m_descr->sizeof_cooked_registers] ());
189 m_register_status.reset
190 (new register_status[m_descr->nr_cooked_registers] ());
194 m_registers.reset (new gdb_byte[m_descr->sizeof_raw_registers] ());
195 m_register_status.reset
196 (new register_status[gdbarch_num_regs (gdbarch)] ());
200 regcache::regcache (gdbarch *gdbarch, const address_space *aspace_)
201 /* The register buffers. A read/write register cache can only hold
202 [0 .. gdbarch_num_regs). */
203 : detached_regcache (gdbarch, false), m_aspace (aspace_)
205 m_ptid = minus_one_ptid;
208 static enum register_status
209 do_cooked_read (void *src, int regnum, gdb_byte *buf)
211 struct regcache *regcache = (struct regcache *) src;
213 return regcache->cooked_read (regnum, buf);
216 readonly_detached_regcache::readonly_detached_regcache (const regcache &src)
217 : readonly_detached_regcache (src.arch (), do_cooked_read, (void *) &src)
222 reg_buffer::arch () const
224 return m_descr->gdbarch;
227 /* Cleanup class for invalidating a register. */
229 class regcache_invalidator
233 regcache_invalidator (struct regcache *regcache, int regnum)
234 : m_regcache (regcache),
239 ~regcache_invalidator ()
241 if (m_regcache != nullptr)
242 m_regcache->invalidate (m_regnum);
245 DISABLE_COPY_AND_ASSIGN (regcache_invalidator);
249 m_regcache = nullptr;
254 struct regcache *m_regcache;
258 /* Return a pointer to register REGNUM's buffer cache. */
261 reg_buffer::register_buffer (int regnum) const
263 return m_registers.get () + m_descr->register_offset[regnum];
267 reg_buffer::save (regcache_cooked_read_ftype *cooked_read,
270 struct gdbarch *gdbarch = m_descr->gdbarch;
273 /* It should have pseudo registers. */
274 gdb_assert (m_has_pseudo);
275 /* Clear the dest. */
276 memset (m_registers.get (), 0, m_descr->sizeof_cooked_registers);
277 memset (m_register_status.get (), REG_UNKNOWN, m_descr->nr_cooked_registers);
278 /* Copy over any registers (identified by their membership in the
279 save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs +
280 gdbarch_num_pseudo_regs) range is checked since some architectures need
281 to save/restore `cooked' registers that live in memory. */
282 for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
284 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
286 gdb_byte *dst_buf = register_buffer (regnum);
287 enum register_status status = cooked_read (src, regnum, dst_buf);
289 gdb_assert (status != REG_UNKNOWN);
291 if (status != REG_VALID)
292 memset (dst_buf, 0, register_size (gdbarch, regnum));
294 m_register_status[regnum] = status;
300 regcache::restore (readonly_detached_regcache *src)
302 struct gdbarch *gdbarch = m_descr->gdbarch;
305 gdb_assert (src != NULL);
306 gdb_assert (src->m_has_pseudo);
308 gdb_assert (gdbarch == src->arch ());
310 /* Copy over any registers, being careful to only restore those that
311 were both saved and need to be restored. The full [0 .. gdbarch_num_regs
312 + gdbarch_num_pseudo_regs) range is checked since some architectures need
313 to save/restore `cooked' registers that live in memory. */
314 for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
316 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
318 if (src->m_register_status[regnum] == REG_VALID)
319 cooked_write (regnum, src->register_buffer (regnum));
324 /* See common/common-regcache.h. */
327 reg_buffer::get_register_status (int regnum) const
329 assert_regnum (regnum);
331 return m_register_status[regnum];
335 reg_buffer::invalidate (int regnum)
337 assert_regnum (regnum);
338 m_register_status[regnum] = REG_UNKNOWN;
342 reg_buffer::assert_regnum (int regnum) const
344 gdb_assert (regnum >= 0);
346 gdb_assert (regnum < m_descr->nr_cooked_registers);
348 gdb_assert (regnum < gdbarch_num_regs (arch ()));
351 /* Global structure containing the current regcache. */
353 /* NOTE: this is a write-through cache. There is no "dirty" bit for
354 recording if the register values have been changed (eg. by the
355 user). Therefore all registers must be written back to the
356 target when appropriate. */
357 std::forward_list<regcache *> regcache::current_regcache;
360 get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
361 struct address_space *aspace)
363 for (const auto ®cache : regcache::current_regcache)
364 if (ptid_equal (regcache->ptid (), ptid) && regcache->arch () == gdbarch)
367 regcache *new_regcache = new regcache (gdbarch, aspace);
369 regcache::current_regcache.push_front (new_regcache);
370 new_regcache->set_ptid (ptid);
376 get_thread_arch_regcache (ptid_t ptid, struct gdbarch *gdbarch)
378 address_space *aspace = target_thread_address_space (ptid);
380 return get_thread_arch_aspace_regcache (ptid, gdbarch, aspace);
383 static ptid_t current_thread_ptid;
384 static struct gdbarch *current_thread_arch;
387 get_thread_regcache (ptid_t ptid)
389 if (!current_thread_arch || !ptid_equal (current_thread_ptid, ptid))
391 current_thread_ptid = ptid;
392 current_thread_arch = target_thread_architecture (ptid);
395 return get_thread_arch_regcache (ptid, current_thread_arch);
399 get_current_regcache (void)
401 return get_thread_regcache (inferior_ptid);
404 /* See common/common-regcache.h. */
407 get_thread_regcache_for_ptid (ptid_t ptid)
409 return get_thread_regcache (ptid);
412 /* Observer for the target_changed event. */
415 regcache_observer_target_changed (struct target_ops *target)
417 registers_changed ();
420 /* Update global variables old ptids to hold NEW_PTID if they were
423 regcache::regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
425 for (auto ®cache : regcache::current_regcache)
427 if (ptid_equal (regcache->ptid (), old_ptid))
428 regcache->set_ptid (new_ptid);
432 /* Low level examining and depositing of registers.
434 The caller is responsible for making sure that the inferior is
435 stopped before calling the fetching routines, or it will get
436 garbage. (a change from GDB version 3, in which the caller got the
437 value from the last stop). */
439 /* REGISTERS_CHANGED ()
441 Indicate that registers may have changed, so invalidate the cache. */
444 registers_changed_ptid (ptid_t ptid)
446 for (auto oit = regcache::current_regcache.before_begin (),
447 it = std::next (oit);
448 it != regcache::current_regcache.end ();
451 if (ptid_match ((*it)->ptid (), ptid))
454 it = regcache::current_regcache.erase_after (oit);
460 if (ptid_match (current_thread_ptid, ptid))
462 current_thread_ptid = null_ptid;
463 current_thread_arch = NULL;
466 if (ptid_match (inferior_ptid, ptid))
468 /* We just deleted the regcache of the current thread. Need to
469 forget about any frames we have cached, too. */
470 reinit_frame_cache ();
475 registers_changed (void)
477 registers_changed_ptid (minus_one_ptid);
479 /* Force cleanup of any alloca areas if using C alloca instead of
480 a builtin alloca. This particular call is used to clean up
481 areas allocated by low level target code which may build up
482 during lengthy interactions between gdb and the target before
483 gdb gives control to the user (ie watchpoints). */
488 regcache::raw_update (int regnum)
490 assert_regnum (regnum);
492 /* Make certain that the register cache is up-to-date with respect
493 to the current thread. This switching shouldn't be necessary
494 only there is still only one target side register cache. Sigh!
495 On the bright side, at least there is a regcache object. */
497 if (get_register_status (regnum) == REG_UNKNOWN)
499 target_fetch_registers (this, regnum);
501 /* A number of targets can't access the whole set of raw
502 registers (because the debug API provides no means to get at
504 if (m_register_status[regnum] == REG_UNKNOWN)
505 m_register_status[regnum] = REG_UNAVAILABLE;
510 readable_regcache::raw_read (int regnum, gdb_byte *buf)
512 gdb_assert (buf != NULL);
515 if (m_register_status[regnum] != REG_VALID)
516 memset (buf, 0, m_descr->sizeof_register[regnum]);
518 memcpy (buf, register_buffer (regnum),
519 m_descr->sizeof_register[regnum]);
521 return m_register_status[regnum];
525 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
527 gdb_assert (regcache != NULL);
528 return regcache->raw_read (regnum, val);
531 template<typename T, typename>
533 readable_regcache::raw_read (int regnum, T *val)
536 enum register_status status;
538 assert_regnum (regnum);
539 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
540 status = raw_read (regnum, buf);
541 if (status == REG_VALID)
542 *val = extract_integer<T> (buf,
543 m_descr->sizeof_register[regnum],
544 gdbarch_byte_order (m_descr->gdbarch));
551 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
554 gdb_assert (regcache != NULL);
555 return regcache->raw_read (regnum, val);
559 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
561 gdb_assert (regcache != NULL);
562 regcache->raw_write (regnum, val);
565 template<typename T, typename>
567 regcache::raw_write (int regnum, T val)
571 assert_regnum (regnum);
572 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
573 store_integer (buf, m_descr->sizeof_register[regnum],
574 gdbarch_byte_order (m_descr->gdbarch), val);
575 raw_write (regnum, buf);
579 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
582 gdb_assert (regcache != NULL);
583 regcache->raw_write (regnum, val);
587 regcache_raw_get_signed (struct regcache *regcache, int regnum)
590 enum register_status status;
592 status = regcache_raw_read_signed (regcache, regnum, &value);
593 if (status == REG_UNAVAILABLE)
594 throw_error (NOT_AVAILABLE_ERROR,
595 _("Register %d is not available"), regnum);
600 readable_regcache::cooked_read (int regnum, gdb_byte *buf)
602 gdb_assert (regnum >= 0);
603 gdb_assert (regnum < m_descr->nr_cooked_registers);
604 if (regnum < num_raw_registers ())
605 return raw_read (regnum, buf);
606 else if (m_has_pseudo
607 && m_register_status[regnum] != REG_UNKNOWN)
609 if (m_register_status[regnum] == REG_VALID)
610 memcpy (buf, register_buffer (regnum),
611 m_descr->sizeof_register[regnum]);
613 memset (buf, 0, m_descr->sizeof_register[regnum]);
615 return m_register_status[regnum];
617 else if (gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
619 struct value *mark, *computed;
620 enum register_status result = REG_VALID;
622 mark = value_mark ();
624 computed = gdbarch_pseudo_register_read_value (m_descr->gdbarch,
626 if (value_entirely_available (computed))
627 memcpy (buf, value_contents_raw (computed),
628 m_descr->sizeof_register[regnum]);
631 memset (buf, 0, m_descr->sizeof_register[regnum]);
632 result = REG_UNAVAILABLE;
635 value_free_to_mark (mark);
640 return gdbarch_pseudo_register_read (m_descr->gdbarch, this,
645 readable_regcache::cooked_read_value (int regnum)
647 gdb_assert (regnum >= 0);
648 gdb_assert (regnum < m_descr->nr_cooked_registers);
650 if (regnum < num_raw_registers ()
651 || (m_has_pseudo && m_register_status[regnum] != REG_UNKNOWN)
652 || !gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
654 struct value *result;
656 result = allocate_value (register_type (m_descr->gdbarch, regnum));
657 VALUE_LVAL (result) = lval_register;
658 VALUE_REGNUM (result) = regnum;
660 /* It is more efficient in general to do this delegation in this
661 direction than in the other one, even though the value-based
663 if (cooked_read (regnum,
664 value_contents_raw (result)) == REG_UNAVAILABLE)
665 mark_value_bytes_unavailable (result, 0,
666 TYPE_LENGTH (value_type (result)));
671 return gdbarch_pseudo_register_read_value (m_descr->gdbarch,
676 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
679 gdb_assert (regcache != NULL);
680 return regcache->cooked_read (regnum, val);
683 template<typename T, typename>
685 readable_regcache::cooked_read (int regnum, T *val)
687 enum register_status status;
690 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
691 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
692 status = cooked_read (regnum, buf);
693 if (status == REG_VALID)
694 *val = extract_integer<T> (buf, m_descr->sizeof_register[regnum],
695 gdbarch_byte_order (m_descr->gdbarch));
702 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
705 gdb_assert (regcache != NULL);
706 return regcache->cooked_read (regnum, val);
710 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
713 gdb_assert (regcache != NULL);
714 regcache->cooked_write (regnum, val);
717 template<typename T, typename>
719 regcache::cooked_write (int regnum, T val)
723 gdb_assert (regnum >=0 && regnum < m_descr->nr_cooked_registers);
724 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
725 store_integer (buf, m_descr->sizeof_register[regnum],
726 gdbarch_byte_order (m_descr->gdbarch), val);
727 cooked_write (regnum, buf);
731 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
734 gdb_assert (regcache != NULL);
735 regcache->cooked_write (regnum, val);
739 regcache::raw_write (int regnum, const gdb_byte *buf)
742 gdb_assert (buf != NULL);
743 assert_regnum (regnum);
745 /* On the sparc, writing %g0 is a no-op, so we don't even want to
746 change the registers array if something writes to this register. */
747 if (gdbarch_cannot_store_register (arch (), regnum))
750 /* If we have a valid copy of the register, and new value == old
751 value, then don't bother doing the actual store. */
752 if (get_register_status (regnum) == REG_VALID
753 && (memcmp (register_buffer (regnum), buf,
754 m_descr->sizeof_register[regnum]) == 0))
757 target_prepare_to_store (this);
758 raw_supply (regnum, buf);
760 /* Invalidate the register after it is written, in case of a
762 regcache_invalidator invalidator (this, regnum);
764 target_store_registers (this, regnum);
766 /* The target did not throw an error so we can discard invalidating
768 invalidator.release ();
772 regcache::cooked_write (int regnum, const gdb_byte *buf)
774 gdb_assert (regnum >= 0);
775 gdb_assert (regnum < m_descr->nr_cooked_registers);
776 if (regnum < num_raw_registers ())
777 raw_write (regnum, buf);
779 gdbarch_pseudo_register_write (m_descr->gdbarch, this,
783 /* Perform a partial register transfer using a read, modify, write
787 readable_regcache::read_part (int regnum, int offset, int len, void *in,
790 struct gdbarch *gdbarch = arch ();
791 gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum));
793 gdb_assert (in != NULL);
794 gdb_assert (offset >= 0 && offset <= m_descr->sizeof_register[regnum]);
795 gdb_assert (len >= 0 && offset + len <= m_descr->sizeof_register[regnum]);
796 /* Something to do? */
797 if (offset + len == 0)
799 /* Read (when needed) ... */
800 enum register_status status;
803 status = raw_read (regnum, reg);
805 status = cooked_read (regnum, reg);
806 if (status != REG_VALID)
810 memcpy (in, reg + offset, len);
816 regcache::write_part (int regnum, int offset, int len,
817 const void *out, bool is_raw)
819 struct gdbarch *gdbarch = arch ();
820 gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum));
822 gdb_assert (out != NULL);
823 gdb_assert (offset >= 0 && offset <= m_descr->sizeof_register[regnum]);
824 gdb_assert (len >= 0 && offset + len <= m_descr->sizeof_register[regnum]);
825 /* Something to do? */
826 if (offset + len == 0)
828 /* Read (when needed) ... */
830 || offset + len < m_descr->sizeof_register[regnum])
832 enum register_status status;
835 status = raw_read (regnum, reg);
837 status = cooked_read (regnum, reg);
838 if (status != REG_VALID)
842 memcpy (reg + offset, out, len);
843 /* ... write (when needed). */
845 raw_write (regnum, reg);
847 cooked_write (regnum, reg);
853 readable_regcache::raw_read_part (int regnum, int offset, int len, gdb_byte *buf)
855 assert_regnum (regnum);
856 return read_part (regnum, offset, len, buf, true);
859 /* See regcache.h. */
862 regcache::raw_write_part (int regnum, int offset, int len,
865 assert_regnum (regnum);
866 write_part (regnum, offset, len, buf, true);
870 readable_regcache::cooked_read_part (int regnum, int offset, int len,
873 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
874 return read_part (regnum, offset, len, buf, false);
878 regcache::cooked_write_part (int regnum, int offset, int len,
881 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
882 write_part (regnum, offset, len, buf, false);
885 /* See common/common-regcache.h. */
888 reg_buffer::raw_supply (int regnum, const void *buf)
893 assert_regnum (regnum);
895 regbuf = register_buffer (regnum);
896 size = m_descr->sizeof_register[regnum];
900 memcpy (regbuf, buf, size);
901 m_register_status[regnum] = REG_VALID;
905 /* This memset not strictly necessary, but better than garbage
906 in case the register value manages to escape somewhere (due
907 to a bug, no less). */
908 memset (regbuf, 0, size);
909 m_register_status[regnum] = REG_UNAVAILABLE;
913 /* See regcache.h. */
916 reg_buffer::raw_supply_integer (int regnum, const gdb_byte *addr,
917 int addr_len, bool is_signed)
919 enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
923 assert_regnum (regnum);
925 regbuf = register_buffer (regnum);
926 regsize = m_descr->sizeof_register[regnum];
928 copy_integer_to_size (regbuf, regsize, addr, addr_len, is_signed,
930 m_register_status[regnum] = REG_VALID;
933 /* See regcache.h. */
936 reg_buffer::raw_supply_zeroed (int regnum)
941 assert_regnum (regnum);
943 regbuf = register_buffer (regnum);
944 size = m_descr->sizeof_register[regnum];
946 memset (regbuf, 0, size);
947 m_register_status[regnum] = REG_VALID;
950 /* See common/common-regcache.h. */
953 reg_buffer::raw_collect (int regnum, void *buf) const
958 gdb_assert (buf != NULL);
959 assert_regnum (regnum);
961 regbuf = register_buffer (regnum);
962 size = m_descr->sizeof_register[regnum];
963 memcpy (buf, regbuf, size);
966 /* See regcache.h. */
969 reg_buffer::raw_collect_integer (int regnum, gdb_byte *addr, int addr_len,
970 bool is_signed) const
972 enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
973 const gdb_byte *regbuf;
976 assert_regnum (regnum);
978 regbuf = register_buffer (regnum);
979 regsize = m_descr->sizeof_register[regnum];
981 copy_integer_to_size (addr, addr_len, regbuf, regsize, is_signed,
985 /* Transfer a single or all registers belonging to a certain register
986 set to or from a buffer. This is the main worker function for
987 regcache_supply_regset and regcache_collect_regset. */
990 regcache::transfer_regset (const struct regset *regset,
991 struct regcache *out_regcache,
992 int regnum, const void *in_buf,
993 void *out_buf, size_t size) const
995 const struct regcache_map_entry *map;
998 for (map = (const struct regcache_map_entry *) regset->regmap;
999 (count = map->count) != 0;
1002 int regno = map->regno;
1003 int slot_size = map->size;
1005 if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
1006 slot_size = m_descr->sizeof_register[regno];
1008 if (regno == REGCACHE_MAP_SKIP
1010 && (regnum < regno || regnum >= regno + count)))
1011 offs += count * slot_size;
1013 else if (regnum == -1)
1014 for (; count--; regno++, offs += slot_size)
1016 if (offs + slot_size > size)
1020 raw_collect (regno, (gdb_byte *) out_buf + offs);
1022 out_regcache->raw_supply (regno, in_buf
1023 ? (const gdb_byte *) in_buf + offs
1028 /* Transfer a single register and return. */
1029 offs += (regnum - regno) * slot_size;
1030 if (offs + slot_size > size)
1034 raw_collect (regnum, (gdb_byte *) out_buf + offs);
1036 out_regcache->raw_supply (regnum, in_buf
1037 ? (const gdb_byte *) in_buf + offs
1044 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1045 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1046 If BUF is NULL, set the register(s) to "unavailable" status. */
1049 regcache_supply_regset (const struct regset *regset,
1050 struct regcache *regcache,
1051 int regnum, const void *buf, size_t size)
1053 regcache->supply_regset (regset, regnum, buf, size);
1057 regcache::supply_regset (const struct regset *regset,
1058 int regnum, const void *buf, size_t size)
1060 transfer_regset (regset, this, regnum, buf, NULL, size);
1063 /* Collect register REGNUM from REGCACHE to BUF, using the register
1064 map in REGSET. If REGNUM is -1, do this for all registers in
1068 regcache_collect_regset (const struct regset *regset,
1069 const struct regcache *regcache,
1070 int regnum, void *buf, size_t size)
1072 regcache->collect_regset (regset, regnum, buf, size);
1076 regcache::collect_regset (const struct regset *regset,
1077 int regnum, void *buf, size_t size) const
1079 transfer_regset (regset, NULL, regnum, NULL, buf, size);
1083 /* Special handling for register PC. */
1086 regcache_read_pc (struct regcache *regcache)
1088 struct gdbarch *gdbarch = regcache->arch ();
1092 if (gdbarch_read_pc_p (gdbarch))
1093 pc_val = gdbarch_read_pc (gdbarch, regcache);
1094 /* Else use per-frame method on get_current_frame. */
1095 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1099 if (regcache_cooked_read_unsigned (regcache,
1100 gdbarch_pc_regnum (gdbarch),
1101 &raw_val) == REG_UNAVAILABLE)
1102 throw_error (NOT_AVAILABLE_ERROR, _("PC register is not available"));
1104 pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val);
1107 internal_error (__FILE__, __LINE__,
1108 _("regcache_read_pc: Unable to find PC"));
1113 regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
1115 struct gdbarch *gdbarch = regcache->arch ();
1117 if (gdbarch_write_pc_p (gdbarch))
1118 gdbarch_write_pc (gdbarch, regcache, pc);
1119 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1120 regcache_cooked_write_unsigned (regcache,
1121 gdbarch_pc_regnum (gdbarch), pc);
1123 internal_error (__FILE__, __LINE__,
1124 _("regcache_write_pc: Unable to update PC"));
1126 /* Writing the PC (for instance, from "load") invalidates the
1128 reinit_frame_cache ();
1132 reg_buffer::num_raw_registers () const
1134 return gdbarch_num_regs (arch ());
1138 regcache::debug_print_register (const char *func, int regno)
1140 struct gdbarch *gdbarch = arch ();
1142 fprintf_unfiltered (gdb_stdlog, "%s ", func);
1143 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
1144 && gdbarch_register_name (gdbarch, regno) != NULL
1145 && gdbarch_register_name (gdbarch, regno)[0] != '\0')
1146 fprintf_unfiltered (gdb_stdlog, "(%s)",
1147 gdbarch_register_name (gdbarch, regno));
1149 fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
1150 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch))
1152 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1153 int size = register_size (gdbarch, regno);
1154 gdb_byte *buf = register_buffer (regno);
1156 fprintf_unfiltered (gdb_stdlog, " = ");
1157 for (int i = 0; i < size; i++)
1159 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
1161 if (size <= sizeof (LONGEST))
1163 ULONGEST val = extract_unsigned_integer (buf, size, byte_order);
1165 fprintf_unfiltered (gdb_stdlog, " %s %s",
1166 core_addr_to_string_nz (val), plongest (val));
1169 fprintf_unfiltered (gdb_stdlog, "\n");
1173 reg_flush_command (const char *command, int from_tty)
1175 /* Force-flush the register cache. */
1176 registers_changed ();
1178 printf_filtered (_("Register cache flushed.\n"));
1182 register_dump::dump (ui_file *file)
1184 auto descr = regcache_descr (m_gdbarch);
1186 int footnote_nr = 0;
1187 int footnote_register_offset = 0;
1188 int footnote_register_type_name_null = 0;
1189 long register_offset = 0;
1191 gdb_assert (descr->nr_cooked_registers
1192 == (gdbarch_num_regs (m_gdbarch)
1193 + gdbarch_num_pseudo_regs (m_gdbarch)));
1195 for (regnum = -1; regnum < descr->nr_cooked_registers; regnum++)
1199 fprintf_unfiltered (file, " %-10s", "Name");
1202 const char *p = gdbarch_register_name (m_gdbarch, regnum);
1206 else if (p[0] == '\0')
1208 fprintf_unfiltered (file, " %-10s", p);
1213 fprintf_unfiltered (file, " %4s", "Nr");
1215 fprintf_unfiltered (file, " %4d", regnum);
1217 /* Relative number. */
1219 fprintf_unfiltered (file, " %4s", "Rel");
1220 else if (regnum < gdbarch_num_regs (m_gdbarch))
1221 fprintf_unfiltered (file, " %4d", regnum);
1223 fprintf_unfiltered (file, " %4d",
1224 (regnum - gdbarch_num_regs (m_gdbarch)));
1228 fprintf_unfiltered (file, " %6s ", "Offset");
1231 fprintf_unfiltered (file, " %6ld",
1232 descr->register_offset[regnum]);
1233 if (register_offset != descr->register_offset[regnum]
1235 && (descr->register_offset[regnum]
1236 != (descr->register_offset[regnum - 1]
1237 + descr->sizeof_register[regnum - 1])))
1240 if (!footnote_register_offset)
1241 footnote_register_offset = ++footnote_nr;
1242 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1245 fprintf_unfiltered (file, " ");
1246 register_offset = (descr->register_offset[regnum]
1247 + descr->sizeof_register[regnum]);
1252 fprintf_unfiltered (file, " %5s ", "Size");
1254 fprintf_unfiltered (file, " %5ld", descr->sizeof_register[regnum]);
1259 std::string name_holder;
1265 static const char blt[] = "builtin_type";
1267 t = TYPE_NAME (register_type (m_gdbarch, regnum));
1270 if (!footnote_register_type_name_null)
1271 footnote_register_type_name_null = ++footnote_nr;
1272 name_holder = string_printf ("*%d",
1273 footnote_register_type_name_null);
1274 t = name_holder.c_str ();
1276 /* Chop a leading builtin_type. */
1277 if (startswith (t, blt))
1280 fprintf_unfiltered (file, " %-15s", t);
1283 /* Leading space always present. */
1284 fprintf_unfiltered (file, " ");
1286 dump_reg (file, regnum);
1288 fprintf_unfiltered (file, "\n");
1291 if (footnote_register_offset)
1292 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1293 footnote_register_offset);
1294 if (footnote_register_type_name_null)
1295 fprintf_unfiltered (file,
1296 "*%d: Register type's name NULL.\n",
1297 footnote_register_type_name_null);
1301 #include "selftest.h"
1302 #include "selftest-arch.h"
1303 #include "gdbthread.h"
1304 #include "target-float.h"
1306 namespace selftests {
1308 class regcache_access : public regcache
1312 /* Return the number of elements in current_regcache. */
1315 current_regcache_size ()
1317 return std::distance (regcache::current_regcache.begin (),
1318 regcache::current_regcache.end ());
1323 current_regcache_test (void)
1325 /* It is empty at the start. */
1326 SELF_CHECK (regcache_access::current_regcache_size () == 0);
1328 ptid_t ptid1 (1), ptid2 (2), ptid3 (3);
1330 /* Get regcache from ptid1, a new regcache is added to
1331 current_regcache. */
1332 regcache *regcache = get_thread_arch_aspace_regcache (ptid1,
1336 SELF_CHECK (regcache != NULL);
1337 SELF_CHECK (regcache->ptid () == ptid1);
1338 SELF_CHECK (regcache_access::current_regcache_size () == 1);
1340 /* Get regcache from ptid2, a new regcache is added to
1341 current_regcache. */
1342 regcache = get_thread_arch_aspace_regcache (ptid2,
1345 SELF_CHECK (regcache != NULL);
1346 SELF_CHECK (regcache->ptid () == ptid2);
1347 SELF_CHECK (regcache_access::current_regcache_size () == 2);
1349 /* Get regcache from ptid3, a new regcache is added to
1350 current_regcache. */
1351 regcache = get_thread_arch_aspace_regcache (ptid3,
1354 SELF_CHECK (regcache != NULL);
1355 SELF_CHECK (regcache->ptid () == ptid3);
1356 SELF_CHECK (regcache_access::current_regcache_size () == 3);
1358 /* Get regcache from ptid2 again, nothing is added to
1359 current_regcache. */
1360 regcache = get_thread_arch_aspace_regcache (ptid2,
1363 SELF_CHECK (regcache != NULL);
1364 SELF_CHECK (regcache->ptid () == ptid2);
1365 SELF_CHECK (regcache_access::current_regcache_size () == 3);
1367 /* Mark ptid2 is changed, so regcache of ptid2 should be removed from
1368 current_regcache. */
1369 registers_changed_ptid (ptid2);
1370 SELF_CHECK (regcache_access::current_regcache_size () == 2);
1373 class target_ops_no_register : public test_target_ops
1376 target_ops_no_register ()
1377 : test_target_ops {}
1382 fetch_registers_called = 0;
1383 store_registers_called = 0;
1384 xfer_partial_called = 0;
1387 void fetch_registers (regcache *regs, int regno) override;
1388 void store_registers (regcache *regs, int regno) override;
1390 enum target_xfer_status xfer_partial (enum target_object object,
1391 const char *annex, gdb_byte *readbuf,
1392 const gdb_byte *writebuf,
1393 ULONGEST offset, ULONGEST len,
1394 ULONGEST *xfered_len) override;
1396 unsigned int fetch_registers_called = 0;
1397 unsigned int store_registers_called = 0;
1398 unsigned int xfer_partial_called = 0;
1402 target_ops_no_register::fetch_registers (regcache *regs, int regno)
1404 /* Mark register available. */
1405 regs->raw_supply_zeroed (regno);
1406 this->fetch_registers_called++;
1410 target_ops_no_register::store_registers (regcache *regs, int regno)
1412 this->store_registers_called++;
1415 enum target_xfer_status
1416 target_ops_no_register::xfer_partial (enum target_object object,
1417 const char *annex, gdb_byte *readbuf,
1418 const gdb_byte *writebuf,
1419 ULONGEST offset, ULONGEST len,
1420 ULONGEST *xfered_len)
1422 this->xfer_partial_called++;
1425 return TARGET_XFER_OK;
1428 class readwrite_regcache : public regcache
1431 readwrite_regcache (struct gdbarch *gdbarch)
1432 : regcache (gdbarch, nullptr)
1436 /* Test regcache::cooked_read gets registers from raw registers and
1437 memory instead of target to_{fetch,store}_registers. */
1440 cooked_read_test (struct gdbarch *gdbarch)
1442 /* Error out if debugging something, because we're going to push the
1443 test target, which would pop any existing target. */
1444 if (current_top_target ()->to_stratum >= process_stratum)
1445 error (_("target already pushed"));
1447 /* Create a mock environment. An inferior with a thread, with a
1448 process_stratum target pushed. */
1450 target_ops_no_register mock_target;
1451 ptid_t mock_ptid (1, 1);
1452 inferior mock_inferior (mock_ptid.pid ());
1453 address_space mock_aspace {};
1454 mock_inferior.gdbarch = gdbarch;
1455 mock_inferior.aspace = &mock_aspace;
1456 thread_info mock_thread (&mock_inferior, mock_ptid);
1458 scoped_restore restore_thread_list
1459 = make_scoped_restore (&thread_list, &mock_thread);
1461 /* Add the mock inferior to the inferior list so that look ups by
1462 target+ptid can find it. */
1463 scoped_restore restore_inferior_list
1464 = make_scoped_restore (&inferior_list);
1465 inferior_list = &mock_inferior;
1467 /* Switch to the mock inferior. */
1468 scoped_restore_current_inferior restore_current_inferior;
1469 set_current_inferior (&mock_inferior);
1471 /* Push the process_stratum target so we can mock accessing
1473 push_target (&mock_target);
1475 /* Pop it again on exit (return/exception). */
1480 pop_all_targets_at_and_above (process_stratum);
1484 /* Switch to the mock thread. */
1485 scoped_restore restore_inferior_ptid
1486 = make_scoped_restore (&inferior_ptid, mock_ptid);
1488 /* Test that read one raw register from regcache_no_target will go
1489 to the target layer. */
1492 /* Find a raw register which size isn't zero. */
1493 for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
1495 if (register_size (gdbarch, regnum) != 0)
1499 readwrite_regcache readwrite (gdbarch);
1500 gdb::def_vector<gdb_byte> buf (register_size (gdbarch, regnum));
1502 readwrite.raw_read (regnum, buf.data ());
1504 /* raw_read calls target_fetch_registers. */
1505 SELF_CHECK (mock_target.fetch_registers_called > 0);
1506 mock_target.reset ();
1508 /* Mark all raw registers valid, so the following raw registers
1509 accesses won't go to target. */
1510 for (auto i = 0; i < gdbarch_num_regs (gdbarch); i++)
1511 readwrite.raw_update (i);
1513 mock_target.reset ();
1514 /* Then, read all raw and pseudo registers, and don't expect calling
1515 to_{fetch,store}_registers. */
1516 for (int regnum = 0;
1517 regnum < gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1520 if (register_size (gdbarch, regnum) == 0)
1523 gdb::def_vector<gdb_byte> buf (register_size (gdbarch, regnum));
1525 SELF_CHECK (REG_VALID == readwrite.cooked_read (regnum, buf.data ()));
1527 SELF_CHECK (mock_target.fetch_registers_called == 0);
1528 SELF_CHECK (mock_target.store_registers_called == 0);
1530 /* Some SPU pseudo registers are got via TARGET_OBJECT_SPU. */
1531 if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_spu)
1532 SELF_CHECK (mock_target.xfer_partial_called == 0);
1534 mock_target.reset ();
1537 readonly_detached_regcache readonly (readwrite);
1539 /* GDB may go to target layer to fetch all registers and memory for
1540 readonly regcache. */
1541 mock_target.reset ();
1543 for (int regnum = 0;
1544 regnum < gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1547 if (register_size (gdbarch, regnum) == 0)
1550 gdb::def_vector<gdb_byte> buf (register_size (gdbarch, regnum));
1551 enum register_status status = readonly.cooked_read (regnum,
1554 if (regnum < gdbarch_num_regs (gdbarch))
1556 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
1558 if (bfd_arch == bfd_arch_frv || bfd_arch == bfd_arch_h8300
1559 || bfd_arch == bfd_arch_m32c || bfd_arch == bfd_arch_sh
1560 || bfd_arch == bfd_arch_alpha || bfd_arch == bfd_arch_v850
1561 || bfd_arch == bfd_arch_msp430 || bfd_arch == bfd_arch_mep
1562 || bfd_arch == bfd_arch_mips || bfd_arch == bfd_arch_v850_rh850
1563 || bfd_arch == bfd_arch_tic6x || bfd_arch == bfd_arch_mn10300
1564 || bfd_arch == bfd_arch_rl78 || bfd_arch == bfd_arch_score
1565 || bfd_arch == bfd_arch_riscv)
1567 /* Raw registers. If raw registers are not in save_reggroup,
1568 their status are unknown. */
1569 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
1570 SELF_CHECK (status == REG_VALID);
1572 SELF_CHECK (status == REG_UNKNOWN);
1575 SELF_CHECK (status == REG_VALID);
1579 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
1580 SELF_CHECK (status == REG_VALID);
1583 /* If pseudo registers are not in save_reggroup, some of
1584 them can be computed from saved raw registers, but some
1585 of them are unknown. */
1586 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
1588 if (bfd_arch == bfd_arch_frv
1589 || bfd_arch == bfd_arch_m32c
1590 || bfd_arch == bfd_arch_mep
1591 || bfd_arch == bfd_arch_sh)
1592 SELF_CHECK (status == REG_VALID || status == REG_UNKNOWN);
1593 else if (bfd_arch == bfd_arch_mips
1594 || bfd_arch == bfd_arch_h8300)
1595 SELF_CHECK (status == REG_UNKNOWN);
1597 SELF_CHECK (status == REG_VALID);
1601 SELF_CHECK (mock_target.fetch_registers_called == 0);
1602 SELF_CHECK (mock_target.store_registers_called == 0);
1603 SELF_CHECK (mock_target.xfer_partial_called == 0);
1605 mock_target.reset ();
1609 /* Test regcache::cooked_write by writing some expected contents to
1610 registers, and checking that contents read from registers and the
1611 expected contents are the same. */
1614 cooked_write_test (struct gdbarch *gdbarch)
1616 /* Error out if debugging something, because we're going to push the
1617 test target, which would pop any existing target. */
1618 if (current_top_target ()->to_stratum >= process_stratum)
1619 error (_("target already pushed"));
1621 /* Create a mock environment. A process_stratum target pushed. */
1623 target_ops_no_register mock_target;
1625 /* Push the process_stratum target so we can mock accessing
1627 push_target (&mock_target);
1629 /* Pop it again on exit (return/exception). */
1634 pop_all_targets_at_and_above (process_stratum);
1638 readwrite_regcache readwrite (gdbarch);
1640 const int num_regs = (gdbarch_num_regs (gdbarch)
1641 + gdbarch_num_pseudo_regs (gdbarch));
1643 for (auto regnum = 0; regnum < num_regs; regnum++)
1645 if (register_size (gdbarch, regnum) == 0
1646 || gdbarch_cannot_store_register (gdbarch, regnum))
1649 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
1651 if ((bfd_arch == bfd_arch_sparc
1652 /* SPARC64_CWP_REGNUM, SPARC64_PSTATE_REGNUM,
1653 SPARC64_ASI_REGNUM and SPARC64_CCR_REGNUM are hard to test. */
1654 && gdbarch_ptr_bit (gdbarch) == 64
1655 && (regnum >= gdbarch_num_regs (gdbarch)
1656 && regnum <= gdbarch_num_regs (gdbarch) + 4))
1657 || (bfd_arch == bfd_arch_spu
1658 /* SPU pseudo registers except SPU_SP_REGNUM are got by
1659 TARGET_OBJECT_SPU. */
1660 && regnum >= gdbarch_num_regs (gdbarch) && regnum != 130))
1663 std::vector<gdb_byte> expected (register_size (gdbarch, regnum), 0);
1664 std::vector<gdb_byte> buf (register_size (gdbarch, regnum), 0);
1665 const auto type = register_type (gdbarch, regnum);
1667 if (TYPE_CODE (type) == TYPE_CODE_FLT
1668 || TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
1670 /* Generate valid float format. */
1671 target_float_from_string (expected.data (), type, "1.25");
1673 else if (TYPE_CODE (type) == TYPE_CODE_INT
1674 || TYPE_CODE (type) == TYPE_CODE_ARRAY
1675 || TYPE_CODE (type) == TYPE_CODE_PTR
1676 || TYPE_CODE (type) == TYPE_CODE_UNION
1677 || TYPE_CODE (type) == TYPE_CODE_STRUCT)
1679 if (bfd_arch == bfd_arch_ia64
1680 || (regnum >= gdbarch_num_regs (gdbarch)
1681 && (bfd_arch == bfd_arch_xtensa
1682 || bfd_arch == bfd_arch_bfin
1683 || bfd_arch == bfd_arch_m32c
1684 /* m68hc11 pseudo registers are in memory. */
1685 || bfd_arch == bfd_arch_m68hc11
1686 || bfd_arch == bfd_arch_m68hc12
1687 || bfd_arch == bfd_arch_s390))
1688 || (bfd_arch == bfd_arch_frv
1689 /* FRV pseudo registers except iacc0. */
1690 && regnum > gdbarch_num_regs (gdbarch)))
1692 /* Skip setting the expected values for some architecture
1695 else if (bfd_arch == bfd_arch_rl78 && regnum == 40)
1697 /* RL78_PC_REGNUM */
1698 for (auto j = 0; j < register_size (gdbarch, regnum) - 1; j++)
1703 for (auto j = 0; j < register_size (gdbarch, regnum); j++)
1707 else if (TYPE_CODE (type) == TYPE_CODE_FLAGS)
1709 /* No idea how to test flags. */
1714 /* If we don't know how to create the expected value for the
1715 this type, make it fail. */
1719 readwrite.cooked_write (regnum, expected.data ());
1721 SELF_CHECK (readwrite.cooked_read (regnum, buf.data ()) == REG_VALID);
1722 SELF_CHECK (expected == buf);
1726 } // namespace selftests
1727 #endif /* GDB_SELF_TEST */
1730 _initialize_regcache (void)
1732 regcache_descr_handle
1733 = gdbarch_data_register_post_init (init_regcache_descr);
1735 gdb::observers::target_changed.attach (regcache_observer_target_changed);
1736 gdb::observers::thread_ptid_changed.attach
1737 (regcache::regcache_thread_ptid_changed);
1739 add_com ("flushregs", class_maintenance, reg_flush_command,
1740 _("Force gdb to flush its register cache (maintainer command)"));
1743 selftests::register_test ("current_regcache", selftests::current_regcache_test);
1745 selftests::register_test_foreach_arch ("regcache::cooked_read_test",
1746 selftests::cooked_read_test);
1747 selftests::register_test_foreach_arch ("regcache::cooked_write_test",
1748 selftests::cooked_write_test);