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 (regcache
->arch (), 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 struct address_space
*
276 get_regcache_aspace (const struct regcache
*regcache
)
278 return regcache
->aspace ();
281 /* Return a pointer to register REGNUM's buffer cache. */
284 regcache::register_buffer (int regnum
) const
286 return m_registers
+ m_descr
->register_offset
[regnum
];
290 regcache_save (struct regcache
*regcache
,
291 regcache_cooked_read_ftype
*cooked_read
, void *src
)
293 regcache
->save (cooked_read
, src
);
297 regcache::save (regcache_cooked_read_ftype
*cooked_read
,
300 struct gdbarch
*gdbarch
= m_descr
->gdbarch
;
303 /* The DST should be `read-only', if it wasn't then the save would
304 end up trying to write the register values back out to the
306 gdb_assert (m_readonly_p
);
307 /* Clear the dest. */
308 memset (m_registers
, 0, m_descr
->sizeof_cooked_registers
);
309 memset (m_register_status
, 0, m_descr
->sizeof_cooked_register_status
);
310 /* Copy over any registers (identified by their membership in the
311 save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs +
312 gdbarch_num_pseudo_regs) range is checked since some architectures need
313 to save/restore `cooked' registers that live in memory. */
314 for (regnum
= 0; regnum
< m_descr
->nr_cooked_registers
; regnum
++)
316 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, save_reggroup
))
318 gdb_byte
*dst_buf
= register_buffer (regnum
);
319 enum register_status status
= cooked_read (src
, regnum
, dst_buf
);
321 gdb_assert (status
!= REG_UNKNOWN
);
323 if (status
!= REG_VALID
)
324 memset (dst_buf
, 0, register_size (gdbarch
, regnum
));
326 m_register_status
[regnum
] = status
;
332 regcache::restore (struct regcache
*src
)
334 struct gdbarch
*gdbarch
= m_descr
->gdbarch
;
337 /* The dst had better not be read-only. If it is, the `restore'
338 doesn't make much sense. */
339 gdb_assert (!m_readonly_p
);
340 gdb_assert (src
->m_readonly_p
);
341 /* Copy over any registers, being careful to only restore those that
342 were both saved and need to be restored. 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
, restore_reggroup
))
349 if (src
->m_register_status
[regnum
] == REG_VALID
)
350 cooked_write (regnum
, src
->register_buffer (regnum
));
356 regcache_cpy (struct regcache
*dst
, struct regcache
*src
)
358 gdb_assert (src
!= NULL
&& dst
!= NULL
);
359 gdb_assert (src
->m_descr
->gdbarch
== dst
->m_descr
->gdbarch
);
360 gdb_assert (src
!= dst
);
361 gdb_assert (src
->m_readonly_p
&& !dst
->m_readonly_p
);
367 regcache_dup (struct regcache
*src
)
369 return new regcache (regcache::readonly
, *src
);
373 regcache_register_status (const struct regcache
*regcache
, int regnum
)
375 gdb_assert (regcache
!= NULL
);
376 return regcache
->get_register_status (regnum
);
380 regcache::get_register_status (int regnum
) const
382 gdb_assert (regnum
>= 0);
384 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
386 gdb_assert (regnum
< m_descr
->nr_raw_registers
);
388 return (enum register_status
) m_register_status
[regnum
];
392 regcache_invalidate (struct regcache
*regcache
, int regnum
)
394 gdb_assert (regcache
!= NULL
);
395 regcache
->invalidate (regnum
);
399 regcache::invalidate (int regnum
)
401 gdb_assert (regnum
>= 0);
402 gdb_assert (!m_readonly_p
);
403 gdb_assert (regnum
< m_descr
->nr_raw_registers
);
404 m_register_status
[regnum
] = REG_UNKNOWN
;
407 /* Global structure containing the current regcache. */
409 /* NOTE: this is a write-through cache. There is no "dirty" bit for
410 recording if the register values have been changed (eg. by the
411 user). Therefore all registers must be written back to the
412 target when appropriate. */
413 std::forward_list
<regcache
*> regcache::current_regcache
;
416 get_thread_arch_aspace_regcache (ptid_t ptid
, struct gdbarch
*gdbarch
,
417 struct address_space
*aspace
)
419 for (const auto ®cache
: regcache::current_regcache
)
420 if (ptid_equal (regcache
->ptid (), ptid
) && regcache
->arch () == gdbarch
)
423 regcache
*new_regcache
= new regcache (gdbarch
, aspace
, false);
425 regcache::current_regcache
.push_front (new_regcache
);
426 new_regcache
->set_ptid (ptid
);
432 get_thread_arch_regcache (ptid_t ptid
, struct gdbarch
*gdbarch
)
434 address_space
*aspace
= target_thread_address_space (ptid
);
436 return get_thread_arch_aspace_regcache (ptid
, gdbarch
, aspace
);
439 static ptid_t current_thread_ptid
;
440 static struct gdbarch
*current_thread_arch
;
443 get_thread_regcache (ptid_t ptid
)
445 if (!current_thread_arch
|| !ptid_equal (current_thread_ptid
, ptid
))
447 current_thread_ptid
= ptid
;
448 current_thread_arch
= target_thread_architecture (ptid
);
451 return get_thread_arch_regcache (ptid
, current_thread_arch
);
455 get_current_regcache (void)
457 return get_thread_regcache (inferior_ptid
);
460 /* See common/common-regcache.h. */
463 get_thread_regcache_for_ptid (ptid_t ptid
)
465 return get_thread_regcache (ptid
);
468 /* Observer for the target_changed event. */
471 regcache_observer_target_changed (struct target_ops
*target
)
473 registers_changed ();
476 /* Update global variables old ptids to hold NEW_PTID if they were
479 regcache::regcache_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
481 for (auto ®cache
: regcache::current_regcache
)
483 if (ptid_equal (regcache
->ptid (), old_ptid
))
484 regcache
->set_ptid (new_ptid
);
488 /* Low level examining and depositing of registers.
490 The caller is responsible for making sure that the inferior is
491 stopped before calling the fetching routines, or it will get
492 garbage. (a change from GDB version 3, in which the caller got the
493 value from the last stop). */
495 /* REGISTERS_CHANGED ()
497 Indicate that registers may have changed, so invalidate the cache. */
500 registers_changed_ptid (ptid_t ptid
)
502 for (auto oit
= regcache::current_regcache
.before_begin (),
503 it
= std::next (oit
);
504 it
!= regcache::current_regcache
.end ();
507 if (ptid_match ((*it
)->ptid (), ptid
))
510 it
= regcache::current_regcache
.erase_after (oit
);
516 if (ptid_match (current_thread_ptid
, ptid
))
518 current_thread_ptid
= null_ptid
;
519 current_thread_arch
= NULL
;
522 if (ptid_match (inferior_ptid
, ptid
))
524 /* We just deleted the regcache of the current thread. Need to
525 forget about any frames we have cached, too. */
526 reinit_frame_cache ();
531 registers_changed (void)
533 registers_changed_ptid (minus_one_ptid
);
535 /* Force cleanup of any alloca areas if using C alloca instead of
536 a builtin alloca. This particular call is used to clean up
537 areas allocated by low level target code which may build up
538 during lengthy interactions between gdb and the target before
539 gdb gives control to the user (ie watchpoints). */
544 regcache_raw_update (struct regcache
*regcache
, int regnum
)
546 gdb_assert (regcache
!= NULL
);
548 regcache
->raw_update (regnum
);
552 regcache::raw_update (int regnum
)
554 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
556 /* Make certain that the register cache is up-to-date with respect
557 to the current thread. This switching shouldn't be necessary
558 only there is still only one target side register cache. Sigh!
559 On the bright side, at least there is a regcache object. */
561 if (!m_readonly_p
&& get_register_status (regnum
) == REG_UNKNOWN
)
563 target_fetch_registers (this, regnum
);
565 /* A number of targets can't access the whole set of raw
566 registers (because the debug API provides no means to get at
568 if (m_register_status
[regnum
] == REG_UNKNOWN
)
569 m_register_status
[regnum
] = REG_UNAVAILABLE
;
574 regcache_raw_read (struct regcache
*regcache
, int regnum
, gdb_byte
*buf
)
576 return regcache
->raw_read (regnum
, buf
);
580 regcache::raw_read (int regnum
, gdb_byte
*buf
)
582 gdb_assert (buf
!= NULL
);
585 if (m_register_status
[regnum
] != REG_VALID
)
586 memset (buf
, 0, m_descr
->sizeof_register
[regnum
]);
588 memcpy (buf
, register_buffer (regnum
),
589 m_descr
->sizeof_register
[regnum
]);
591 return (enum register_status
) m_register_status
[regnum
];
595 regcache_raw_read_signed (struct regcache
*regcache
, int regnum
, LONGEST
*val
)
597 gdb_assert (regcache
!= NULL
);
598 return regcache
->raw_read (regnum
, val
);
601 template<typename T
, typename
>
603 regcache::raw_read (int regnum
, T
*val
)
606 enum register_status status
;
608 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
609 buf
= (gdb_byte
*) alloca (m_descr
->sizeof_register
[regnum
]);
610 status
= raw_read (regnum
, buf
);
611 if (status
== REG_VALID
)
612 *val
= extract_integer
<T
> (buf
,
613 m_descr
->sizeof_register
[regnum
],
614 gdbarch_byte_order (m_descr
->gdbarch
));
621 regcache_raw_read_unsigned (struct regcache
*regcache
, int regnum
,
624 gdb_assert (regcache
!= NULL
);
625 return regcache
->raw_read (regnum
, val
);
629 regcache_raw_write_signed (struct regcache
*regcache
, int regnum
, LONGEST val
)
631 gdb_assert (regcache
!= NULL
);
632 regcache
->raw_write (regnum
, val
);
635 template<typename T
, typename
>
637 regcache::raw_write (int regnum
, T val
)
641 gdb_assert (regnum
>=0 && regnum
< m_descr
->nr_raw_registers
);
642 buf
= (gdb_byte
*) alloca (m_descr
->sizeof_register
[regnum
]);
643 store_integer (buf
, m_descr
->sizeof_register
[regnum
],
644 gdbarch_byte_order (m_descr
->gdbarch
), val
);
645 raw_write (regnum
, buf
);
649 regcache_raw_write_unsigned (struct regcache
*regcache
, int regnum
,
652 gdb_assert (regcache
!= NULL
);
653 regcache
->raw_write (regnum
, val
);
657 regcache_raw_get_signed (struct regcache
*regcache
, int regnum
)
660 enum register_status status
;
662 status
= regcache_raw_read_signed (regcache
, regnum
, &value
);
663 if (status
== REG_UNAVAILABLE
)
664 throw_error (NOT_AVAILABLE_ERROR
,
665 _("Register %d is not available"), regnum
);
670 regcache_cooked_read (struct regcache
*regcache
, int regnum
, gdb_byte
*buf
)
672 return regcache
->cooked_read (regnum
, buf
);
676 regcache::cooked_read (int regnum
, gdb_byte
*buf
)
678 gdb_assert (regnum
>= 0);
679 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
680 if (regnum
< m_descr
->nr_raw_registers
)
681 return raw_read (regnum
, buf
);
682 else if (m_readonly_p
683 && m_register_status
[regnum
] != REG_UNKNOWN
)
685 /* Read-only register cache, perhaps the cooked value was
687 if (m_register_status
[regnum
] == REG_VALID
)
688 memcpy (buf
, register_buffer (regnum
),
689 m_descr
->sizeof_register
[regnum
]);
691 memset (buf
, 0, m_descr
->sizeof_register
[regnum
]);
693 return (enum register_status
) m_register_status
[regnum
];
695 else if (gdbarch_pseudo_register_read_value_p (m_descr
->gdbarch
))
697 struct value
*mark
, *computed
;
698 enum register_status result
= REG_VALID
;
700 mark
= value_mark ();
702 computed
= gdbarch_pseudo_register_read_value (m_descr
->gdbarch
,
704 if (value_entirely_available (computed
))
705 memcpy (buf
, value_contents_raw (computed
),
706 m_descr
->sizeof_register
[regnum
]);
709 memset (buf
, 0, m_descr
->sizeof_register
[regnum
]);
710 result
= REG_UNAVAILABLE
;
713 value_free_to_mark (mark
);
718 return gdbarch_pseudo_register_read (m_descr
->gdbarch
, this,
723 regcache_cooked_read_value (struct regcache
*regcache
, int regnum
)
725 return regcache
->cooked_read_value (regnum
);
729 regcache::cooked_read_value (int regnum
)
731 gdb_assert (regnum
>= 0);
732 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
734 if (regnum
< m_descr
->nr_raw_registers
735 || (m_readonly_p
&& m_register_status
[regnum
] != REG_UNKNOWN
)
736 || !gdbarch_pseudo_register_read_value_p (m_descr
->gdbarch
))
738 struct value
*result
;
740 result
= allocate_value (register_type (m_descr
->gdbarch
, regnum
));
741 VALUE_LVAL (result
) = lval_register
;
742 VALUE_REGNUM (result
) = regnum
;
744 /* It is more efficient in general to do this delegation in this
745 direction than in the other one, even though the value-based
747 if (cooked_read (regnum
,
748 value_contents_raw (result
)) == REG_UNAVAILABLE
)
749 mark_value_bytes_unavailable (result
, 0,
750 TYPE_LENGTH (value_type (result
)));
755 return gdbarch_pseudo_register_read_value (m_descr
->gdbarch
,
760 regcache_cooked_read_signed (struct regcache
*regcache
, int regnum
,
763 gdb_assert (regcache
!= NULL
);
764 return regcache
->cooked_read (regnum
, val
);
767 template<typename T
, typename
>
769 regcache::cooked_read (int regnum
, T
*val
)
771 enum register_status status
;
774 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_cooked_registers
);
775 buf
= (gdb_byte
*) alloca (m_descr
->sizeof_register
[regnum
]);
776 status
= cooked_read (regnum
, buf
);
777 if (status
== REG_VALID
)
778 *val
= extract_integer
<T
> (buf
, m_descr
->sizeof_register
[regnum
],
779 gdbarch_byte_order (m_descr
->gdbarch
));
786 regcache_cooked_read_unsigned (struct regcache
*regcache
, int regnum
,
789 gdb_assert (regcache
!= NULL
);
790 return regcache
->cooked_read (regnum
, val
);
794 regcache_cooked_write_signed (struct regcache
*regcache
, int regnum
,
797 gdb_assert (regcache
!= NULL
);
798 regcache
->cooked_write (regnum
, val
);
801 template<typename T
, typename
>
803 regcache::cooked_write (int regnum
, T val
)
807 gdb_assert (regnum
>=0 && regnum
< m_descr
->nr_cooked_registers
);
808 buf
= (gdb_byte
*) alloca (m_descr
->sizeof_register
[regnum
]);
809 store_integer (buf
, m_descr
->sizeof_register
[regnum
],
810 gdbarch_byte_order (m_descr
->gdbarch
), val
);
811 cooked_write (regnum
, buf
);
815 regcache_cooked_write_unsigned (struct regcache
*regcache
, int regnum
,
818 gdb_assert (regcache
!= NULL
);
819 regcache
->cooked_write (regnum
, val
);
822 /* See regcache.h. */
825 regcache_raw_set_cached_value (struct regcache
*regcache
, int regnum
,
828 regcache
->raw_set_cached_value (regnum
, buf
);
832 regcache::raw_set_cached_value (int regnum
, const gdb_byte
*buf
)
834 memcpy (register_buffer (regnum
), buf
,
835 m_descr
->sizeof_register
[regnum
]);
836 m_register_status
[regnum
] = REG_VALID
;
840 regcache_raw_write (struct regcache
*regcache
, int regnum
,
843 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
844 regcache
->raw_write (regnum
, buf
);
848 regcache::raw_write (int regnum
, const gdb_byte
*buf
)
851 gdb_assert (buf
!= NULL
);
852 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
853 gdb_assert (!m_readonly_p
);
855 /* On the sparc, writing %g0 is a no-op, so we don't even want to
856 change the registers array if something writes to this register. */
857 if (gdbarch_cannot_store_register (arch (), regnum
))
860 /* If we have a valid copy of the register, and new value == old
861 value, then don't bother doing the actual store. */
862 if (get_register_status (regnum
) == REG_VALID
863 && (memcmp (register_buffer (regnum
), buf
,
864 m_descr
->sizeof_register
[regnum
]) == 0))
867 target_prepare_to_store (this);
868 raw_set_cached_value (regnum
, buf
);
870 /* Invalidate the register after it is written, in case of a
872 regcache_invalidator
invalidator (this, regnum
);
874 target_store_registers (this, regnum
);
876 /* The target did not throw an error so we can discard invalidating
878 invalidator
.release ();
882 regcache_cooked_write (struct regcache
*regcache
, int regnum
,
885 regcache
->cooked_write (regnum
, buf
);
889 regcache::cooked_write (int regnum
, const gdb_byte
*buf
)
891 gdb_assert (regnum
>= 0);
892 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
893 if (regnum
< m_descr
->nr_raw_registers
)
894 raw_write (regnum
, buf
);
896 gdbarch_pseudo_register_write (m_descr
->gdbarch
, this,
900 /* Perform a partial register transfer using a read, modify, write
903 typedef void (regcache_read_ftype
) (struct regcache
*regcache
, int regnum
,
905 typedef void (regcache_write_ftype
) (struct regcache
*regcache
, int regnum
,
909 regcache::xfer_part (int regnum
, int offset
, int len
, void *in
,
910 const void *out
, bool is_raw
)
912 struct gdbarch
*gdbarch
= arch ();
913 gdb_byte
*reg
= (gdb_byte
*) alloca (register_size (gdbarch
, regnum
));
915 gdb_assert (offset
>= 0 && offset
<= m_descr
->sizeof_register
[regnum
]);
916 gdb_assert (len
>= 0 && offset
+ len
<= m_descr
->sizeof_register
[regnum
]);
917 /* Something to do? */
918 if (offset
+ len
== 0)
920 /* Read (when needed) ... */
923 || offset
+ len
< m_descr
->sizeof_register
[regnum
])
925 enum register_status status
;
928 status
= raw_read (regnum
, reg
);
930 status
= cooked_read (regnum
, reg
);
931 if (status
!= REG_VALID
)
936 memcpy (in
, reg
+ offset
, len
);
938 memcpy (reg
+ offset
, out
, len
);
939 /* ... write (when needed). */
943 raw_write (regnum
, reg
);
945 cooked_write (regnum
, reg
);
952 regcache_raw_read_part (struct regcache
*regcache
, int regnum
,
953 int offset
, int len
, gdb_byte
*buf
)
955 return regcache
->raw_read_part (regnum
, offset
, len
, buf
);
959 regcache::raw_read_part (int regnum
, int offset
, int len
, gdb_byte
*buf
)
961 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
962 return xfer_part (regnum
, offset
, len
, buf
, NULL
, true);
966 regcache_raw_write_part (struct regcache
*regcache
, int regnum
,
967 int offset
, int len
, const gdb_byte
*buf
)
969 regcache
->raw_write_part (regnum
, offset
, len
, buf
);
973 regcache::raw_write_part (int regnum
, int offset
, int len
,
976 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
977 xfer_part (regnum
, offset
, len
, NULL
, buf
, true);
981 regcache_cooked_read_part (struct regcache
*regcache
, int regnum
,
982 int offset
, int len
, gdb_byte
*buf
)
984 return regcache
->cooked_read_part (regnum
, offset
, len
, buf
);
989 regcache::cooked_read_part (int regnum
, int offset
, int len
, gdb_byte
*buf
)
991 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_cooked_registers
);
992 return xfer_part (regnum
, offset
, len
, buf
, NULL
, false);
996 regcache_cooked_write_part (struct regcache
*regcache
, int regnum
,
997 int offset
, int len
, const gdb_byte
*buf
)
999 regcache
->cooked_write_part (regnum
, offset
, len
, buf
);
1003 regcache::cooked_write_part (int regnum
, int offset
, int len
,
1004 const gdb_byte
*buf
)
1006 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_cooked_registers
);
1007 xfer_part (regnum
, offset
, len
, NULL
, buf
, false);
1010 /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */
1013 regcache_raw_supply (struct regcache
*regcache
, int regnum
, const void *buf
)
1015 gdb_assert (regcache
!= NULL
);
1016 regcache
->raw_supply (regnum
, buf
);
1020 regcache::raw_supply (int regnum
, const void *buf
)
1025 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
1026 gdb_assert (!m_readonly_p
);
1028 regbuf
= register_buffer (regnum
);
1029 size
= m_descr
->sizeof_register
[regnum
];
1033 memcpy (regbuf
, buf
, size
);
1034 m_register_status
[regnum
] = REG_VALID
;
1038 /* This memset not strictly necessary, but better than garbage
1039 in case the register value manages to escape somewhere (due
1040 to a bug, no less). */
1041 memset (regbuf
, 0, size
);
1042 m_register_status
[regnum
] = REG_UNAVAILABLE
;
1046 /* Supply register REGNUM to REGCACHE. Value to supply is an integer stored at
1047 address ADDR, in target endian, with length ADDR_LEN and sign IS_SIGNED. If
1048 the register size is greater than ADDR_LEN, then the integer will be sign or
1049 zero extended. If the register size is smaller than the integer, then the
1050 most significant bytes of the integer will be truncated. */
1053 regcache::raw_supply_integer (int regnum
, const gdb_byte
*addr
, int addr_len
,
1056 enum bfd_endian byte_order
= gdbarch_byte_order (m_descr
->gdbarch
);
1060 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
1061 gdb_assert (!m_readonly_p
);
1063 regbuf
= register_buffer (regnum
);
1064 regsize
= m_descr
->sizeof_register
[regnum
];
1066 copy_integer_to_size (regbuf
, regsize
, addr
, addr_len
, is_signed
,
1068 m_register_status
[regnum
] = REG_VALID
;
1071 /* Supply register REGNUM with zeroed value to REGCACHE. This is not the same
1072 as calling raw_supply with NULL (which will set the state to
1076 regcache::raw_supply_zeroed (int regnum
)
1081 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
1082 gdb_assert (!m_readonly_p
);
1084 regbuf
= register_buffer (regnum
);
1085 size
= m_descr
->sizeof_register
[regnum
];
1087 memset (regbuf
, 0, size
);
1088 m_register_status
[regnum
] = REG_VALID
;
1091 /* Collect register REGNUM from REGCACHE and store its contents in BUF. */
1094 regcache_raw_collect (const struct regcache
*regcache
, int regnum
, void *buf
)
1096 gdb_assert (regcache
!= NULL
&& buf
!= NULL
);
1097 regcache
->raw_collect (regnum
, buf
);
1101 regcache::raw_collect (int regnum
, void *buf
) const
1106 gdb_assert (buf
!= NULL
);
1107 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
1109 regbuf
= register_buffer (regnum
);
1110 size
= m_descr
->sizeof_register
[regnum
];
1111 memcpy (buf
, regbuf
, size
);
1114 /* Transfer a single or all registers belonging to a certain register
1115 set to or from a buffer. This is the main worker function for
1116 regcache_supply_regset and regcache_collect_regset. */
1118 /* Collect register REGNUM from REGCACHE. Store collected value as an integer
1119 at address ADDR, in target endian, with length ADDR_LEN and sign IS_SIGNED.
1120 If ADDR_LEN is greater than the register size, then the integer will be sign
1121 or zero extended. If ADDR_LEN is smaller than the register size, then the
1122 most significant bytes of the integer will be truncated. */
1125 regcache::raw_collect_integer (int regnum
, gdb_byte
*addr
, int addr_len
,
1126 bool is_signed
) const
1128 enum bfd_endian byte_order
= gdbarch_byte_order (m_descr
->gdbarch
);
1129 const gdb_byte
*regbuf
;
1132 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_raw_registers
);
1134 regbuf
= register_buffer (regnum
);
1135 regsize
= m_descr
->sizeof_register
[regnum
];
1137 copy_integer_to_size (addr
, addr_len
, regbuf
, regsize
, is_signed
,
1142 regcache::transfer_regset (const struct regset
*regset
,
1143 struct regcache
*out_regcache
,
1144 int regnum
, const void *in_buf
,
1145 void *out_buf
, size_t size
) const
1147 const struct regcache_map_entry
*map
;
1148 int offs
= 0, count
;
1150 for (map
= (const struct regcache_map_entry
*) regset
->regmap
;
1151 (count
= map
->count
) != 0;
1154 int regno
= map
->regno
;
1155 int slot_size
= map
->size
;
1157 if (slot_size
== 0 && regno
!= REGCACHE_MAP_SKIP
)
1158 slot_size
= m_descr
->sizeof_register
[regno
];
1160 if (regno
== REGCACHE_MAP_SKIP
1162 && (regnum
< regno
|| regnum
>= regno
+ count
)))
1163 offs
+= count
* slot_size
;
1165 else if (regnum
== -1)
1166 for (; count
--; regno
++, offs
+= slot_size
)
1168 if (offs
+ slot_size
> size
)
1172 raw_collect (regno
, (gdb_byte
*) out_buf
+ offs
);
1174 out_regcache
->raw_supply (regno
, in_buf
1175 ? (const gdb_byte
*) in_buf
+ offs
1180 /* Transfer a single register and return. */
1181 offs
+= (regnum
- regno
) * slot_size
;
1182 if (offs
+ slot_size
> size
)
1186 raw_collect (regnum
, (gdb_byte
*) out_buf
+ offs
);
1188 out_regcache
->raw_supply (regnum
, in_buf
1189 ? (const gdb_byte
*) in_buf
+ offs
1196 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1197 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1198 If BUF is NULL, set the register(s) to "unavailable" status. */
1201 regcache_supply_regset (const struct regset
*regset
,
1202 struct regcache
*regcache
,
1203 int regnum
, const void *buf
, size_t size
)
1205 regcache
->supply_regset (regset
, regnum
, buf
, size
);
1209 regcache::supply_regset (const struct regset
*regset
,
1210 int regnum
, const void *buf
, size_t size
)
1212 transfer_regset (regset
, this, regnum
, buf
, NULL
, size
);
1215 /* Collect register REGNUM from REGCACHE to BUF, using the register
1216 map in REGSET. If REGNUM is -1, do this for all registers in
1220 regcache_collect_regset (const struct regset
*regset
,
1221 const struct regcache
*regcache
,
1222 int regnum
, void *buf
, size_t size
)
1224 regcache
->collect_regset (regset
, regnum
, buf
, size
);
1228 regcache::collect_regset (const struct regset
*regset
,
1229 int regnum
, void *buf
, size_t size
) const
1231 transfer_regset (regset
, NULL
, regnum
, NULL
, buf
, size
);
1235 /* Special handling for register PC. */
1238 regcache_read_pc (struct regcache
*regcache
)
1240 struct gdbarch
*gdbarch
= regcache
->arch ();
1244 if (gdbarch_read_pc_p (gdbarch
))
1245 pc_val
= gdbarch_read_pc (gdbarch
, regcache
);
1246 /* Else use per-frame method on get_current_frame. */
1247 else if (gdbarch_pc_regnum (gdbarch
) >= 0)
1251 if (regcache_cooked_read_unsigned (regcache
,
1252 gdbarch_pc_regnum (gdbarch
),
1253 &raw_val
) == REG_UNAVAILABLE
)
1254 throw_error (NOT_AVAILABLE_ERROR
, _("PC register is not available"));
1256 pc_val
= gdbarch_addr_bits_remove (gdbarch
, raw_val
);
1259 internal_error (__FILE__
, __LINE__
,
1260 _("regcache_read_pc: Unable to find PC"));
1265 regcache_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1267 struct gdbarch
*gdbarch
= regcache
->arch ();
1269 if (gdbarch_write_pc_p (gdbarch
))
1270 gdbarch_write_pc (gdbarch
, regcache
, pc
);
1271 else if (gdbarch_pc_regnum (gdbarch
) >= 0)
1272 regcache_cooked_write_unsigned (regcache
,
1273 gdbarch_pc_regnum (gdbarch
), pc
);
1275 internal_error (__FILE__
, __LINE__
,
1276 _("regcache_write_pc: Unable to update PC"));
1278 /* Writing the PC (for instance, from "load") invalidates the
1280 reinit_frame_cache ();
1284 regcache::debug_print_register (const char *func
, int regno
)
1286 struct gdbarch
*gdbarch
= arch ();
1288 fprintf_unfiltered (gdb_stdlog
, "%s ", func
);
1289 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
)
1290 && gdbarch_register_name (gdbarch
, regno
) != NULL
1291 && gdbarch_register_name (gdbarch
, regno
)[0] != '\0')
1292 fprintf_unfiltered (gdb_stdlog
, "(%s)",
1293 gdbarch_register_name (gdbarch
, regno
));
1295 fprintf_unfiltered (gdb_stdlog
, "(%d)", regno
);
1296 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
))
1298 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1299 int size
= register_size (gdbarch
, regno
);
1300 gdb_byte
*buf
= register_buffer (regno
);
1302 fprintf_unfiltered (gdb_stdlog
, " = ");
1303 for (int i
= 0; i
< size
; i
++)
1305 fprintf_unfiltered (gdb_stdlog
, "%02x", buf
[i
]);
1307 if (size
<= sizeof (LONGEST
))
1309 ULONGEST val
= extract_unsigned_integer (buf
, size
, byte_order
);
1311 fprintf_unfiltered (gdb_stdlog
, " %s %s",
1312 core_addr_to_string_nz (val
), plongest (val
));
1315 fprintf_unfiltered (gdb_stdlog
, "\n");
1319 reg_flush_command (char *command
, int from_tty
)
1321 /* Force-flush the register cache. */
1322 registers_changed ();
1324 printf_filtered (_("Register cache flushed.\n"));
1328 regcache::dump (ui_file
*file
, enum regcache_dump_what what_to_dump
)
1330 struct gdbarch
*gdbarch
= m_descr
->gdbarch
;
1332 int footnote_nr
= 0;
1333 int footnote_register_size
= 0;
1334 int footnote_register_offset
= 0;
1335 int footnote_register_type_name_null
= 0;
1336 long register_offset
= 0;
1339 fprintf_unfiltered (file
, "nr_raw_registers %d\n",
1340 m_descr
->nr_raw_registers
);
1341 fprintf_unfiltered (file
, "nr_cooked_registers %d\n",
1342 m_descr
->nr_cooked_registers
);
1343 fprintf_unfiltered (file
, "sizeof_raw_registers %ld\n",
1344 m_descr
->sizeof_raw_registers
);
1345 fprintf_unfiltered (file
, "sizeof_raw_register_status %ld\n",
1346 m_descr
->sizeof_raw_register_status
);
1347 fprintf_unfiltered (file
, "gdbarch_num_regs %d\n",
1348 gdbarch_num_regs (gdbarch
));
1349 fprintf_unfiltered (file
, "gdbarch_num_pseudo_regs %d\n",
1350 gdbarch_num_pseudo_regs (gdbarch
));
1353 gdb_assert (m_descr
->nr_cooked_registers
1354 == (gdbarch_num_regs (gdbarch
)
1355 + gdbarch_num_pseudo_regs (gdbarch
)));
1357 for (regnum
= -1; regnum
< m_descr
->nr_cooked_registers
; regnum
++)
1361 fprintf_unfiltered (file
, " %-10s", "Name");
1364 const char *p
= gdbarch_register_name (gdbarch
, regnum
);
1368 else if (p
[0] == '\0')
1370 fprintf_unfiltered (file
, " %-10s", p
);
1375 fprintf_unfiltered (file
, " %4s", "Nr");
1377 fprintf_unfiltered (file
, " %4d", regnum
);
1379 /* Relative number. */
1381 fprintf_unfiltered (file
, " %4s", "Rel");
1382 else if (regnum
< gdbarch_num_regs (gdbarch
))
1383 fprintf_unfiltered (file
, " %4d", regnum
);
1385 fprintf_unfiltered (file
, " %4d",
1386 (regnum
- gdbarch_num_regs (gdbarch
)));
1390 fprintf_unfiltered (file
, " %6s ", "Offset");
1393 fprintf_unfiltered (file
, " %6ld",
1394 m_descr
->register_offset
[regnum
]);
1395 if (register_offset
!= m_descr
->register_offset
[regnum
]
1397 && (m_descr
->register_offset
[regnum
]
1398 != (m_descr
->register_offset
[regnum
- 1]
1399 + m_descr
->sizeof_register
[regnum
- 1])))
1402 if (!footnote_register_offset
)
1403 footnote_register_offset
= ++footnote_nr
;
1404 fprintf_unfiltered (file
, "*%d", footnote_register_offset
);
1407 fprintf_unfiltered (file
, " ");
1408 register_offset
= (m_descr
->register_offset
[regnum
]
1409 + m_descr
->sizeof_register
[regnum
]);
1414 fprintf_unfiltered (file
, " %5s ", "Size");
1416 fprintf_unfiltered (file
, " %5ld", m_descr
->sizeof_register
[regnum
]);
1421 std::string name_holder
;
1427 static const char blt
[] = "builtin_type";
1429 t
= TYPE_NAME (register_type (arch (), regnum
));
1432 if (!footnote_register_type_name_null
)
1433 footnote_register_type_name_null
= ++footnote_nr
;
1434 name_holder
= string_printf ("*%d",
1435 footnote_register_type_name_null
);
1436 t
= name_holder
.c_str ();
1438 /* Chop a leading builtin_type. */
1439 if (startswith (t
, blt
))
1442 fprintf_unfiltered (file
, " %-15s", t
);
1445 /* Leading space always present. */
1446 fprintf_unfiltered (file
, " ");
1449 if (what_to_dump
== regcache_dump_raw
)
1452 fprintf_unfiltered (file
, "Raw value");
1453 else if (regnum
>= m_descr
->nr_raw_registers
)
1454 fprintf_unfiltered (file
, "<cooked>");
1455 else if (get_register_status (regnum
) == REG_UNKNOWN
)
1456 fprintf_unfiltered (file
, "<invalid>");
1457 else if (get_register_status (regnum
) == REG_UNAVAILABLE
)
1458 fprintf_unfiltered (file
, "<unavailable>");
1461 raw_update (regnum
);
1462 print_hex_chars (file
, register_buffer (regnum
),
1463 m_descr
->sizeof_register
[regnum
],
1464 gdbarch_byte_order (gdbarch
), true);
1468 /* Value, cooked. */
1469 if (what_to_dump
== regcache_dump_cooked
)
1472 fprintf_unfiltered (file
, "Cooked value");
1475 const gdb_byte
*buf
= NULL
;
1476 enum register_status status
;
1477 struct value
*value
= NULL
;
1479 if (regnum
< m_descr
->nr_raw_registers
)
1481 raw_update (regnum
);
1482 status
= get_register_status (regnum
);
1483 buf
= register_buffer (regnum
);
1487 value
= cooked_read_value (regnum
);
1489 if (!value_optimized_out (value
)
1490 && value_entirely_available (value
))
1493 buf
= value_contents_all (value
);
1496 status
= REG_UNAVAILABLE
;
1499 if (status
== REG_UNKNOWN
)
1500 fprintf_unfiltered (file
, "<invalid>");
1501 else if (status
== REG_UNAVAILABLE
)
1502 fprintf_unfiltered (file
, "<unavailable>");
1504 print_hex_chars (file
, buf
,
1505 m_descr
->sizeof_register
[regnum
],
1506 gdbarch_byte_order (gdbarch
), true);
1510 release_value (value
);
1516 /* Group members. */
1517 if (what_to_dump
== regcache_dump_groups
)
1520 fprintf_unfiltered (file
, "Groups");
1523 const char *sep
= "";
1524 struct reggroup
*group
;
1526 for (group
= reggroup_next (gdbarch
, NULL
);
1528 group
= reggroup_next (gdbarch
, group
))
1530 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, group
))
1532 fprintf_unfiltered (file
,
1533 "%s%s", sep
, reggroup_name (group
));
1540 /* Remote packet configuration. */
1541 if (what_to_dump
== regcache_dump_remote
)
1545 fprintf_unfiltered (file
, "Rmt Nr g/G Offset");
1547 else if (regnum
< m_descr
->nr_raw_registers
)
1551 if (remote_register_number_and_offset (arch (), regnum
,
1553 fprintf_unfiltered (file
, "%7d %11d", pnum
, poffset
);
1557 fprintf_unfiltered (file
, "\n");
1560 if (footnote_register_size
)
1561 fprintf_unfiltered (file
, "*%d: Inconsistent register sizes.\n",
1562 footnote_register_size
);
1563 if (footnote_register_offset
)
1564 fprintf_unfiltered (file
, "*%d: Inconsistent register offsets.\n",
1565 footnote_register_offset
);
1566 if (footnote_register_type_name_null
)
1567 fprintf_unfiltered (file
,
1568 "*%d: Register type's name NULL.\n",
1569 footnote_register_type_name_null
);
1573 regcache_print (const char *args
, enum regcache_dump_what what_to_dump
)
1575 /* Where to send output. */
1583 if (!file
.open (args
, "w"))
1584 perror_with_name (_("maintenance print architecture"));
1588 if (target_has_registers
)
1589 get_current_regcache ()->dump (out
, what_to_dump
);
1592 /* For the benefit of "maint print registers" & co when
1593 debugging an executable, allow dumping a regcache even when
1594 there is no thread selected / no registers. */
1595 regcache
dummy_regs (target_gdbarch (), nullptr);
1596 dummy_regs
.dump (out
, what_to_dump
);
1601 maintenance_print_registers (const char *args
, int from_tty
)
1603 regcache_print (args
, regcache_dump_none
);
1607 maintenance_print_raw_registers (const char *args
, int from_tty
)
1609 regcache_print (args
, regcache_dump_raw
);
1613 maintenance_print_cooked_registers (const char *args
, int from_tty
)
1615 regcache_print (args
, regcache_dump_cooked
);
1619 maintenance_print_register_groups (const char *args
, int from_tty
)
1621 regcache_print (args
, regcache_dump_groups
);
1625 maintenance_print_remote_registers (const char *args
, int from_tty
)
1627 regcache_print (args
, regcache_dump_remote
);
1631 #include "selftest.h"
1633 namespace selftests
{
1635 class regcache_access
: public regcache
1639 /* Return the number of elements in current_regcache. */
1642 current_regcache_size ()
1644 return std::distance (regcache::current_regcache
.begin (),
1645 regcache::current_regcache
.end ());
1650 current_regcache_test (void)
1652 /* It is empty at the start. */
1653 SELF_CHECK (regcache_access::current_regcache_size () == 0);
1655 ptid_t
ptid1 (1), ptid2 (2), ptid3 (3);
1657 /* Get regcache from ptid1, a new regcache is added to
1658 current_regcache. */
1659 regcache
*regcache
= get_thread_arch_aspace_regcache (ptid1
,
1663 SELF_CHECK (regcache
!= NULL
);
1664 SELF_CHECK (regcache
->ptid () == ptid1
);
1665 SELF_CHECK (regcache_access::current_regcache_size () == 1);
1667 /* Get regcache from ptid2, a new regcache is added to
1668 current_regcache. */
1669 regcache
= get_thread_arch_aspace_regcache (ptid2
,
1672 SELF_CHECK (regcache
!= NULL
);
1673 SELF_CHECK (regcache
->ptid () == ptid2
);
1674 SELF_CHECK (regcache_access::current_regcache_size () == 2);
1676 /* Get regcache from ptid3, a new regcache is added to
1677 current_regcache. */
1678 regcache
= get_thread_arch_aspace_regcache (ptid3
,
1681 SELF_CHECK (regcache
!= NULL
);
1682 SELF_CHECK (regcache
->ptid () == ptid3
);
1683 SELF_CHECK (regcache_access::current_regcache_size () == 3);
1685 /* Get regcache from ptid2 again, nothing is added to
1686 current_regcache. */
1687 regcache
= get_thread_arch_aspace_regcache (ptid2
,
1690 SELF_CHECK (regcache
!= NULL
);
1691 SELF_CHECK (regcache
->ptid () == ptid2
);
1692 SELF_CHECK (regcache_access::current_regcache_size () == 3);
1694 /* Mark ptid2 is changed, so regcache of ptid2 should be removed from
1695 current_regcache. */
1696 registers_changed_ptid (ptid2
);
1697 SELF_CHECK (regcache_access::current_regcache_size () == 2);
1700 } // namespace selftests
1701 #endif /* GDB_SELF_TEST */
1704 _initialize_regcache (void)
1706 regcache_descr_handle
1707 = gdbarch_data_register_post_init (init_regcache_descr
);
1709 observer_attach_target_changed (regcache_observer_target_changed
);
1710 observer_attach_thread_ptid_changed (regcache::regcache_thread_ptid_changed
);
1712 add_com ("flushregs", class_maintenance
, reg_flush_command
,
1713 _("Force gdb to flush its register cache (maintainer command)"));
1715 add_cmd ("registers", class_maintenance
, maintenance_print_registers
,
1716 _("Print the internal register configuration.\n"
1717 "Takes an optional file parameter."), &maintenanceprintlist
);
1718 add_cmd ("raw-registers", class_maintenance
,
1719 maintenance_print_raw_registers
,
1720 _("Print the internal register configuration "
1721 "including raw values.\n"
1722 "Takes an optional file parameter."), &maintenanceprintlist
);
1723 add_cmd ("cooked-registers", class_maintenance
,
1724 maintenance_print_cooked_registers
,
1725 _("Print the internal register configuration "
1726 "including cooked values.\n"
1727 "Takes an optional file parameter."), &maintenanceprintlist
);
1728 add_cmd ("register-groups", class_maintenance
,
1729 maintenance_print_register_groups
,
1730 _("Print the internal register configuration "
1731 "including each register's group.\n"
1732 "Takes an optional file parameter."),
1733 &maintenanceprintlist
);
1734 add_cmd ("remote-registers", class_maintenance
,
1735 maintenance_print_remote_registers
, _("\
1736 Print the internal register configuration including each register's\n\
1737 remote register number and buffer offset in the g/G packets.\n\
1738 Takes an optional file parameter."),
1739 &maintenanceprintlist
);
1742 selftests::register_test ("current_regcache", selftests::current_regcache_test
);