Automatic date update in version.in
[binutils-gdb.git] / gdb / regcache.c
blobaf298893acf992d2d16f5be1569c259dbe35b532
1 /* Cache and manage the values of registers for GDB, the GNU debugger.
3 Copyright (C) 1986-2024 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/>. */
20 #include "defs.h"
21 #include "inferior.h"
22 #include "gdbthread.h"
23 #include "target.h"
24 #include "test-target.h"
25 #include "scoped-mock-context.h"
26 #include "gdbarch.h"
27 #include "gdbcmd.h"
28 #include "regcache.h"
29 #include "reggroups.h"
30 #include "observable.h"
31 #include "regset.h"
32 #include <unordered_map>
33 #include "cli/cli-cmds.h"
36 * DATA STRUCTURE
38 * Here is the actual register cache.
41 /* Per-architecture object describing the layout of a register cache.
42 Computed once when the architecture is created. */
44 struct regcache_descr
46 /* The architecture this descriptor belongs to. */
47 struct gdbarch *gdbarch = nullptr;
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
53 cache. */
54 long sizeof_raw_registers = 0;
56 /* The cooked register space. Each cooked register in the range
57 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
58 register. The remaining [NR_RAW_REGISTERS
59 .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto
60 both raw registers and memory by the architecture methods
61 gdbarch_pseudo_register_read and gdbarch_pseudo_register_write. */
62 int nr_cooked_registers = 0;
63 long sizeof_cooked_registers = 0;
65 /* Offset and size (in 8 bit bytes), of each register in the
66 register cache. All registers (including those in the range
67 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an
68 offset. */
69 long *register_offset = nullptr;
70 long *sizeof_register = nullptr;
72 /* Cached table containing the type of each register. */
73 struct type **register_type = nullptr;
76 static const registry<gdbarch>::key<struct regcache_descr>
77 regcache_descr_handle;
79 static struct regcache_descr *
80 init_regcache_descr (struct gdbarch *gdbarch)
82 int i;
83 struct regcache_descr *descr;
84 gdb_assert (gdbarch != NULL);
86 /* Create an initial, zero filled, table. */
87 descr = new 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_cooked_regs (gdbarch);
95 /* Fill in a table of register types. */
96 descr->register_type
97 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers,
98 struct type *);
99 for (i = 0; i < descr->nr_cooked_registers; i++)
100 descr->register_type[i] = gdbarch_register_type (gdbarch, i);
102 /* Construct a strictly RAW register cache. Don't allow pseudo's
103 into the register cache. */
105 /* Lay out the register cache.
107 NOTE: cagney/2002-05-22: Only register_type () is used when
108 constructing the register cache. It is assumed that the
109 register's raw size, virtual size and type length are all the
110 same. */
113 long offset = 0;
115 descr->sizeof_register
116 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
117 descr->register_offset
118 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers, long);
119 for (i = 0; i < gdbarch_num_regs (gdbarch); i++)
121 descr->sizeof_register[i] = descr->register_type[i]->length ();
122 descr->register_offset[i] = offset;
123 offset += descr->sizeof_register[i];
125 /* Set the real size of the raw register cache buffer. */
126 descr->sizeof_raw_registers = offset;
128 for (; i < descr->nr_cooked_registers; i++)
130 descr->sizeof_register[i] = descr->register_type[i]->length ();
131 descr->register_offset[i] = offset;
132 offset += descr->sizeof_register[i];
134 /* Set the real size of the readonly register cache buffer. */
135 descr->sizeof_cooked_registers = offset;
138 return descr;
141 static struct regcache_descr *
142 regcache_descr (struct gdbarch *gdbarch)
144 struct regcache_descr *result = regcache_descr_handle.get (gdbarch);
145 if (result == nullptr)
147 result = init_regcache_descr (gdbarch);
148 regcache_descr_handle.set (gdbarch, result);
151 return result;
154 /* Utility functions returning useful register attributes stored in
155 the regcache descr. */
157 struct type *
158 register_type (struct gdbarch *gdbarch, int regnum)
160 struct regcache_descr *descr = regcache_descr (gdbarch);
162 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
163 return descr->register_type[regnum];
166 /* Utility functions returning useful register attributes stored in
167 the regcache descr. */
170 register_size (struct gdbarch *gdbarch, int regnum)
172 struct regcache_descr *descr = regcache_descr (gdbarch);
173 int size;
175 gdb_assert (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch));
176 size = descr->sizeof_register[regnum];
177 return size;
180 /* See gdbsupport/common-regcache.h. */
183 regcache_register_size (const reg_buffer_common *regcache, int n)
185 return register_size
186 (gdb::checked_static_cast<const struct regcache *> (regcache)->arch (), n);
189 reg_buffer::reg_buffer (gdbarch *gdbarch, bool has_pseudo)
190 : m_has_pseudo (has_pseudo)
192 gdb_assert (gdbarch != NULL);
193 m_descr = regcache_descr (gdbarch);
195 /* We don't zero-initialize the M_REGISTERS array, as the bytes it contains
196 aren't meaningful as long as the corresponding register status is not
197 REG_VALID. */
198 if (has_pseudo)
200 m_registers.reset (new gdb_byte[m_descr->sizeof_cooked_registers]);
201 m_register_status.reset
202 (new register_status[m_descr->nr_cooked_registers] ());
204 else
206 m_registers.reset (new gdb_byte[m_descr->sizeof_raw_registers]);
207 m_register_status.reset
208 (new register_status[gdbarch_num_regs (gdbarch)] ());
212 regcache::regcache (inferior *inf_for_target_calls, gdbarch *gdbarch)
213 /* The register buffers. A read/write register cache can only hold
214 [0 .. gdbarch_num_regs). */
215 : detached_regcache (gdbarch, false),
216 m_inf_for_target_calls (inf_for_target_calls)
218 m_ptid = minus_one_ptid;
221 readonly_detached_regcache::readonly_detached_regcache (regcache &src)
222 : readonly_detached_regcache (src.arch (),
223 [&src] (int regnum,
224 gdb::array_view<gdb_byte> buf)
225 { return src.cooked_read (regnum, buf); })
229 gdbarch *
230 reg_buffer::arch () const
232 return m_descr->gdbarch;
235 /* Helper for reg_buffer::register_buffer. */
237 template<typename ElemType>
238 gdb::array_view<ElemType>
239 reg_buffer::register_buffer (int regnum) const
241 assert_regnum (regnum);
242 ElemType *start = &m_registers[m_descr->register_offset[regnum]];
243 int size = m_descr->sizeof_register[regnum];
244 return gdb::array_view<ElemType> (start, size);
247 /* See regcache.h. */
249 gdb::array_view<const gdb_byte>
250 reg_buffer::register_buffer (int regnum) const
252 return register_buffer<const gdb_byte> (regnum);
255 /* See regcache.h. */
257 gdb::array_view<gdb_byte>
258 reg_buffer::register_buffer (int regnum)
260 return register_buffer<gdb_byte> (regnum);
263 void
264 reg_buffer::save (register_read_ftype cooked_read)
266 struct gdbarch *gdbarch = m_descr->gdbarch;
268 /* It should have pseudo registers. */
269 gdb_assert (m_has_pseudo);
270 /* Clear the dest. */
271 memset (m_registers.get (), 0, m_descr->sizeof_cooked_registers);
272 memset (m_register_status.get (), REG_UNKNOWN, m_descr->nr_cooked_registers);
273 /* Copy over any registers (identified by their membership in the
274 save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs +
275 gdbarch_num_pseudo_regs) range is checked since some architectures need
276 to save/restore `cooked' registers that live in memory. */
277 for (int regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
279 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
281 gdb::array_view<gdb_byte> dst_buf = register_buffer (regnum);
282 register_status status = cooked_read (regnum, dst_buf);
284 gdb_assert (status != REG_UNKNOWN);
286 if (status != REG_VALID)
287 memset (dst_buf.data (), 0, dst_buf.size ());
289 m_register_status[regnum] = status;
294 void
295 regcache::restore (readonly_detached_regcache *src)
297 struct gdbarch *gdbarch = m_descr->gdbarch;
298 int regnum;
300 gdb_assert (src != NULL);
301 gdb_assert (src->m_has_pseudo);
303 gdb_assert (gdbarch == src->arch ());
305 /* Copy over any registers, being careful to only restore those that
306 were both saved and need to be restored. The full [0 .. gdbarch_num_regs
307 + gdbarch_num_pseudo_regs) range is checked since some architectures need
308 to save/restore `cooked' registers that live in memory. */
309 for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
311 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
313 if (src->m_register_status[regnum] == REG_VALID)
314 cooked_write (regnum, src->register_buffer (regnum));
319 /* See gdbsupport/common-regcache.h. */
321 enum register_status
322 reg_buffer::get_register_status (int regnum) const
324 assert_regnum (regnum);
326 return m_register_status[regnum];
329 void
330 reg_buffer::invalidate (int regnum)
332 assert_regnum (regnum);
333 m_register_status[regnum] = REG_UNKNOWN;
336 void
337 reg_buffer::assert_regnum (int regnum) const
339 gdb_assert (regnum >= 0);
340 if (m_has_pseudo)
341 gdb_assert (regnum < m_descr->nr_cooked_registers);
342 else
343 gdb_assert (regnum < gdbarch_num_regs (arch ()));
346 /* Type to map a ptid to a list of regcaches (one thread may have multiple
347 regcaches, associated to different gdbarches). */
349 using ptid_regcache_map
350 = std::unordered_multimap<ptid_t, regcache_up>;
352 /* Type holding regcaches for a given pid. */
354 using pid_ptid_regcache_map = std::unordered_map<int, ptid_regcache_map>;
356 /* Type holding regcaches for a given target. */
358 using target_pid_ptid_regcache_map
359 = std::unordered_map<process_stratum_target *, pid_ptid_regcache_map>;
361 /* Global structure containing the existing regcaches. */
363 /* NOTE: this is a write-through cache. There is no "dirty" bit for
364 recording if the register values have been changed (eg. by the
365 user). Therefore all registers must be written back to the
366 target when appropriate. */
367 static target_pid_ptid_regcache_map regcaches;
369 regcache *
370 get_thread_arch_regcache (inferior *inf_for_target_calls, ptid_t ptid,
371 gdbarch *arch)
373 gdb_assert (inf_for_target_calls != nullptr);
375 process_stratum_target *proc_target = inf_for_target_calls->process_target ();
376 gdb_assert (proc_target != nullptr);
378 /* Find the map for this target. */
379 pid_ptid_regcache_map &pid_ptid_regc_map = regcaches[proc_target];
381 /* Find the map for this pid. */
382 ptid_regcache_map &ptid_regc_map = pid_ptid_regc_map[ptid.pid ()];
384 /* Check first if a regcache for this arch already exists. */
385 auto range = ptid_regc_map.equal_range (ptid);
386 for (auto it = range.first; it != range.second; ++it)
388 if (it->second->arch () == arch)
389 return it->second.get ();
392 /* It does not exist, create it. */
393 regcache *new_regcache = new regcache (inf_for_target_calls, arch);
394 new_regcache->set_ptid (ptid);
395 /* Work around a problem with g++ 4.8 (PR96537): Call the regcache_up
396 constructor explicitly instead of implicitly. */
397 ptid_regc_map.insert (std::make_pair (ptid, regcache_up (new_regcache)));
399 return new_regcache;
402 static process_stratum_target *current_thread_target;
403 static ptid_t current_thread_ptid;
404 static struct gdbarch *current_thread_arch;
406 struct regcache *
407 get_thread_regcache (process_stratum_target *target, ptid_t ptid)
409 inferior *inf = find_inferior_ptid (target, ptid);
411 if (!current_thread_arch
412 || target != current_thread_target
413 || current_thread_ptid != ptid)
415 gdb_assert (ptid != null_ptid);
417 current_thread_ptid = ptid;
418 current_thread_target = target;
420 scoped_restore_current_inferior restore_current_inferior;
421 set_current_inferior (inf);
422 current_thread_arch = target_thread_architecture (ptid);
425 return get_thread_arch_regcache (inf, ptid, current_thread_arch);
428 /* See regcache.h. */
430 struct regcache *
431 get_thread_regcache (thread_info *thread)
433 gdb_assert (thread->state != THREAD_EXITED);
435 return get_thread_regcache (thread->inf->process_target (),
436 thread->ptid);
439 /* See gdbsupport/common-regcache.h. */
441 reg_buffer_common *
442 get_thread_regcache_for_ptid (ptid_t ptid)
444 /* This function doesn't take a process_stratum_target parameter
445 because it's a gdbsupport/ routine implemented by both gdb and
446 gdbserver. It always refers to a ptid of the current target. */
447 process_stratum_target *proc_target = current_inferior ()->process_target ();
448 return get_thread_regcache (proc_target, ptid);
451 /* Observer for the target_changed event. */
453 static void
454 regcache_observer_target_changed (struct target_ops *target)
456 registers_changed ();
459 /* Update regcaches related to OLD_PTID to now use NEW_PTID. */
460 static void
461 regcache_thread_ptid_changed (process_stratum_target *target,
462 ptid_t old_ptid, ptid_t new_ptid)
464 /* Look up map for target. */
465 auto pid_ptid_regc_map_it = regcaches.find (target);
466 if (pid_ptid_regc_map_it == regcaches.end ())
467 return;
469 /* Look up map for pid. */
470 pid_ptid_regcache_map &pid_ptid_regc_map = pid_ptid_regc_map_it->second;
471 auto ptid_regc_map_it = pid_ptid_regc_map.find (old_ptid.pid ());
472 if (ptid_regc_map_it == pid_ptid_regc_map.end ())
473 return;
475 /* Update all regcaches belonging to old_ptid. */
476 ptid_regcache_map &ptid_regc_map = ptid_regc_map_it->second;
477 auto range = ptid_regc_map.equal_range (old_ptid);
478 for (auto it = range.first; it != range.second;)
480 regcache_up rc = std::move (it->second);
481 rc->set_ptid (new_ptid);
483 /* Remove old before inserting new, to avoid rehashing,
484 which would invalidate iterators. */
485 it = ptid_regc_map.erase (it);
486 ptid_regc_map.insert (std::make_pair (new_ptid, std::move (rc)));
490 /* Low level examining and depositing of registers.
492 The caller is responsible for making sure that the inferior is
493 stopped before calling the fetching routines, or it will get
494 garbage. (a change from GDB version 3, in which the caller got the
495 value from the last stop). */
497 /* REGISTERS_CHANGED ()
499 Indicate that registers may have changed, so invalidate the cache. */
501 void
502 registers_changed_ptid (process_stratum_target *target, ptid_t ptid)
504 if (target == nullptr)
506 /* Since there can be ptid clashes between targets, it's not valid to
507 pass a ptid without saying to which target it belongs. */
508 gdb_assert (ptid == minus_one_ptid);
510 /* Delete all the regcaches of all targets. */
511 regcaches.clear ();
513 else if (ptid.is_pid ())
515 /* Non-NULL target and pid ptid, delete all regcaches belonging
516 to this (TARGET, PID). */
518 /* Look up map for target. */
519 auto pid_ptid_regc_map_it = regcaches.find (target);
520 if (pid_ptid_regc_map_it != regcaches.end ())
522 pid_ptid_regcache_map &pid_ptid_regc_map
523 = pid_ptid_regc_map_it->second;
525 pid_ptid_regc_map.erase (ptid.pid ());
528 else if (ptid != minus_one_ptid)
530 /* Non-NULL target and non-minus_one_ptid, delete all regcaches belonging
531 to this (TARGET, PTID). */
533 /* Look up map for target. */
534 auto pid_ptid_regc_map_it = regcaches.find (target);
535 if (pid_ptid_regc_map_it != regcaches.end ())
537 pid_ptid_regcache_map &pid_ptid_regc_map
538 = pid_ptid_regc_map_it->second;
540 /* Look up map for pid. */
541 auto ptid_regc_map_it
542 = pid_ptid_regc_map.find (ptid.pid ());
543 if (ptid_regc_map_it != pid_ptid_regc_map.end ())
545 ptid_regcache_map &ptid_regc_map
546 = ptid_regc_map_it->second;
548 ptid_regc_map.erase (ptid);
552 else
554 /* Non-NULL target and minus_one_ptid, delete all regcaches
555 associated to this target. */
556 regcaches.erase (target);
559 if ((target == nullptr || current_thread_target == target)
560 && current_thread_ptid.matches (ptid))
562 current_thread_target = NULL;
563 current_thread_ptid = null_ptid;
564 current_thread_arch = NULL;
567 if ((target == nullptr || current_inferior ()->process_target () == target)
568 && inferior_ptid.matches (ptid))
570 /* We just deleted the regcache of the current thread. Need to
571 forget about any frames we have cached, too. */
572 reinit_frame_cache ();
576 /* See regcache.h. */
578 void
579 registers_changed_thread (thread_info *thread)
581 registers_changed_ptid (thread->inf->process_target (), thread->ptid);
584 void
585 registers_changed (void)
587 registers_changed_ptid (nullptr, minus_one_ptid);
590 void
591 regcache::raw_update (int regnum)
593 assert_regnum (regnum);
595 /* Make certain that the register cache is up-to-date with respect
596 to the current thread. This switching shouldn't be necessary
597 only there is still only one target side register cache. Sigh!
598 On the bright side, at least there is a regcache object. */
600 if (get_register_status (regnum) == REG_UNKNOWN)
602 std::optional<scoped_restore_current_thread> maybe_restore_thread
603 = maybe_switch_inferior (m_inf_for_target_calls);
605 target_fetch_registers (this, regnum);
607 /* A number of targets can't access the whole set of raw
608 registers (because the debug API provides no means to get at
609 them). */
610 if (m_register_status[regnum] == REG_UNKNOWN)
611 m_register_status[regnum] = REG_UNAVAILABLE;
615 register_status
616 readable_regcache::raw_read (int regnum, gdb::array_view<gdb_byte> dst)
618 assert_regnum (regnum);
619 gdb_assert (dst.size () == m_descr->sizeof_register[regnum]);
621 raw_update (regnum);
623 if (m_register_status[regnum] != REG_VALID)
624 memset (dst.data (), 0, dst.size ());
625 else
626 copy (register_buffer (regnum), dst);
628 return m_register_status[regnum];
631 register_status
632 readable_regcache::raw_read (int regnum, gdb_byte *dst)
634 assert_regnum (regnum);
635 int size = m_descr->sizeof_register[regnum];
636 return raw_read (regnum, gdb::make_array_view (dst, size));
639 enum register_status
640 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
642 gdb_assert (regcache != NULL);
643 return regcache->raw_read (regnum, val);
646 template<typename T, typename>
647 enum register_status
648 readable_regcache::raw_read (int regnum, T *val)
650 assert_regnum (regnum);
651 size_t size = m_descr->sizeof_register[regnum];
652 gdb_byte *buf = (gdb_byte *) alloca (size);
653 auto view = gdb::make_array_view (buf, size);
654 register_status status = raw_read (regnum, view);
656 if (status == REG_VALID)
657 *val = extract_integer<T> (view, gdbarch_byte_order (m_descr->gdbarch));
658 else
659 *val = 0;
661 return status;
664 enum register_status
665 regcache_raw_read_unsigned (reg_buffer_common *regcache, int regnum,
666 ULONGEST *val)
668 gdb_assert (regcache != NULL);
669 return gdb::checked_static_cast<struct regcache *> (regcache)->raw_read
670 (regnum, val);
673 void
674 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
676 gdb_assert (regcache != NULL);
677 regcache->raw_write (regnum, val);
680 template<typename T, typename>
681 void
682 regcache::raw_write (int regnum, T val)
684 assert_regnum (regnum);
686 int size = m_descr->sizeof_register[regnum];
687 gdb_byte *buf = (gdb_byte *) alloca (size);
688 auto view = gdb::make_array_view (buf, size);
689 store_integer (view, gdbarch_byte_order (m_descr->gdbarch), val);
690 raw_write (regnum, view);
693 void
694 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
695 ULONGEST val)
697 gdb_assert (regcache != NULL);
698 regcache->raw_write (regnum, val);
701 LONGEST
702 regcache_raw_get_signed (struct regcache *regcache, int regnum)
704 LONGEST value;
705 enum register_status status;
707 status = regcache_raw_read_signed (regcache, regnum, &value);
708 if (status == REG_UNAVAILABLE)
709 throw_error (NOT_AVAILABLE_ERROR,
710 _("Register %d is not available"), regnum);
711 return value;
714 /* See regcache.h. */
716 register_status
717 readable_regcache::cooked_read (int regnum, gdb::array_view<gdb_byte> dst)
719 gdb_assert (regnum >= 0);
720 gdb_assert (regnum < m_descr->nr_cooked_registers);
722 if (regnum < num_raw_registers ())
723 return raw_read (regnum, dst);
725 gdb_assert (dst.size () == m_descr->sizeof_register[regnum]);
727 if (m_has_pseudo && m_register_status[regnum] != REG_UNKNOWN)
729 if (m_register_status[regnum] == REG_VALID)
730 copy (register_buffer (regnum), dst);
731 else
732 memset (dst.data (), 0, dst.size ());
734 return m_register_status[regnum];
736 else if (gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
738 register_status result = REG_VALID;
739 scoped_value_mark mark;
740 value *computed = gdbarch_pseudo_register_read_value
741 (m_descr->gdbarch, get_next_frame_sentinel_okay (get_current_frame ()),
742 regnum);
744 if (computed->entirely_available ())
745 copy (computed->contents_raw (), dst);
746 else
748 memset (dst.data (), 0, dst.size ());
749 result = REG_UNAVAILABLE;
752 return result;
754 else
755 return gdbarch_pseudo_register_read (m_descr->gdbarch, this, regnum,
756 dst.data ());
759 /* See regcache.h. */
761 register_status
762 readable_regcache::cooked_read (int regnum, gdb_byte *dst)
764 gdb_assert (regnum >= 0);
765 gdb_assert (regnum < m_descr->nr_cooked_registers);
767 int size = m_descr->sizeof_register[regnum];
768 return cooked_read (regnum, gdb::make_array_view (dst, size));
771 struct value *
772 readable_regcache::cooked_read_value (int regnum)
774 gdb_assert (regnum >= 0);
775 gdb_assert (regnum < m_descr->nr_cooked_registers);
777 if (regnum < num_raw_registers ()
778 || (m_has_pseudo && m_register_status[regnum] != REG_UNKNOWN)
779 || !gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
781 value *result = value::allocate_register
782 (get_next_frame_sentinel_okay (get_current_frame ()), regnum);
784 /* It is more efficient in general to do this delegation in this
785 direction than in the other one, even though the value-based
786 API is preferred. */
787 if (cooked_read (regnum, result->contents_raw ()) == REG_UNAVAILABLE)
788 result->mark_bytes_unavailable (0,
789 result->type ()->length ());
791 return result;
793 else
794 return gdbarch_pseudo_register_read_value
795 (m_descr->gdbarch, get_next_frame_sentinel_okay (get_current_frame ()),
796 regnum);
799 enum register_status
800 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
801 LONGEST *val)
803 gdb_assert (regcache != NULL);
804 return regcache->cooked_read (regnum, val);
807 template<typename T, typename>
808 enum register_status
809 readable_regcache::cooked_read (int regnum, T *val)
811 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
812 size_t size = m_descr->sizeof_register[regnum];
813 gdb_byte *buf = (gdb_byte *) alloca (size);
814 auto view = gdb::make_array_view (buf, size);
815 register_status status = cooked_read (regnum, view);
816 if (status == REG_VALID)
817 *val = extract_integer<T> (view, gdbarch_byte_order (m_descr->gdbarch));
818 else
819 *val = 0;
820 return status;
823 enum register_status
824 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
825 ULONGEST *val)
827 gdb_assert (regcache != NULL);
828 return regcache->cooked_read (regnum, val);
831 void
832 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
833 LONGEST val)
835 gdb_assert (regcache != NULL);
836 regcache->cooked_write (regnum, val);
839 template<typename T, typename>
840 void
841 regcache::cooked_write (int regnum, T val)
843 gdb_assert (regnum >= 0);
844 gdb_assert (regnum < m_descr->nr_cooked_registers);
846 int size = m_descr->sizeof_register[regnum];
847 gdb_byte *buf = (gdb_byte *) alloca (size);
848 auto view = gdb::make_array_view (buf, size);
849 store_integer (view, gdbarch_byte_order (m_descr->gdbarch), val);
850 cooked_write (regnum, view);
853 void
854 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
855 ULONGEST val)
857 gdb_assert (regcache != NULL);
858 regcache->cooked_write (regnum, val);
861 void
862 regcache::raw_write (int regnum, gdb::array_view<const gdb_byte> src)
864 assert_regnum (regnum);
865 gdb_assert (src.size () == m_descr->sizeof_register[regnum]);
867 /* On the sparc, writing %g0 is a no-op, so we don't even want to
868 change the registers array if something writes to this register. */
869 if (gdbarch_cannot_store_register (arch (), regnum))
870 return;
872 /* If we have a valid copy of the register, and new value == old
873 value, then don't bother doing the actual store. */
874 if (get_register_status (regnum) == REG_VALID
875 && (memcmp (register_buffer (regnum).data (), src.data (), src.size ())
876 == 0))
877 return;
879 std::optional<scoped_restore_current_thread> maybe_restore_thread
880 = maybe_switch_inferior (m_inf_for_target_calls);
882 target_prepare_to_store (this);
883 raw_supply (regnum, src);
885 /* Invalidate the register after it is written, in case of a
886 failure. */
887 auto invalidator
888 = make_scope_exit ([&] { this->invalidate (regnum); });
890 target_store_registers (this, regnum);
892 /* The target did not throw an error so we can discard invalidating
893 the register. */
894 invalidator.release ();
897 void
898 regcache::raw_write (int regnum, const gdb_byte *src)
900 assert_regnum (regnum);
902 int size = m_descr->sizeof_register[regnum];
903 raw_write (regnum, gdb::make_array_view (src, size));
906 /* See regcache.h. */
908 void
909 regcache::cooked_write (int regnum, gdb::array_view<const gdb_byte> src)
911 gdb_assert (regnum >= 0);
912 gdb_assert (regnum < m_descr->nr_cooked_registers);
914 if (regnum < num_raw_registers ())
915 raw_write (regnum, src);
916 else if (gdbarch_pseudo_register_write_p (m_descr->gdbarch))
917 gdbarch_pseudo_register_write
918 (m_descr->gdbarch, get_next_frame_sentinel_okay (get_current_frame ()),
919 regnum, src);
920 else
921 gdbarch_deprecated_pseudo_register_write (m_descr->gdbarch, this, regnum,
922 src.data ());
925 /* See regcache.h. */
927 void
928 regcache::cooked_write (int regnum, const gdb_byte *src)
930 gdb_assert (regnum >= 0);
931 gdb_assert (regnum < m_descr->nr_cooked_registers);
933 int size = m_descr->sizeof_register[regnum];
934 return cooked_write (regnum, gdb::make_array_view (src, size));
937 /* See regcache.h. */
939 register_status
940 readable_regcache::read_part (int regnum, int offset,
941 gdb::array_view<gdb_byte> dst, bool is_raw)
943 int reg_size = register_size (arch (), regnum);
945 gdb_assert (offset >= 0);
946 gdb_assert (offset + dst.size () <= reg_size);
948 if (dst.size () == 0)
950 /* Nothing to do. */
951 return REG_VALID;
954 if (dst.size () == reg_size)
956 /* Read the full register. */
957 if (is_raw)
958 return raw_read (regnum, dst);
959 else
960 return cooked_read (regnum, dst);
963 /* Read full register to buffer. */
964 register_status status;
965 gdb_byte *reg_buf = (gdb_byte *) alloca (reg_size);
966 auto reg = gdb::make_array_view (reg_buf, reg_size);
968 if (is_raw)
969 status = raw_read (regnum, reg);
970 else
971 status = cooked_read (regnum, reg);
973 if (status != REG_VALID)
974 return status;
976 /* Copy out. */
977 copy (reg.slice (offset, dst.size ()), dst);
978 return REG_VALID;
981 /* See regcache.h. */
983 void
984 reg_buffer::raw_collect_part (int regnum, int offset,
985 gdb::array_view<gdb_byte> dst) const
987 int reg_size = register_size (arch (), regnum);
989 gdb_assert (offset >= 0);
990 gdb_assert (offset + dst.size () <= reg_size);
992 if (dst.size () == 0)
994 /* Nothing to do. */
995 return;
998 if (dst.size () == reg_size)
1000 /* Collect the full register. */
1001 return raw_collect (regnum, dst);
1004 /* Read to buffer, then write out. */
1005 gdb_byte *reg_buf = (gdb_byte *) alloca (reg_size);
1006 auto reg = gdb::make_array_view (reg_buf, reg_size);
1007 raw_collect (regnum, reg);
1008 copy (reg.slice (offset, dst.size ()), dst);
1011 /* See regcache.h. */
1013 register_status
1014 regcache::write_part (int regnum, int offset,
1015 gdb::array_view<const gdb_byte> src, bool is_raw)
1017 int reg_size = register_size (arch (), regnum);
1019 gdb_assert (offset >= 0);
1020 gdb_assert (offset + src.size () <= reg_size);
1022 if (src.size () == 0)
1024 /* Nothing to do. */
1025 return REG_VALID;
1028 if (src.size () == reg_size)
1030 /* Write the full register. */
1031 if (is_raw)
1032 raw_write (regnum, src);
1033 else
1034 cooked_write (regnum, src);
1036 return REG_VALID;
1039 /* Read existing register to buffer. */
1040 register_status status;
1041 gdb_byte *reg_buf = (gdb_byte *) alloca (reg_size);
1042 auto reg = gdb::make_array_view (reg_buf, reg_size);
1044 if (is_raw)
1045 status = raw_read (regnum, reg);
1046 else
1047 status = cooked_read (regnum, reg);
1049 if (status != REG_VALID)
1050 return status;
1052 /* Update buffer, then write back to regcache. */
1053 copy (src, reg.slice (offset, src.size ()));
1055 if (is_raw)
1056 raw_write (regnum, reg);
1057 else
1058 cooked_write (regnum, reg);
1060 return REG_VALID;
1063 /* See regcache.h. */
1065 void
1066 reg_buffer::raw_supply_part (int regnum, int offset,
1067 gdb::array_view<const gdb_byte> src)
1069 int reg_size = register_size (arch (), regnum);
1071 gdb_assert (offset >= 0);
1072 gdb_assert (offset + src.size () <= reg_size);
1074 if (src.size () == 0)
1076 /* Nothing to do. */
1077 return;
1080 if (src.size () == reg_size)
1082 /* Supply the full register. */
1083 return raw_supply (regnum, src);
1086 /* Read existing value to buffer. */
1087 gdb_byte *reg_buf = (gdb_byte *) alloca (reg_size);
1088 auto reg = gdb::make_array_view (reg_buf, reg_size);
1089 raw_collect (regnum, reg);
1091 /* Write to buffer, then write out. */
1092 copy (src, reg.slice (offset, src.size ()));
1093 raw_supply (regnum, reg);
1096 register_status
1097 readable_regcache::raw_read_part (int regnum, int offset,
1098 gdb::array_view<gdb_byte> dst)
1100 assert_regnum (regnum);
1101 return read_part (regnum, offset, dst, true);
1104 /* See regcache.h. */
1106 void
1107 regcache::raw_write_part (int regnum, int offset,
1108 gdb::array_view<const gdb_byte> src)
1110 assert_regnum (regnum);
1111 write_part (regnum, offset, src, true);
1114 /* See regcache.h. */
1116 register_status
1117 readable_regcache::cooked_read_part (int regnum, int offset,
1118 gdb::array_view<gdb_byte> dst)
1120 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
1121 return read_part (regnum, offset, dst, false);
1124 /* See regcache.h. */
1126 void
1127 regcache::cooked_write_part (int regnum, int offset,
1128 gdb::array_view<const gdb_byte> src)
1130 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
1131 write_part (regnum, offset, src, false);
1134 /* See gdbsupport/common-regcache.h. */
1136 void
1137 reg_buffer::raw_supply (int regnum, gdb::array_view<const gdb_byte> src)
1139 gdb::array_view<gdb_byte> dst = register_buffer (regnum);
1141 if (src.data () != nullptr)
1143 copy (src, dst);
1144 m_register_status[regnum] = REG_VALID;
1146 else
1148 /* This memset not strictly necessary, but better than garbage
1149 in case the register value manages to escape somewhere (due
1150 to a bug, no less). */
1151 memset (dst.data (), 0, dst.size ());
1152 m_register_status[regnum] = REG_UNAVAILABLE;
1156 /* See regcache.h. */
1158 void
1159 reg_buffer::raw_supply (int regnum, const void *src)
1161 assert_regnum (regnum);
1163 int size = m_descr->sizeof_register[regnum];
1164 raw_supply (regnum, gdb::make_array_view ((const gdb_byte *) src, size));
1167 /* See regcache.h. */
1169 void
1170 reg_buffer::raw_supply_integer (int regnum, const gdb_byte *addr, int addr_len,
1171 bool is_signed)
1173 gdb::array_view<gdb_byte> dst = register_buffer (regnum);
1174 bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
1176 copy_integer_to_size (dst.data (), dst.size (), addr, addr_len, is_signed,
1177 byte_order);
1178 m_register_status[regnum] = REG_VALID;
1181 /* See regcache.h. */
1183 void
1184 reg_buffer::raw_supply_zeroed (int regnum)
1186 gdb::array_view<gdb_byte> dst = register_buffer (regnum);
1187 memset (dst.data (), 0, dst.size ());
1188 m_register_status[regnum] = REG_VALID;
1191 /* See gdbsupport/common-regcache.h. */
1193 void
1194 reg_buffer::raw_collect (int regnum, gdb::array_view<gdb_byte> dst) const
1196 gdb::array_view<const gdb_byte> src = register_buffer (regnum);
1197 copy (src, dst);
1200 /* See regcache.h. */
1202 void
1203 reg_buffer::raw_collect (int regnum, void *dst) const
1205 assert_regnum (regnum);
1207 int size = m_descr->sizeof_register[regnum];
1208 return raw_collect (regnum, gdb::make_array_view ((gdb_byte *) dst, size));
1211 /* See regcache.h. */
1213 void
1214 reg_buffer::raw_collect_integer (int regnum, gdb_byte *addr, int addr_len,
1215 bool is_signed) const
1217 gdb::array_view<const gdb_byte> dst = register_buffer (regnum);
1218 bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
1219 copy_integer_to_size (addr, addr_len, dst.data (), dst.size (), is_signed,
1220 byte_order);
1223 /* See regcache.h. */
1225 void
1226 regcache::transfer_regset_register (struct regcache *out_regcache, int regnum,
1227 const gdb_byte *in_buf, gdb_byte *out_buf,
1228 int slot_size, int offs) const
1230 struct gdbarch *gdbarch = arch ();
1231 int reg_size = std::min (register_size (gdbarch, regnum), slot_size);
1233 /* Use part versions and reg_size to prevent possible buffer overflows when
1234 accessing the regcache. */
1236 if (out_buf != nullptr)
1238 raw_collect_part (regnum, 0,
1239 gdb::make_array_view (out_buf + offs, reg_size));
1241 /* Ensure any additional space is cleared. */
1242 if (slot_size > reg_size)
1243 memset (out_buf + offs + reg_size, 0, slot_size - reg_size);
1245 else if (in_buf != nullptr)
1247 /* Zero-extend the register value if the slot is smaller than the register. */
1248 if (slot_size < register_size (gdbarch, regnum))
1249 out_regcache->raw_supply_zeroed (regnum);
1250 out_regcache->raw_supply_part (regnum, 0,
1251 gdb::make_array_view (in_buf + offs,
1252 reg_size));
1254 else
1256 /* Invalidate the register. */
1257 out_regcache->raw_supply (regnum, {});
1261 /* See regcache.h. */
1263 void
1264 regcache::transfer_regset (const struct regset *regset, int regbase,
1265 struct regcache *out_regcache,
1266 int regnum, const gdb_byte *in_buf,
1267 gdb_byte *out_buf, size_t size) const
1269 const struct regcache_map_entry *map;
1270 int offs = 0, count;
1272 for (map = (const struct regcache_map_entry *) regset->regmap;
1273 (count = map->count) != 0;
1274 map++)
1276 int regno = map->regno;
1277 int slot_size = map->size;
1279 if (regno != REGCACHE_MAP_SKIP)
1280 regno += regbase;
1282 if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
1283 slot_size = m_descr->sizeof_register[regno];
1285 if (regno == REGCACHE_MAP_SKIP
1286 || (regnum != -1
1287 && (regnum < regno || regnum >= regno + count)))
1288 offs += count * slot_size;
1290 else if (regnum == -1)
1291 for (; count--; regno++, offs += slot_size)
1293 if (offs + slot_size > size)
1294 return;
1296 transfer_regset_register (out_regcache, regno, in_buf, out_buf,
1297 slot_size, offs);
1299 else
1301 /* Transfer a single register and return. */
1302 offs += (regnum - regno) * slot_size;
1303 if (offs + slot_size > size)
1304 return;
1306 transfer_regset_register (out_regcache, regnum, in_buf, out_buf,
1307 slot_size, offs);
1308 return;
1313 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1314 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1315 If BUF is NULL, set the register(s) to "unavailable" status. */
1317 void
1318 regcache_supply_regset (const struct regset *regset,
1319 struct regcache *regcache,
1320 int regnum, const void *buf, size_t size)
1322 regcache->supply_regset (regset, regnum, (const gdb_byte *) buf, size);
1325 /* See regcache.h. */
1327 void
1328 regcache::supply_regset (const struct regset *regset, int regbase,
1329 int regnum, const void *buf, size_t size)
1331 transfer_regset (regset, regbase, this, regnum, (const gdb_byte *) buf,
1332 nullptr, size);
1335 /* Collect register REGNUM from REGCACHE to BUF, using the register
1336 map in REGSET. If REGNUM is -1, do this for all registers in
1337 REGSET. */
1339 void
1340 regcache_collect_regset (const struct regset *regset,
1341 const struct regcache *regcache,
1342 int regnum, void *buf, size_t size)
1344 regcache->collect_regset (regset, regnum, (gdb_byte *) buf, size);
1347 /* See regcache.h */
1349 void
1350 regcache::collect_regset (const struct regset *regset, int regbase,
1351 int regnum, void *buf, size_t size) const
1353 transfer_regset (regset, regbase, nullptr, regnum, nullptr, (gdb_byte *) buf,
1354 size);
1357 bool
1358 regcache_map_supplies (const struct regcache_map_entry *map, int regnum,
1359 struct gdbarch *gdbarch, size_t size)
1361 int offs = 0, count;
1363 for (; (count = map->count) != 0; map++)
1365 int regno = map->regno;
1366 int slot_size = map->size;
1368 if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
1369 slot_size = register_size (gdbarch, regno);
1371 if (regno != REGCACHE_MAP_SKIP && regnum >= regno
1372 && regnum < regno + count)
1373 return offs + (regnum - regno + 1) * slot_size <= size;
1375 offs += count * slot_size;
1376 if (offs >= size)
1377 return false;
1379 return false;
1382 /* See gdbsupport/common-regcache.h. */
1384 bool
1385 reg_buffer::raw_compare (int regnum, const void *buf, int offset) const
1387 gdb_assert (buf != NULL);
1389 gdb::array_view<const gdb_byte> regbuf = register_buffer (regnum);
1390 gdb_assert (offset <= regbuf.size ());
1391 regbuf = regbuf.slice (offset);
1393 return memcmp (buf, regbuf.data (), regbuf.size ()) == 0;
1396 /* Special handling for register PC. */
1398 CORE_ADDR
1399 regcache_read_pc (reg_buffer_common *reg_buf)
1401 regcache *regcache = gdb::checked_static_cast<struct regcache *> (reg_buf);
1402 struct gdbarch *gdbarch = regcache->arch ();
1404 CORE_ADDR pc_val;
1406 if (gdbarch_read_pc_p (gdbarch))
1407 pc_val = gdbarch_read_pc (gdbarch, regcache);
1408 /* Else use per-frame method on get_current_frame. */
1409 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1411 ULONGEST raw_val;
1413 if (regcache_cooked_read_unsigned (regcache,
1414 gdbarch_pc_regnum (gdbarch),
1415 &raw_val) == REG_UNAVAILABLE)
1416 throw_error (NOT_AVAILABLE_ERROR, _("PC register is not available"));
1418 pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val);
1420 else
1421 internal_error (_("regcache_read_pc: Unable to find PC"));
1422 return pc_val;
1425 /* See gdbsupport/common-regcache.h. */
1427 CORE_ADDR
1428 regcache_read_pc_protected (reg_buffer_common *regcache)
1430 CORE_ADDR pc;
1433 pc = regcache_read_pc (regcache);
1435 catch (const gdb_exception_error &ex)
1437 pc = 0;
1440 return pc;
1443 void
1444 regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
1446 struct gdbarch *gdbarch = regcache->arch ();
1448 if (gdbarch_write_pc_p (gdbarch))
1449 gdbarch_write_pc (gdbarch, regcache, pc);
1450 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1451 regcache_cooked_write_unsigned (regcache,
1452 gdbarch_pc_regnum (gdbarch), pc);
1453 else
1454 internal_error (_("regcache_write_pc: Unable to update PC"));
1456 /* Writing the PC (for instance, from "load") invalidates the
1457 current frame. */
1458 reinit_frame_cache ();
1462 reg_buffer::num_raw_registers () const
1464 return gdbarch_num_regs (arch ());
1467 void
1468 regcache::debug_print_register (const char *func, int regno)
1470 struct gdbarch *gdbarch = arch ();
1472 gdb_printf (gdb_stdlog, "%s ", func);
1473 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
1474 && gdbarch_register_name (gdbarch, regno)[0] != '\0')
1475 gdb_printf (gdb_stdlog, "(%s)",
1476 gdbarch_register_name (gdbarch, regno));
1477 else
1478 gdb_printf (gdb_stdlog, "(%d)", regno);
1479 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch))
1481 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1482 gdb::array_view<gdb_byte> buf = register_buffer (regno);
1484 gdb_printf (gdb_stdlog, " = ");
1485 for (gdb_byte byte : buf)
1486 gdb_printf (gdb_stdlog, "%02x", byte);
1488 if (buf.size () <= sizeof (LONGEST))
1490 ULONGEST val = extract_unsigned_integer (buf, byte_order);
1492 gdb_printf (gdb_stdlog, " %s %s",
1493 core_addr_to_string_nz (val), plongest (val));
1496 gdb_printf (gdb_stdlog, "\n");
1499 /* Implement 'maint flush register-cache' command. */
1501 static void
1502 reg_flush_command (const char *command, int from_tty)
1504 /* Force-flush the register cache. */
1505 registers_changed ();
1506 if (from_tty)
1507 gdb_printf (_("Register cache flushed.\n"));
1510 void
1511 register_dump::dump (ui_file *file)
1513 auto descr = regcache_descr (m_gdbarch);
1514 int regnum;
1515 int footnote_nr = 0;
1516 int footnote_register_offset = 0;
1517 int footnote_register_type_name_null = 0;
1518 long register_offset = 0;
1520 gdb_assert (descr->nr_cooked_registers
1521 == gdbarch_num_cooked_regs (m_gdbarch));
1523 for (regnum = -1; regnum < descr->nr_cooked_registers; regnum++)
1525 /* Name. */
1526 if (regnum < 0)
1527 gdb_printf (file, " %-10s", "Name");
1528 else
1530 const char *p = gdbarch_register_name (m_gdbarch, regnum);
1532 if (p[0] == '\0')
1533 p = "''";
1534 gdb_printf (file, " %-10s", p);
1537 /* Number. */
1538 if (regnum < 0)
1539 gdb_printf (file, " %4s", "Nr");
1540 else
1541 gdb_printf (file, " %4d", regnum);
1543 /* Relative number. */
1544 if (regnum < 0)
1545 gdb_printf (file, " %4s", "Rel");
1546 else if (regnum < gdbarch_num_regs (m_gdbarch))
1547 gdb_printf (file, " %4d", regnum);
1548 else
1549 gdb_printf (file, " %4d",
1550 (regnum - gdbarch_num_regs (m_gdbarch)));
1552 /* Offset. */
1553 if (regnum < 0)
1554 gdb_printf (file, " %6s ", "Offset");
1555 else
1557 gdb_printf (file, " %6ld",
1558 descr->register_offset[regnum]);
1559 if (register_offset != descr->register_offset[regnum]
1560 || (regnum > 0
1561 && (descr->register_offset[regnum]
1562 != (descr->register_offset[regnum - 1]
1563 + descr->sizeof_register[regnum - 1])))
1566 if (!footnote_register_offset)
1567 footnote_register_offset = ++footnote_nr;
1568 gdb_printf (file, "*%d", footnote_register_offset);
1570 else
1571 gdb_printf (file, " ");
1572 register_offset = (descr->register_offset[regnum]
1573 + descr->sizeof_register[regnum]);
1576 /* Size. */
1577 if (regnum < 0)
1578 gdb_printf (file, " %5s ", "Size");
1579 else
1580 gdb_printf (file, " %5ld", descr->sizeof_register[regnum]);
1582 /* Type. */
1584 const char *t;
1585 std::string name_holder;
1587 if (regnum < 0)
1588 t = "Type";
1589 else
1591 static const char blt[] = "builtin_type";
1593 t = register_type (m_gdbarch, regnum)->name ();
1594 if (t == NULL)
1596 if (!footnote_register_type_name_null)
1597 footnote_register_type_name_null = ++footnote_nr;
1598 name_holder = string_printf ("*%d",
1599 footnote_register_type_name_null);
1600 t = name_holder.c_str ();
1602 /* Chop a leading builtin_type. */
1603 if (startswith (t, blt))
1604 t += strlen (blt);
1606 gdb_printf (file, " %-15s", t);
1609 /* Leading space always present. */
1610 gdb_printf (file, " ");
1612 dump_reg (file, regnum);
1614 gdb_printf (file, "\n");
1617 if (footnote_register_offset)
1618 gdb_printf (file, "*%d: Inconsistent register offsets.\n",
1619 footnote_register_offset);
1620 if (footnote_register_type_name_null)
1621 gdb_printf (file,
1622 "*%d: Register type's name NULL.\n",
1623 footnote_register_type_name_null);
1626 #if GDB_SELF_TEST
1627 #include "gdbsupport/selftest.h"
1628 #include "selftest-arch.h"
1629 #include "target-float.h"
1631 namespace selftests {
1633 static size_t
1634 regcaches_size ()
1636 size_t size = 0;
1638 for (auto pid_ptid_regc_map_it = regcaches.cbegin ();
1639 pid_ptid_regc_map_it != regcaches.cend ();
1640 ++pid_ptid_regc_map_it)
1642 const pid_ptid_regcache_map &pid_ptid_regc_map
1643 = pid_ptid_regc_map_it->second;
1645 for (auto ptid_regc_map_it = pid_ptid_regc_map.cbegin ();
1646 ptid_regc_map_it != pid_ptid_regc_map.cend ();
1647 ++ptid_regc_map_it)
1649 const ptid_regcache_map &ptid_regc_map
1650 = ptid_regc_map_it->second;
1652 size += ptid_regc_map.size ();
1656 return size;
1659 /* Return the count of regcaches for (TARGET, PTID) in REGCACHES. */
1661 static int
1662 regcache_count (process_stratum_target *target, ptid_t ptid)
1664 /* Look up map for target. */
1665 auto pid_ptid_regc_map_it = regcaches.find (target);
1666 if (pid_ptid_regc_map_it != regcaches.end ())
1668 pid_ptid_regcache_map &pid_ptid_regc_map = pid_ptid_regc_map_it->second;
1670 /* Look map for pid. */
1671 auto ptid_regc_map_it = pid_ptid_regc_map.find (ptid.pid ());
1672 if (ptid_regc_map_it != pid_ptid_regc_map.end ())
1674 ptid_regcache_map &ptid_regc_map = ptid_regc_map_it->second;
1675 auto range = ptid_regc_map.equal_range (ptid);
1677 return std::distance (range.first, range.second);
1681 return 0;
1684 /* Wrapper around get_thread_arch_regcache that does some self checks. */
1686 static void
1687 get_thread_arch_regcache_and_check (inferior *inf_for_target_calls,
1688 ptid_t ptid)
1690 /* We currently only test with a single gdbarch. Any gdbarch will do, so use
1691 the current inferior's gdbarch. Also use the current inferior's address
1692 space. */
1693 gdbarch *arch = inf_for_target_calls->arch ();
1694 regcache *regcache
1695 = get_thread_arch_regcache (inf_for_target_calls, ptid, arch);
1697 SELF_CHECK (regcache != NULL);
1698 SELF_CHECK (regcache->ptid () == ptid);
1699 SELF_CHECK (regcache->arch () == arch);
1702 /* The data that the regcaches selftests must hold onto for the duration of the
1703 test. */
1705 struct regcache_test_data
1707 regcache_test_data ()
1708 /* The specific arch doesn't matter. */
1709 : test_ctx_1 (current_inferior ()->arch ()),
1710 test_ctx_2 (current_inferior ()->arch ())
1712 /* Ensure the regcaches container is empty at the start. */
1713 registers_changed ();
1716 ~regcache_test_data ()
1718 /* Make sure to leave the global regcaches container empty. */
1719 registers_changed ();
1722 scoped_mock_context<test_target_ops> test_ctx_1;
1723 scoped_mock_context<test_target_ops> test_ctx_2;
1726 using regcache_test_data_up = std::unique_ptr<regcache_test_data>;
1728 /* Set up a few regcaches from two different targets, for use in
1729 regcache-management tests.
1731 Return a pointer, because the `regcache_test_data` type is not moveable. */
1733 static regcache_test_data_up
1734 populate_regcaches_for_test ()
1736 regcache_test_data_up data (new regcache_test_data);
1737 size_t expected_regcache_size = 0;
1739 SELF_CHECK (regcaches_size () == 0);
1741 /* Populate the regcache container with a few regcaches for the two test
1742 targets. */
1743 for (int pid : { 1, 2 })
1745 for (long lwp : { 1, 2, 3 })
1747 get_thread_arch_regcache_and_check
1748 (&data->test_ctx_1.mock_inferior, ptid_t (pid, lwp));
1749 expected_regcache_size++;
1750 SELF_CHECK (regcaches_size () == expected_regcache_size);
1752 get_thread_arch_regcache_and_check
1753 (&data->test_ctx_2.mock_inferior, ptid_t (pid, lwp));
1754 expected_regcache_size++;
1755 SELF_CHECK (regcaches_size () == expected_regcache_size);
1759 return data;
1762 static void
1763 get_thread_arch_regcache_test ()
1765 /* populate_regcaches_for_test already tests most of the
1766 get_thread_arch_regcache functionality. */
1767 regcache_test_data_up data = populate_regcaches_for_test ();
1768 size_t regcaches_size_before = regcaches_size ();
1770 /* Test that getting an existing regcache doesn't create a new one. */
1771 get_thread_arch_regcache_and_check (&data->test_ctx_1.mock_inferior,
1772 ptid_t (2, 2));
1773 SELF_CHECK (regcaches_size () == regcaches_size_before);
1776 /* Test marking all regcaches of all targets as changed. */
1778 static void
1779 registers_changed_ptid_all_test ()
1781 regcache_test_data_up data = populate_regcaches_for_test ();
1783 registers_changed_ptid (nullptr, minus_one_ptid);
1784 SELF_CHECK (regcaches_size () == 0);
1787 /* Test marking regcaches of a specific target as changed. */
1789 static void
1790 registers_changed_ptid_target_test ()
1792 regcache_test_data_up data = populate_regcaches_for_test ();
1794 registers_changed_ptid (&data->test_ctx_1.mock_target, minus_one_ptid);
1795 SELF_CHECK (regcaches_size () == 6);
1797 /* Check that we deleted the regcache for the right target. */
1798 SELF_CHECK (regcache_count (&data->test_ctx_1.mock_target,
1799 ptid_t (2, 2)) == 0);
1800 SELF_CHECK (regcache_count (&data->test_ctx_2.mock_target,
1801 ptid_t (2, 2)) == 1);
1804 /* Test marking regcaches of a specific (target, pid) as changed. */
1806 static void
1807 registers_changed_ptid_target_pid_test ()
1809 regcache_test_data_up data = populate_regcaches_for_test ();
1811 registers_changed_ptid (&data->test_ctx_1.mock_target, ptid_t (2));
1812 SELF_CHECK (regcaches_size () == 9);
1814 /* Regcaches from target1 should not exist, while regcaches from target2
1815 should exist. */
1816 SELF_CHECK (regcache_count (&data->test_ctx_1.mock_target,
1817 ptid_t (2, 2)) == 0);
1818 SELF_CHECK (regcache_count (&data->test_ctx_2.mock_target,
1819 ptid_t (2, 2)) == 1);
1822 /* Test marking regcaches of a specific (target, ptid) as changed. */
1824 static void
1825 registers_changed_ptid_target_ptid_test ()
1827 regcache_test_data_up data = populate_regcaches_for_test ();
1829 registers_changed_ptid (&data->test_ctx_1.mock_target, ptid_t (2, 2));
1830 SELF_CHECK (regcaches_size () == 11);
1832 /* Check that we deleted the regcache for the right target. */
1833 SELF_CHECK (regcache_count (&data->test_ctx_1.mock_target,
1834 ptid_t (2, 2)) == 0);
1835 SELF_CHECK (regcache_count (&data->test_ctx_2.mock_target,
1836 ptid_t (2, 2)) == 1);
1839 /* Test using reg_buffer::raw_compare with offset equal to the register size
1840 (thus comparing 0 bytes). */
1842 static void
1843 reg_buffer_raw_compare_zero_len_test ()
1845 regcache_test_data_up data = populate_regcaches_for_test ();
1846 inferior &inf = data->test_ctx_1.mock_inferior;
1847 const regcache *regcache
1848 = get_thread_arch_regcache (&inf, ptid_t (1, 1), inf.arch ());
1850 /* The buffer address is irrelevant since we end up comparing 0 bytes, we just
1851 need to pass something. */
1852 gdb_byte buf;
1853 SELF_CHECK (regcache->raw_compare (0, &buf, register_size (inf.arch (), 0)));
1856 class target_ops_no_register : public test_target_ops
1858 public:
1859 target_ops_no_register ()
1860 : test_target_ops {}
1863 void reset ()
1865 fetch_registers_called = 0;
1866 store_registers_called = 0;
1867 xfer_partial_called = 0;
1870 void fetch_registers (regcache *regs, int regno) override;
1871 void store_registers (regcache *regs, int regno) override;
1873 enum target_xfer_status xfer_partial (enum target_object object,
1874 const char *annex, gdb_byte *readbuf,
1875 const gdb_byte *writebuf,
1876 ULONGEST offset, ULONGEST len,
1877 ULONGEST *xfered_len) override;
1879 unsigned int fetch_registers_called = 0;
1880 unsigned int store_registers_called = 0;
1881 unsigned int xfer_partial_called = 0;
1884 void
1885 target_ops_no_register::fetch_registers (regcache *regs, int regno)
1887 /* Mark register available. */
1888 regs->raw_supply_zeroed (regno);
1889 this->fetch_registers_called++;
1892 void
1893 target_ops_no_register::store_registers (regcache *regs, int regno)
1895 this->store_registers_called++;
1898 enum target_xfer_status
1899 target_ops_no_register::xfer_partial (enum target_object object,
1900 const char *annex, gdb_byte *readbuf,
1901 const gdb_byte *writebuf,
1902 ULONGEST offset, ULONGEST len,
1903 ULONGEST *xfered_len)
1905 this->xfer_partial_called++;
1907 *xfered_len = len;
1908 return TARGET_XFER_OK;
1911 class readwrite_regcache : public regcache
1913 public:
1914 readwrite_regcache (inferior *inf_for_target_calls,
1915 struct gdbarch *gdbarch)
1916 : regcache (inf_for_target_calls, gdbarch)
1920 /* Return true if regcache::cooked_{read,write}_test should be skipped for
1921 GDBARCH. */
1923 static bool
1924 selftest_skiparch (struct gdbarch *gdbarch)
1926 const char *name = gdbarch_bfd_arch_info (gdbarch)->printable_name;
1928 /* Avoid warning:
1929 Running selftest regcache::cooked_{read,write}_test::m68hc11.
1930 warning: No frame soft register found in the symbol table.
1931 Stack backtrace will not work.
1932 We could instead capture the output and then filter out the warning, but
1933 that seems more trouble than it's worth. */
1934 return (strcmp (name, "m68hc11") == 0
1935 || strcmp (name, "m68hc12") == 0
1936 || strcmp (name, "m68hc12:HCS12") == 0);
1939 /* Test regcache::cooked_read gets registers from raw registers and
1940 memory instead of target to_{fetch,store}_registers. */
1942 static void
1943 cooked_read_test (struct gdbarch *gdbarch)
1945 if (selftest_skiparch (gdbarch))
1946 return;
1948 scoped_mock_context<target_ops_no_register> mockctx (gdbarch);
1950 /* Test that read one raw register from regcache_no_target will go
1951 to the target layer. */
1953 /* Find a raw register which size isn't zero. */
1954 int nonzero_regnum;
1955 for (nonzero_regnum = 0;
1956 nonzero_regnum < gdbarch_num_regs (gdbarch);
1957 nonzero_regnum++)
1959 if (register_size (gdbarch, nonzero_regnum) != 0)
1960 break;
1963 /* Install this regcache in the regcaches global structure, so that. */
1964 pid_ptid_regcache_map &x = regcaches[&mockctx.mock_target];
1965 ptid_regcache_map &y = x[mockctx.mock_ptid.pid ()];
1966 regcache &readwrite
1967 = *y.emplace (std::make_pair (mockctx.mock_ptid,
1968 std::make_unique<readwrite_regcache> (
1969 &mockctx.mock_inferior, gdbarch)))
1970 ->second;
1972 readwrite.set_ptid (mockctx.mock_ptid);
1974 gdb::byte_vector buf (register_size (gdbarch, nonzero_regnum));
1975 readwrite.raw_read (nonzero_regnum, buf);
1977 /* raw_read calls target_fetch_registers. */
1978 SELF_CHECK (mockctx.mock_target.fetch_registers_called > 0);
1979 mockctx.mock_target.reset ();
1981 /* Mark all raw registers valid, so the following raw registers
1982 accesses won't go to target. */
1983 for (auto i = 0; i < gdbarch_num_regs (gdbarch); i++)
1984 readwrite.raw_update (i);
1986 mockctx.mock_target.reset ();
1987 /* Then, read all raw and pseudo registers, and don't expect calling
1988 to_{fetch,store}_registers. */
1989 for (int regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++)
1991 if (register_size (gdbarch, regnum) == 0)
1992 continue;
1994 gdb::byte_vector inner_buf (register_size (gdbarch, regnum));
1996 SELF_CHECK (REG_VALID == readwrite.cooked_read (regnum, inner_buf));
1997 SELF_CHECK (mockctx.mock_target.fetch_registers_called == 0);
1998 SELF_CHECK (mockctx.mock_target.store_registers_called == 0);
1999 SELF_CHECK (mockctx.mock_target.xfer_partial_called == 0);
2001 mockctx.mock_target.reset ();
2004 readonly_detached_regcache readonly (readwrite);
2006 /* GDB may go to target layer to fetch all registers and memory for
2007 readonly regcache. */
2008 mockctx.mock_target.reset ();
2010 for (int regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++)
2012 if (register_size (gdbarch, regnum) == 0)
2013 continue;
2015 gdb::byte_vector inner_buf (register_size (gdbarch, regnum));
2016 register_status status = readonly.cooked_read (regnum, inner_buf);
2018 if (regnum < gdbarch_num_regs (gdbarch))
2020 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
2022 if (bfd_arch == bfd_arch_amdgcn
2023 || bfd_arch == bfd_arch_frv || bfd_arch == bfd_arch_h8300
2024 || bfd_arch == bfd_arch_m32c || bfd_arch == bfd_arch_sh
2025 || bfd_arch == bfd_arch_alpha || bfd_arch == bfd_arch_v850
2026 || bfd_arch == bfd_arch_msp430 || bfd_arch == bfd_arch_mep
2027 || bfd_arch == bfd_arch_mips || bfd_arch == bfd_arch_v850_rh850
2028 || bfd_arch == bfd_arch_tic6x || bfd_arch == bfd_arch_mn10300
2029 || bfd_arch == bfd_arch_rl78 || bfd_arch == bfd_arch_score
2030 || bfd_arch == bfd_arch_riscv || bfd_arch == bfd_arch_csky)
2032 /* Raw registers. If raw registers are not in save_reggroup,
2033 their status are unknown. */
2034 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
2035 SELF_CHECK (status == REG_VALID);
2036 else
2037 SELF_CHECK (status == REG_UNKNOWN);
2039 else
2040 SELF_CHECK (status == REG_VALID);
2042 else
2044 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
2045 SELF_CHECK (status == REG_VALID);
2046 else
2048 /* If pseudo registers are not in save_reggroup, some of
2049 them can be computed from saved raw registers, but some
2050 of them are unknown. */
2051 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
2053 if (bfd_arch == bfd_arch_frv
2054 || bfd_arch == bfd_arch_m32c
2055 || bfd_arch == bfd_arch_mep
2056 || bfd_arch == bfd_arch_sh)
2057 SELF_CHECK (status == REG_VALID || status == REG_UNKNOWN);
2058 else if (bfd_arch == bfd_arch_mips
2059 || bfd_arch == bfd_arch_h8300)
2060 SELF_CHECK (status == REG_UNKNOWN);
2061 else
2062 SELF_CHECK (status == REG_VALID);
2066 SELF_CHECK (mockctx.mock_target.fetch_registers_called == 0);
2067 SELF_CHECK (mockctx.mock_target.store_registers_called == 0);
2068 SELF_CHECK (mockctx.mock_target.xfer_partial_called == 0);
2070 mockctx.mock_target.reset ();
2073 regcaches.erase (&mockctx.mock_target);
2076 /* Test regcache::cooked_write by writing some expected contents to
2077 registers, and checking that contents read from registers and the
2078 expected contents are the same. */
2080 static void
2081 cooked_write_test (struct gdbarch *gdbarch)
2083 if (selftest_skiparch (gdbarch))
2084 return;
2086 /* Create a mock environment. A process_stratum target pushed. */
2087 scoped_mock_context<target_ops_no_register> ctx (gdbarch);
2090 /* Install this regcache in the regcaches global structure, so that. */
2091 pid_ptid_regcache_map &x = regcaches[&ctx.mock_target];
2092 ptid_regcache_map &y = x[ctx.mock_ptid.pid ()];
2093 regcache &readwrite
2094 = *y.emplace (std::make_pair (ctx.mock_ptid,
2095 std::make_unique<readwrite_regcache> (
2096 &ctx.mock_inferior, gdbarch)))
2097 ->second;
2099 readwrite.set_ptid (ctx.mock_ptid);
2100 const int num_regs = gdbarch_num_cooked_regs (gdbarch);
2102 for (auto regnum = 0; regnum < num_regs; regnum++)
2104 if (register_size (gdbarch, regnum) == 0
2105 || gdbarch_cannot_store_register (gdbarch, regnum))
2106 continue;
2108 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
2110 if (bfd_arch == bfd_arch_sparc
2111 /* SPARC64_CWP_REGNUM, SPARC64_PSTATE_REGNUM,
2112 SPARC64_ASI_REGNUM and SPARC64_CCR_REGNUM are hard to test. */
2113 && gdbarch_ptr_bit (gdbarch) == 64
2114 && (regnum >= gdbarch_num_regs (gdbarch)
2115 && regnum <= gdbarch_num_regs (gdbarch) + 4))
2116 continue;
2118 gdb::byte_vector expected (register_size (gdbarch, regnum), 0);
2119 gdb::byte_vector buf (register_size (gdbarch, regnum), 0);
2120 const auto type = register_type (gdbarch, regnum);
2122 if (type->code () == TYPE_CODE_FLT
2123 || type->code () == TYPE_CODE_DECFLOAT)
2125 /* Generate valid float format. */
2126 target_float_from_string (expected.data (), type, "1.25");
2128 else if (type->code () == TYPE_CODE_INT
2129 || type->code () == TYPE_CODE_ARRAY
2130 || type->code () == TYPE_CODE_PTR
2131 || type->code () == TYPE_CODE_UNION
2132 || type->code () == TYPE_CODE_STRUCT)
2134 if (bfd_arch == bfd_arch_ia64
2135 || (regnum >= gdbarch_num_regs (gdbarch)
2136 && (bfd_arch == bfd_arch_xtensa
2137 || bfd_arch == bfd_arch_bfin
2138 || bfd_arch == bfd_arch_m32c
2139 /* m68hc11 pseudo registers are in memory. */
2140 || bfd_arch == bfd_arch_m68hc11
2141 || bfd_arch == bfd_arch_m68hc12
2142 || bfd_arch == bfd_arch_s390))
2143 || (bfd_arch == bfd_arch_frv
2144 /* FRV pseudo registers except iacc0. */
2145 && regnum > gdbarch_num_regs (gdbarch)))
2147 /* Skip setting the expected values for some architecture
2148 registers. */
2150 else if (bfd_arch == bfd_arch_rl78 && regnum == 40)
2152 /* RL78_PC_REGNUM */
2153 for (auto j = 0; j < register_size (gdbarch, regnum) - 1; j++)
2154 expected[j] = j;
2156 else
2158 for (auto j = 0; j < register_size (gdbarch, regnum); j++)
2159 expected[j] = j;
2162 else if (type->code () == TYPE_CODE_FLAGS)
2164 /* No idea how to test flags. */
2165 continue;
2167 else
2169 /* If we don't know how to create the expected value for the
2170 this type, make it fail. */
2171 SELF_CHECK (0);
2174 readwrite.cooked_write (regnum, expected);
2176 SELF_CHECK (readwrite.cooked_read (regnum, buf) == REG_VALID);
2177 SELF_CHECK (expected == buf);
2180 regcaches.erase (&ctx.mock_target);
2183 /* Verify that when two threads with the same ptid exist (from two different
2184 targets) and one of them changes ptid, we only update the appropriate
2185 regcaches. */
2187 static void
2188 regcache_thread_ptid_changed ()
2190 /* This test relies on the global regcache list to initially be empty. */
2191 registers_changed ();
2193 /* Any arch will do. */
2194 gdbarch *arch = current_inferior ()->arch ();
2196 /* Prepare two targets with one thread each, with the same ptid. */
2197 scoped_mock_context<test_target_ops> target1 (arch);
2198 scoped_mock_context<test_target_ops> target2 (arch);
2200 ptid_t old_ptid (111, 222);
2201 ptid_t new_ptid (111, 333);
2203 target1.mock_inferior.pid = old_ptid.pid ();
2204 target1.mock_thread.ptid = old_ptid;
2205 target1.mock_inferior.ptid_thread_map.clear ();
2206 target1.mock_inferior.ptid_thread_map[old_ptid] = &target1.mock_thread;
2208 target2.mock_inferior.pid = old_ptid.pid ();
2209 target2.mock_thread.ptid = old_ptid;
2210 target2.mock_inferior.ptid_thread_map.clear ();
2211 target2.mock_inferior.ptid_thread_map[old_ptid] = &target2.mock_thread;
2213 gdb_assert (regcaches.empty ());
2215 /* Populate the regcaches container. */
2216 get_thread_arch_regcache (&target1.mock_inferior, old_ptid, arch);
2217 get_thread_arch_regcache (&target2.mock_inferior, old_ptid, arch);
2219 gdb_assert (regcaches.size () == 2);
2220 gdb_assert (regcache_count (&target1.mock_target, old_ptid) == 1);
2221 gdb_assert (regcache_count (&target1.mock_target, new_ptid) == 0);
2222 gdb_assert (regcache_count (&target2.mock_target, old_ptid) == 1);
2223 gdb_assert (regcache_count (&target2.mock_target, new_ptid) == 0);
2225 thread_change_ptid (&target1.mock_target, old_ptid, new_ptid);
2227 gdb_assert (regcaches.size () == 2);
2228 gdb_assert (regcache_count (&target1.mock_target, old_ptid) == 0);
2229 gdb_assert (regcache_count (&target1.mock_target, new_ptid) == 1);
2230 gdb_assert (regcache_count (&target2.mock_target, old_ptid) == 1);
2231 gdb_assert (regcache_count (&target2.mock_target, new_ptid) == 0);
2233 /* Leave the regcache list empty. */
2234 registers_changed ();
2235 gdb_assert (regcaches.empty ());
2238 } // namespace selftests
2239 #endif /* GDB_SELF_TEST */
2241 void _initialize_regcache ();
2242 void
2243 _initialize_regcache ()
2245 struct cmd_list_element *c;
2247 gdb::observers::target_changed.attach (regcache_observer_target_changed,
2248 "regcache");
2249 gdb::observers::thread_ptid_changed.attach (regcache_thread_ptid_changed,
2250 "regcache");
2252 cmd_list_element *maintenance_flush_register_cache_cmd
2253 = add_cmd ("register-cache", class_maintenance, reg_flush_command,
2254 _("Force gdb to flush its register and frame cache."),
2255 &maintenanceflushlist);
2256 c = add_com_alias ("flushregs", maintenance_flush_register_cache_cmd,
2257 class_maintenance, 0);
2258 deprecate_cmd (c, "maintenance flush register-cache");
2260 #if GDB_SELF_TEST
2261 selftests::register_test ("get_thread_arch_regcache",
2262 selftests::get_thread_arch_regcache_test);
2263 selftests::register_test ("registers_changed_ptid_all",
2264 selftests::registers_changed_ptid_all_test);
2265 selftests::register_test ("registers_changed_ptid_target",
2266 selftests::registers_changed_ptid_target_test);
2267 selftests::register_test ("registers_changed_ptid_target_pid",
2268 selftests::registers_changed_ptid_target_pid_test);
2269 selftests::register_test ("registers_changed_ptid_target_ptid",
2270 selftests::registers_changed_ptid_target_ptid_test);
2271 selftests::register_test ("reg_buffer_raw_compare_zero_len",
2272 selftests::reg_buffer_raw_compare_zero_len_test);
2274 selftests::register_test_foreach_arch ("regcache::cooked_read_test",
2275 selftests::cooked_read_test);
2276 selftests::register_test_foreach_arch ("regcache::cooked_write_test",
2277 selftests::cooked_write_test);
2278 selftests::register_test ("regcache_thread_ptid_changed",
2279 selftests::regcache_thread_ptid_changed);
2280 #endif