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 "extract-store-integer.h"
22 #include "gdbthread.h"
24 #include "test-target.h"
25 #include "scoped-mock-context.h"
28 #include "reggroups.h"
29 #include "observable.h"
31 #include <unordered_map>
32 #include "cli/cli-cmds.h"
37 * Here is the actual register cache.
40 /* Per-architecture object describing the layout of a register cache.
41 Computed once when the architecture is created. */
45 /* The architecture this descriptor belongs to. */
46 struct gdbarch
*gdbarch
= nullptr;
48 /* The raw register cache. Each raw (or hard) register is supplied
49 by the target interface. The raw cache should not contain
50 redundant information - if the PC is constructed from two
51 registers then those registers and not the PC lives in the raw
53 long sizeof_raw_registers
= 0;
55 /* The cooked register space. Each cooked register in the range
56 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
57 register. The remaining [NR_RAW_REGISTERS
58 .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto
59 both raw registers and memory by the architecture methods
60 gdbarch_pseudo_register_read and gdbarch_pseudo_register_write. */
61 int nr_cooked_registers
= 0;
62 long sizeof_cooked_registers
= 0;
64 /* Offset and size (in 8 bit bytes), of each register in the
65 register cache. All registers (including those in the range
66 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an
68 long *register_offset
= nullptr;
69 long *sizeof_register
= nullptr;
71 /* Cached table containing the type of each register. */
72 struct type
**register_type
= nullptr;
75 static const registry
<gdbarch
>::key
<struct regcache_descr
>
76 regcache_descr_handle
;
78 static struct regcache_descr
*
79 init_regcache_descr (struct gdbarch
*gdbarch
)
82 struct regcache_descr
*descr
;
83 gdb_assert (gdbarch
!= NULL
);
85 /* Create an initial, zero filled, table. */
86 descr
= new struct regcache_descr
;
87 descr
->gdbarch
= gdbarch
;
89 /* Total size of the register space. The raw registers are mapped
90 directly onto the raw register cache while the pseudo's are
91 either mapped onto raw-registers or memory. */
92 descr
->nr_cooked_registers
= gdbarch_num_cooked_regs (gdbarch
);
94 /* Fill in a table of register types. */
96 = GDBARCH_OBSTACK_CALLOC (gdbarch
, descr
->nr_cooked_registers
,
98 for (i
= 0; i
< descr
->nr_cooked_registers
; i
++)
99 descr
->register_type
[i
] = gdbarch_register_type (gdbarch
, i
);
101 /* Construct a strictly RAW register cache. Don't allow pseudo's
102 into the register cache. */
104 /* Lay out the register cache.
106 NOTE: cagney/2002-05-22: Only register_type () is used when
107 constructing the register cache. It is assumed that the
108 register's raw size, virtual size and type length are all the
114 descr
->sizeof_register
115 = GDBARCH_OBSTACK_CALLOC (gdbarch
, descr
->nr_cooked_registers
, long);
116 descr
->register_offset
117 = GDBARCH_OBSTACK_CALLOC (gdbarch
, descr
->nr_cooked_registers
, long);
118 for (i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
120 descr
->sizeof_register
[i
] = descr
->register_type
[i
]->length ();
121 descr
->register_offset
[i
] = offset
;
122 offset
+= descr
->sizeof_register
[i
];
124 /* Set the real size of the raw register cache buffer. */
125 descr
->sizeof_raw_registers
= offset
;
127 for (; i
< descr
->nr_cooked_registers
; i
++)
129 descr
->sizeof_register
[i
] = descr
->register_type
[i
]->length ();
130 descr
->register_offset
[i
] = offset
;
131 offset
+= descr
->sizeof_register
[i
];
133 /* Set the real size of the readonly register cache buffer. */
134 descr
->sizeof_cooked_registers
= offset
;
140 static struct regcache_descr
*
141 regcache_descr (struct gdbarch
*gdbarch
)
143 struct regcache_descr
*result
= regcache_descr_handle
.get (gdbarch
);
144 if (result
== nullptr)
146 result
= init_regcache_descr (gdbarch
);
147 regcache_descr_handle
.set (gdbarch
, result
);
153 /* Utility functions returning useful register attributes stored in
154 the regcache descr. */
157 register_type (struct gdbarch
*gdbarch
, int regnum
)
159 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
161 gdb_assert (regnum
>= 0 && regnum
< descr
->nr_cooked_registers
);
162 return descr
->register_type
[regnum
];
165 /* Utility functions returning useful register attributes stored in
166 the regcache descr. */
169 register_size (struct gdbarch
*gdbarch
, int regnum
)
171 struct regcache_descr
*descr
= regcache_descr (gdbarch
);
174 gdb_assert (regnum
>= 0 && regnum
< gdbarch_num_cooked_regs (gdbarch
));
175 size
= descr
->sizeof_register
[regnum
];
179 /* See gdbsupport/common-regcache.h. */
182 reg_buffer::register_size (int regnum
) const
184 return ::register_size (this->arch (), regnum
);
187 reg_buffer::reg_buffer (gdbarch
*gdbarch
, bool has_pseudo
)
188 : m_has_pseudo (has_pseudo
)
190 gdb_assert (gdbarch
!= NULL
);
191 m_descr
= regcache_descr (gdbarch
);
193 /* We don't zero-initialize the M_REGISTERS array, as the bytes it contains
194 aren't meaningful as long as the corresponding register status is not
198 m_registers
.reset (new gdb_byte
[m_descr
->sizeof_cooked_registers
]);
199 m_register_status
.reset
200 (new register_status
[m_descr
->nr_cooked_registers
] ());
204 m_registers
.reset (new gdb_byte
[m_descr
->sizeof_raw_registers
]);
205 m_register_status
.reset
206 (new register_status
[gdbarch_num_regs (gdbarch
)] ());
210 regcache::regcache (inferior
*inf_for_target_calls
, gdbarch
*gdbarch
)
211 /* The register buffers. A read/write register cache can only hold
212 [0 .. gdbarch_num_regs). */
213 : detached_regcache (gdbarch
, false),
214 m_inf_for_target_calls (inf_for_target_calls
)
216 m_ptid
= minus_one_ptid
;
219 readonly_detached_regcache::readonly_detached_regcache (regcache
&src
)
220 : readonly_detached_regcache (src
.arch (),
222 gdb::array_view
<gdb_byte
> buf
)
223 { return src
.cooked_read (regnum
, buf
); })
228 reg_buffer::arch () const
230 return m_descr
->gdbarch
;
233 /* Helper for reg_buffer::register_buffer. */
235 template<typename ElemType
>
236 gdb::array_view
<ElemType
>
237 reg_buffer::register_buffer (int regnum
) const
239 assert_regnum (regnum
);
240 ElemType
*start
= &m_registers
[m_descr
->register_offset
[regnum
]];
241 int size
= m_descr
->sizeof_register
[regnum
];
242 return gdb::array_view
<ElemType
> (start
, size
);
245 /* See regcache.h. */
247 gdb::array_view
<const gdb_byte
>
248 reg_buffer::register_buffer (int regnum
) const
250 return register_buffer
<const gdb_byte
> (regnum
);
253 /* See regcache.h. */
255 gdb::array_view
<gdb_byte
>
256 reg_buffer::register_buffer (int regnum
)
258 return register_buffer
<gdb_byte
> (regnum
);
262 reg_buffer::save (register_read_ftype cooked_read
)
264 struct gdbarch
*gdbarch
= m_descr
->gdbarch
;
266 /* It should have pseudo registers. */
267 gdb_assert (m_has_pseudo
);
268 /* Clear the dest. */
269 memset (m_registers
.get (), 0, m_descr
->sizeof_cooked_registers
);
270 memset (m_register_status
.get (), REG_UNKNOWN
, m_descr
->nr_cooked_registers
);
271 /* Copy over any registers (identified by their membership in the
272 save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs +
273 gdbarch_num_pseudo_regs) range is checked since some architectures need
274 to save/restore `cooked' registers that live in memory. */
275 for (int regnum
= 0; regnum
< m_descr
->nr_cooked_registers
; regnum
++)
277 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, save_reggroup
))
279 gdb::array_view
<gdb_byte
> dst_buf
= register_buffer (regnum
);
280 register_status status
= cooked_read (regnum
, dst_buf
);
282 gdb_assert (status
!= REG_UNKNOWN
);
284 if (status
!= REG_VALID
)
285 memset (dst_buf
.data (), 0, dst_buf
.size ());
287 m_register_status
[regnum
] = status
;
293 regcache::restore (readonly_detached_regcache
*src
)
295 struct gdbarch
*gdbarch
= m_descr
->gdbarch
;
298 gdb_assert (src
!= NULL
);
299 gdb_assert (src
->m_has_pseudo
);
301 gdb_assert (gdbarch
== src
->arch ());
303 /* Copy over any registers, being careful to only restore those that
304 were both saved and need to be restored. The full [0 .. gdbarch_num_regs
305 + gdbarch_num_pseudo_regs) range is checked since some architectures need
306 to save/restore `cooked' registers that live in memory. */
307 for (regnum
= 0; regnum
< m_descr
->nr_cooked_registers
; regnum
++)
309 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, restore_reggroup
))
311 if (src
->m_register_status
[regnum
] == REG_VALID
)
312 cooked_write (regnum
, src
->register_buffer (regnum
));
317 /* See gdbsupport/common-regcache.h. */
320 reg_buffer::get_register_status (int regnum
) const
322 assert_regnum (regnum
);
324 return m_register_status
[regnum
];
328 reg_buffer::invalidate (int regnum
)
330 assert_regnum (regnum
);
331 m_register_status
[regnum
] = REG_UNKNOWN
;
335 reg_buffer::assert_regnum (int regnum
) const
337 gdb_assert (regnum
>= 0);
339 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
341 gdb_assert (regnum
< gdbarch_num_regs (arch ()));
344 /* Type to map a ptid to a list of regcaches (one thread may have multiple
345 regcaches, associated to different gdbarches). */
347 using ptid_regcache_map
348 = std::unordered_multimap
<ptid_t
, regcache_up
>;
350 /* Type holding regcaches for a given pid. */
352 using pid_ptid_regcache_map
= std::unordered_map
<int, ptid_regcache_map
>;
354 /* Type holding regcaches for a given target. */
356 using target_pid_ptid_regcache_map
357 = std::unordered_map
<process_stratum_target
*, pid_ptid_regcache_map
>;
359 /* Global structure containing the existing regcaches. */
361 /* NOTE: this is a write-through cache. There is no "dirty" bit for
362 recording if the register values have been changed (eg. by the
363 user). Therefore all registers must be written back to the
364 target when appropriate. */
365 static target_pid_ptid_regcache_map regcaches
;
368 get_thread_arch_regcache (inferior
*inf_for_target_calls
, ptid_t ptid
,
371 gdb_assert (inf_for_target_calls
!= nullptr);
373 process_stratum_target
*proc_target
= inf_for_target_calls
->process_target ();
374 gdb_assert (proc_target
!= nullptr);
376 /* Find the map for this target. */
377 pid_ptid_regcache_map
&pid_ptid_regc_map
= regcaches
[proc_target
];
379 /* Find the map for this pid. */
380 ptid_regcache_map
&ptid_regc_map
= pid_ptid_regc_map
[ptid
.pid ()];
382 /* Check first if a regcache for this arch already exists. */
383 auto range
= ptid_regc_map
.equal_range (ptid
);
384 for (auto it
= range
.first
; it
!= range
.second
; ++it
)
386 if (it
->second
->arch () == arch
)
387 return it
->second
.get ();
390 /* It does not exist, create it. */
391 regcache
*new_regcache
= new regcache (inf_for_target_calls
, arch
);
392 new_regcache
->set_ptid (ptid
);
393 /* Work around a problem with g++ 4.8 (PR96537): Call the regcache_up
394 constructor explicitly instead of implicitly. */
395 ptid_regc_map
.insert (std::make_pair (ptid
, regcache_up (new_regcache
)));
400 static process_stratum_target
*current_thread_target
;
401 static ptid_t current_thread_ptid
;
402 static struct gdbarch
*current_thread_arch
;
405 get_thread_regcache (process_stratum_target
*target
, ptid_t ptid
)
407 inferior
*inf
= find_inferior_ptid (target
, ptid
);
409 if (!current_thread_arch
410 || target
!= current_thread_target
411 || current_thread_ptid
!= ptid
)
413 gdb_assert (ptid
!= null_ptid
);
415 current_thread_ptid
= ptid
;
416 current_thread_target
= target
;
418 scoped_restore_current_inferior restore_current_inferior
;
419 set_current_inferior (inf
);
420 current_thread_arch
= target_thread_architecture (ptid
);
423 return get_thread_arch_regcache (inf
, ptid
, current_thread_arch
);
426 /* See regcache.h. */
429 get_thread_regcache (thread_info
*thread
)
431 gdb_assert (thread
->state
!= THREAD_EXITED
);
433 return get_thread_regcache (thread
->inf
->process_target (),
437 /* See gdbsupport/common-regcache.h. */
440 get_thread_regcache_for_ptid (ptid_t ptid
)
442 /* This function doesn't take a process_stratum_target parameter
443 because it's a gdbsupport/ routine implemented by both gdb and
444 gdbserver. It always refers to a ptid of the current target. */
445 process_stratum_target
*proc_target
= current_inferior ()->process_target ();
446 return get_thread_regcache (proc_target
, ptid
);
449 /* Observer for the target_changed event. */
452 regcache_observer_target_changed (struct target_ops
*target
)
454 registers_changed ();
457 /* Update regcaches related to OLD_PTID to now use NEW_PTID. */
459 regcache_thread_ptid_changed (process_stratum_target
*target
,
460 ptid_t old_ptid
, ptid_t new_ptid
)
462 /* Look up map for target. */
463 auto pid_ptid_regc_map_it
= regcaches
.find (target
);
464 if (pid_ptid_regc_map_it
== regcaches
.end ())
467 /* Look up map for pid. */
468 pid_ptid_regcache_map
&pid_ptid_regc_map
= pid_ptid_regc_map_it
->second
;
469 auto ptid_regc_map_it
= pid_ptid_regc_map
.find (old_ptid
.pid ());
470 if (ptid_regc_map_it
== pid_ptid_regc_map
.end ())
473 /* Update all regcaches belonging to old_ptid. */
474 ptid_regcache_map
&ptid_regc_map
= ptid_regc_map_it
->second
;
475 auto range
= ptid_regc_map
.equal_range (old_ptid
);
476 for (auto it
= range
.first
; it
!= range
.second
;)
478 regcache_up rc
= std::move (it
->second
);
479 rc
->set_ptid (new_ptid
);
481 /* Remove old before inserting new, to avoid rehashing,
482 which would invalidate iterators. */
483 it
= ptid_regc_map
.erase (it
);
484 ptid_regc_map
.insert (std::make_pair (new_ptid
, std::move (rc
)));
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 (process_stratum_target
*target
, ptid_t ptid
)
502 if (target
== nullptr)
504 /* Since there can be ptid clashes between targets, it's not valid to
505 pass a ptid without saying to which target it belongs. */
506 gdb_assert (ptid
== minus_one_ptid
);
508 /* Delete all the regcaches of all targets. */
511 else if (ptid
.is_pid ())
513 /* Non-NULL target and pid ptid, delete all regcaches belonging
514 to this (TARGET, PID). */
516 /* Look up map for target. */
517 auto pid_ptid_regc_map_it
= regcaches
.find (target
);
518 if (pid_ptid_regc_map_it
!= regcaches
.end ())
520 pid_ptid_regcache_map
&pid_ptid_regc_map
521 = pid_ptid_regc_map_it
->second
;
523 pid_ptid_regc_map
.erase (ptid
.pid ());
526 else if (ptid
!= minus_one_ptid
)
528 /* Non-NULL target and non-minus_one_ptid, delete all regcaches belonging
529 to this (TARGET, PTID). */
531 /* Look up map for target. */
532 auto pid_ptid_regc_map_it
= regcaches
.find (target
);
533 if (pid_ptid_regc_map_it
!= regcaches
.end ())
535 pid_ptid_regcache_map
&pid_ptid_regc_map
536 = pid_ptid_regc_map_it
->second
;
538 /* Look up map for pid. */
539 auto ptid_regc_map_it
540 = pid_ptid_regc_map
.find (ptid
.pid ());
541 if (ptid_regc_map_it
!= pid_ptid_regc_map
.end ())
543 ptid_regcache_map
&ptid_regc_map
544 = ptid_regc_map_it
->second
;
546 ptid_regc_map
.erase (ptid
);
552 /* Non-NULL target and minus_one_ptid, delete all regcaches
553 associated to this target. */
554 regcaches
.erase (target
);
557 if ((target
== nullptr || current_thread_target
== target
)
558 && current_thread_ptid
.matches (ptid
))
560 current_thread_target
= NULL
;
561 current_thread_ptid
= null_ptid
;
562 current_thread_arch
= NULL
;
565 if ((target
== nullptr || current_inferior ()->process_target () == target
)
566 && inferior_ptid
.matches (ptid
))
568 /* We just deleted the regcache of the current thread. Need to
569 forget about any frames we have cached, too. */
570 reinit_frame_cache ();
574 /* See regcache.h. */
577 registers_changed_thread (thread_info
*thread
)
579 registers_changed_ptid (thread
->inf
->process_target (), thread
->ptid
);
583 registers_changed (void)
585 registers_changed_ptid (nullptr, minus_one_ptid
);
589 regcache::raw_update (int regnum
)
591 assert_regnum (regnum
);
593 /* Make certain that the register cache is up-to-date with respect
594 to the current thread. This switching shouldn't be necessary
595 only there is still only one target side register cache. Sigh!
596 On the bright side, at least there is a regcache object. */
598 if (get_register_status (regnum
) == REG_UNKNOWN
)
600 std::optional
<scoped_restore_current_thread
> maybe_restore_thread
601 = maybe_switch_inferior (m_inf_for_target_calls
);
603 target_fetch_registers (this, regnum
);
605 /* A number of targets can't access the whole set of raw
606 registers (because the debug API provides no means to get at
608 if (m_register_status
[regnum
] == REG_UNKNOWN
)
609 m_register_status
[regnum
] = REG_UNAVAILABLE
;
614 readable_regcache::raw_read (int regnum
, gdb::array_view
<gdb_byte
> dst
)
616 assert_regnum (regnum
);
617 gdb_assert (dst
.size () == m_descr
->sizeof_register
[regnum
]);
621 if (m_register_status
[regnum
] != REG_VALID
)
622 memset (dst
.data (), 0, dst
.size ());
624 copy (register_buffer (regnum
), dst
);
626 return m_register_status
[regnum
];
630 readable_regcache::raw_read (int regnum
, gdb_byte
*dst
)
632 assert_regnum (regnum
);
633 int size
= m_descr
->sizeof_register
[regnum
];
634 return raw_read (regnum
, gdb::make_array_view (dst
, size
));
638 regcache_raw_read_signed (struct regcache
*regcache
, int regnum
, LONGEST
*val
)
640 gdb_assert (regcache
!= NULL
);
641 return regcache
->raw_read (regnum
, val
);
644 template<typename T
, typename
>
646 readable_regcache::raw_read (int regnum
, T
*val
)
648 assert_regnum (regnum
);
649 size_t size
= m_descr
->sizeof_register
[regnum
];
650 gdb_byte
*buf
= (gdb_byte
*) alloca (size
);
651 auto view
= gdb::make_array_view (buf
, size
);
652 register_status status
= raw_read (regnum
, view
);
654 if (status
== REG_VALID
)
655 *val
= extract_integer
<T
> (view
, gdbarch_byte_order (m_descr
->gdbarch
));
663 regcache_raw_read_unsigned (reg_buffer_common
*regcache
, int regnum
,
666 gdb_assert (regcache
!= NULL
);
667 return gdb::checked_static_cast
<struct regcache
*> (regcache
)->raw_read
672 regcache_raw_write_signed (struct regcache
*regcache
, int regnum
, LONGEST val
)
674 gdb_assert (regcache
!= NULL
);
675 regcache
->raw_write (regnum
, val
);
678 template<typename T
, typename
>
680 regcache::raw_write (int regnum
, T val
)
682 assert_regnum (regnum
);
684 int size
= m_descr
->sizeof_register
[regnum
];
685 gdb_byte
*buf
= (gdb_byte
*) alloca (size
);
686 auto view
= gdb::make_array_view (buf
, size
);
687 store_integer (view
, gdbarch_byte_order (m_descr
->gdbarch
), val
);
688 raw_write (regnum
, view
);
692 regcache_raw_write_unsigned (struct regcache
*regcache
, int regnum
,
695 gdb_assert (regcache
!= NULL
);
696 regcache
->raw_write (regnum
, val
);
700 regcache_raw_get_signed (struct regcache
*regcache
, int regnum
)
703 enum register_status status
;
705 status
= regcache_raw_read_signed (regcache
, regnum
, &value
);
706 if (status
== REG_UNAVAILABLE
)
707 throw_error (NOT_AVAILABLE_ERROR
,
708 _("Register %d is not available"), regnum
);
712 /* See regcache.h. */
715 readable_regcache::cooked_read (int regnum
, gdb::array_view
<gdb_byte
> dst
)
717 gdb_assert (regnum
>= 0);
718 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
720 if (regnum
< num_raw_registers ())
721 return raw_read (regnum
, dst
);
723 gdb_assert (dst
.size () == m_descr
->sizeof_register
[regnum
]);
725 if (m_has_pseudo
&& m_register_status
[regnum
] != REG_UNKNOWN
)
727 if (m_register_status
[regnum
] == REG_VALID
)
728 copy (register_buffer (regnum
), dst
);
730 memset (dst
.data (), 0, dst
.size ());
732 return m_register_status
[regnum
];
734 else if (gdbarch_pseudo_register_read_value_p (m_descr
->gdbarch
))
736 register_status result
= REG_VALID
;
737 scoped_value_mark mark
;
738 value
*computed
= gdbarch_pseudo_register_read_value
739 (m_descr
->gdbarch
, get_next_frame_sentinel_okay (get_current_frame ()),
742 if (computed
->entirely_available ())
743 copy (computed
->contents_raw (), dst
);
746 memset (dst
.data (), 0, dst
.size ());
747 result
= REG_UNAVAILABLE
;
753 return gdbarch_pseudo_register_read (m_descr
->gdbarch
, this, regnum
,
757 /* See regcache.h. */
760 readable_regcache::cooked_read (int regnum
, gdb_byte
*dst
)
762 gdb_assert (regnum
>= 0);
763 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
765 int size
= m_descr
->sizeof_register
[regnum
];
766 return cooked_read (regnum
, gdb::make_array_view (dst
, size
));
770 readable_regcache::cooked_read_value (int regnum
)
772 gdb_assert (regnum
>= 0);
773 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
775 if (regnum
< num_raw_registers ()
776 || (m_has_pseudo
&& m_register_status
[regnum
] != REG_UNKNOWN
)
777 || !gdbarch_pseudo_register_read_value_p (m_descr
->gdbarch
))
779 value
*result
= value::allocate_register
780 (get_next_frame_sentinel_okay (get_current_frame ()), regnum
);
782 /* It is more efficient in general to do this delegation in this
783 direction than in the other one, even though the value-based
785 if (cooked_read (regnum
, result
->contents_raw ()) == REG_UNAVAILABLE
)
786 result
->mark_bytes_unavailable (0,
787 result
->type ()->length ());
792 return gdbarch_pseudo_register_read_value
793 (m_descr
->gdbarch
, get_next_frame_sentinel_okay (get_current_frame ()),
798 regcache_cooked_read_signed (struct regcache
*regcache
, int regnum
,
801 gdb_assert (regcache
!= NULL
);
802 return regcache
->cooked_read (regnum
, val
);
805 template<typename T
, typename
>
807 readable_regcache::cooked_read (int regnum
, T
*val
)
809 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_cooked_registers
);
810 size_t size
= m_descr
->sizeof_register
[regnum
];
811 gdb_byte
*buf
= (gdb_byte
*) alloca (size
);
812 auto view
= gdb::make_array_view (buf
, size
);
813 register_status status
= cooked_read (regnum
, view
);
814 if (status
== REG_VALID
)
815 *val
= extract_integer
<T
> (view
, gdbarch_byte_order (m_descr
->gdbarch
));
822 regcache_cooked_read_unsigned (struct regcache
*regcache
, int regnum
,
825 gdb_assert (regcache
!= NULL
);
826 return regcache
->cooked_read (regnum
, val
);
830 regcache_cooked_write_signed (struct regcache
*regcache
, int regnum
,
833 gdb_assert (regcache
!= NULL
);
834 regcache
->cooked_write (regnum
, val
);
837 template<typename T
, typename
>
839 regcache::cooked_write (int regnum
, T val
)
841 gdb_assert (regnum
>= 0);
842 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
844 int size
= m_descr
->sizeof_register
[regnum
];
845 gdb_byte
*buf
= (gdb_byte
*) alloca (size
);
846 auto view
= gdb::make_array_view (buf
, size
);
847 store_integer (view
, gdbarch_byte_order (m_descr
->gdbarch
), val
);
848 cooked_write (regnum
, view
);
852 regcache_cooked_write_unsigned (struct regcache
*regcache
, int regnum
,
855 gdb_assert (regcache
!= NULL
);
856 regcache
->cooked_write (regnum
, val
);
860 regcache::raw_write (int regnum
, gdb::array_view
<const gdb_byte
> src
)
862 assert_regnum (regnum
);
863 gdb_assert (src
.size () == m_descr
->sizeof_register
[regnum
]);
865 /* On the sparc, writing %g0 is a no-op, so we don't even want to
866 change the registers array if something writes to this register. */
867 if (gdbarch_cannot_store_register (arch (), regnum
))
870 /* If we have a valid copy of the register, and new value == old
871 value, then don't bother doing the actual store. */
872 if (get_register_status (regnum
) == REG_VALID
873 && (memcmp (register_buffer (regnum
).data (), src
.data (), src
.size ())
877 std::optional
<scoped_restore_current_thread
> maybe_restore_thread
878 = maybe_switch_inferior (m_inf_for_target_calls
);
880 target_prepare_to_store (this);
881 raw_supply (regnum
, src
);
883 /* Invalidate the register after it is written, in case of a
886 = make_scope_exit ([&] { this->invalidate (regnum
); });
888 target_store_registers (this, regnum
);
890 /* The target did not throw an error so we can discard invalidating
892 invalidator
.release ();
896 regcache::raw_write (int regnum
, const gdb_byte
*src
)
898 assert_regnum (regnum
);
900 int size
= m_descr
->sizeof_register
[regnum
];
901 raw_write (regnum
, gdb::make_array_view (src
, size
));
904 /* See regcache.h. */
907 regcache::cooked_write (int regnum
, gdb::array_view
<const gdb_byte
> src
)
909 gdb_assert (regnum
>= 0);
910 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
912 if (regnum
< num_raw_registers ())
913 raw_write (regnum
, src
);
914 else if (gdbarch_pseudo_register_write_p (m_descr
->gdbarch
))
915 gdbarch_pseudo_register_write
916 (m_descr
->gdbarch
, get_next_frame_sentinel_okay (get_current_frame ()),
919 gdbarch_deprecated_pseudo_register_write (m_descr
->gdbarch
, this, regnum
,
923 /* See regcache.h. */
926 regcache::cooked_write (int regnum
, const gdb_byte
*src
)
928 gdb_assert (regnum
>= 0);
929 gdb_assert (regnum
< m_descr
->nr_cooked_registers
);
931 int size
= m_descr
->sizeof_register
[regnum
];
932 return cooked_write (regnum
, gdb::make_array_view (src
, size
));
935 /* See regcache.h. */
938 readable_regcache::read_part (int regnum
, int offset
,
939 gdb::array_view
<gdb_byte
> dst
, bool is_raw
)
941 int reg_size
= register_size (regnum
);
943 gdb_assert (offset
>= 0);
944 gdb_assert (offset
+ dst
.size () <= reg_size
);
946 if (dst
.size () == 0)
952 if (dst
.size () == reg_size
)
954 /* Read the full register. */
956 return raw_read (regnum
, dst
);
958 return cooked_read (regnum
, dst
);
961 /* Read full register to buffer. */
962 register_status status
;
963 gdb_byte
*reg_buf
= (gdb_byte
*) alloca (reg_size
);
964 auto reg
= gdb::make_array_view (reg_buf
, reg_size
);
967 status
= raw_read (regnum
, reg
);
969 status
= cooked_read (regnum
, reg
);
971 if (status
!= REG_VALID
)
975 copy (reg
.slice (offset
, dst
.size ()), dst
);
979 /* See regcache.h. */
982 reg_buffer::raw_collect_part (int regnum
, int offset
,
983 gdb::array_view
<gdb_byte
> dst
) const
985 int reg_size
= register_size (regnum
);
987 gdb_assert (offset
>= 0);
988 gdb_assert (offset
+ dst
.size () <= reg_size
);
990 if (dst
.size () == 0)
996 if (dst
.size () == reg_size
)
998 /* Collect the full register. */
999 return raw_collect (regnum
, dst
);
1002 /* Read to buffer, then write out. */
1003 gdb_byte
*reg_buf
= (gdb_byte
*) alloca (reg_size
);
1004 auto reg
= gdb::make_array_view (reg_buf
, reg_size
);
1005 raw_collect (regnum
, reg
);
1006 copy (reg
.slice (offset
, dst
.size ()), dst
);
1009 /* See regcache.h. */
1012 regcache::write_part (int regnum
, int offset
,
1013 gdb::array_view
<const gdb_byte
> src
, bool is_raw
)
1015 int reg_size
= register_size (regnum
);
1017 gdb_assert (offset
>= 0);
1018 gdb_assert (offset
+ src
.size () <= reg_size
);
1020 if (src
.size () == 0)
1022 /* Nothing to do. */
1026 if (src
.size () == reg_size
)
1028 /* Write the full register. */
1030 raw_write (regnum
, src
);
1032 cooked_write (regnum
, src
);
1037 /* Read existing register to buffer. */
1038 register_status status
;
1039 gdb_byte
*reg_buf
= (gdb_byte
*) alloca (reg_size
);
1040 auto reg
= gdb::make_array_view (reg_buf
, reg_size
);
1043 status
= raw_read (regnum
, reg
);
1045 status
= cooked_read (regnum
, reg
);
1047 if (status
!= REG_VALID
)
1050 /* Update buffer, then write back to regcache. */
1051 copy (src
, reg
.slice (offset
, src
.size ()));
1054 raw_write (regnum
, reg
);
1056 cooked_write (regnum
, reg
);
1061 /* See regcache.h. */
1064 reg_buffer::raw_supply_part (int regnum
, int offset
,
1065 gdb::array_view
<const gdb_byte
> src
)
1067 int reg_size
= register_size (regnum
);
1069 gdb_assert (offset
>= 0);
1070 gdb_assert (offset
+ src
.size () <= reg_size
);
1072 if (src
.size () == 0)
1074 /* Nothing to do. */
1078 if (src
.size () == reg_size
)
1080 /* Supply the full register. */
1081 return raw_supply (regnum
, src
);
1084 /* Read existing value to buffer. */
1085 gdb_byte
*reg_buf
= (gdb_byte
*) alloca (reg_size
);
1086 auto reg
= gdb::make_array_view (reg_buf
, reg_size
);
1087 raw_collect (regnum
, reg
);
1089 /* Write to buffer, then write out. */
1090 copy (src
, reg
.slice (offset
, src
.size ()));
1091 raw_supply (regnum
, reg
);
1095 readable_regcache::raw_read_part (int regnum
, int offset
,
1096 gdb::array_view
<gdb_byte
> dst
)
1098 assert_regnum (regnum
);
1099 return read_part (regnum
, offset
, dst
, true);
1102 /* See regcache.h. */
1105 regcache::raw_write_part (int regnum
, int offset
,
1106 gdb::array_view
<const gdb_byte
> src
)
1108 assert_regnum (regnum
);
1109 write_part (regnum
, offset
, src
, true);
1112 /* See regcache.h. */
1115 readable_regcache::cooked_read_part (int regnum
, int offset
,
1116 gdb::array_view
<gdb_byte
> dst
)
1118 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_cooked_registers
);
1119 return read_part (regnum
, offset
, dst
, false);
1122 /* See regcache.h. */
1125 regcache::cooked_write_part (int regnum
, int offset
,
1126 gdb::array_view
<const gdb_byte
> src
)
1128 gdb_assert (regnum
>= 0 && regnum
< m_descr
->nr_cooked_registers
);
1129 write_part (regnum
, offset
, src
, false);
1132 /* See gdbsupport/common-regcache.h. */
1135 reg_buffer::raw_supply (int regnum
, gdb::array_view
<const gdb_byte
> src
)
1137 gdb::array_view
<gdb_byte
> dst
= register_buffer (regnum
);
1139 if (src
.data () != nullptr)
1142 m_register_status
[regnum
] = REG_VALID
;
1146 /* This memset not strictly necessary, but better than garbage
1147 in case the register value manages to escape somewhere (due
1148 to a bug, no less). */
1149 memset (dst
.data (), 0, dst
.size ());
1150 m_register_status
[regnum
] = REG_UNAVAILABLE
;
1154 /* See regcache.h. */
1157 reg_buffer::raw_supply (int regnum
, const void *src
)
1159 assert_regnum (regnum
);
1161 int size
= m_descr
->sizeof_register
[regnum
];
1162 raw_supply (regnum
, gdb::make_array_view ((const gdb_byte
*) src
, size
));
1165 /* See regcache.h. */
1168 reg_buffer::raw_supply_integer (int regnum
, const gdb_byte
*addr
, int addr_len
,
1171 gdb::array_view
<gdb_byte
> dst
= register_buffer (regnum
);
1172 bfd_endian byte_order
= gdbarch_byte_order (m_descr
->gdbarch
);
1174 copy_integer_to_size (dst
.data (), dst
.size (), addr
, addr_len
, is_signed
,
1176 m_register_status
[regnum
] = REG_VALID
;
1179 /* See regcache.h. */
1182 reg_buffer::raw_supply_zeroed (int regnum
)
1184 gdb::array_view
<gdb_byte
> dst
= register_buffer (regnum
);
1185 memset (dst
.data (), 0, dst
.size ());
1186 m_register_status
[regnum
] = REG_VALID
;
1189 /* See gdbsupport/common-regcache.h. */
1192 reg_buffer::raw_supply_part_zeroed (int regnum
, int offset
, size_t size
)
1194 gdb::array_view
<gdb_byte
> dst
= register_buffer (regnum
).slice (offset
, size
);
1195 memset (dst
.data (), 0, dst
.size ());
1196 m_register_status
[regnum
] = REG_VALID
;
1199 /* See gdbsupport/common-regcache.h. */
1202 reg_buffer::raw_collect (int regnum
, gdb::array_view
<gdb_byte
> dst
) const
1204 gdb::array_view
<const gdb_byte
> src
= register_buffer (regnum
);
1208 /* See regcache.h. */
1211 reg_buffer::raw_collect (int regnum
, void *dst
) const
1213 assert_regnum (regnum
);
1215 int size
= m_descr
->sizeof_register
[regnum
];
1216 return raw_collect (regnum
, gdb::make_array_view ((gdb_byte
*) dst
, size
));
1219 /* See regcache.h. */
1222 reg_buffer::raw_collect_integer (int regnum
, gdb_byte
*addr
, int addr_len
,
1223 bool is_signed
) const
1225 gdb::array_view
<const gdb_byte
> dst
= register_buffer (regnum
);
1226 bfd_endian byte_order
= gdbarch_byte_order (m_descr
->gdbarch
);
1227 copy_integer_to_size (addr
, addr_len
, dst
.data (), dst
.size (), is_signed
,
1231 /* See regcache.h. */
1234 regcache::transfer_regset_register (struct regcache
*out_regcache
, int regnum
,
1235 const gdb_byte
*in_buf
, gdb_byte
*out_buf
,
1236 int slot_size
, int offs
) const
1238 int reg_size
= std::min (register_size (regnum
), slot_size
);
1240 /* Use part versions and reg_size to prevent possible buffer overflows when
1241 accessing the regcache. */
1243 if (out_buf
!= nullptr)
1245 raw_collect_part (regnum
, 0,
1246 gdb::make_array_view (out_buf
+ offs
, reg_size
));
1248 /* Ensure any additional space is cleared. */
1249 if (slot_size
> reg_size
)
1250 memset (out_buf
+ offs
+ reg_size
, 0, slot_size
- reg_size
);
1252 else if (in_buf
!= nullptr)
1254 /* Zero-extend the register value if the slot is smaller than the register. */
1255 if (slot_size
< register_size (regnum
))
1256 out_regcache
->raw_supply_zeroed (regnum
);
1257 out_regcache
->raw_supply_part (regnum
, 0,
1258 gdb::make_array_view (in_buf
+ offs
,
1263 /* Invalidate the register. */
1264 out_regcache
->raw_supply (regnum
, {});
1268 /* See regcache.h. */
1271 regcache::transfer_regset (const struct regset
*regset
, int regbase
,
1272 struct regcache
*out_regcache
,
1273 int regnum
, const gdb_byte
*in_buf
,
1274 gdb_byte
*out_buf
, size_t size
) const
1276 const struct regcache_map_entry
*map
;
1277 int offs
= 0, count
;
1279 for (map
= (const struct regcache_map_entry
*) regset
->regmap
;
1280 (count
= map
->count
) != 0;
1283 int regno
= map
->regno
;
1284 int slot_size
= map
->size
;
1286 if (regno
!= REGCACHE_MAP_SKIP
)
1289 if (slot_size
== 0 && regno
!= REGCACHE_MAP_SKIP
)
1290 slot_size
= m_descr
->sizeof_register
[regno
];
1292 if (regno
== REGCACHE_MAP_SKIP
1294 && (regnum
< regno
|| regnum
>= regno
+ count
)))
1295 offs
+= count
* slot_size
;
1297 else if (regnum
== -1)
1298 for (; count
--; regno
++, offs
+= slot_size
)
1300 if (offs
+ slot_size
> size
)
1303 transfer_regset_register (out_regcache
, regno
, in_buf
, out_buf
,
1308 /* Transfer a single register and return. */
1309 offs
+= (regnum
- regno
) * slot_size
;
1310 if (offs
+ slot_size
> size
)
1313 transfer_regset_register (out_regcache
, regnum
, in_buf
, out_buf
,
1320 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1321 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1322 If BUF is NULL, set the register(s) to "unavailable" status. */
1325 regcache_supply_regset (const struct regset
*regset
,
1326 struct regcache
*regcache
,
1327 int regnum
, const void *buf
, size_t size
)
1329 regcache
->supply_regset (regset
, regnum
, (const gdb_byte
*) buf
, size
);
1332 /* See regcache.h. */
1335 regcache::supply_regset (const struct regset
*regset
, int regbase
,
1336 int regnum
, const void *buf
, size_t size
)
1338 transfer_regset (regset
, regbase
, this, regnum
, (const gdb_byte
*) buf
,
1342 /* Collect register REGNUM from REGCACHE to BUF, using the register
1343 map in REGSET. If REGNUM is -1, do this for all registers in
1347 regcache_collect_regset (const struct regset
*regset
,
1348 const struct regcache
*regcache
,
1349 int regnum
, void *buf
, size_t size
)
1351 regcache
->collect_regset (regset
, regnum
, (gdb_byte
*) buf
, size
);
1354 /* See regcache.h */
1357 regcache::collect_regset (const struct regset
*regset
, int regbase
,
1358 int regnum
, void *buf
, size_t size
) const
1360 transfer_regset (regset
, regbase
, nullptr, regnum
, nullptr, (gdb_byte
*) buf
,
1365 regcache_map_supplies (const struct regcache_map_entry
*map
, int regnum
,
1366 struct gdbarch
*gdbarch
, size_t size
)
1368 int offs
= 0, count
;
1370 for (; (count
= map
->count
) != 0; map
++)
1372 int regno
= map
->regno
;
1373 int slot_size
= map
->size
;
1375 if (slot_size
== 0 && regno
!= REGCACHE_MAP_SKIP
)
1376 slot_size
= register_size (gdbarch
, regno
);
1378 if (regno
!= REGCACHE_MAP_SKIP
&& regnum
>= regno
1379 && regnum
< regno
+ count
)
1380 return offs
+ (regnum
- regno
+ 1) * slot_size
<= size
;
1382 offs
+= count
* slot_size
;
1389 /* See gdbsupport/common-regcache.h. */
1392 reg_buffer::raw_compare (int regnum
, const void *buf
, int offset
) const
1394 gdb_assert (buf
!= NULL
);
1396 gdb::array_view
<const gdb_byte
> regbuf
= register_buffer (regnum
);
1397 gdb_assert (offset
<= regbuf
.size ());
1398 regbuf
= regbuf
.slice (offset
);
1400 return memcmp (buf
, regbuf
.data (), regbuf
.size ()) == 0;
1403 /* Special handling for register PC. */
1406 regcache_read_pc (reg_buffer_common
*reg_buf
)
1408 regcache
*regcache
= gdb::checked_static_cast
<struct regcache
*> (reg_buf
);
1409 struct gdbarch
*gdbarch
= regcache
->arch ();
1413 if (gdbarch_read_pc_p (gdbarch
))
1414 pc_val
= gdbarch_read_pc (gdbarch
, regcache
);
1415 /* Else use per-frame method on get_current_frame. */
1416 else if (gdbarch_pc_regnum (gdbarch
) >= 0)
1420 if (regcache_cooked_read_unsigned (regcache
,
1421 gdbarch_pc_regnum (gdbarch
),
1422 &raw_val
) == REG_UNAVAILABLE
)
1423 throw_error (NOT_AVAILABLE_ERROR
, _("PC register is not available"));
1425 pc_val
= gdbarch_addr_bits_remove (gdbarch
, raw_val
);
1428 internal_error (_("regcache_read_pc: Unable to find PC"));
1432 /* See gdbsupport/common-regcache.h. */
1435 regcache_read_pc_protected (reg_buffer_common
*regcache
)
1440 pc
= regcache_read_pc (regcache
);
1442 catch (const gdb_exception_error
&ex
)
1451 regcache_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1453 struct gdbarch
*gdbarch
= regcache
->arch ();
1455 if (gdbarch_write_pc_p (gdbarch
))
1456 gdbarch_write_pc (gdbarch
, regcache
, pc
);
1457 else if (gdbarch_pc_regnum (gdbarch
) >= 0)
1458 regcache_cooked_write_unsigned (regcache
,
1459 gdbarch_pc_regnum (gdbarch
), pc
);
1461 internal_error (_("regcache_write_pc: Unable to update PC"));
1463 /* Writing the PC (for instance, from "load") invalidates the
1465 reinit_frame_cache ();
1469 reg_buffer::num_raw_registers () const
1471 return gdbarch_num_regs (arch ());
1475 regcache::register_debug_string (int regno
)
1477 struct gdbarch
*gdbarch
= arch ();
1480 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
)
1481 && gdbarch_register_name (gdbarch
, regno
)[0] != '\0')
1482 string_appendf (s
, "register %s:", gdbarch_register_name (gdbarch
, regno
));
1484 string_appendf (s
, "register %d:", regno
);
1486 if (regno
>= 0 && regno
< gdbarch_num_regs (gdbarch
))
1488 gdb::array_view
<gdb_byte
> buf
= register_buffer (regno
);
1490 string_appendf (s
, " = ");
1492 for (gdb_byte byte
: buf
)
1493 string_appendf (s
, "%02x", byte
);
1495 if (buf
.size () <= sizeof (LONGEST
))
1498 = extract_unsigned_integer (buf
, gdbarch_byte_order (gdbarch
));
1500 string_appendf (s
, " %s %s",
1501 core_addr_to_string_nz (val
), plongest (val
));
1508 /* Implement 'maint flush register-cache' command. */
1511 reg_flush_command (const char *command
, int from_tty
)
1513 /* Force-flush the register cache. */
1514 registers_changed ();
1516 gdb_printf (_("Register cache flushed.\n"));
1520 register_dump::dump (ui_out
*out
, const char *name
)
1522 auto descr
= regcache_descr (m_gdbarch
);
1524 int footnote_nr
= 0;
1525 int footnote_register_offset
= 0;
1526 int footnote_register_type_name_null
= 0;
1527 long register_offset
= 0;
1529 gdb_assert (descr
->nr_cooked_registers
1530 == gdbarch_num_cooked_regs (m_gdbarch
));
1532 ui_out_emit_table
table (out
, 6 + num_additional_headers (), -1, name
);
1533 out
->table_header (10, ui_left
, "name", "Name");
1534 out
->table_header (4, ui_left
, "num", "Nr");
1535 out
->table_header (4, ui_left
, "relnum", "Rel");
1536 out
->table_header (8, ui_left
, "offset", "Offset");
1537 out
->table_header (5, ui_left
, "size", "Size");
1538 out
->table_header (15, ui_left
, "type", "Type");
1539 additional_headers (out
);
1542 for (regnum
= 0; regnum
< descr
->nr_cooked_registers
; regnum
++)
1544 ui_out_emit_tuple
tuple_emitter (out
, nullptr);
1547 const char *p
= gdbarch_register_name (m_gdbarch
, regnum
);
1550 out
->field_string ("name", p
);
1553 out
->field_signed ("num", regnum
);
1555 /* Relative number. */
1556 if (regnum
< gdbarch_num_regs (m_gdbarch
))
1557 out
->field_signed ("relnum", regnum
);
1559 out
->field_signed ("relnum", (regnum
- gdbarch_num_regs (m_gdbarch
)));
1562 if (register_offset
!= descr
->register_offset
[regnum
]
1564 && (descr
->register_offset
[regnum
]
1565 != (descr
->register_offset
[regnum
- 1]
1566 + descr
->sizeof_register
[regnum
- 1]))))
1568 if (!footnote_register_offset
)
1569 footnote_register_offset
= ++footnote_nr
;
1570 std::string val
= string_printf ("%ld*%d",
1571 descr
->register_offset
[regnum
],
1572 footnote_register_offset
);
1573 out
->field_string ("offset", val
);
1576 out
->field_signed ("offset", descr
->register_offset
[regnum
]);
1577 register_offset
= (descr
->register_offset
[regnum
]
1578 + descr
->sizeof_register
[regnum
]);
1581 out
->field_signed ("size", descr
->sizeof_register
[regnum
]);
1586 std::string name_holder
;
1588 static const char blt
[] = "builtin_type";
1590 t
= register_type (m_gdbarch
, regnum
)->name ();
1593 if (!footnote_register_type_name_null
)
1594 footnote_register_type_name_null
= ++footnote_nr
;
1595 name_holder
= string_printf ("*%d",
1596 footnote_register_type_name_null
);
1597 t
= name_holder
.c_str ();
1599 /* Chop a leading builtin_type. */
1600 if (startswith (t
, blt
))
1603 out
->field_string ("type", t
);
1606 dump_reg (out
, regnum
);
1611 if (footnote_register_offset
)
1612 out
->message ("*%d: Inconsistent register offsets.\n",
1613 footnote_register_offset
);
1614 if (footnote_register_type_name_null
)
1615 out
->message ("*%d: Register type's name NULL.\n",
1616 footnote_register_type_name_null
);
1620 #include "gdbsupport/selftest.h"
1621 #include "selftest-arch.h"
1622 #include "target-float.h"
1624 namespace selftests
{
1631 for (auto pid_ptid_regc_map_it
= regcaches
.cbegin ();
1632 pid_ptid_regc_map_it
!= regcaches
.cend ();
1633 ++pid_ptid_regc_map_it
)
1635 const pid_ptid_regcache_map
&pid_ptid_regc_map
1636 = pid_ptid_regc_map_it
->second
;
1638 for (auto ptid_regc_map_it
= pid_ptid_regc_map
.cbegin ();
1639 ptid_regc_map_it
!= pid_ptid_regc_map
.cend ();
1642 const ptid_regcache_map
&ptid_regc_map
1643 = ptid_regc_map_it
->second
;
1645 size
+= ptid_regc_map
.size ();
1652 /* Return the count of regcaches for (TARGET, PTID) in REGCACHES. */
1655 regcache_count (process_stratum_target
*target
, ptid_t ptid
)
1657 /* Look up map for target. */
1658 auto pid_ptid_regc_map_it
= regcaches
.find (target
);
1659 if (pid_ptid_regc_map_it
!= regcaches
.end ())
1661 pid_ptid_regcache_map
&pid_ptid_regc_map
= pid_ptid_regc_map_it
->second
;
1663 /* Look map for pid. */
1664 auto ptid_regc_map_it
= pid_ptid_regc_map
.find (ptid
.pid ());
1665 if (ptid_regc_map_it
!= pid_ptid_regc_map
.end ())
1667 ptid_regcache_map
&ptid_regc_map
= ptid_regc_map_it
->second
;
1668 auto range
= ptid_regc_map
.equal_range (ptid
);
1670 return std::distance (range
.first
, range
.second
);
1677 /* Wrapper around get_thread_arch_regcache that does some self checks. */
1680 get_thread_arch_regcache_and_check (inferior
*inf_for_target_calls
,
1683 /* We currently only test with a single gdbarch. Any gdbarch will do, so use
1684 the current inferior's gdbarch. Also use the current inferior's address
1686 gdbarch
*arch
= inf_for_target_calls
->arch ();
1688 = get_thread_arch_regcache (inf_for_target_calls
, ptid
, arch
);
1690 SELF_CHECK (regcache
!= NULL
);
1691 SELF_CHECK (regcache
->ptid () == ptid
);
1692 SELF_CHECK (regcache
->arch () == arch
);
1695 /* The data that the regcaches selftests must hold onto for the duration of the
1698 struct regcache_test_data
1700 regcache_test_data ()
1701 /* The specific arch doesn't matter. */
1702 : test_ctx_1 (current_inferior ()->arch ()),
1703 test_ctx_2 (current_inferior ()->arch ())
1705 /* Ensure the regcaches container is empty at the start. */
1706 registers_changed ();
1709 ~regcache_test_data ()
1711 /* Make sure to leave the global regcaches container empty. */
1712 registers_changed ();
1715 scoped_mock_context
<test_target_ops
> test_ctx_1
;
1716 scoped_mock_context
<test_target_ops
> test_ctx_2
;
1719 using regcache_test_data_up
= std::unique_ptr
<regcache_test_data
>;
1721 /* Set up a few regcaches from two different targets, for use in
1722 regcache-management tests.
1724 Return a pointer, because the `regcache_test_data` type is not moveable. */
1726 static regcache_test_data_up
1727 populate_regcaches_for_test ()
1729 regcache_test_data_up
data (new regcache_test_data
);
1730 size_t expected_regcache_size
= 0;
1732 SELF_CHECK (regcaches_size () == 0);
1734 /* Populate the regcache container with a few regcaches for the two test
1736 for (int pid
: { 1, 2 })
1738 for (long lwp
: { 1, 2, 3 })
1740 get_thread_arch_regcache_and_check
1741 (&data
->test_ctx_1
.mock_inferior
, ptid_t (pid
, lwp
));
1742 expected_regcache_size
++;
1743 SELF_CHECK (regcaches_size () == expected_regcache_size
);
1745 get_thread_arch_regcache_and_check
1746 (&data
->test_ctx_2
.mock_inferior
, ptid_t (pid
, lwp
));
1747 expected_regcache_size
++;
1748 SELF_CHECK (regcaches_size () == expected_regcache_size
);
1756 get_thread_arch_regcache_test ()
1758 /* populate_regcaches_for_test already tests most of the
1759 get_thread_arch_regcache functionality. */
1760 regcache_test_data_up data
= populate_regcaches_for_test ();
1761 size_t regcaches_size_before
= regcaches_size ();
1763 /* Test that getting an existing regcache doesn't create a new one. */
1764 get_thread_arch_regcache_and_check (&data
->test_ctx_1
.mock_inferior
,
1766 SELF_CHECK (regcaches_size () == regcaches_size_before
);
1769 /* Test marking all regcaches of all targets as changed. */
1772 registers_changed_ptid_all_test ()
1774 regcache_test_data_up data
= populate_regcaches_for_test ();
1776 registers_changed_ptid (nullptr, minus_one_ptid
);
1777 SELF_CHECK (regcaches_size () == 0);
1780 /* Test marking regcaches of a specific target as changed. */
1783 registers_changed_ptid_target_test ()
1785 regcache_test_data_up data
= populate_regcaches_for_test ();
1787 registers_changed_ptid (&data
->test_ctx_1
.mock_target
, minus_one_ptid
);
1788 SELF_CHECK (regcaches_size () == 6);
1790 /* Check that we deleted the regcache for the right target. */
1791 SELF_CHECK (regcache_count (&data
->test_ctx_1
.mock_target
,
1792 ptid_t (2, 2)) == 0);
1793 SELF_CHECK (regcache_count (&data
->test_ctx_2
.mock_target
,
1794 ptid_t (2, 2)) == 1);
1797 /* Test marking regcaches of a specific (target, pid) as changed. */
1800 registers_changed_ptid_target_pid_test ()
1802 regcache_test_data_up data
= populate_regcaches_for_test ();
1804 registers_changed_ptid (&data
->test_ctx_1
.mock_target
, ptid_t (2));
1805 SELF_CHECK (regcaches_size () == 9);
1807 /* Regcaches from target1 should not exist, while regcaches from target2
1809 SELF_CHECK (regcache_count (&data
->test_ctx_1
.mock_target
,
1810 ptid_t (2, 2)) == 0);
1811 SELF_CHECK (regcache_count (&data
->test_ctx_2
.mock_target
,
1812 ptid_t (2, 2)) == 1);
1815 /* Test marking regcaches of a specific (target, ptid) as changed. */
1818 registers_changed_ptid_target_ptid_test ()
1820 regcache_test_data_up data
= populate_regcaches_for_test ();
1822 registers_changed_ptid (&data
->test_ctx_1
.mock_target
, ptid_t (2, 2));
1823 SELF_CHECK (regcaches_size () == 11);
1825 /* Check that we deleted the regcache for the right target. */
1826 SELF_CHECK (regcache_count (&data
->test_ctx_1
.mock_target
,
1827 ptid_t (2, 2)) == 0);
1828 SELF_CHECK (regcache_count (&data
->test_ctx_2
.mock_target
,
1829 ptid_t (2, 2)) == 1);
1832 /* Test using reg_buffer::raw_compare with offset equal to the register size
1833 (thus comparing 0 bytes). */
1836 reg_buffer_raw_compare_zero_len_test ()
1838 regcache_test_data_up data
= populate_regcaches_for_test ();
1839 inferior
&inf
= data
->test_ctx_1
.mock_inferior
;
1840 const regcache
*regcache
1841 = get_thread_arch_regcache (&inf
, ptid_t (1, 1), inf
.arch ());
1843 /* The buffer address is irrelevant since we end up comparing 0 bytes, we just
1844 need to pass something. */
1846 SELF_CHECK (regcache
->raw_compare (0, &buf
, register_size (inf
.arch (), 0)));
1849 class target_ops_no_register
: public test_target_ops
1852 target_ops_no_register ()
1853 : test_target_ops
{}
1858 fetch_registers_called
= 0;
1859 store_registers_called
= 0;
1860 xfer_partial_called
= 0;
1863 void fetch_registers (regcache
*regs
, int regno
) override
;
1864 void store_registers (regcache
*regs
, int regno
) override
;
1866 enum target_xfer_status
xfer_partial (enum target_object object
,
1867 const char *annex
, gdb_byte
*readbuf
,
1868 const gdb_byte
*writebuf
,
1869 ULONGEST offset
, ULONGEST len
,
1870 ULONGEST
*xfered_len
) override
;
1872 unsigned int fetch_registers_called
= 0;
1873 unsigned int store_registers_called
= 0;
1874 unsigned int xfer_partial_called
= 0;
1878 target_ops_no_register::fetch_registers (regcache
*regs
, int regno
)
1880 /* Mark register available. */
1881 regs
->raw_supply_zeroed (regno
);
1882 this->fetch_registers_called
++;
1886 target_ops_no_register::store_registers (regcache
*regs
, int regno
)
1888 this->store_registers_called
++;
1891 enum target_xfer_status
1892 target_ops_no_register::xfer_partial (enum target_object object
,
1893 const char *annex
, gdb_byte
*readbuf
,
1894 const gdb_byte
*writebuf
,
1895 ULONGEST offset
, ULONGEST len
,
1896 ULONGEST
*xfered_len
)
1898 this->xfer_partial_called
++;
1901 return TARGET_XFER_OK
;
1904 class readwrite_regcache
: public regcache
1907 readwrite_regcache (inferior
*inf_for_target_calls
,
1908 struct gdbarch
*gdbarch
)
1909 : regcache (inf_for_target_calls
, gdbarch
)
1913 /* Return true if regcache::cooked_{read,write}_test should be skipped for
1917 selftest_skiparch (struct gdbarch
*gdbarch
)
1919 const char *name
= gdbarch_bfd_arch_info (gdbarch
)->printable_name
;
1922 Running selftest regcache::cooked_{read,write}_test::m68hc11.
1923 warning: No frame soft register found in the symbol table.
1924 Stack backtrace will not work.
1925 We could instead capture the output and then filter out the warning, but
1926 that seems more trouble than it's worth. */
1927 return (strcmp (name
, "m68hc11") == 0
1928 || strcmp (name
, "m68hc12") == 0
1929 || strcmp (name
, "m68hc12:HCS12") == 0);
1932 /* Test regcache::cooked_read gets registers from raw registers and
1933 memory instead of target to_{fetch,store}_registers. */
1936 cooked_read_test (struct gdbarch
*gdbarch
)
1938 if (selftest_skiparch (gdbarch
))
1941 scoped_mock_context
<target_ops_no_register
> mockctx (gdbarch
);
1943 /* Test that read one raw register from regcache_no_target will go
1944 to the target layer. */
1946 /* Find a raw register which size isn't zero. */
1948 for (nonzero_regnum
= 0;
1949 nonzero_regnum
< gdbarch_num_regs (gdbarch
);
1952 if (register_size (gdbarch
, nonzero_regnum
) != 0)
1956 /* Install this regcache in the regcaches global structure, so that. */
1957 pid_ptid_regcache_map
&x
= regcaches
[&mockctx
.mock_target
];
1958 ptid_regcache_map
&y
= x
[mockctx
.mock_ptid
.pid ()];
1960 = *y
.emplace (std::make_pair (mockctx
.mock_ptid
,
1961 std::make_unique
<readwrite_regcache
> (
1962 &mockctx
.mock_inferior
, gdbarch
)))
1965 readwrite
.set_ptid (mockctx
.mock_ptid
);
1967 gdb::byte_vector
buf (register_size (gdbarch
, nonzero_regnum
));
1968 readwrite
.raw_read (nonzero_regnum
, buf
);
1970 /* raw_read calls target_fetch_registers. */
1971 SELF_CHECK (mockctx
.mock_target
.fetch_registers_called
> 0);
1972 mockctx
.mock_target
.reset ();
1974 /* Mark all raw registers valid, so the following raw registers
1975 accesses won't go to target. */
1976 for (auto i
= 0; i
< gdbarch_num_regs (gdbarch
); i
++)
1977 readwrite
.raw_update (i
);
1979 mockctx
.mock_target
.reset ();
1980 /* Then, read all raw and pseudo registers, and don't expect calling
1981 to_{fetch,store}_registers. */
1982 for (int regnum
= 0; regnum
< gdbarch_num_cooked_regs (gdbarch
); regnum
++)
1984 if (register_size (gdbarch
, regnum
) == 0)
1987 gdb::byte_vector
inner_buf (register_size (gdbarch
, regnum
));
1989 SELF_CHECK (REG_VALID
== readwrite
.cooked_read (regnum
, inner_buf
));
1990 SELF_CHECK (mockctx
.mock_target
.fetch_registers_called
== 0);
1991 SELF_CHECK (mockctx
.mock_target
.store_registers_called
== 0);
1992 SELF_CHECK (mockctx
.mock_target
.xfer_partial_called
== 0);
1994 mockctx
.mock_target
.reset ();
1997 readonly_detached_regcache
readonly (readwrite
);
1999 /* GDB may go to target layer to fetch all registers and memory for
2000 readonly regcache. */
2001 mockctx
.mock_target
.reset ();
2003 for (int regnum
= 0; regnum
< gdbarch_num_cooked_regs (gdbarch
); regnum
++)
2005 if (register_size (gdbarch
, regnum
) == 0)
2008 gdb::byte_vector
inner_buf (register_size (gdbarch
, regnum
));
2009 register_status status
= readonly
.cooked_read (regnum
, inner_buf
);
2011 if (regnum
< gdbarch_num_regs (gdbarch
))
2013 auto bfd_arch
= gdbarch_bfd_arch_info (gdbarch
)->arch
;
2015 if (bfd_arch
== bfd_arch_amdgcn
2016 || bfd_arch
== bfd_arch_frv
|| bfd_arch
== bfd_arch_h8300
2017 || bfd_arch
== bfd_arch_m32c
|| bfd_arch
== bfd_arch_sh
2018 || bfd_arch
== bfd_arch_alpha
|| bfd_arch
== bfd_arch_v850
2019 || bfd_arch
== bfd_arch_msp430
|| bfd_arch
== bfd_arch_mep
2020 || bfd_arch
== bfd_arch_mips
|| bfd_arch
== bfd_arch_v850_rh850
2021 || bfd_arch
== bfd_arch_tic6x
|| bfd_arch
== bfd_arch_mn10300
2022 || bfd_arch
== bfd_arch_rl78
|| bfd_arch
== bfd_arch_score
2023 || bfd_arch
== bfd_arch_riscv
|| bfd_arch
== bfd_arch_csky
)
2025 /* Raw registers. If raw registers are not in save_reggroup,
2026 their status are unknown. */
2027 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, save_reggroup
))
2028 SELF_CHECK (status
== REG_VALID
);
2030 SELF_CHECK (status
== REG_UNKNOWN
);
2033 SELF_CHECK (status
== REG_VALID
);
2037 if (gdbarch_register_reggroup_p (gdbarch
, regnum
, save_reggroup
))
2038 SELF_CHECK (status
== REG_VALID
);
2041 /* If pseudo registers are not in save_reggroup, some of
2042 them can be computed from saved raw registers, but some
2043 of them are unknown. */
2044 auto bfd_arch
= gdbarch_bfd_arch_info (gdbarch
)->arch
;
2046 if (bfd_arch
== bfd_arch_frv
2047 || bfd_arch
== bfd_arch_m32c
2048 || bfd_arch
== bfd_arch_mep
2049 || bfd_arch
== bfd_arch_sh
)
2050 SELF_CHECK (status
== REG_VALID
|| status
== REG_UNKNOWN
);
2051 else if (bfd_arch
== bfd_arch_mips
2052 || bfd_arch
== bfd_arch_h8300
)
2053 SELF_CHECK (status
== REG_UNKNOWN
);
2055 SELF_CHECK (status
== REG_VALID
);
2059 SELF_CHECK (mockctx
.mock_target
.fetch_registers_called
== 0);
2060 SELF_CHECK (mockctx
.mock_target
.store_registers_called
== 0);
2061 SELF_CHECK (mockctx
.mock_target
.xfer_partial_called
== 0);
2063 mockctx
.mock_target
.reset ();
2066 regcaches
.erase (&mockctx
.mock_target
);
2069 /* Test regcache::cooked_write by writing some expected contents to
2070 registers, and checking that contents read from registers and the
2071 expected contents are the same. */
2074 cooked_write_test (struct gdbarch
*gdbarch
)
2076 if (selftest_skiparch (gdbarch
))
2079 /* Create a mock environment. A process_stratum target pushed. */
2080 scoped_mock_context
<target_ops_no_register
> ctx (gdbarch
);
2083 /* Install this regcache in the regcaches global structure, so that. */
2084 pid_ptid_regcache_map
&x
= regcaches
[&ctx
.mock_target
];
2085 ptid_regcache_map
&y
= x
[ctx
.mock_ptid
.pid ()];
2087 = *y
.emplace (std::make_pair (ctx
.mock_ptid
,
2088 std::make_unique
<readwrite_regcache
> (
2089 &ctx
.mock_inferior
, gdbarch
)))
2092 readwrite
.set_ptid (ctx
.mock_ptid
);
2093 const int num_regs
= gdbarch_num_cooked_regs (gdbarch
);
2095 for (auto regnum
= 0; regnum
< num_regs
; regnum
++)
2097 if (register_size (gdbarch
, regnum
) == 0
2098 || gdbarch_cannot_store_register (gdbarch
, regnum
))
2101 auto bfd_arch
= gdbarch_bfd_arch_info (gdbarch
)->arch
;
2103 if (bfd_arch
== bfd_arch_sparc
2104 /* SPARC64_CWP_REGNUM, SPARC64_PSTATE_REGNUM,
2105 SPARC64_ASI_REGNUM and SPARC64_CCR_REGNUM are hard to test. */
2106 && gdbarch_ptr_bit (gdbarch
) == 64
2107 && (regnum
>= gdbarch_num_regs (gdbarch
)
2108 && regnum
<= gdbarch_num_regs (gdbarch
) + 4))
2111 gdb::byte_vector
expected (register_size (gdbarch
, regnum
), 0);
2112 gdb::byte_vector
buf (register_size (gdbarch
, regnum
), 0);
2113 const auto type
= register_type (gdbarch
, regnum
);
2115 if (type
->code () == TYPE_CODE_FLT
2116 || type
->code () == TYPE_CODE_DECFLOAT
)
2118 /* Generate valid float format. */
2119 target_float_from_string (expected
.data (), type
, "1.25");
2121 else if (type
->code () == TYPE_CODE_INT
2122 || type
->code () == TYPE_CODE_ARRAY
2123 || type
->code () == TYPE_CODE_PTR
2124 || type
->code () == TYPE_CODE_UNION
2125 || type
->code () == TYPE_CODE_STRUCT
)
2127 if (bfd_arch
== bfd_arch_ia64
2128 || (regnum
>= gdbarch_num_regs (gdbarch
)
2129 && (bfd_arch
== bfd_arch_xtensa
2130 || bfd_arch
== bfd_arch_bfin
2131 || bfd_arch
== bfd_arch_m32c
2132 /* m68hc11 pseudo registers are in memory. */
2133 || bfd_arch
== bfd_arch_m68hc11
2134 || bfd_arch
== bfd_arch_m68hc12
2135 || bfd_arch
== bfd_arch_s390
))
2136 || (bfd_arch
== bfd_arch_frv
2137 /* FRV pseudo registers except iacc0. */
2138 && regnum
> gdbarch_num_regs (gdbarch
)))
2140 /* Skip setting the expected values for some architecture
2143 else if (bfd_arch
== bfd_arch_rl78
&& regnum
== 40)
2145 /* RL78_PC_REGNUM */
2146 for (auto j
= 0; j
< register_size (gdbarch
, regnum
) - 1; j
++)
2151 for (auto j
= 0; j
< register_size (gdbarch
, regnum
); j
++)
2155 else if (type
->code () == TYPE_CODE_FLAGS
)
2157 /* No idea how to test flags. */
2162 /* If we don't know how to create the expected value for the
2163 this type, make it fail. */
2167 readwrite
.cooked_write (regnum
, expected
);
2169 SELF_CHECK (readwrite
.cooked_read (regnum
, buf
) == REG_VALID
);
2170 SELF_CHECK (expected
== buf
);
2173 regcaches
.erase (&ctx
.mock_target
);
2176 /* Verify that when two threads with the same ptid exist (from two different
2177 targets) and one of them changes ptid, we only update the appropriate
2181 regcache_thread_ptid_changed ()
2183 /* This test relies on the global regcache list to initially be empty. */
2184 registers_changed ();
2186 /* Any arch will do. */
2187 gdbarch
*arch
= current_inferior ()->arch ();
2189 /* Prepare two targets with one thread each, with the same ptid. */
2190 scoped_mock_context
<test_target_ops
> target1 (arch
);
2191 scoped_mock_context
<test_target_ops
> target2 (arch
);
2193 ptid_t
old_ptid (111, 222);
2194 ptid_t
new_ptid (111, 333);
2196 target1
.mock_inferior
.pid
= old_ptid
.pid ();
2197 target1
.mock_thread
.ptid
= old_ptid
;
2198 target1
.mock_inferior
.ptid_thread_map
.clear ();
2199 target1
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target1
.mock_thread
;
2201 target2
.mock_inferior
.pid
= old_ptid
.pid ();
2202 target2
.mock_thread
.ptid
= old_ptid
;
2203 target2
.mock_inferior
.ptid_thread_map
.clear ();
2204 target2
.mock_inferior
.ptid_thread_map
[old_ptid
] = &target2
.mock_thread
;
2206 gdb_assert (regcaches
.empty ());
2208 /* Populate the regcaches container. */
2209 get_thread_arch_regcache (&target1
.mock_inferior
, old_ptid
, arch
);
2210 get_thread_arch_regcache (&target2
.mock_inferior
, old_ptid
, arch
);
2212 gdb_assert (regcaches
.size () == 2);
2213 gdb_assert (regcache_count (&target1
.mock_target
, old_ptid
) == 1);
2214 gdb_assert (regcache_count (&target1
.mock_target
, new_ptid
) == 0);
2215 gdb_assert (regcache_count (&target2
.mock_target
, old_ptid
) == 1);
2216 gdb_assert (regcache_count (&target2
.mock_target
, new_ptid
) == 0);
2218 thread_change_ptid (&target1
.mock_target
, old_ptid
, new_ptid
);
2220 gdb_assert (regcaches
.size () == 2);
2221 gdb_assert (regcache_count (&target1
.mock_target
, old_ptid
) == 0);
2222 gdb_assert (regcache_count (&target1
.mock_target
, new_ptid
) == 1);
2223 gdb_assert (regcache_count (&target2
.mock_target
, old_ptid
) == 1);
2224 gdb_assert (regcache_count (&target2
.mock_target
, new_ptid
) == 0);
2226 /* Leave the regcache list empty. */
2227 registers_changed ();
2228 gdb_assert (regcaches
.empty ());
2231 } // namespace selftests
2232 #endif /* GDB_SELF_TEST */
2234 void _initialize_regcache ();
2236 _initialize_regcache ()
2238 struct cmd_list_element
*c
;
2240 gdb::observers::target_changed
.attach (regcache_observer_target_changed
,
2242 gdb::observers::thread_ptid_changed
.attach (regcache_thread_ptid_changed
,
2245 cmd_list_element
*maintenance_flush_register_cache_cmd
2246 = add_cmd ("register-cache", class_maintenance
, reg_flush_command
,
2247 _("Force gdb to flush its register and frame cache."),
2248 &maintenanceflushlist
);
2249 c
= add_com_alias ("flushregs", maintenance_flush_register_cache_cmd
,
2250 class_maintenance
, 0);
2251 deprecate_cmd (c
, "maintenance flush register-cache");
2254 selftests::register_test ("get_thread_arch_regcache",
2255 selftests::get_thread_arch_regcache_test
);
2256 selftests::register_test ("registers_changed_ptid_all",
2257 selftests::registers_changed_ptid_all_test
);
2258 selftests::register_test ("registers_changed_ptid_target",
2259 selftests::registers_changed_ptid_target_test
);
2260 selftests::register_test ("registers_changed_ptid_target_pid",
2261 selftests::registers_changed_ptid_target_pid_test
);
2262 selftests::register_test ("registers_changed_ptid_target_ptid",
2263 selftests::registers_changed_ptid_target_ptid_test
);
2264 selftests::register_test ("reg_buffer_raw_compare_zero_len",
2265 selftests::reg_buffer_raw_compare_zero_len_test
);
2267 selftests::register_test_foreach_arch ("regcache::cooked_read_test",
2268 selftests::cooked_read_test
);
2269 selftests::register_test_foreach_arch ("regcache::cooked_write_test",
2270 selftests::cooked_write_test
);
2271 selftests::register_test ("regcache_thread_ptid_changed",
2272 selftests::regcache_thread_ptid_changed
);