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 readonly_detached_regcache::readonly_detached_regcache (regcache &src)
209 : readonly_detached_regcache (src.arch (),
210 [&src] (int regnum, gdb_byte *buf)
212 return src.cooked_read (regnum, buf);
218 reg_buffer::arch () const
220 return m_descr->gdbarch;
223 /* Cleanup class for invalidating a register. */
225 class regcache_invalidator
229 regcache_invalidator (struct regcache *regcache, int regnum)
230 : m_regcache (regcache),
235 ~regcache_invalidator ()
237 if (m_regcache != nullptr)
238 m_regcache->invalidate (m_regnum);
241 DISABLE_COPY_AND_ASSIGN (regcache_invalidator);
245 m_regcache = nullptr;
250 struct regcache *m_regcache;
254 /* Return a pointer to register REGNUM's buffer cache. */
257 reg_buffer::register_buffer (int regnum) const
259 return m_registers.get () + m_descr->register_offset[regnum];
263 reg_buffer::save (register_read_ftype cooked_read)
265 struct gdbarch *gdbarch = m_descr->gdbarch;
268 /* It should have pseudo registers. */
269 gdb_assert (m_has_pseudo);
270 /* Clear the dest. */
271 memset (m_registers.get (), 0, m_descr->sizeof_cooked_registers);
272 memset (m_register_status.get (), REG_UNKNOWN, m_descr->nr_cooked_registers);
273 /* Copy over any registers (identified by their membership in the
274 save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs +
275 gdbarch_num_pseudo_regs) range is checked since some architectures need
276 to save/restore `cooked' registers that live in memory. */
277 for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
279 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
281 gdb_byte *dst_buf = register_buffer (regnum);
282 enum register_status status = cooked_read (regnum, dst_buf);
284 gdb_assert (status != REG_UNKNOWN);
286 if (status != REG_VALID)
287 memset (dst_buf, 0, register_size (gdbarch, regnum));
289 m_register_status[regnum] = status;
295 regcache::restore (readonly_detached_regcache *src)
297 struct gdbarch *gdbarch = m_descr->gdbarch;
300 gdb_assert (src != NULL);
301 gdb_assert (src->m_has_pseudo);
303 gdb_assert (gdbarch == src->arch ());
305 /* Copy over any registers, being careful to only restore those that
306 were both saved and need to be restored. The full [0 .. gdbarch_num_regs
307 + gdbarch_num_pseudo_regs) range is checked since some architectures need
308 to save/restore `cooked' registers that live in memory. */
309 for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
311 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
313 if (src->m_register_status[regnum] == REG_VALID)
314 cooked_write (regnum, src->register_buffer (regnum));
319 /* See common/common-regcache.h. */
322 reg_buffer::get_register_status (int regnum) const
324 assert_regnum (regnum);
326 return m_register_status[regnum];
330 reg_buffer::invalidate (int regnum)
332 assert_regnum (regnum);
333 m_register_status[regnum] = REG_UNKNOWN;
337 reg_buffer::assert_regnum (int regnum) const
339 gdb_assert (regnum >= 0);
341 gdb_assert (regnum < m_descr->nr_cooked_registers);
343 gdb_assert (regnum < gdbarch_num_regs (arch ()));
346 /* Global structure containing the current regcache. */
348 /* NOTE: this is a write-through cache. There is no "dirty" bit for
349 recording if the register values have been changed (eg. by the
350 user). Therefore all registers must be written back to the
351 target when appropriate. */
352 std::forward_list<regcache *> regcache::current_regcache;
355 get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
356 struct address_space *aspace)
358 for (const auto ®cache : regcache::current_regcache)
359 if (ptid_equal (regcache->ptid (), ptid) && regcache->arch () == gdbarch)
362 regcache *new_regcache = new regcache (gdbarch, aspace);
364 regcache::current_regcache.push_front (new_regcache);
365 new_regcache->set_ptid (ptid);
371 get_thread_arch_regcache (ptid_t ptid, struct gdbarch *gdbarch)
373 address_space *aspace = target_thread_address_space (ptid);
375 return get_thread_arch_aspace_regcache (ptid, gdbarch, aspace);
378 static ptid_t current_thread_ptid;
379 static struct gdbarch *current_thread_arch;
382 get_thread_regcache (ptid_t ptid)
384 if (!current_thread_arch || !ptid_equal (current_thread_ptid, ptid))
386 current_thread_ptid = ptid;
387 current_thread_arch = target_thread_architecture (ptid);
390 return get_thread_arch_regcache (ptid, current_thread_arch);
394 get_current_regcache (void)
396 return get_thread_regcache (inferior_ptid);
399 /* See common/common-regcache.h. */
402 get_thread_regcache_for_ptid (ptid_t ptid)
404 return get_thread_regcache (ptid);
407 /* Observer for the target_changed event. */
410 regcache_observer_target_changed (struct target_ops *target)
412 registers_changed ();
415 /* Update global variables old ptids to hold NEW_PTID if they were
418 regcache::regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
420 for (auto ®cache : regcache::current_regcache)
422 if (ptid_equal (regcache->ptid (), old_ptid))
423 regcache->set_ptid (new_ptid);
427 /* Low level examining and depositing of registers.
429 The caller is responsible for making sure that the inferior is
430 stopped before calling the fetching routines, or it will get
431 garbage. (a change from GDB version 3, in which the caller got the
432 value from the last stop). */
434 /* REGISTERS_CHANGED ()
436 Indicate that registers may have changed, so invalidate the cache. */
439 registers_changed_ptid (ptid_t ptid)
441 for (auto oit = regcache::current_regcache.before_begin (),
442 it = std::next (oit);
443 it != regcache::current_regcache.end ();
446 if (ptid_match ((*it)->ptid (), ptid))
449 it = regcache::current_regcache.erase_after (oit);
455 if (ptid_match (current_thread_ptid, ptid))
457 current_thread_ptid = null_ptid;
458 current_thread_arch = NULL;
461 if (ptid_match (inferior_ptid, ptid))
463 /* We just deleted the regcache of the current thread. Need to
464 forget about any frames we have cached, too. */
465 reinit_frame_cache ();
470 registers_changed (void)
472 registers_changed_ptid (minus_one_ptid);
474 /* Force cleanup of any alloca areas if using C alloca instead of
475 a builtin alloca. This particular call is used to clean up
476 areas allocated by low level target code which may build up
477 during lengthy interactions between gdb and the target before
478 gdb gives control to the user (ie watchpoints). */
483 regcache::raw_update (int regnum)
485 assert_regnum (regnum);
487 /* Make certain that the register cache is up-to-date with respect
488 to the current thread. This switching shouldn't be necessary
489 only there is still only one target side register cache. Sigh!
490 On the bright side, at least there is a regcache object. */
492 if (get_register_status (regnum) == REG_UNKNOWN)
494 target_fetch_registers (this, regnum);
496 /* A number of targets can't access the whole set of raw
497 registers (because the debug API provides no means to get at
499 if (m_register_status[regnum] == REG_UNKNOWN)
500 m_register_status[regnum] = REG_UNAVAILABLE;
505 readable_regcache::raw_read (int regnum, gdb_byte *buf)
507 gdb_assert (buf != NULL);
510 if (m_register_status[regnum] != REG_VALID)
511 memset (buf, 0, m_descr->sizeof_register[regnum]);
513 memcpy (buf, register_buffer (regnum),
514 m_descr->sizeof_register[regnum]);
516 return m_register_status[regnum];
520 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
522 gdb_assert (regcache != NULL);
523 return regcache->raw_read (regnum, val);
526 template<typename T, typename>
528 readable_regcache::raw_read (int regnum, T *val)
531 enum register_status status;
533 assert_regnum (regnum);
534 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
535 status = raw_read (regnum, buf);
536 if (status == REG_VALID)
537 *val = extract_integer<T> (buf,
538 m_descr->sizeof_register[regnum],
539 gdbarch_byte_order (m_descr->gdbarch));
546 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
549 gdb_assert (regcache != NULL);
550 return regcache->raw_read (regnum, val);
554 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
556 gdb_assert (regcache != NULL);
557 regcache->raw_write (regnum, val);
560 template<typename T, typename>
562 regcache::raw_write (int regnum, T val)
566 assert_regnum (regnum);
567 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
568 store_integer (buf, m_descr->sizeof_register[regnum],
569 gdbarch_byte_order (m_descr->gdbarch), val);
570 raw_write (regnum, buf);
574 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
577 gdb_assert (regcache != NULL);
578 regcache->raw_write (regnum, val);
582 regcache_raw_get_signed (struct regcache *regcache, int regnum)
585 enum register_status status;
587 status = regcache_raw_read_signed (regcache, regnum, &value);
588 if (status == REG_UNAVAILABLE)
589 throw_error (NOT_AVAILABLE_ERROR,
590 _("Register %d is not available"), regnum);
595 readable_regcache::cooked_read (int regnum, gdb_byte *buf)
597 gdb_assert (regnum >= 0);
598 gdb_assert (regnum < m_descr->nr_cooked_registers);
599 if (regnum < num_raw_registers ())
600 return raw_read (regnum, buf);
601 else if (m_has_pseudo
602 && m_register_status[regnum] != REG_UNKNOWN)
604 if (m_register_status[regnum] == REG_VALID)
605 memcpy (buf, register_buffer (regnum),
606 m_descr->sizeof_register[regnum]);
608 memset (buf, 0, m_descr->sizeof_register[regnum]);
610 return m_register_status[regnum];
612 else if (gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
614 struct value *mark, *computed;
615 enum register_status result = REG_VALID;
617 mark = value_mark ();
619 computed = gdbarch_pseudo_register_read_value (m_descr->gdbarch,
621 if (value_entirely_available (computed))
622 memcpy (buf, value_contents_raw (computed),
623 m_descr->sizeof_register[regnum]);
626 memset (buf, 0, m_descr->sizeof_register[regnum]);
627 result = REG_UNAVAILABLE;
630 value_free_to_mark (mark);
635 return gdbarch_pseudo_register_read (m_descr->gdbarch, this,
640 readable_regcache::cooked_read_value (int regnum)
642 gdb_assert (regnum >= 0);
643 gdb_assert (regnum < m_descr->nr_cooked_registers);
645 if (regnum < num_raw_registers ()
646 || (m_has_pseudo && m_register_status[regnum] != REG_UNKNOWN)
647 || !gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
649 struct value *result;
651 result = allocate_value (register_type (m_descr->gdbarch, regnum));
652 VALUE_LVAL (result) = lval_register;
653 VALUE_REGNUM (result) = regnum;
655 /* It is more efficient in general to do this delegation in this
656 direction than in the other one, even though the value-based
658 if (cooked_read (regnum,
659 value_contents_raw (result)) == REG_UNAVAILABLE)
660 mark_value_bytes_unavailable (result, 0,
661 TYPE_LENGTH (value_type (result)));
666 return gdbarch_pseudo_register_read_value (m_descr->gdbarch,
671 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
674 gdb_assert (regcache != NULL);
675 return regcache->cooked_read (regnum, val);
678 template<typename T, typename>
680 readable_regcache::cooked_read (int regnum, T *val)
682 enum register_status status;
685 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
686 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
687 status = cooked_read (regnum, buf);
688 if (status == REG_VALID)
689 *val = extract_integer<T> (buf, m_descr->sizeof_register[regnum],
690 gdbarch_byte_order (m_descr->gdbarch));
697 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
700 gdb_assert (regcache != NULL);
701 return regcache->cooked_read (regnum, val);
705 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
708 gdb_assert (regcache != NULL);
709 regcache->cooked_write (regnum, val);
712 template<typename T, typename>
714 regcache::cooked_write (int regnum, T val)
718 gdb_assert (regnum >=0 && regnum < m_descr->nr_cooked_registers);
719 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
720 store_integer (buf, m_descr->sizeof_register[regnum],
721 gdbarch_byte_order (m_descr->gdbarch), val);
722 cooked_write (regnum, buf);
726 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
729 gdb_assert (regcache != NULL);
730 regcache->cooked_write (regnum, val);
734 regcache::raw_write (int regnum, const gdb_byte *buf)
737 gdb_assert (buf != NULL);
738 assert_regnum (regnum);
740 /* On the sparc, writing %g0 is a no-op, so we don't even want to
741 change the registers array if something writes to this register. */
742 if (gdbarch_cannot_store_register (arch (), regnum))
745 /* If we have a valid copy of the register, and new value == old
746 value, then don't bother doing the actual store. */
747 if (get_register_status (regnum) == REG_VALID
748 && (memcmp (register_buffer (regnum), buf,
749 m_descr->sizeof_register[regnum]) == 0))
752 target_prepare_to_store (this);
753 raw_supply (regnum, buf);
755 /* Invalidate the register after it is written, in case of a
757 regcache_invalidator invalidator (this, regnum);
759 target_store_registers (this, regnum);
761 /* The target did not throw an error so we can discard invalidating
763 invalidator.release ();
767 regcache::cooked_write (int regnum, const gdb_byte *buf)
769 gdb_assert (regnum >= 0);
770 gdb_assert (regnum < m_descr->nr_cooked_registers);
771 if (regnum < num_raw_registers ())
772 raw_write (regnum, buf);
774 gdbarch_pseudo_register_write (m_descr->gdbarch, this,
778 /* See regcache.h. */
781 readable_regcache::read_part (int regnum, int offset, int len,
782 gdb_byte *out, bool is_raw)
784 int reg_size = register_size (arch (), regnum);
786 gdb_assert (out != NULL);
787 gdb_assert (offset >= 0 && len >= 0 && offset + len <= reg_size);
789 if (offset == 0 && len == 0)
795 if (offset == 0 && len == reg_size)
797 /* Read the full register. */
798 return (is_raw) ? raw_read (regnum, out) : cooked_read (regnum, out);
801 enum register_status status;
802 gdb_byte *reg = (gdb_byte *) alloca (reg_size);
804 /* Read full register to buffer. */
805 status = (is_raw) ? raw_read (regnum, reg) : cooked_read (regnum, reg);
806 if (status != REG_VALID)
810 memcpy (out, reg + offset, len);
814 /* See regcache.h. */
817 regcache::write_part (int regnum, int offset, int len,
818 const gdb_byte *in, bool is_raw)
820 int reg_size = register_size (arch (), regnum);
822 gdb_assert (in != NULL);
823 gdb_assert (offset >= 0 && len >= 0 && offset + len <= reg_size);
825 if (offset == 0 && len == 0)
831 if (offset == 0 && len == reg_size)
833 /* Write the full register. */
834 (is_raw) ? raw_write (regnum, in) : cooked_write (regnum, in);
838 enum register_status status;
839 gdb_byte *reg = (gdb_byte *) alloca (reg_size);
841 /* Read existing register to buffer. */
842 status = (is_raw) ? raw_read (regnum, reg) : cooked_read (regnum, reg);
843 if (status != REG_VALID)
846 /* Update buffer, then write back to regcache. */
847 memcpy (reg + offset, in, len);
848 is_raw ? raw_write (regnum, reg) : cooked_write (regnum, reg);
852 /* See regcache.h. */
855 readable_regcache::raw_read_part (int regnum, int offset, int len,
858 assert_regnum (regnum);
859 return read_part (regnum, offset, len, buf, true);
862 /* See regcache.h. */
865 regcache::raw_write_part (int regnum, int offset, int len,
868 assert_regnum (regnum);
869 write_part (regnum, offset, len, buf, true);
872 /* See regcache.h. */
875 readable_regcache::cooked_read_part (int regnum, int offset, int len,
878 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
879 return read_part (regnum, offset, len, buf, false);
882 /* See regcache.h. */
885 regcache::cooked_write_part (int regnum, int offset, int len,
888 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
889 write_part (regnum, offset, len, buf, false);
892 /* See common/common-regcache.h. */
895 reg_buffer::raw_supply (int regnum, const void *buf)
900 assert_regnum (regnum);
902 regbuf = register_buffer (regnum);
903 size = m_descr->sizeof_register[regnum];
907 memcpy (regbuf, buf, size);
908 m_register_status[regnum] = REG_VALID;
912 /* This memset not strictly necessary, but better than garbage
913 in case the register value manages to escape somewhere (due
914 to a bug, no less). */
915 memset (regbuf, 0, size);
916 m_register_status[regnum] = REG_UNAVAILABLE;
920 /* See regcache.h. */
923 reg_buffer::raw_supply_integer (int regnum, const gdb_byte *addr,
924 int addr_len, bool is_signed)
926 enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
930 assert_regnum (regnum);
932 regbuf = register_buffer (regnum);
933 regsize = m_descr->sizeof_register[regnum];
935 copy_integer_to_size (regbuf, regsize, addr, addr_len, is_signed,
937 m_register_status[regnum] = REG_VALID;
940 /* See regcache.h. */
943 reg_buffer::raw_supply_zeroed (int regnum)
948 assert_regnum (regnum);
950 regbuf = register_buffer (regnum);
951 size = m_descr->sizeof_register[regnum];
953 memset (regbuf, 0, size);
954 m_register_status[regnum] = REG_VALID;
957 /* See common/common-regcache.h. */
960 reg_buffer::raw_collect (int regnum, void *buf) const
965 gdb_assert (buf != NULL);
966 assert_regnum (regnum);
968 regbuf = register_buffer (regnum);
969 size = m_descr->sizeof_register[regnum];
970 memcpy (buf, regbuf, size);
973 /* See regcache.h. */
976 reg_buffer::raw_collect_integer (int regnum, gdb_byte *addr, int addr_len,
977 bool is_signed) const
979 enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
980 const gdb_byte *regbuf;
983 assert_regnum (regnum);
985 regbuf = register_buffer (regnum);
986 regsize = m_descr->sizeof_register[regnum];
988 copy_integer_to_size (addr, addr_len, regbuf, regsize, is_signed,
992 /* Transfer a single or all registers belonging to a certain register
993 set to or from a buffer. This is the main worker function for
994 regcache_supply_regset and regcache_collect_regset. */
997 regcache::transfer_regset (const struct regset *regset,
998 struct regcache *out_regcache,
999 int regnum, const void *in_buf,
1000 void *out_buf, size_t size) const
1002 const struct regcache_map_entry *map;
1003 int offs = 0, count;
1005 for (map = (const struct regcache_map_entry *) regset->regmap;
1006 (count = map->count) != 0;
1009 int regno = map->regno;
1010 int slot_size = map->size;
1012 if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
1013 slot_size = m_descr->sizeof_register[regno];
1015 if (regno == REGCACHE_MAP_SKIP
1017 && (regnum < regno || regnum >= regno + count)))
1018 offs += count * slot_size;
1020 else if (regnum == -1)
1021 for (; count--; regno++, offs += slot_size)
1023 if (offs + slot_size > size)
1027 raw_collect (regno, (gdb_byte *) out_buf + offs);
1029 out_regcache->raw_supply (regno, in_buf
1030 ? (const gdb_byte *) in_buf + offs
1035 /* Transfer a single register and return. */
1036 offs += (regnum - regno) * slot_size;
1037 if (offs + slot_size > size)
1041 raw_collect (regnum, (gdb_byte *) out_buf + offs);
1043 out_regcache->raw_supply (regnum, in_buf
1044 ? (const gdb_byte *) in_buf + offs
1051 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1052 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1053 If BUF is NULL, set the register(s) to "unavailable" status. */
1056 regcache_supply_regset (const struct regset *regset,
1057 struct regcache *regcache,
1058 int regnum, const void *buf, size_t size)
1060 regcache->supply_regset (regset, regnum, buf, size);
1064 regcache::supply_regset (const struct regset *regset,
1065 int regnum, const void *buf, size_t size)
1067 transfer_regset (regset, this, regnum, buf, NULL, size);
1070 /* Collect register REGNUM from REGCACHE to BUF, using the register
1071 map in REGSET. If REGNUM is -1, do this for all registers in
1075 regcache_collect_regset (const struct regset *regset,
1076 const struct regcache *regcache,
1077 int regnum, void *buf, size_t size)
1079 regcache->collect_regset (regset, regnum, buf, size);
1083 regcache::collect_regset (const struct regset *regset,
1084 int regnum, void *buf, size_t size) const
1086 transfer_regset (regset, NULL, regnum, NULL, buf, size);
1089 /* See common/common-regcache.h. */
1092 reg_buffer::raw_compare (int regnum, const void *buf, int offset) const
1094 gdb_assert (buf != NULL);
1095 assert_regnum (regnum);
1097 const char *regbuf = (const char *) register_buffer (regnum);
1098 size_t size = m_descr->sizeof_register[regnum];
1099 gdb_assert (size >= offset);
1101 return (memcmp (buf, regbuf + offset, size - offset) == 0);
1104 /* Special handling for register PC. */
1107 regcache_read_pc (struct regcache *regcache)
1109 struct gdbarch *gdbarch = regcache->arch ();
1113 if (gdbarch_read_pc_p (gdbarch))
1114 pc_val = gdbarch_read_pc (gdbarch, regcache);
1115 /* Else use per-frame method on get_current_frame. */
1116 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1120 if (regcache_cooked_read_unsigned (regcache,
1121 gdbarch_pc_regnum (gdbarch),
1122 &raw_val) == REG_UNAVAILABLE)
1123 throw_error (NOT_AVAILABLE_ERROR, _("PC register is not available"));
1125 pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val);
1128 internal_error (__FILE__, __LINE__,
1129 _("regcache_read_pc: Unable to find PC"));
1134 regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
1136 struct gdbarch *gdbarch = regcache->arch ();
1138 if (gdbarch_write_pc_p (gdbarch))
1139 gdbarch_write_pc (gdbarch, regcache, pc);
1140 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1141 regcache_cooked_write_unsigned (regcache,
1142 gdbarch_pc_regnum (gdbarch), pc);
1144 internal_error (__FILE__, __LINE__,
1145 _("regcache_write_pc: Unable to update PC"));
1147 /* Writing the PC (for instance, from "load") invalidates the
1149 reinit_frame_cache ();
1153 reg_buffer::num_raw_registers () const
1155 return gdbarch_num_regs (arch ());
1159 regcache::debug_print_register (const char *func, int regno)
1161 struct gdbarch *gdbarch = arch ();
1163 fprintf_unfiltered (gdb_stdlog, "%s ", func);
1164 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
1165 && gdbarch_register_name (gdbarch, regno) != NULL
1166 && gdbarch_register_name (gdbarch, regno)[0] != '\0')
1167 fprintf_unfiltered (gdb_stdlog, "(%s)",
1168 gdbarch_register_name (gdbarch, regno));
1170 fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
1171 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch))
1173 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1174 int size = register_size (gdbarch, regno);
1175 gdb_byte *buf = register_buffer (regno);
1177 fprintf_unfiltered (gdb_stdlog, " = ");
1178 for (int i = 0; i < size; i++)
1180 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
1182 if (size <= sizeof (LONGEST))
1184 ULONGEST val = extract_unsigned_integer (buf, size, byte_order);
1186 fprintf_unfiltered (gdb_stdlog, " %s %s",
1187 core_addr_to_string_nz (val), plongest (val));
1190 fprintf_unfiltered (gdb_stdlog, "\n");
1194 reg_flush_command (const char *command, int from_tty)
1196 /* Force-flush the register cache. */
1197 registers_changed ();
1199 printf_filtered (_("Register cache flushed.\n"));
1203 register_dump::dump (ui_file *file)
1205 auto descr = regcache_descr (m_gdbarch);
1207 int footnote_nr = 0;
1208 int footnote_register_offset = 0;
1209 int footnote_register_type_name_null = 0;
1210 long register_offset = 0;
1212 gdb_assert (descr->nr_cooked_registers
1213 == (gdbarch_num_regs (m_gdbarch)
1214 + gdbarch_num_pseudo_regs (m_gdbarch)));
1216 for (regnum = -1; regnum < descr->nr_cooked_registers; regnum++)
1220 fprintf_unfiltered (file, " %-10s", "Name");
1223 const char *p = gdbarch_register_name (m_gdbarch, regnum);
1227 else if (p[0] == '\0')
1229 fprintf_unfiltered (file, " %-10s", p);
1234 fprintf_unfiltered (file, " %4s", "Nr");
1236 fprintf_unfiltered (file, " %4d", regnum);
1238 /* Relative number. */
1240 fprintf_unfiltered (file, " %4s", "Rel");
1241 else if (regnum < gdbarch_num_regs (m_gdbarch))
1242 fprintf_unfiltered (file, " %4d", regnum);
1244 fprintf_unfiltered (file, " %4d",
1245 (regnum - gdbarch_num_regs (m_gdbarch)));
1249 fprintf_unfiltered (file, " %6s ", "Offset");
1252 fprintf_unfiltered (file, " %6ld",
1253 descr->register_offset[regnum]);
1254 if (register_offset != descr->register_offset[regnum]
1256 && (descr->register_offset[regnum]
1257 != (descr->register_offset[regnum - 1]
1258 + descr->sizeof_register[regnum - 1])))
1261 if (!footnote_register_offset)
1262 footnote_register_offset = ++footnote_nr;
1263 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1266 fprintf_unfiltered (file, " ");
1267 register_offset = (descr->register_offset[regnum]
1268 + descr->sizeof_register[regnum]);
1273 fprintf_unfiltered (file, " %5s ", "Size");
1275 fprintf_unfiltered (file, " %5ld", descr->sizeof_register[regnum]);
1280 std::string name_holder;
1286 static const char blt[] = "builtin_type";
1288 t = TYPE_NAME (register_type (m_gdbarch, regnum));
1291 if (!footnote_register_type_name_null)
1292 footnote_register_type_name_null = ++footnote_nr;
1293 name_holder = string_printf ("*%d",
1294 footnote_register_type_name_null);
1295 t = name_holder.c_str ();
1297 /* Chop a leading builtin_type. */
1298 if (startswith (t, blt))
1301 fprintf_unfiltered (file, " %-15s", t);
1304 /* Leading space always present. */
1305 fprintf_unfiltered (file, " ");
1307 dump_reg (file, regnum);
1309 fprintf_unfiltered (file, "\n");
1312 if (footnote_register_offset)
1313 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1314 footnote_register_offset);
1315 if (footnote_register_type_name_null)
1316 fprintf_unfiltered (file,
1317 "*%d: Register type's name NULL.\n",
1318 footnote_register_type_name_null);
1322 #include "selftest.h"
1323 #include "selftest-arch.h"
1324 #include "gdbthread.h"
1325 #include "target-float.h"
1327 namespace selftests {
1329 class regcache_access : public regcache
1333 /* Return the number of elements in current_regcache. */
1336 current_regcache_size ()
1338 return std::distance (regcache::current_regcache.begin (),
1339 regcache::current_regcache.end ());
1344 current_regcache_test (void)
1346 /* It is empty at the start. */
1347 SELF_CHECK (regcache_access::current_regcache_size () == 0);
1349 ptid_t ptid1 (1), ptid2 (2), ptid3 (3);
1351 /* Get regcache from ptid1, a new regcache is added to
1352 current_regcache. */
1353 regcache *regcache = get_thread_arch_aspace_regcache (ptid1,
1357 SELF_CHECK (regcache != NULL);
1358 SELF_CHECK (regcache->ptid () == ptid1);
1359 SELF_CHECK (regcache_access::current_regcache_size () == 1);
1361 /* Get regcache from ptid2, a new regcache is added to
1362 current_regcache. */
1363 regcache = get_thread_arch_aspace_regcache (ptid2,
1366 SELF_CHECK (regcache != NULL);
1367 SELF_CHECK (regcache->ptid () == ptid2);
1368 SELF_CHECK (regcache_access::current_regcache_size () == 2);
1370 /* Get regcache from ptid3, a new regcache is added to
1371 current_regcache. */
1372 regcache = get_thread_arch_aspace_regcache (ptid3,
1375 SELF_CHECK (regcache != NULL);
1376 SELF_CHECK (regcache->ptid () == ptid3);
1377 SELF_CHECK (regcache_access::current_regcache_size () == 3);
1379 /* Get regcache from ptid2 again, nothing is added to
1380 current_regcache. */
1381 regcache = get_thread_arch_aspace_regcache (ptid2,
1384 SELF_CHECK (regcache != NULL);
1385 SELF_CHECK (regcache->ptid () == ptid2);
1386 SELF_CHECK (regcache_access::current_regcache_size () == 3);
1388 /* Mark ptid2 is changed, so regcache of ptid2 should be removed from
1389 current_regcache. */
1390 registers_changed_ptid (ptid2);
1391 SELF_CHECK (regcache_access::current_regcache_size () == 2);
1394 class target_ops_no_register : public test_target_ops
1397 target_ops_no_register ()
1398 : test_target_ops {}
1403 fetch_registers_called = 0;
1404 store_registers_called = 0;
1405 xfer_partial_called = 0;
1408 void fetch_registers (regcache *regs, int regno) override;
1409 void store_registers (regcache *regs, int regno) override;
1411 enum target_xfer_status xfer_partial (enum target_object object,
1412 const char *annex, gdb_byte *readbuf,
1413 const gdb_byte *writebuf,
1414 ULONGEST offset, ULONGEST len,
1415 ULONGEST *xfered_len) override;
1417 unsigned int fetch_registers_called = 0;
1418 unsigned int store_registers_called = 0;
1419 unsigned int xfer_partial_called = 0;
1423 target_ops_no_register::fetch_registers (regcache *regs, int regno)
1425 /* Mark register available. */
1426 regs->raw_supply_zeroed (regno);
1427 this->fetch_registers_called++;
1431 target_ops_no_register::store_registers (regcache *regs, int regno)
1433 this->store_registers_called++;
1436 enum target_xfer_status
1437 target_ops_no_register::xfer_partial (enum target_object object,
1438 const char *annex, gdb_byte *readbuf,
1439 const gdb_byte *writebuf,
1440 ULONGEST offset, ULONGEST len,
1441 ULONGEST *xfered_len)
1443 this->xfer_partial_called++;
1446 return TARGET_XFER_OK;
1449 class readwrite_regcache : public regcache
1452 readwrite_regcache (struct gdbarch *gdbarch)
1453 : regcache (gdbarch, nullptr)
1457 /* Test regcache::cooked_read gets registers from raw registers and
1458 memory instead of target to_{fetch,store}_registers. */
1461 cooked_read_test (struct gdbarch *gdbarch)
1463 /* Error out if debugging something, because we're going to push the
1464 test target, which would pop any existing target. */
1465 if (current_top_target ()->to_stratum >= process_stratum)
1466 error (_("target already pushed"));
1468 /* Create a mock environment. An inferior with a thread, with a
1469 process_stratum target pushed. */
1471 target_ops_no_register mock_target;
1472 ptid_t mock_ptid (1, 1);
1473 inferior mock_inferior (mock_ptid.pid ());
1474 address_space mock_aspace {};
1475 mock_inferior.gdbarch = gdbarch;
1476 mock_inferior.aspace = &mock_aspace;
1477 thread_info mock_thread (&mock_inferior, mock_ptid);
1479 scoped_restore restore_thread_list
1480 = make_scoped_restore (&thread_list, &mock_thread);
1482 /* Add the mock inferior to the inferior list so that look ups by
1483 target+ptid can find it. */
1484 scoped_restore restore_inferior_list
1485 = make_scoped_restore (&inferior_list);
1486 inferior_list = &mock_inferior;
1488 /* Switch to the mock inferior. */
1489 scoped_restore_current_inferior restore_current_inferior;
1490 set_current_inferior (&mock_inferior);
1492 /* Push the process_stratum target so we can mock accessing
1494 push_target (&mock_target);
1496 /* Pop it again on exit (return/exception). */
1501 pop_all_targets_at_and_above (process_stratum);
1505 /* Switch to the mock thread. */
1506 scoped_restore restore_inferior_ptid
1507 = make_scoped_restore (&inferior_ptid, mock_ptid);
1509 /* Test that read one raw register from regcache_no_target will go
1510 to the target layer. */
1513 /* Find a raw register which size isn't zero. */
1514 for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
1516 if (register_size (gdbarch, regnum) != 0)
1520 readwrite_regcache readwrite (gdbarch);
1521 gdb::def_vector<gdb_byte> buf (register_size (gdbarch, regnum));
1523 readwrite.raw_read (regnum, buf.data ());
1525 /* raw_read calls target_fetch_registers. */
1526 SELF_CHECK (mock_target.fetch_registers_called > 0);
1527 mock_target.reset ();
1529 /* Mark all raw registers valid, so the following raw registers
1530 accesses won't go to target. */
1531 for (auto i = 0; i < gdbarch_num_regs (gdbarch); i++)
1532 readwrite.raw_update (i);
1534 mock_target.reset ();
1535 /* Then, read all raw and pseudo registers, and don't expect calling
1536 to_{fetch,store}_registers. */
1537 for (int regnum = 0;
1538 regnum < gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1541 if (register_size (gdbarch, regnum) == 0)
1544 gdb::def_vector<gdb_byte> buf (register_size (gdbarch, regnum));
1546 SELF_CHECK (REG_VALID == readwrite.cooked_read (regnum, buf.data ()));
1548 SELF_CHECK (mock_target.fetch_registers_called == 0);
1549 SELF_CHECK (mock_target.store_registers_called == 0);
1551 /* Some SPU pseudo registers are got via TARGET_OBJECT_SPU. */
1552 if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_spu)
1553 SELF_CHECK (mock_target.xfer_partial_called == 0);
1555 mock_target.reset ();
1558 readonly_detached_regcache readonly (readwrite);
1560 /* GDB may go to target layer to fetch all registers and memory for
1561 readonly regcache. */
1562 mock_target.reset ();
1564 for (int regnum = 0;
1565 regnum < gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
1568 if (register_size (gdbarch, regnum) == 0)
1571 gdb::def_vector<gdb_byte> buf (register_size (gdbarch, regnum));
1572 enum register_status status = readonly.cooked_read (regnum,
1575 if (regnum < gdbarch_num_regs (gdbarch))
1577 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
1579 if (bfd_arch == bfd_arch_frv || bfd_arch == bfd_arch_h8300
1580 || bfd_arch == bfd_arch_m32c || bfd_arch == bfd_arch_sh
1581 || bfd_arch == bfd_arch_alpha || bfd_arch == bfd_arch_v850
1582 || bfd_arch == bfd_arch_msp430 || bfd_arch == bfd_arch_mep
1583 || bfd_arch == bfd_arch_mips || bfd_arch == bfd_arch_v850_rh850
1584 || bfd_arch == bfd_arch_tic6x || bfd_arch == bfd_arch_mn10300
1585 || bfd_arch == bfd_arch_rl78 || bfd_arch == bfd_arch_score
1586 || bfd_arch == bfd_arch_riscv)
1588 /* Raw registers. If raw registers are not in save_reggroup,
1589 their status are unknown. */
1590 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
1591 SELF_CHECK (status == REG_VALID);
1593 SELF_CHECK (status == REG_UNKNOWN);
1596 SELF_CHECK (status == REG_VALID);
1600 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
1601 SELF_CHECK (status == REG_VALID);
1604 /* If pseudo registers are not in save_reggroup, some of
1605 them can be computed from saved raw registers, but some
1606 of them are unknown. */
1607 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
1609 if (bfd_arch == bfd_arch_frv
1610 || bfd_arch == bfd_arch_m32c
1611 || bfd_arch == bfd_arch_mep
1612 || bfd_arch == bfd_arch_sh)
1613 SELF_CHECK (status == REG_VALID || status == REG_UNKNOWN);
1614 else if (bfd_arch == bfd_arch_mips
1615 || bfd_arch == bfd_arch_h8300)
1616 SELF_CHECK (status == REG_UNKNOWN);
1618 SELF_CHECK (status == REG_VALID);
1622 SELF_CHECK (mock_target.fetch_registers_called == 0);
1623 SELF_CHECK (mock_target.store_registers_called == 0);
1624 SELF_CHECK (mock_target.xfer_partial_called == 0);
1626 mock_target.reset ();
1630 /* Test regcache::cooked_write by writing some expected contents to
1631 registers, and checking that contents read from registers and the
1632 expected contents are the same. */
1635 cooked_write_test (struct gdbarch *gdbarch)
1637 /* Error out if debugging something, because we're going to push the
1638 test target, which would pop any existing target. */
1639 if (current_top_target ()->to_stratum >= process_stratum)
1640 error (_("target already pushed"));
1642 /* Create a mock environment. A process_stratum target pushed. */
1644 target_ops_no_register mock_target;
1646 /* Push the process_stratum target so we can mock accessing
1648 push_target (&mock_target);
1650 /* Pop it again on exit (return/exception). */
1655 pop_all_targets_at_and_above (process_stratum);
1659 readwrite_regcache readwrite (gdbarch);
1661 const int num_regs = (gdbarch_num_regs (gdbarch)
1662 + gdbarch_num_pseudo_regs (gdbarch));
1664 for (auto regnum = 0; regnum < num_regs; regnum++)
1666 if (register_size (gdbarch, regnum) == 0
1667 || gdbarch_cannot_store_register (gdbarch, regnum))
1670 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
1672 if ((bfd_arch == bfd_arch_sparc
1673 /* SPARC64_CWP_REGNUM, SPARC64_PSTATE_REGNUM,
1674 SPARC64_ASI_REGNUM and SPARC64_CCR_REGNUM are hard to test. */
1675 && gdbarch_ptr_bit (gdbarch) == 64
1676 && (regnum >= gdbarch_num_regs (gdbarch)
1677 && regnum <= gdbarch_num_regs (gdbarch) + 4))
1678 || (bfd_arch == bfd_arch_spu
1679 /* SPU pseudo registers except SPU_SP_REGNUM are got by
1680 TARGET_OBJECT_SPU. */
1681 && regnum >= gdbarch_num_regs (gdbarch) && regnum != 130))
1684 std::vector<gdb_byte> expected (register_size (gdbarch, regnum), 0);
1685 std::vector<gdb_byte> buf (register_size (gdbarch, regnum), 0);
1686 const auto type = register_type (gdbarch, regnum);
1688 if (TYPE_CODE (type) == TYPE_CODE_FLT
1689 || TYPE_CODE (type) == TYPE_CODE_DECFLOAT)
1691 /* Generate valid float format. */
1692 target_float_from_string (expected.data (), type, "1.25");
1694 else if (TYPE_CODE (type) == TYPE_CODE_INT
1695 || TYPE_CODE (type) == TYPE_CODE_ARRAY
1696 || TYPE_CODE (type) == TYPE_CODE_PTR
1697 || TYPE_CODE (type) == TYPE_CODE_UNION
1698 || TYPE_CODE (type) == TYPE_CODE_STRUCT)
1700 if (bfd_arch == bfd_arch_ia64
1701 || (regnum >= gdbarch_num_regs (gdbarch)
1702 && (bfd_arch == bfd_arch_xtensa
1703 || bfd_arch == bfd_arch_bfin
1704 || bfd_arch == bfd_arch_m32c
1705 /* m68hc11 pseudo registers are in memory. */
1706 || bfd_arch == bfd_arch_m68hc11
1707 || bfd_arch == bfd_arch_m68hc12
1708 || bfd_arch == bfd_arch_s390))
1709 || (bfd_arch == bfd_arch_frv
1710 /* FRV pseudo registers except iacc0. */
1711 && regnum > gdbarch_num_regs (gdbarch)))
1713 /* Skip setting the expected values for some architecture
1716 else if (bfd_arch == bfd_arch_rl78 && regnum == 40)
1718 /* RL78_PC_REGNUM */
1719 for (auto j = 0; j < register_size (gdbarch, regnum) - 1; j++)
1724 for (auto j = 0; j < register_size (gdbarch, regnum); j++)
1728 else if (TYPE_CODE (type) == TYPE_CODE_FLAGS)
1730 /* No idea how to test flags. */
1735 /* If we don't know how to create the expected value for the
1736 this type, make it fail. */
1740 readwrite.cooked_write (regnum, expected.data ());
1742 SELF_CHECK (readwrite.cooked_read (regnum, buf.data ()) == REG_VALID);
1743 SELF_CHECK (expected == buf);
1747 } // namespace selftests
1748 #endif /* GDB_SELF_TEST */
1751 _initialize_regcache (void)
1753 regcache_descr_handle
1754 = gdbarch_data_register_post_init (init_regcache_descr);
1756 gdb::observers::target_changed.attach (regcache_observer_target_changed);
1757 gdb::observers::thread_ptid_changed.attach
1758 (regcache::regcache_thread_ptid_changed);
1760 add_com ("flushregs", class_maintenance, reg_flush_command,
1761 _("Force gdb to flush its register cache (maintainer command)"));
1764 selftests::register_test ("current_regcache", selftests::current_regcache_test);
1766 selftests::register_test_foreach_arch ("regcache::cooked_read_test",
1767 selftests::cooked_read_test);
1768 selftests::register_test_foreach_arch ("regcache::cooked_write_test",
1769 selftests::cooked_write_test);