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;
331 gdb_byte buf[MAX_REGISTER_SIZE];
334 /* The DST should be `read-only', if it wasn't then the save would
335 end up trying to write the register values back out to the
337 gdb_assert (m_readonly_p);
338 /* Clear the dest. */
339 memset (m_registers, 0, m_descr->sizeof_cooked_registers);
340 memset (m_register_status, 0, m_descr->sizeof_cooked_register_status);
341 /* Copy over any registers (identified by their membership in the
342 save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs +
343 gdbarch_num_pseudo_regs) range is checked since some architectures need
344 to save/restore `cooked' registers that live in memory. */
345 for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
347 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
349 enum register_status status = cooked_read (src, regnum, buf);
351 if (status == REG_VALID)
352 memcpy (register_buffer (regnum), buf,
353 register_size (gdbarch, regnum));
356 gdb_assert (status != REG_UNKNOWN);
358 memset (register_buffer (regnum), 0,
359 register_size (gdbarch, regnum));
361 m_register_status[regnum] = status;
367 regcache::restore (struct regcache *src)
369 struct gdbarch *gdbarch = m_descr->gdbarch;
372 /* The dst had better not be read-only. If it is, the `restore'
373 doesn't make much sense. */
374 gdb_assert (!m_readonly_p);
375 gdb_assert (src->m_readonly_p);
376 /* Copy over any registers, being careful to only restore those that
377 were both saved and need to be restored. The full [0 .. gdbarch_num_regs
378 + gdbarch_num_pseudo_regs) range is checked since some architectures need
379 to save/restore `cooked' registers that live in memory. */
380 for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
382 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
384 if (src->m_register_status[regnum] == REG_VALID)
385 cooked_write (regnum, src->register_buffer (regnum));
391 regcache_cpy (struct regcache *dst, struct regcache *src)
393 gdb_assert (src != NULL && dst != NULL);
394 gdb_assert (src->m_descr->gdbarch == dst->m_descr->gdbarch);
395 gdb_assert (src != dst);
396 gdb_assert (src->m_readonly_p || dst->m_readonly_p);
398 if (!src->m_readonly_p)
399 regcache_save (dst, do_cooked_read, src);
400 else if (!dst->m_readonly_p)
403 dst->cpy_no_passthrough (src);
406 /* Copy/duplicate the contents of a register cache. Unlike regcache_cpy,
407 which is pass-through, this does not go through to the target.
408 Only values values already in the cache are transferred. The SRC and DST
409 buffers must not overlap. */
412 regcache::cpy_no_passthrough (struct regcache *src)
414 gdb_assert (src != NULL);
415 gdb_assert (src->m_descr->gdbarch == m_descr->gdbarch);
416 /* NOTE: cagney/2002-05-17: Don't let the caller do a no-passthrough
417 move of data into a thread's regcache. Doing this would be silly
418 - it would mean that regcache->register_status would be
419 completely invalid. */
420 gdb_assert (m_readonly_p && src->m_readonly_p);
422 memcpy (m_registers, src->m_registers,
423 m_descr->sizeof_cooked_registers);
424 memcpy (m_register_status, src->m_register_status,
425 m_descr->sizeof_cooked_register_status);
429 regcache_dup (struct regcache *src)
431 return new regcache (regcache::readonly, *src);
435 regcache_register_status (const struct regcache *regcache, int regnum)
437 gdb_assert (regcache != NULL);
438 return regcache->get_register_status (regnum);
442 regcache::get_register_status (int regnum) const
444 gdb_assert (regnum >= 0);
446 gdb_assert (regnum < m_descr->nr_cooked_registers);
448 gdb_assert (regnum < m_descr->nr_raw_registers);
450 return (enum register_status) m_register_status[regnum];
454 regcache_invalidate (struct regcache *regcache, int regnum)
456 gdb_assert (regcache != NULL);
457 regcache->invalidate (regnum);
461 regcache::invalidate (int regnum)
463 gdb_assert (regnum >= 0);
464 gdb_assert (!m_readonly_p);
465 gdb_assert (regnum < m_descr->nr_raw_registers);
466 m_register_status[regnum] = REG_UNKNOWN;
469 /* Global structure containing the current regcache. */
471 /* NOTE: this is a write-through cache. There is no "dirty" bit for
472 recording if the register values have been changed (eg. by the
473 user). Therefore all registers must be written back to the
474 target when appropriate. */
476 static std::forward_list<regcache *> current_regcache;
479 get_thread_arch_aspace_regcache (ptid_t ptid, struct gdbarch *gdbarch,
480 struct address_space *aspace)
482 for (const auto ®cache : current_regcache)
483 if (ptid_equal (regcache->ptid (), ptid) && regcache->arch () == gdbarch)
486 regcache *new_regcache = new regcache (gdbarch, aspace, false);
488 current_regcache.push_front (new_regcache);
489 new_regcache->set_ptid (ptid);
495 get_thread_arch_regcache (ptid_t ptid, struct gdbarch *gdbarch)
497 struct address_space *aspace;
499 /* For the benefit of "maint print registers" & co when debugging an
500 executable, allow dumping the regcache even when there is no
501 thread selected (target_thread_address_space internal-errors if
502 no address space is found). Note that normal user commands will
503 fail higher up on the call stack due to no
504 target_has_registers. */
505 aspace = (ptid_equal (null_ptid, ptid)
507 : target_thread_address_space (ptid));
509 return get_thread_arch_aspace_regcache (ptid, gdbarch, aspace);
512 static ptid_t current_thread_ptid;
513 static struct gdbarch *current_thread_arch;
516 get_thread_regcache (ptid_t ptid)
518 if (!current_thread_arch || !ptid_equal (current_thread_ptid, ptid))
520 current_thread_ptid = ptid;
521 current_thread_arch = target_thread_architecture (ptid);
524 return get_thread_arch_regcache (ptid, current_thread_arch);
528 get_current_regcache (void)
530 return get_thread_regcache (inferior_ptid);
533 /* See common/common-regcache.h. */
536 get_thread_regcache_for_ptid (ptid_t ptid)
538 return get_thread_regcache (ptid);
541 /* Observer for the target_changed event. */
544 regcache_observer_target_changed (struct target_ops *target)
546 registers_changed ();
549 /* Update global variables old ptids to hold NEW_PTID if they were
552 regcache_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
554 for (auto ®cache : current_regcache)
556 if (ptid_equal (regcache->ptid (), old_ptid))
557 regcache->set_ptid (new_ptid);
561 /* Low level examining and depositing of registers.
563 The caller is responsible for making sure that the inferior is
564 stopped before calling the fetching routines, or it will get
565 garbage. (a change from GDB version 3, in which the caller got the
566 value from the last stop). */
568 /* REGISTERS_CHANGED ()
570 Indicate that registers may have changed, so invalidate the cache. */
573 registers_changed_ptid (ptid_t ptid)
575 for (auto oit = current_regcache.before_begin (),
576 it = std::next (oit);
577 it != current_regcache.end ();
580 if (ptid_match ((*it)->ptid (), ptid))
583 it = current_regcache.erase_after (oit);
589 if (ptid_match (current_thread_ptid, ptid))
591 current_thread_ptid = null_ptid;
592 current_thread_arch = NULL;
595 if (ptid_match (inferior_ptid, ptid))
597 /* We just deleted the regcache of the current thread. Need to
598 forget about any frames we have cached, too. */
599 reinit_frame_cache ();
604 registers_changed (void)
606 registers_changed_ptid (minus_one_ptid);
608 /* Force cleanup of any alloca areas if using C alloca instead of
609 a builtin alloca. This particular call is used to clean up
610 areas allocated by low level target code which may build up
611 during lengthy interactions between gdb and the target before
612 gdb gives control to the user (ie watchpoints). */
617 regcache_raw_update (struct regcache *regcache, int regnum)
619 gdb_assert (regcache != NULL);
621 regcache->raw_update (regnum);
625 regcache::raw_update (int regnum)
627 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
629 /* Make certain that the register cache is up-to-date with respect
630 to the current thread. This switching shouldn't be necessary
631 only there is still only one target side register cache. Sigh!
632 On the bright side, at least there is a regcache object. */
634 if (!m_readonly_p && get_register_status (regnum) == REG_UNKNOWN)
636 target_fetch_registers (this, regnum);
638 /* A number of targets can't access the whole set of raw
639 registers (because the debug API provides no means to get at
641 if (m_register_status[regnum] == REG_UNKNOWN)
642 m_register_status[regnum] = REG_UNAVAILABLE;
647 regcache_raw_read (struct regcache *regcache, int regnum, gdb_byte *buf)
649 return regcache->raw_read (regnum, buf);
653 regcache::raw_read (int regnum, gdb_byte *buf)
655 gdb_assert (buf != NULL);
658 if (m_register_status[regnum] != REG_VALID)
659 memset (buf, 0, m_descr->sizeof_register[regnum]);
661 memcpy (buf, register_buffer (regnum),
662 m_descr->sizeof_register[regnum]);
664 return (enum register_status) m_register_status[regnum];
668 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
670 gdb_assert (regcache != NULL);
671 return regcache->raw_read_signed (regnum, val);
675 regcache::raw_read_signed (int regnum, LONGEST *val)
678 enum register_status status;
680 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
681 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
682 status = raw_read (regnum, buf);
683 if (status == REG_VALID)
684 *val = extract_signed_integer
685 (buf, m_descr->sizeof_register[regnum],
686 gdbarch_byte_order (m_descr->gdbarch));
693 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
696 gdb_assert (regcache != NULL);
697 return regcache->raw_read_unsigned (regnum, val);
702 regcache::raw_read_unsigned (int regnum, ULONGEST *val)
705 enum register_status status;
707 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
708 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
709 status = raw_read (regnum, buf);
710 if (status == REG_VALID)
711 *val = extract_unsigned_integer
712 (buf, m_descr->sizeof_register[regnum],
713 gdbarch_byte_order (m_descr->gdbarch));
720 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
722 gdb_assert (regcache != NULL);
723 regcache->raw_write_signed (regnum, val);
727 regcache::raw_write_signed (int regnum, LONGEST val)
731 gdb_assert (regnum >=0 && regnum < m_descr->nr_raw_registers);
732 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
733 store_signed_integer (buf, m_descr->sizeof_register[regnum],
734 gdbarch_byte_order (m_descr->gdbarch), val);
735 raw_write (regnum, buf);
739 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
742 gdb_assert (regcache != NULL);
743 regcache->raw_write_unsigned (regnum, val);
747 regcache::raw_write_unsigned (int regnum, ULONGEST val)
751 gdb_assert (regnum >=0 && regnum < m_descr->nr_raw_registers);
752 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
753 store_unsigned_integer (buf, m_descr->sizeof_register[regnum],
754 gdbarch_byte_order (m_descr->gdbarch), val);
755 raw_write (regnum, buf);
759 regcache_raw_get_signed (struct regcache *regcache, int regnum)
762 enum register_status status;
764 status = regcache_raw_read_signed (regcache, regnum, &value);
765 if (status == REG_UNAVAILABLE)
766 throw_error (NOT_AVAILABLE_ERROR,
767 _("Register %d is not available"), regnum);
772 regcache_cooked_read (struct regcache *regcache, int regnum, gdb_byte *buf)
774 return regcache->cooked_read (regnum, buf);
778 regcache::cooked_read (int regnum, gdb_byte *buf)
780 gdb_assert (regnum >= 0);
781 gdb_assert (regnum < m_descr->nr_cooked_registers);
782 if (regnum < m_descr->nr_raw_registers)
783 return raw_read (regnum, buf);
784 else if (m_readonly_p
785 && m_register_status[regnum] != REG_UNKNOWN)
787 /* Read-only register cache, perhaps the cooked value was
789 if (m_register_status[regnum] == REG_VALID)
790 memcpy (buf, register_buffer (regnum),
791 m_descr->sizeof_register[regnum]);
793 memset (buf, 0, m_descr->sizeof_register[regnum]);
795 return (enum register_status) m_register_status[regnum];
797 else if (gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
799 struct value *mark, *computed;
800 enum register_status result = REG_VALID;
802 mark = value_mark ();
804 computed = gdbarch_pseudo_register_read_value (m_descr->gdbarch,
806 if (value_entirely_available (computed))
807 memcpy (buf, value_contents_raw (computed),
808 m_descr->sizeof_register[regnum]);
811 memset (buf, 0, m_descr->sizeof_register[regnum]);
812 result = REG_UNAVAILABLE;
815 value_free_to_mark (mark);
820 return gdbarch_pseudo_register_read (m_descr->gdbarch, this,
825 regcache_cooked_read_value (struct regcache *regcache, int regnum)
827 return regcache->cooked_read_value (regnum);
831 regcache::cooked_read_value (int regnum)
833 gdb_assert (regnum >= 0);
834 gdb_assert (regnum < m_descr->nr_cooked_registers);
836 if (regnum < m_descr->nr_raw_registers
837 || (m_readonly_p && m_register_status[regnum] != REG_UNKNOWN)
838 || !gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
840 struct value *result;
842 result = allocate_value (register_type (m_descr->gdbarch, regnum));
843 VALUE_LVAL (result) = lval_register;
844 VALUE_REGNUM (result) = regnum;
846 /* It is more efficient in general to do this delegation in this
847 direction than in the other one, even though the value-based
849 if (cooked_read (regnum,
850 value_contents_raw (result)) == REG_UNAVAILABLE)
851 mark_value_bytes_unavailable (result, 0,
852 TYPE_LENGTH (value_type (result)));
857 return gdbarch_pseudo_register_read_value (m_descr->gdbarch,
862 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
865 gdb_assert (regcache != NULL);
866 return regcache->cooked_read_signed (regnum, val);
870 regcache::cooked_read_signed (int regnum, LONGEST *val)
872 enum register_status status;
875 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
876 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
877 status = cooked_read (regnum, buf);
878 if (status == REG_VALID)
879 *val = extract_signed_integer
880 (buf, m_descr->sizeof_register[regnum],
881 gdbarch_byte_order (m_descr->gdbarch));
888 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
891 gdb_assert (regcache != NULL);
892 return regcache->cooked_read_unsigned (regnum, val);
896 regcache::cooked_read_unsigned (int regnum, ULONGEST *val)
898 enum register_status status;
901 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
902 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
903 status = cooked_read (regnum, buf);
904 if (status == REG_VALID)
905 *val = extract_unsigned_integer
906 (buf, m_descr->sizeof_register[regnum],
907 gdbarch_byte_order (m_descr->gdbarch));
914 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
917 gdb_assert (regcache != NULL);
918 regcache->cooked_write_signed (regnum, val);
922 regcache::cooked_write_signed (int regnum, LONGEST val)
926 gdb_assert (regnum >=0 && regnum < m_descr->nr_cooked_registers);
927 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
928 store_signed_integer (buf, m_descr->sizeof_register[regnum],
929 gdbarch_byte_order (m_descr->gdbarch), val);
930 cooked_write (regnum, buf);
934 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
937 gdb_assert (regcache != NULL);
938 regcache->cooked_write_unsigned (regnum, val);
942 regcache::cooked_write_unsigned (int regnum, ULONGEST val)
946 gdb_assert (regnum >=0 && regnum < m_descr->nr_cooked_registers);
947 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
948 store_unsigned_integer (buf, m_descr->sizeof_register[regnum],
949 gdbarch_byte_order (m_descr->gdbarch), val);
950 cooked_write (regnum, buf);
953 /* See regcache.h. */
956 regcache_raw_set_cached_value (struct regcache *regcache, int regnum,
959 regcache->raw_set_cached_value (regnum, buf);
963 regcache::raw_set_cached_value (int regnum, const gdb_byte *buf)
965 memcpy (register_buffer (regnum), buf,
966 m_descr->sizeof_register[regnum]);
967 m_register_status[regnum] = REG_VALID;
971 regcache_raw_write (struct regcache *regcache, int regnum,
974 gdb_assert (regcache != NULL && buf != NULL);
975 regcache->raw_write (regnum, buf);
979 regcache::raw_write (int regnum, const gdb_byte *buf)
981 struct cleanup *old_chain;
983 gdb_assert (buf != NULL);
984 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
985 gdb_assert (!m_readonly_p);
987 /* On the sparc, writing %g0 is a no-op, so we don't even want to
988 change the registers array if something writes to this register. */
989 if (gdbarch_cannot_store_register (arch (), regnum))
992 /* If we have a valid copy of the register, and new value == old
993 value, then don't bother doing the actual store. */
994 if (get_register_status (regnum) == REG_VALID
995 && (memcmp (register_buffer (regnum), buf,
996 m_descr->sizeof_register[regnum]) == 0))
999 target_prepare_to_store (this);
1000 raw_set_cached_value (regnum, buf);
1002 /* Register a cleanup function for invalidating the register after it is
1003 written, in case of a failure. */
1004 old_chain = make_cleanup_regcache_invalidate (this, regnum);
1006 target_store_registers (this, regnum);
1008 /* The target did not throw an error so we can discard invalidating the
1009 register and restore the cleanup chain to what it was. */
1010 discard_cleanups (old_chain);
1014 regcache_cooked_write (struct regcache *regcache, int regnum,
1015 const gdb_byte *buf)
1017 regcache->cooked_write (regnum, buf);
1021 regcache::cooked_write (int regnum, const gdb_byte *buf)
1023 gdb_assert (regnum >= 0);
1024 gdb_assert (regnum < m_descr->nr_cooked_registers);
1025 if (regnum < m_descr->nr_raw_registers)
1026 raw_write (regnum, buf);
1028 gdbarch_pseudo_register_write (m_descr->gdbarch, this,
1032 /* Perform a partial register transfer using a read, modify, write
1035 typedef void (regcache_read_ftype) (struct regcache *regcache, int regnum,
1037 typedef void (regcache_write_ftype) (struct regcache *regcache, int regnum,
1040 enum register_status
1041 regcache::xfer_part (int regnum, int offset, int len, void *in,
1043 enum register_status (*read) (struct regcache *regcache,
1046 void (*write) (struct regcache *regcache, int regnum,
1047 const gdb_byte *buf))
1049 struct gdbarch *gdbarch = arch ();
1050 gdb_byte *reg = (gdb_byte *) alloca (register_size (gdbarch, regnum));
1052 gdb_assert (offset >= 0 && offset <= m_descr->sizeof_register[regnum]);
1053 gdb_assert (len >= 0 && offset + len <= m_descr->sizeof_register[regnum]);
1054 /* Something to do? */
1055 if (offset + len == 0)
1057 /* Read (when needed) ... */
1060 || offset + len < m_descr->sizeof_register[regnum])
1062 enum register_status status;
1064 gdb_assert (read != NULL);
1065 status = read (this, regnum, reg);
1066 if (status != REG_VALID)
1069 /* ... modify ... */
1071 memcpy (in, reg + offset, len);
1073 memcpy (reg + offset, out, len);
1074 /* ... write (when needed). */
1077 gdb_assert (write != NULL);
1078 write (this, regnum, reg);
1084 enum register_status
1085 regcache_raw_read_part (struct regcache *regcache, int regnum,
1086 int offset, int len, gdb_byte *buf)
1088 return regcache->raw_read_part (regnum, offset, len, buf);
1091 enum register_status
1092 regcache::raw_read_part (int regnum, int offset, int len, gdb_byte *buf)
1094 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
1095 return xfer_part (regnum, offset, len, buf, NULL,
1096 regcache_raw_read, regcache_raw_write);
1100 regcache_raw_write_part (struct regcache *regcache, int regnum,
1101 int offset, int len, const gdb_byte *buf)
1103 regcache->raw_write_part (regnum, offset, len, buf);
1107 regcache::raw_write_part (int regnum, int offset, int len,
1108 const gdb_byte *buf)
1110 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
1111 xfer_part (regnum, offset, len, NULL, buf, regcache_raw_read,
1112 regcache_raw_write);
1115 enum register_status
1116 regcache_cooked_read_part (struct regcache *regcache, int regnum,
1117 int offset, int len, gdb_byte *buf)
1119 return regcache->cooked_read_part (regnum, offset, len, buf);
1123 enum register_status
1124 regcache::cooked_read_part (int regnum, int offset, int len, gdb_byte *buf)
1126 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
1127 return xfer_part (regnum, offset, len, buf, NULL,
1128 regcache_cooked_read, regcache_cooked_write);
1132 regcache_cooked_write_part (struct regcache *regcache, int regnum,
1133 int offset, int len, const gdb_byte *buf)
1135 regcache->cooked_write_part (regnum, offset, len, buf);
1139 regcache::cooked_write_part (int regnum, int offset, int len,
1140 const gdb_byte *buf)
1142 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
1143 xfer_part (regnum, offset, len, NULL, buf,
1144 regcache_cooked_read, regcache_cooked_write);
1147 /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */
1150 regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf)
1152 gdb_assert (regcache != NULL);
1153 regcache->raw_supply (regnum, buf);
1157 regcache::raw_supply (int regnum, const void *buf)
1162 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
1163 gdb_assert (!m_readonly_p);
1165 regbuf = register_buffer (regnum);
1166 size = m_descr->sizeof_register[regnum];
1170 memcpy (regbuf, buf, size);
1171 m_register_status[regnum] = REG_VALID;
1175 /* This memset not strictly necessary, but better than garbage
1176 in case the register value manages to escape somewhere (due
1177 to a bug, no less). */
1178 memset (regbuf, 0, size);
1179 m_register_status[regnum] = REG_UNAVAILABLE;
1183 /* Supply register REGNUM with zeroed value to REGCACHE. This is not the same
1184 as calling raw_supply with NULL (which will set the state to
1188 regcache::raw_supply_zeroed (int regnum)
1193 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
1194 gdb_assert (!m_readonly_p);
1196 regbuf = register_buffer (regnum);
1197 size = m_descr->sizeof_register[regnum];
1199 memset (regbuf, 0, size);
1200 m_register_status[regnum] = REG_VALID;
1203 /* Collect register REGNUM from REGCACHE and store its contents in BUF. */
1206 regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf)
1208 gdb_assert (regcache != NULL && buf != NULL);
1209 regcache->raw_collect (regnum, buf);
1213 regcache::raw_collect (int regnum, void *buf) const
1218 gdb_assert (buf != NULL);
1219 gdb_assert (regnum >= 0 && regnum < m_descr->nr_raw_registers);
1221 regbuf = register_buffer (regnum);
1222 size = m_descr->sizeof_register[regnum];
1223 memcpy (buf, regbuf, size);
1226 /* Transfer a single or all registers belonging to a certain register
1227 set to or from a buffer. This is the main worker function for
1228 regcache_supply_regset and regcache_collect_regset. */
1231 regcache::transfer_regset (const struct regset *regset,
1232 struct regcache *out_regcache,
1233 int regnum, const void *in_buf,
1234 void *out_buf, size_t size) const
1236 const struct regcache_map_entry *map;
1237 int offs = 0, count;
1239 for (map = (const struct regcache_map_entry *) regset->regmap;
1240 (count = map->count) != 0;
1243 int regno = map->regno;
1244 int slot_size = map->size;
1246 if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
1247 slot_size = m_descr->sizeof_register[regno];
1249 if (regno == REGCACHE_MAP_SKIP
1251 && (regnum < regno || regnum >= regno + count)))
1252 offs += count * slot_size;
1254 else if (regnum == -1)
1255 for (; count--; regno++, offs += slot_size)
1257 if (offs + slot_size > size)
1261 raw_collect (regno, (gdb_byte *) out_buf + offs);
1263 out_regcache->raw_supply (regno, in_buf
1264 ? (const gdb_byte *) in_buf + offs
1269 /* Transfer a single register and return. */
1270 offs += (regnum - regno) * slot_size;
1271 if (offs + slot_size > size)
1275 raw_collect (regnum, (gdb_byte *) out_buf + offs);
1277 out_regcache->raw_supply (regnum, in_buf
1278 ? (const gdb_byte *) in_buf + offs
1285 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1286 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1287 If BUF is NULL, set the register(s) to "unavailable" status. */
1290 regcache_supply_regset (const struct regset *regset,
1291 struct regcache *regcache,
1292 int regnum, const void *buf, size_t size)
1294 regcache->supply_regset (regset, regnum, buf, size);
1298 regcache::supply_regset (const struct regset *regset,
1299 int regnum, const void *buf, size_t size)
1301 transfer_regset (regset, this, regnum, buf, NULL, size);
1304 /* Collect register REGNUM from REGCACHE to BUF, using the register
1305 map in REGSET. If REGNUM is -1, do this for all registers in
1309 regcache_collect_regset (const struct regset *regset,
1310 const struct regcache *regcache,
1311 int regnum, void *buf, size_t size)
1313 regcache->collect_regset (regset, regnum, buf, size);
1317 regcache::collect_regset (const struct regset *regset,
1318 int regnum, void *buf, size_t size) const
1320 transfer_regset (regset, NULL, regnum, NULL, buf, size);
1324 /* Special handling for register PC. */
1327 regcache_read_pc (struct regcache *regcache)
1329 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1333 if (gdbarch_read_pc_p (gdbarch))
1334 pc_val = gdbarch_read_pc (gdbarch, regcache);
1335 /* Else use per-frame method on get_current_frame. */
1336 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1340 if (regcache_cooked_read_unsigned (regcache,
1341 gdbarch_pc_regnum (gdbarch),
1342 &raw_val) == REG_UNAVAILABLE)
1343 throw_error (NOT_AVAILABLE_ERROR, _("PC register is not available"));
1345 pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val);
1348 internal_error (__FILE__, __LINE__,
1349 _("regcache_read_pc: Unable to find PC"));
1354 regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
1356 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1358 if (gdbarch_write_pc_p (gdbarch))
1359 gdbarch_write_pc (gdbarch, regcache, pc);
1360 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1361 regcache_cooked_write_unsigned (regcache,
1362 gdbarch_pc_regnum (gdbarch), pc);
1364 internal_error (__FILE__, __LINE__,
1365 _("regcache_write_pc: Unable to update PC"));
1367 /* Writing the PC (for instance, from "load") invalidates the
1369 reinit_frame_cache ();
1373 regcache::debug_print_register (const char *func, int regno)
1375 struct gdbarch *gdbarch = arch ();
1377 fprintf_unfiltered (gdb_stdlog, "%s ", func);
1378 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
1379 && gdbarch_register_name (gdbarch, regno) != NULL
1380 && gdbarch_register_name (gdbarch, regno)[0] != '\0')
1381 fprintf_unfiltered (gdb_stdlog, "(%s)",
1382 gdbarch_register_name (gdbarch, regno));
1384 fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
1385 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch))
1387 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1388 int size = register_size (gdbarch, regno);
1389 gdb_byte *buf = register_buffer (regno);
1391 fprintf_unfiltered (gdb_stdlog, " = ");
1392 for (int i = 0; i < size; i++)
1394 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
1396 if (size <= sizeof (LONGEST))
1398 ULONGEST val = extract_unsigned_integer (buf, size, byte_order);
1400 fprintf_unfiltered (gdb_stdlog, " %s %s",
1401 core_addr_to_string_nz (val), plongest (val));
1404 fprintf_unfiltered (gdb_stdlog, "\n");
1408 reg_flush_command (char *command, int from_tty)
1410 /* Force-flush the register cache. */
1411 registers_changed ();
1413 printf_filtered (_("Register cache flushed.\n"));
1417 regcache::dump (ui_file *file, enum regcache_dump_what what_to_dump)
1419 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
1420 struct gdbarch *gdbarch = m_descr->gdbarch;
1422 int footnote_nr = 0;
1423 int footnote_register_size = 0;
1424 int footnote_register_offset = 0;
1425 int footnote_register_type_name_null = 0;
1426 long register_offset = 0;
1427 gdb_byte buf[MAX_REGISTER_SIZE];
1430 fprintf_unfiltered (file, "nr_raw_registers %d\n",
1431 m_descr->nr_raw_registers);
1432 fprintf_unfiltered (file, "nr_cooked_registers %d\n",
1433 m_descr->nr_cooked_registers);
1434 fprintf_unfiltered (file, "sizeof_raw_registers %ld\n",
1435 m_descr->sizeof_raw_registers);
1436 fprintf_unfiltered (file, "sizeof_raw_register_status %ld\n",
1437 m_descr->sizeof_raw_register_status);
1438 fprintf_unfiltered (file, "gdbarch_num_regs %d\n",
1439 gdbarch_num_regs (gdbarch));
1440 fprintf_unfiltered (file, "gdbarch_num_pseudo_regs %d\n",
1441 gdbarch_num_pseudo_regs (gdbarch));
1444 gdb_assert (m_descr->nr_cooked_registers
1445 == (gdbarch_num_regs (gdbarch)
1446 + gdbarch_num_pseudo_regs (gdbarch)));
1448 for (regnum = -1; regnum < m_descr->nr_cooked_registers; regnum++)
1452 fprintf_unfiltered (file, " %-10s", "Name");
1455 const char *p = gdbarch_register_name (gdbarch, regnum);
1459 else if (p[0] == '\0')
1461 fprintf_unfiltered (file, " %-10s", p);
1466 fprintf_unfiltered (file, " %4s", "Nr");
1468 fprintf_unfiltered (file, " %4d", regnum);
1470 /* Relative number. */
1472 fprintf_unfiltered (file, " %4s", "Rel");
1473 else if (regnum < gdbarch_num_regs (gdbarch))
1474 fprintf_unfiltered (file, " %4d", regnum);
1476 fprintf_unfiltered (file, " %4d",
1477 (regnum - gdbarch_num_regs (gdbarch)));
1481 fprintf_unfiltered (file, " %6s ", "Offset");
1484 fprintf_unfiltered (file, " %6ld",
1485 m_descr->register_offset[regnum]);
1486 if (register_offset != m_descr->register_offset[regnum]
1488 && (m_descr->register_offset[regnum]
1489 != (m_descr->register_offset[regnum - 1]
1490 + m_descr->sizeof_register[regnum - 1])))
1493 if (!footnote_register_offset)
1494 footnote_register_offset = ++footnote_nr;
1495 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1498 fprintf_unfiltered (file, " ");
1499 register_offset = (m_descr->register_offset[regnum]
1500 + m_descr->sizeof_register[regnum]);
1505 fprintf_unfiltered (file, " %5s ", "Size");
1507 fprintf_unfiltered (file, " %5ld", m_descr->sizeof_register[regnum]);
1517 static const char blt[] = "builtin_type";
1519 t = TYPE_NAME (register_type (arch (), regnum));
1524 if (!footnote_register_type_name_null)
1525 footnote_register_type_name_null = ++footnote_nr;
1526 n = xstrprintf ("*%d", footnote_register_type_name_null);
1527 make_cleanup (xfree, n);
1530 /* Chop a leading builtin_type. */
1531 if (startswith (t, blt))
1534 fprintf_unfiltered (file, " %-15s", t);
1537 /* Leading space always present. */
1538 fprintf_unfiltered (file, " ");
1541 if (what_to_dump == regcache_dump_raw)
1544 fprintf_unfiltered (file, "Raw value");
1545 else if (regnum >= m_descr->nr_raw_registers)
1546 fprintf_unfiltered (file, "<cooked>");
1547 else if (get_register_status (regnum) == REG_UNKNOWN)
1548 fprintf_unfiltered (file, "<invalid>");
1549 else if (get_register_status (regnum) == REG_UNAVAILABLE)
1550 fprintf_unfiltered (file, "<unavailable>");
1553 raw_read (regnum, buf);
1554 print_hex_chars (file, buf,
1555 m_descr->sizeof_register[regnum],
1556 gdbarch_byte_order (gdbarch));
1560 /* Value, cooked. */
1561 if (what_to_dump == regcache_dump_cooked)
1564 fprintf_unfiltered (file, "Cooked value");
1567 enum register_status status;
1569 status = cooked_read (regnum, buf);
1570 if (status == REG_UNKNOWN)
1571 fprintf_unfiltered (file, "<invalid>");
1572 else if (status == REG_UNAVAILABLE)
1573 fprintf_unfiltered (file, "<unavailable>");
1575 print_hex_chars (file, buf,
1576 m_descr->sizeof_register[regnum],
1577 gdbarch_byte_order (gdbarch));
1581 /* Group members. */
1582 if (what_to_dump == regcache_dump_groups)
1585 fprintf_unfiltered (file, "Groups");
1588 const char *sep = "";
1589 struct reggroup *group;
1591 for (group = reggroup_next (gdbarch, NULL);
1593 group = reggroup_next (gdbarch, group))
1595 if (gdbarch_register_reggroup_p (gdbarch, regnum, group))
1597 fprintf_unfiltered (file,
1598 "%s%s", sep, reggroup_name (group));
1605 /* Remote packet configuration. */
1606 if (what_to_dump == regcache_dump_remote)
1610 fprintf_unfiltered (file, "Rmt Nr g/G Offset");
1612 else if (regnum < m_descr->nr_raw_registers)
1616 if (remote_register_number_and_offset (arch (), regnum,
1618 fprintf_unfiltered (file, "%7d %11d", pnum, poffset);
1622 fprintf_unfiltered (file, "\n");
1625 if (footnote_register_size)
1626 fprintf_unfiltered (file, "*%d: Inconsistent register sizes.\n",
1627 footnote_register_size);
1628 if (footnote_register_offset)
1629 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1630 footnote_register_offset);
1631 if (footnote_register_type_name_null)
1632 fprintf_unfiltered (file,
1633 "*%d: Register type's name NULL.\n",
1634 footnote_register_type_name_null);
1635 do_cleanups (cleanups);
1639 regcache_print (char *args, enum regcache_dump_what what_to_dump)
1642 get_current_regcache ()->dump (gdb_stdout, what_to_dump);
1647 if (!file.open (args, "w"))
1648 perror_with_name (_("maintenance print architecture"));
1649 get_current_regcache ()->dump (&file, what_to_dump);
1654 maintenance_print_registers (char *args, int from_tty)
1656 regcache_print (args, regcache_dump_none);
1660 maintenance_print_raw_registers (char *args, int from_tty)
1662 regcache_print (args, regcache_dump_raw);
1666 maintenance_print_cooked_registers (char *args, int from_tty)
1668 regcache_print (args, regcache_dump_cooked);
1672 maintenance_print_register_groups (char *args, int from_tty)
1674 regcache_print (args, regcache_dump_groups);
1678 maintenance_print_remote_registers (char *args, int from_tty)
1680 regcache_print (args, regcache_dump_remote);
1684 #include "selftest.h"
1686 namespace selftests {
1688 /* Return the number of elements in current_regcache. */
1691 current_regcache_size ()
1693 return std::distance (current_regcache.begin (), current_regcache.end ());
1697 current_regcache_test (void)
1699 /* It is empty at the start. */
1700 SELF_CHECK (current_regcache_size () == 0);
1702 ptid_t ptid1 (1), ptid2 (2), ptid3 (3);
1704 /* Get regcache from ptid1, a new regcache is added to
1705 current_regcache. */
1706 regcache *regcache = get_thread_arch_aspace_regcache (ptid1,
1710 SELF_CHECK (regcache != NULL);
1711 SELF_CHECK (regcache->ptid () == ptid1);
1712 SELF_CHECK (current_regcache_size () == 1);
1714 /* Get regcache from ptid2, a new regcache is added to
1715 current_regcache. */
1716 regcache = get_thread_arch_aspace_regcache (ptid2,
1719 SELF_CHECK (regcache != NULL);
1720 SELF_CHECK (regcache->ptid () == ptid2);
1721 SELF_CHECK (current_regcache_size () == 2);
1723 /* Get regcache from ptid3, a new regcache is added to
1724 current_regcache. */
1725 regcache = get_thread_arch_aspace_regcache (ptid3,
1728 SELF_CHECK (regcache != NULL);
1729 SELF_CHECK (regcache->ptid () == ptid3);
1730 SELF_CHECK (current_regcache_size () == 3);
1732 /* Get regcache from ptid2 again, nothing is added to
1733 current_regcache. */
1734 regcache = get_thread_arch_aspace_regcache (ptid2,
1737 SELF_CHECK (regcache != NULL);
1738 SELF_CHECK (regcache->ptid () == ptid2);
1739 SELF_CHECK (current_regcache_size () == 3);
1741 /* Mark ptid2 is changed, so regcache of ptid2 should be removed from
1742 current_regcache. */
1743 registers_changed_ptid (ptid2);
1744 SELF_CHECK (current_regcache_size () == 2);
1747 } // namespace selftests
1748 #endif /* GDB_SELF_TEST */
1750 extern initialize_file_ftype _initialize_regcache; /* -Wmissing-prototype */
1753 _initialize_regcache (void)
1755 regcache_descr_handle
1756 = gdbarch_data_register_post_init (init_regcache_descr);
1758 observer_attach_target_changed (regcache_observer_target_changed);
1759 observer_attach_thread_ptid_changed (regcache_thread_ptid_changed);
1761 add_com ("flushregs", class_maintenance, reg_flush_command,
1762 _("Force gdb to flush its register cache (maintainer command)"));
1764 add_cmd ("registers", class_maintenance, maintenance_print_registers,
1765 _("Print the internal register configuration.\n"
1766 "Takes an optional file parameter."), &maintenanceprintlist);
1767 add_cmd ("raw-registers", class_maintenance,
1768 maintenance_print_raw_registers,
1769 _("Print the internal register configuration "
1770 "including raw values.\n"
1771 "Takes an optional file parameter."), &maintenanceprintlist);
1772 add_cmd ("cooked-registers", class_maintenance,
1773 maintenance_print_cooked_registers,
1774 _("Print the internal register configuration "
1775 "including cooked values.\n"
1776 "Takes an optional file parameter."), &maintenanceprintlist);
1777 add_cmd ("register-groups", class_maintenance,
1778 maintenance_print_register_groups,
1779 _("Print the internal register configuration "
1780 "including each register's group.\n"
1781 "Takes an optional file parameter."),
1782 &maintenanceprintlist);
1783 add_cmd ("remote-registers", class_maintenance,
1784 maintenance_print_remote_registers, _("\
1785 Print the internal register configuration including each register's\n\
1786 remote register number and buffer offset in the g/G packets.\n\
1787 Takes an optional file parameter."),
1788 &maintenanceprintlist);
1790 register_self_test (selftests::current_regcache_test);