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 ();
244 /* Cleanup class for invalidating a register. */
246 class regcache_invalidator
250 regcache_invalidator (struct regcache
*regcache
, int regnum
)
251 : m_regcache (regcache
),
256 ~regcache_invalidator ()
258 if (m_regcache
!= nullptr)
259 regcache_invalidate (m_regcache
, m_regnum
);
262 DISABLE_COPY_AND_ASSIGN (regcache_invalidator
);
266 m_regcache
= nullptr;
271 struct regcache
*m_regcache
;
275 /* Return REGCACHE's architecture. */
278 get_regcache_arch (const struct regcache
*regcache
)
280 return regcache
->arch ();
283 struct address_space
*
284 get_regcache_aspace (const struct regcache
*regcache
)
286 return regcache
->aspace ();
289 /* Return a pointer to register REGNUM's buffer cache. */
292 regcache::register_buffer (int regnum
) const
294 return m_registers
+ m_descr
->register_offset
[regnum
];
298 regcache_save (struct regcache
*regcache
,
299 regcache_cooked_read_ftype
*cooked_read
, void *src
)
301 regcache
->save (cooked_read
, src
);
305 regcache::save (regcache_cooked_read_ftype
*cooked_read
,
308 struct gdbarch
*gdbarch
= m_descr
->gdbarch
;
311 /* The DST should be `read-only', if it wasn't then the save would
312 end up trying to write the register values back out to the
314 gdb_assert (m_readonly_p
);
315 /* Clear the dest. */
316 memset (m_registers
, 0, m_descr
->sizeof_cooked_registers
);
317 memset (m_register_status
, 0, m_descr
->sizeof_cooked_register_status
);
318 /* Copy over any registers (identified by their membership in the
319 save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs +
320 gdbarch_num_pseudo_regs) range is checked since some architectures need
321 to save/restore `cooked' registers that live in memory. */
322 for (regnum
= 0; regnum
< m_descr
->nr_cooked_registers
; regnum
++)
324 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, save_reggroup
))
326 gdb_byte
*dst_buf
= register_buffer (regnum
);
327 enum register_status status
= cooked_read (src
, regnum
, dst_buf
);
329 gdb_assert (status
!= REG_UNKNOWN
);
331 if (status
!= REG_VALID
)
332 memset (dst_buf
, 0, register_size (gdbarch
, regnum
));
334 m_register_status
[regnum
] = status
;
340 regcache::restore (struct regcache
*src
)
342 struct gdbarch
*gdbarch
= m_descr
->gdbarch
;
345 /* The dst had better not be read-only. If it is, the `restore'
346 doesn't make much sense. */
347 gdb_assert (!m_readonly_p
);
348 gdb_assert (src
->m_readonly_p
);
349 /* Copy over any registers, being careful to only restore those that
350 were both saved and need to be restored. The full [0 .. gdbarch_num_regs
351 + gdbarch_num_pseudo_regs) range is checked since some architectures need
352 to save/restore `cooked' registers that live in memory. */
353 for (regnum
= 0; regnum
< m_descr
->nr_cooked_registers
; regnum
++)
355 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, restore_reggroup
))
357 if (src
->m_register_status
[regnum
] == REG_VALID
)
358 cooked_write (regnum
, src
->register_buffer (regnum
));
364 regcache_cpy (struct regcache
*dst
, struct regcache
*src
)
366 gdb_assert (src
!= NULL
&& dst
!= NULL
);
367 gdb_assert (src
->m_descr
->gdbarch
== dst
->m_descr
->gdbarch
);
368 gdb_assert (src
!= dst
);
369 gdb_assert (src
->m_readonly_p
&& !dst
->m_readonly_p
);
375 regcache_dup (struct regcache
*src
)
377 return new regcache (regcache::readonly
, *src
);
381 regcache_register_status (const struct regcache
*regcache
, int regnum
)
383 gdb_assert (regcache
!= NULL
);
384 return regcache
->get_register_status (regnum
);
388 regcache::get_register_status (int regnum
) const
390 gdb_assert (regnum
>= 0);
392 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
394 gdb_assert (regnum
< m_descr
->nr_raw_registers
);
396 return (enum register_status
) m_register_status
[regnum
];
400 regcache_invalidate (struct regcache
*regcache
, int regnum
)
402 gdb_assert (regcache
!= NULL
);
403 regcache
->invalidate (regnum
);
407 regcache::invalidate (int regnum
)
409 gdb_assert (regnum
>= 0);
410 gdb_assert (!m_readonly_p
);
411 gdb_assert (regnum
< m_descr
->nr_raw_registers
);
412 m_register_status
[regnum
] = REG_UNKNOWN
;
415 /* Global structure containing the current regcache. */
417 /* NOTE: this is a write-through cache. There is no "dirty" bit for
418 recording if the register values have been changed (eg. by the
419 user). Therefore all registers must be written back to the
420 target when appropriate. */
421 std::forward_list
<regcache
*> regcache::current_regcache
;
424 get_thread_arch_aspace_regcache (ptid_t ptid
, struct gdbarch
*gdbarch
,
425 struct address_space
*aspace
)
427 for (const auto ®cache
: regcache::current_regcache
)
428 if (ptid_equal (regcache
->ptid (), ptid
) && regcache
->arch () == gdbarch
)
431 regcache
*new_regcache
= new regcache (gdbarch
, aspace
, false);
433 regcache::current_regcache
.push_front (new_regcache
);
434 new_regcache
->set_ptid (ptid
);
440 get_thread_arch_regcache (ptid_t ptid
, struct gdbarch
*gdbarch
)
442 address_space
*aspace
= target_thread_address_space (ptid
);
444 return get_thread_arch_aspace_regcache (ptid
, gdbarch
, aspace
);
447 static ptid_t current_thread_ptid
;
448 static struct gdbarch
*current_thread_arch
;
451 get_thread_regcache (ptid_t ptid
)
453 if (!current_thread_arch
|| !ptid_equal (current_thread_ptid
, ptid
))
455 current_thread_ptid
= ptid
;
456 current_thread_arch
= target_thread_architecture (ptid
);
459 return get_thread_arch_regcache (ptid
, current_thread_arch
);
463 get_current_regcache (void)
465 return get_thread_regcache (inferior_ptid
);
468 /* See common/common-regcache.h. */
471 get_thread_regcache_for_ptid (ptid_t ptid
)
473 return get_thread_regcache (ptid
);
476 /* Observer for the target_changed event. */
479 regcache_observer_target_changed (struct target_ops
*target
)
481 registers_changed ();
484 /* Update global variables old ptids to hold NEW_PTID if they were
487 regcache::regcache_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
489 for (auto ®cache
: regcache::current_regcache
)
491 if (ptid_equal (regcache
->ptid (), old_ptid
))
492 regcache
->set_ptid (new_ptid
);
496 /* Low level examining and depositing of registers.
498 The caller is responsible for making sure that the inferior is
499 stopped before calling the fetching routines, or it will get
500 garbage. (a change from GDB version 3, in which the caller got the
501 value from the last stop). */
503 /* REGISTERS_CHANGED ()
505 Indicate that registers may have changed, so invalidate the cache. */
508 registers_changed_ptid (ptid_t ptid
)
510 for (auto oit
= regcache::current_regcache
.before_begin (),
511 it
= std::next (oit
);
512 it
!= regcache::current_regcache
.end ();
515 if (ptid_match ((*it
)->ptid (), ptid
))
518 it
= regcache::current_regcache
.erase_after (oit
);
524 if (ptid_match (current_thread_ptid
, ptid
))
526 current_thread_ptid
= null_ptid
;
527 current_thread_arch
= NULL
;
530 if (ptid_match (inferior_ptid
, ptid
))
532 /* We just deleted the regcache of the current thread. Need to
533 forget about any frames we have cached, too. */
534 reinit_frame_cache ();
539 registers_changed (void)
541 registers_changed_ptid (minus_one_ptid
);
543 /* Force cleanup of any alloca areas if using C alloca instead of
544 a builtin alloca. This particular call is used to clean up
545 areas allocated by low level target code which may build up
546 during lengthy interactions between gdb and the target before
547 gdb gives control to the user (ie watchpoints). */
552 regcache_raw_update (struct regcache
*regcache
, int regnum
)
554 gdb_assert (regcache
!= NULL
);
556 regcache
->raw_update (regnum
);
560 regcache::raw_update (int regnum
)
562 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
564 /* Make certain that the register cache is up-to-date with respect
565 to the current thread. This switching shouldn't be necessary
566 only there is still only one target side register cache. Sigh!
567 On the bright side, at least there is a regcache object. */
569 if (!m_readonly_p
&& get_register_status (regnum
) == REG_UNKNOWN
)
571 target_fetch_registers (this, regnum
);
573 /* A number of targets can't access the whole set of raw
574 registers (because the debug API provides no means to get at
576 if (m_register_status
[regnum
] == REG_UNKNOWN
)
577 m_register_status
[regnum
] = REG_UNAVAILABLE
;
582 regcache_raw_read (struct regcache
*regcache
, int regnum
, gdb_byte
*buf
)
584 return regcache
->raw_read (regnum
, buf
);
588 regcache::raw_read (int regnum
, gdb_byte
*buf
)
590 gdb_assert (buf
!= NULL
);
593 if (m_register_status
[regnum
] != REG_VALID
)
594 memset (buf
, 0, m_descr
->sizeof_register
[regnum
]);
596 memcpy (buf
, register_buffer (regnum
),
597 m_descr
->sizeof_register
[regnum
]);
599 return (enum register_status
) m_register_status
[regnum
];
603 regcache_raw_read_signed (struct regcache
*regcache
, int regnum
, LONGEST
*val
)
605 gdb_assert (regcache
!= NULL
);
606 return regcache
->raw_read (regnum
, val
);
609 template<typename T
, typename
>
611 regcache::raw_read (int regnum
, T
*val
)
614 enum register_status status
;
616 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
617 buf
= (gdb_byte
*) alloca (m_descr
->sizeof_register
[regnum
]);
618 status
= raw_read (regnum
, buf
);
619 if (status
== REG_VALID
)
620 *val
= extract_integer
<T
> (buf
,
621 m_descr
->sizeof_register
[regnum
],
622 gdbarch_byte_order (m_descr
->gdbarch
));
629 regcache_raw_read_unsigned (struct regcache
*regcache
, int regnum
,
632 gdb_assert (regcache
!= NULL
);
633 return regcache
->raw_read (regnum
, val
);
637 regcache_raw_write_signed (struct regcache
*regcache
, int regnum
, LONGEST val
)
639 gdb_assert (regcache
!= NULL
);
640 regcache
->raw_write (regnum
, val
);
643 template<typename T
, typename
>
645 regcache::raw_write (int regnum
, T val
)
649 gdb_assert (regnum
>=0 && regnum
< m_descr
->nr_raw_registers
);
650 buf
= (gdb_byte
*) alloca (m_descr
->sizeof_register
[regnum
]);
651 store_integer (buf
, m_descr
->sizeof_register
[regnum
],
652 gdbarch_byte_order (m_descr
->gdbarch
), val
);
653 raw_write (regnum
, buf
);
657 regcache_raw_write_unsigned (struct regcache
*regcache
, int regnum
,
660 gdb_assert (regcache
!= NULL
);
661 regcache
->raw_write (regnum
, val
);
665 regcache_raw_get_signed (struct regcache
*regcache
, int regnum
)
668 enum register_status status
;
670 status
= regcache_raw_read_signed (regcache
, regnum
, &value
);
671 if (status
== REG_UNAVAILABLE
)
672 throw_error (NOT_AVAILABLE_ERROR
,
673 _("Register %d is not available"), regnum
);
678 regcache_cooked_read (struct regcache
*regcache
, int regnum
, gdb_byte
*buf
)
680 return regcache
->cooked_read (regnum
, buf
);
684 regcache::cooked_read (int regnum
, gdb_byte
*buf
)
686 gdb_assert (regnum
>= 0);
687 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
688 if (regnum
< m_descr
->nr_raw_registers
)
689 return raw_read (regnum
, buf
);
690 else if (m_readonly_p
691 && m_register_status
[regnum
] != REG_UNKNOWN
)
693 /* Read-only register cache, perhaps the cooked value was
695 if (m_register_status
[regnum
] == REG_VALID
)
696 memcpy (buf
, register_buffer (regnum
),
697 m_descr
->sizeof_register
[regnum
]);
699 memset (buf
, 0, m_descr
->sizeof_register
[regnum
]);
701 return (enum register_status
) m_register_status
[regnum
];
703 else if (gdbarch_pseudo_register_read_value_p (m_descr
->gdbarch
))
705 struct value
*mark
, *computed
;
706 enum register_status result
= REG_VALID
;
708 mark
= value_mark ();
710 computed
= gdbarch_pseudo_register_read_value (m_descr
->gdbarch
,
712 if (value_entirely_available (computed
))
713 memcpy (buf
, value_contents_raw (computed
),
714 m_descr
->sizeof_register
[regnum
]);
717 memset (buf
, 0, m_descr
->sizeof_register
[regnum
]);
718 result
= REG_UNAVAILABLE
;
721 value_free_to_mark (mark
);
726 return gdbarch_pseudo_register_read (m_descr
->gdbarch
, this,
731 regcache_cooked_read_value (struct regcache
*regcache
, int regnum
)
733 return regcache
->cooked_read_value (regnum
);
737 regcache::cooked_read_value (int regnum
)
739 gdb_assert (regnum
>= 0);
740 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
742 if (regnum
< m_descr
->nr_raw_registers
743 || (m_readonly_p
&& m_register_status
[regnum
] != REG_UNKNOWN
)
744 || !gdbarch_pseudo_register_read_value_p (m_descr
->gdbarch
))
746 struct value
*result
;
748 result
= allocate_value (register_type (m_descr
->gdbarch
, regnum
));
749 VALUE_LVAL (result
) = lval_register
;
750 VALUE_REGNUM (result
) = regnum
;
752 /* It is more efficient in general to do this delegation in this
753 direction than in the other one, even though the value-based
755 if (cooked_read (regnum
,
756 value_contents_raw (result
)) == REG_UNAVAILABLE
)
757 mark_value_bytes_unavailable (result
, 0,
758 TYPE_LENGTH (value_type (result
)));
763 return gdbarch_pseudo_register_read_value (m_descr
->gdbarch
,
768 regcache_cooked_read_signed (struct regcache
*regcache
, int regnum
,
771 gdb_assert (regcache
!= NULL
);
772 return regcache
->cooked_read (regnum
, val
);
775 template<typename T
, typename
>
777 regcache::cooked_read (int regnum
, T
*val
)
779 enum register_status status
;
782 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_cooked_registers
);
783 buf
= (gdb_byte
*) alloca (m_descr
->sizeof_register
[regnum
]);
784 status
= cooked_read (regnum
, buf
);
785 if (status
== REG_VALID
)
786 *val
= extract_integer
<T
> (buf
, m_descr
->sizeof_register
[regnum
],
787 gdbarch_byte_order (m_descr
->gdbarch
));
794 regcache_cooked_read_unsigned (struct regcache
*regcache
, int regnum
,
797 gdb_assert (regcache
!= NULL
);
798 return regcache
->cooked_read (regnum
, val
);
802 regcache_cooked_write_signed (struct regcache
*regcache
, int regnum
,
805 gdb_assert (regcache
!= NULL
);
806 regcache
->cooked_write (regnum
, val
);
809 template<typename T
, typename
>
811 regcache::cooked_write (int regnum
, T val
)
815 gdb_assert (regnum
>=0 && regnum
< m_descr
->nr_cooked_registers
);
816 buf
= (gdb_byte
*) alloca (m_descr
->sizeof_register
[regnum
]);
817 store_integer (buf
, m_descr
->sizeof_register
[regnum
],
818 gdbarch_byte_order (m_descr
->gdbarch
), val
);
819 cooked_write (regnum
, buf
);
823 regcache_cooked_write_unsigned (struct regcache
*regcache
, int regnum
,
826 gdb_assert (regcache
!= NULL
);
827 regcache
->cooked_write (regnum
, val
);
830 /* See regcache.h. */
833 regcache_raw_set_cached_value (struct regcache
*regcache
, int regnum
,
836 regcache
->raw_set_cached_value (regnum
, buf
);
840 regcache::raw_set_cached_value (int regnum
, const gdb_byte
*buf
)
842 memcpy (register_buffer (regnum
), buf
,
843 m_descr
->sizeof_register
[regnum
]);
844 m_register_status
[regnum
] = REG_VALID
;
848 regcache_raw_write (struct regcache
*regcache
, int regnum
,
851 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
852 regcache
->raw_write (regnum
, buf
);
856 regcache::raw_write (int regnum
, const gdb_byte
*buf
)
859 gdb_assert (buf
!= NULL
);
860 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
861 gdb_assert (!m_readonly_p
);
863 /* On the sparc, writing %g0 is a no-op, so we don't even want to
864 change the registers array if something writes to this register. */
865 if (gdbarch_cannot_store_register (arch (), regnum
))
868 /* If we have a valid copy of the register, and new value == old
869 value, then don't bother doing the actual store. */
870 if (get_register_status (regnum
) == REG_VALID
871 && (memcmp (register_buffer (regnum
), buf
,
872 m_descr
->sizeof_register
[regnum
]) == 0))
875 target_prepare_to_store (this);
876 raw_set_cached_value (regnum
, buf
);
878 /* Invalidate the register after it is written, in case of a
880 regcache_invalidator
invalidator (this, regnum
);
882 target_store_registers (this, regnum
);
884 /* The target did not throw an error so we can discard invalidating
886 invalidator
.release ();
890 regcache_cooked_write (struct regcache
*regcache
, int regnum
,
893 regcache
->cooked_write (regnum
, buf
);
897 regcache::cooked_write (int regnum
, const gdb_byte
*buf
)
899 gdb_assert (regnum
>= 0);
900 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
901 if (regnum
< m_descr
->nr_raw_registers
)
902 raw_write (regnum
, buf
);
904 gdbarch_pseudo_register_write (m_descr
->gdbarch
, this,
908 /* Perform a partial register transfer using a read, modify, write
911 typedef void (regcache_read_ftype
) (struct regcache
*regcache
, int regnum
,
913 typedef void (regcache_write_ftype
) (struct regcache
*regcache
, int regnum
,
917 regcache::xfer_part (int regnum
, int offset
, int len
, void *in
,
918 const void *out
, bool is_raw
)
920 struct gdbarch
*gdbarch
= arch ();
921 gdb_byte
*reg
= (gdb_byte
*) alloca (register_size (gdbarch
, regnum
));
923 gdb_assert (offset
>= 0 && offset
<= m_descr
->sizeof_register
[regnum
]);
924 gdb_assert (len
>= 0 && offset
+ len
<= m_descr
->sizeof_register
[regnum
]);
925 /* Something to do? */
926 if (offset
+ len
== 0)
928 /* Read (when needed) ... */
931 || offset
+ len
< m_descr
->sizeof_register
[regnum
])
933 enum register_status status
;
935 gdb_assert (read
!= NULL
);
937 status
= raw_read (regnum
, reg
);
939 status
= cooked_read (regnum
, reg
);
940 if (status
!= REG_VALID
)
945 memcpy (in
, reg
+ offset
, len
);
947 memcpy (reg
+ offset
, out
, len
);
948 /* ... write (when needed). */
952 raw_write (regnum
, reg
);
954 cooked_write (regnum
, reg
);
961 regcache_raw_read_part (struct regcache
*regcache
, int regnum
,
962 int offset
, int len
, gdb_byte
*buf
)
964 return regcache
->raw_read_part (regnum
, offset
, len
, buf
);
968 regcache::raw_read_part (int regnum
, int offset
, int len
, gdb_byte
*buf
)
970 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
971 return xfer_part (regnum
, offset
, len
, buf
, NULL
, true);
975 regcache_raw_write_part (struct regcache
*regcache
, int regnum
,
976 int offset
, int len
, const gdb_byte
*buf
)
978 regcache
->raw_write_part (regnum
, offset
, len
, buf
);
982 regcache::raw_write_part (int regnum
, int offset
, int len
,
985 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
986 xfer_part (regnum
, offset
, len
, NULL
, buf
, true);
990 regcache_cooked_read_part (struct regcache
*regcache
, int regnum
,
991 int offset
, int len
, gdb_byte
*buf
)
993 return regcache
->cooked_read_part (regnum
, offset
, len
, buf
);
998 regcache::cooked_read_part (int regnum
, int offset
, int len
, gdb_byte
*buf
)
1000 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_cooked_registers
);
1001 return xfer_part (regnum
, offset
, len
, buf
, NULL
, false);
1005 regcache_cooked_write_part (struct regcache
*regcache
, int regnum
,
1006 int offset
, int len
, const gdb_byte
*buf
)
1008 regcache
->cooked_write_part (regnum
, offset
, len
, buf
);
1012 regcache::cooked_write_part (int regnum
, int offset
, int len
,
1013 const gdb_byte
*buf
)
1015 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_cooked_registers
);
1016 xfer_part (regnum
, offset
, len
, NULL
, buf
, false);
1019 /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */
1022 regcache_raw_supply (struct regcache
*regcache
, int regnum
, const void *buf
)
1024 gdb_assert (regcache
!= NULL
);
1025 regcache
->raw_supply (regnum
, buf
);
1029 regcache::raw_supply (int regnum
, const void *buf
)
1034 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
1035 gdb_assert (!m_readonly_p
);
1037 regbuf
= register_buffer (regnum
);
1038 size
= m_descr
->sizeof_register
[regnum
];
1042 memcpy (regbuf
, buf
, size
);
1043 m_register_status
[regnum
] = REG_VALID
;
1047 /* This memset not strictly necessary, but better than garbage
1048 in case the register value manages to escape somewhere (due
1049 to a bug, no less). */
1050 memset (regbuf
, 0, size
);
1051 m_register_status
[regnum
] = REG_UNAVAILABLE
;
1055 /* Supply register REGNUM to REGCACHE. Value to supply is an integer stored at
1056 address ADDR, in target endian, with length ADDR_LEN and sign IS_SIGNED. If
1057 the register size is greater than ADDR_LEN, then the integer will be sign or
1058 zero extended. If the register size is smaller than the integer, then the
1059 most significant bytes of the integer will be truncated. */
1062 regcache::raw_supply_integer (int regnum
, const gdb_byte
*addr
, int addr_len
,
1065 enum bfd_endian byte_order
= gdbarch_byte_order (m_descr
->gdbarch
);
1069 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
1070 gdb_assert (!m_readonly_p
);
1072 regbuf
= register_buffer (regnum
);
1073 regsize
= m_descr
->sizeof_register
[regnum
];
1075 copy_integer_to_size (regbuf
, regsize
, addr
, addr_len
, is_signed
,
1077 m_register_status
[regnum
] = REG_VALID
;
1080 /* Supply register REGNUM with zeroed value to REGCACHE. This is not the same
1081 as calling raw_supply with NULL (which will set the state to
1085 regcache::raw_supply_zeroed (int regnum
)
1090 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
1091 gdb_assert (!m_readonly_p
);
1093 regbuf
= register_buffer (regnum
);
1094 size
= m_descr
->sizeof_register
[regnum
];
1096 memset (regbuf
, 0, size
);
1097 m_register_status
[regnum
] = REG_VALID
;
1100 /* Collect register REGNUM from REGCACHE and store its contents in BUF. */
1103 regcache_raw_collect (const struct regcache
*regcache
, int regnum
, void *buf
)
1105 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
1106 regcache
->raw_collect (regnum
, buf
);
1110 regcache::raw_collect (int regnum
, void *buf
) const
1115 gdb_assert (buf
!= NULL
);
1116 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
1118 regbuf
= register_buffer (regnum
);
1119 size
= m_descr
->sizeof_register
[regnum
];
1120 memcpy (buf
, regbuf
, size
);
1123 /* Transfer a single or all registers belonging to a certain register
1124 set to or from a buffer. This is the main worker function for
1125 regcache_supply_regset and regcache_collect_regset. */
1127 /* Collect register REGNUM from REGCACHE. Store collected value as an integer
1128 at address ADDR, in target endian, with length ADDR_LEN and sign IS_SIGNED.
1129 If ADDR_LEN is greater than the register size, then the integer will be sign
1130 or zero extended. If ADDR_LEN is smaller than the register size, then the
1131 most significant bytes of the integer will be truncated. */
1134 regcache::raw_collect_integer (int regnum
, gdb_byte
*addr
, int addr_len
,
1135 bool is_signed
) const
1137 enum bfd_endian byte_order
= gdbarch_byte_order (m_descr
->gdbarch
);
1138 const gdb_byte
*regbuf
;
1141 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
1143 regbuf
= register_buffer (regnum
);
1144 regsize
= m_descr
->sizeof_register
[regnum
];
1146 copy_integer_to_size (addr
, addr_len
, regbuf
, regsize
, is_signed
,
1151 regcache::transfer_regset (const struct regset
*regset
,
1152 struct regcache
*out_regcache
,
1153 int regnum
, const void *in_buf
,
1154 void *out_buf
, size_t size
) const
1156 const struct regcache_map_entry
*map
;
1157 int offs
= 0, count
;
1159 for (map
= (const struct regcache_map_entry
*) regset
->regmap
;
1160 (count
= map
->count
) != 0;
1163 int regno
= map
->regno
;
1164 int slot_size
= map
->size
;
1166 if (slot_size
== 0 && regno
!= REGCACHE_MAP_SKIP
)
1167 slot_size
= m_descr
->sizeof_register
[regno
];
1169 if (regno
== REGCACHE_MAP_SKIP
1171 && (regnum
< regno
|| regnum
>= regno
+ count
)))
1172 offs
+= count
* slot_size
;
1174 else if (regnum
== -1)
1175 for (; count
--; regno
++, offs
+= slot_size
)
1177 if (offs
+ slot_size
> size
)
1181 raw_collect (regno
, (gdb_byte
*) out_buf
+ offs
);
1183 out_regcache
->raw_supply (regno
, in_buf
1184 ? (const gdb_byte
*) in_buf
+ offs
1189 /* Transfer a single register and return. */
1190 offs
+= (regnum
- regno
) * slot_size
;
1191 if (offs
+ slot_size
> size
)
1195 raw_collect (regnum
, (gdb_byte
*) out_buf
+ offs
);
1197 out_regcache
->raw_supply (regnum
, in_buf
1198 ? (const gdb_byte
*) in_buf
+ offs
1205 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1206 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1207 If BUF is NULL, set the register(s) to "unavailable" status. */
1210 regcache_supply_regset (const struct regset
*regset
,
1211 struct regcache
*regcache
,
1212 int regnum
, const void *buf
, size_t size
)
1214 regcache
->supply_regset (regset
, regnum
, buf
, size
);
1218 regcache::supply_regset (const struct regset
*regset
,
1219 int regnum
, const void *buf
, size_t size
)
1221 transfer_regset (regset
, this, regnum
, buf
, NULL
, size
);
1224 /* Collect register REGNUM from REGCACHE to BUF, using the register
1225 map in REGSET. If REGNUM is -1, do this for all registers in
1229 regcache_collect_regset (const struct regset
*regset
,
1230 const struct regcache
*regcache
,
1231 int regnum
, void *buf
, size_t size
)
1233 regcache
->collect_regset (regset
, regnum
, buf
, size
);
1237 regcache::collect_regset (const struct regset
*regset
,
1238 int regnum
, void *buf
, size_t size
) const
1240 transfer_regset (regset
, NULL
, regnum
, NULL
, buf
, size
);
1244 /* Special handling for register PC. */
1247 regcache_read_pc (struct regcache
*regcache
)
1249 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1253 if (gdbarch_read_pc_p (gdbarch
))
1254 pc_val
= gdbarch_read_pc (gdbarch
, regcache
);
1255 /* Else use per-frame method on get_current_frame. */
1256 else if (gdbarch_pc_regnum (gdbarch
) >= 0)
1260 if (regcache_cooked_read_unsigned (regcache
,
1261 gdbarch_pc_regnum (gdbarch
),
1262 &raw_val
) == REG_UNAVAILABLE
)
1263 throw_error (NOT_AVAILABLE_ERROR
, _("PC register is not available"));
1265 pc_val
= gdbarch_addr_bits_remove (gdbarch
, raw_val
);
1268 internal_error (__FILE__
, __LINE__
,
1269 _("regcache_read_pc: Unable to find PC"));
1274 regcache_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1276 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1278 if (gdbarch_write_pc_p (gdbarch
))
1279 gdbarch_write_pc (gdbarch
, regcache
, pc
);
1280 else if (gdbarch_pc_regnum (gdbarch
) >= 0)
1281 regcache_cooked_write_unsigned (regcache
,
1282 gdbarch_pc_regnum (gdbarch
), pc
);
1284 internal_error (__FILE__
, __LINE__
,
1285 _("regcache_write_pc: Unable to update PC"));
1287 /* Writing the PC (for instance, from "load") invalidates the
1289 reinit_frame_cache ();
1293 regcache::debug_print_register (const char *func
, int regno
)
1295 struct gdbarch
*gdbarch
= arch ();
1297 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
1298 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
)
1299 && gdbarch_register_name (gdbarch
, regno
) != NULL
1300 && gdbarch_register_name (gdbarch
, regno
)[0] != '\0')
1301 fprintf_unfiltered (gdb_stdlog
, "(%s)",
1302 gdbarch_register_name (gdbarch
, regno
));
1304 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
1305 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
))
1307 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1308 int size
= register_size (gdbarch
, regno
);
1309 gdb_byte
*buf
= register_buffer (regno
);
1311 fprintf_unfiltered (gdb_stdlog
, " = ");
1312 for (int i
= 0; i
< size
; i
++)
1314 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
1316 if (size
<= sizeof (LONGEST
))
1318 ULONGEST val
= extract_unsigned_integer (buf
, size
, byte_order
);
1320 fprintf_unfiltered (gdb_stdlog
, " %s %s",
1321 core_addr_to_string_nz (val
), plongest (val
));
1324 fprintf_unfiltered (gdb_stdlog
, "\n");
1328 reg_flush_command (char *command
, int from_tty
)
1330 /* Force-flush the register cache. */
1331 registers_changed ();
1333 printf_filtered (_("Register cache flushed.\n"));
1337 regcache::dump (ui_file
*file
, enum regcache_dump_what what_to_dump
)
1339 struct gdbarch
*gdbarch
= m_descr
->gdbarch
;
1341 int footnote_nr
= 0;
1342 int footnote_register_size
= 0;
1343 int footnote_register_offset
= 0;
1344 int footnote_register_type_name_null
= 0;
1345 long register_offset
= 0;
1348 fprintf_unfiltered (file
, "nr_raw_registers %d\n",
1349 m_descr
->nr_raw_registers
);
1350 fprintf_unfiltered (file
, "nr_cooked_registers %d\n",
1351 m_descr
->nr_cooked_registers
);
1352 fprintf_unfiltered (file
, "sizeof_raw_registers %ld\n",
1353 m_descr
->sizeof_raw_registers
);
1354 fprintf_unfiltered (file
, "sizeof_raw_register_status %ld\n",
1355 m_descr
->sizeof_raw_register_status
);
1356 fprintf_unfiltered (file
, "gdbarch_num_regs %d\n",
1357 gdbarch_num_regs (gdbarch
));
1358 fprintf_unfiltered (file
, "gdbarch_num_pseudo_regs %d\n",
1359 gdbarch_num_pseudo_regs (gdbarch
));
1362 gdb_assert (m_descr
->nr_cooked_registers
1363 == (gdbarch_num_regs (gdbarch
)
1364 + gdbarch_num_pseudo_regs (gdbarch
)));
1366 for (regnum
= -1; regnum
< m_descr
->nr_cooked_registers
; regnum
++)
1370 fprintf_unfiltered (file
, " %-10s", "Name");
1373 const char *p
= gdbarch_register_name (gdbarch
, regnum
);
1377 else if (p
[0] == '\0')
1379 fprintf_unfiltered (file
, " %-10s", p
);
1384 fprintf_unfiltered (file
, " %4s", "Nr");
1386 fprintf_unfiltered (file
, " %4d", regnum
);
1388 /* Relative number. */
1390 fprintf_unfiltered (file
, " %4s", "Rel");
1391 else if (regnum
< gdbarch_num_regs (gdbarch
))
1392 fprintf_unfiltered (file
, " %4d", regnum
);
1394 fprintf_unfiltered (file
, " %4d",
1395 (regnum
- gdbarch_num_regs (gdbarch
)));
1399 fprintf_unfiltered (file
, " %6s ", "Offset");
1402 fprintf_unfiltered (file
, " %6ld",
1403 m_descr
->register_offset
[regnum
]);
1404 if (register_offset
!= m_descr
->register_offset
[regnum
]
1406 && (m_descr
->register_offset
[regnum
]
1407 != (m_descr
->register_offset
[regnum
- 1]
1408 + m_descr
->sizeof_register
[regnum
- 1])))
1411 if (!footnote_register_offset
)
1412 footnote_register_offset
= ++footnote_nr
;
1413 fprintf_unfiltered (file
, "*%d", footnote_register_offset
);
1416 fprintf_unfiltered (file
, " ");
1417 register_offset
= (m_descr
->register_offset
[regnum
]
1418 + m_descr
->sizeof_register
[regnum
]);
1423 fprintf_unfiltered (file
, " %5s ", "Size");
1425 fprintf_unfiltered (file
, " %5ld", m_descr
->sizeof_register
[regnum
]);
1430 std::string name_holder
;
1436 static const char blt
[] = "builtin_type";
1438 t
= TYPE_NAME (register_type (arch (), regnum
));
1441 if (!footnote_register_type_name_null
)
1442 footnote_register_type_name_null
= ++footnote_nr
;
1443 name_holder
= string_printf ("*%d",
1444 footnote_register_type_name_null
);
1445 t
= name_holder
.c_str ();
1447 /* Chop a leading builtin_type. */
1448 if (startswith (t
, blt
))
1451 fprintf_unfiltered (file
, " %-15s", t
);
1454 /* Leading space always present. */
1455 fprintf_unfiltered (file
, " ");
1458 if (what_to_dump
== regcache_dump_raw
)
1461 fprintf_unfiltered (file
, "Raw value");
1462 else if (regnum
>= m_descr
->nr_raw_registers
)
1463 fprintf_unfiltered (file
, "<cooked>");
1464 else if (get_register_status (regnum
) == REG_UNKNOWN
)
1465 fprintf_unfiltered (file
, "<invalid>");
1466 else if (get_register_status (regnum
) == REG_UNAVAILABLE
)
1467 fprintf_unfiltered (file
, "<unavailable>");
1470 raw_update (regnum
);
1471 print_hex_chars (file
, register_buffer (regnum
),
1472 m_descr
->sizeof_register
[regnum
],
1473 gdbarch_byte_order (gdbarch
), true);
1477 /* Value, cooked. */
1478 if (what_to_dump
== regcache_dump_cooked
)
1481 fprintf_unfiltered (file
, "Cooked value");
1484 const gdb_byte
*buf
= NULL
;
1485 enum register_status status
;
1486 struct value
*value
= NULL
;
1488 if (regnum
< m_descr
->nr_raw_registers
)
1490 raw_update (regnum
);
1491 status
= get_register_status (regnum
);
1492 buf
= register_buffer (regnum
);
1496 value
= cooked_read_value (regnum
);
1498 if (!value_optimized_out (value
)
1499 && value_entirely_available (value
))
1502 buf
= value_contents_all (value
);
1505 status
= REG_UNAVAILABLE
;
1508 if (status
== REG_UNKNOWN
)
1509 fprintf_unfiltered (file
, "<invalid>");
1510 else if (status
== REG_UNAVAILABLE
)
1511 fprintf_unfiltered (file
, "<unavailable>");
1513 print_hex_chars (file
, buf
,
1514 m_descr
->sizeof_register
[regnum
],
1515 gdbarch_byte_order (gdbarch
), true);
1519 release_value (value
);
1525 /* Group members. */
1526 if (what_to_dump
== regcache_dump_groups
)
1529 fprintf_unfiltered (file
, "Groups");
1532 const char *sep
= "";
1533 struct reggroup
*group
;
1535 for (group
= reggroup_next (gdbarch
, NULL
);
1537 group
= reggroup_next (gdbarch
, group
))
1539 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
1541 fprintf_unfiltered (file
,
1542 "%s%s", sep
, reggroup_name (group
));
1549 /* Remote packet configuration. */
1550 if (what_to_dump
== regcache_dump_remote
)
1554 fprintf_unfiltered (file
, "Rmt Nr g/G Offset");
1556 else if (regnum
< m_descr
->nr_raw_registers
)
1560 if (remote_register_number_and_offset (arch (), regnum
,
1562 fprintf_unfiltered (file
, "%7d %11d", pnum
, poffset
);
1566 fprintf_unfiltered (file
, "\n");
1569 if (footnote_register_size
)
1570 fprintf_unfiltered (file
, "*%d: Inconsistent register sizes.\n",
1571 footnote_register_size
);
1572 if (footnote_register_offset
)
1573 fprintf_unfiltered (file
, "*%d: Inconsistent register offsets.\n",
1574 footnote_register_offset
);
1575 if (footnote_register_type_name_null
)
1576 fprintf_unfiltered (file
,
1577 "*%d: Register type's name NULL.\n",
1578 footnote_register_type_name_null
);
1582 regcache_print (const char *args
, enum regcache_dump_what what_to_dump
)
1584 /* Where to send output. */
1592 if (!file
.open (args
, "w"))
1593 perror_with_name (_("maintenance print architecture"));
1597 if (target_has_registers
)
1598 get_current_regcache ()->dump (out
, what_to_dump
);
1601 /* For the benefit of "maint print registers" & co when
1602 debugging an executable, allow dumping a regcache even when
1603 there is no thread selected / no registers. */
1604 regcache
dummy_regs (target_gdbarch (), nullptr);
1605 dummy_regs
.dump (out
, what_to_dump
);
1610 maintenance_print_registers (const char *args
, int from_tty
)
1612 regcache_print (args
, regcache_dump_none
);
1616 maintenance_print_raw_registers (const char *args
, int from_tty
)
1618 regcache_print (args
, regcache_dump_raw
);
1622 maintenance_print_cooked_registers (const char *args
, int from_tty
)
1624 regcache_print (args
, regcache_dump_cooked
);
1628 maintenance_print_register_groups (const char *args
, int from_tty
)
1630 regcache_print (args
, regcache_dump_groups
);
1634 maintenance_print_remote_registers (const char *args
, int from_tty
)
1636 regcache_print (args
, regcache_dump_remote
);
1640 #include "selftest.h"
1642 namespace selftests
{
1644 class regcache_access
: public regcache
1648 /* Return the number of elements in current_regcache. */
1651 current_regcache_size ()
1653 return std::distance (regcache::current_regcache
.begin (),
1654 regcache::current_regcache
.end ());
1659 current_regcache_test (void)
1661 /* It is empty at the start. */
1662 SELF_CHECK (regcache_access::current_regcache_size () == 0);
1664 ptid_t
ptid1 (1), ptid2 (2), ptid3 (3);
1666 /* Get regcache from ptid1, a new regcache is added to
1667 current_regcache. */
1668 regcache
*regcache
= get_thread_arch_aspace_regcache (ptid1
,
1672 SELF_CHECK (regcache
!= NULL
);
1673 SELF_CHECK (regcache
->ptid () == ptid1
);
1674 SELF_CHECK (regcache_access::current_regcache_size () == 1);
1676 /* Get regcache from ptid2, a new regcache is added to
1677 current_regcache. */
1678 regcache
= get_thread_arch_aspace_regcache (ptid2
,
1681 SELF_CHECK (regcache
!= NULL
);
1682 SELF_CHECK (regcache
->ptid () == ptid2
);
1683 SELF_CHECK (regcache_access::current_regcache_size () == 2);
1685 /* Get regcache from ptid3, a new regcache is added to
1686 current_regcache. */
1687 regcache
= get_thread_arch_aspace_regcache (ptid3
,
1690 SELF_CHECK (regcache
!= NULL
);
1691 SELF_CHECK (regcache
->ptid () == ptid3
);
1692 SELF_CHECK (regcache_access::current_regcache_size () == 3);
1694 /* Get regcache from ptid2 again, nothing is added to
1695 current_regcache. */
1696 regcache
= get_thread_arch_aspace_regcache (ptid2
,
1699 SELF_CHECK (regcache
!= NULL
);
1700 SELF_CHECK (regcache
->ptid () == ptid2
);
1701 SELF_CHECK (regcache_access::current_regcache_size () == 3);
1703 /* Mark ptid2 is changed, so regcache of ptid2 should be removed from
1704 current_regcache. */
1705 registers_changed_ptid (ptid2
);
1706 SELF_CHECK (regcache_access::current_regcache_size () == 2);
1709 } // namespace selftests
1710 #endif /* GDB_SELF_TEST */
1713 _initialize_regcache (void)
1715 regcache_descr_handle
1716 = gdbarch_data_register_post_init (init_regcache_descr
);
1718 observer_attach_target_changed (regcache_observer_target_changed
);
1719 observer_attach_thread_ptid_changed (regcache::regcache_thread_ptid_changed
);
1721 add_com ("flushregs", class_maintenance
, reg_flush_command
,
1722 _("Force gdb to flush its register cache (maintainer command)"));
1724 add_cmd ("registers", class_maintenance
, maintenance_print_registers
,
1725 _("Print the internal register configuration.\n"
1726 "Takes an optional file parameter."), &maintenanceprintlist
);
1727 add_cmd ("raw-registers", class_maintenance
,
1728 maintenance_print_raw_registers
,
1729 _("Print the internal register configuration "
1730 "including raw values.\n"
1731 "Takes an optional file parameter."), &maintenanceprintlist
);
1732 add_cmd ("cooked-registers", class_maintenance
,
1733 maintenance_print_cooked_registers
,
1734 _("Print the internal register configuration "
1735 "including cooked values.\n"
1736 "Takes an optional file parameter."), &maintenanceprintlist
);
1737 add_cmd ("register-groups", class_maintenance
,
1738 maintenance_print_register_groups
,
1739 _("Print the internal register configuration "
1740 "including each register's group.\n"
1741 "Takes an optional file parameter."),
1742 &maintenanceprintlist
);
1743 add_cmd ("remote-registers", class_maintenance
,
1744 maintenance_print_remote_registers
, _("\
1745 Print the internal register configuration including each register's\n\
1746 remote register number and buffer offset in the g/G packets.\n\
1747 Takes an optional file parameter."),
1748 &maintenanceprintlist
);
1751 selftests::register_test ("current_regcache", selftests::current_regcache_test
);