]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/regcache.c
gdb: remove push_target free functions
[thirdparty/binutils-gdb.git] / gdb / regcache.c
1 /* Cache and manage the values of registers for GDB, the GNU debugger.
2
3 Copyright (C) 1986-2021 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
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"
34
35 /*
36 * DATA STRUCTURE
37 *
38 * Here is the actual register cache.
39 */
40
41 /* Per-architecture object describing the layout of a register cache.
42 Computed once when the architecture is created. */
43
44 static struct gdbarch_data *regcache_descr_handle;
45
46 struct regcache_descr
47 {
48 /* The architecture this descriptor belongs to. */
49 struct gdbarch *gdbarch;
50
51 /* The raw register cache. Each raw (or hard) register is supplied
52 by the target interface. The raw cache should not contain
53 redundant information - if the PC is constructed from two
54 registers then those registers and not the PC lives in the raw
55 cache. */
56 long sizeof_raw_registers;
57
58 /* The cooked register space. Each cooked register in the range
59 [0..NR_RAW_REGISTERS) is direct-mapped onto the corresponding raw
60 register. The remaining [NR_RAW_REGISTERS
61 .. NR_COOKED_REGISTERS) (a.k.a. pseudo registers) are mapped onto
62 both raw registers and memory by the architecture methods
63 gdbarch_pseudo_register_read and gdbarch_pseudo_register_write. */
64 int nr_cooked_registers;
65 long sizeof_cooked_registers;
66
67 /* Offset and size (in 8 bit bytes), of each register in the
68 register cache. All registers (including those in the range
69 [NR_RAW_REGISTERS .. NR_COOKED_REGISTERS) are given an
70 offset. */
71 long *register_offset;
72 long *sizeof_register;
73
74 /* Cached table containing the type of each register. */
75 struct type **register_type;
76 };
77
78 static void *
79 init_regcache_descr (struct gdbarch *gdbarch)
80 {
81 int i;
82 struct regcache_descr *descr;
83 gdb_assert (gdbarch != NULL);
84
85 /* Create an initial, zero filled, table. */
86 descr = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct regcache_descr);
87 descr->gdbarch = gdbarch;
88
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);
93
94 /* Fill in a table of register types. */
95 descr->register_type
96 = GDBARCH_OBSTACK_CALLOC (gdbarch, descr->nr_cooked_registers,
97 struct type *);
98 for (i = 0; i < descr->nr_cooked_registers; i++)
99 descr->register_type[i] = gdbarch_register_type (gdbarch, i);
100
101 /* Construct a strictly RAW register cache. Don't allow pseudo's
102 into the register cache. */
103
104 /* Lay out the register cache.
105
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
109 same. */
110
111 {
112 long offset = 0;
113
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++)
119 {
120 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
121 descr->register_offset[i] = offset;
122 offset += descr->sizeof_register[i];
123 }
124 /* Set the real size of the raw register cache buffer. */
125 descr->sizeof_raw_registers = offset;
126
127 for (; i < descr->nr_cooked_registers; i++)
128 {
129 descr->sizeof_register[i] = TYPE_LENGTH (descr->register_type[i]);
130 descr->register_offset[i] = offset;
131 offset += descr->sizeof_register[i];
132 }
133 /* Set the real size of the readonly register cache buffer. */
134 descr->sizeof_cooked_registers = offset;
135 }
136
137 return descr;
138 }
139
140 static struct regcache_descr *
141 regcache_descr (struct gdbarch *gdbarch)
142 {
143 return (struct regcache_descr *) gdbarch_data (gdbarch,
144 regcache_descr_handle);
145 }
146
147 /* Utility functions returning useful register attributes stored in
148 the regcache descr. */
149
150 struct type *
151 register_type (struct gdbarch *gdbarch, int regnum)
152 {
153 struct regcache_descr *descr = regcache_descr (gdbarch);
154
155 gdb_assert (regnum >= 0 && regnum < descr->nr_cooked_registers);
156 return descr->register_type[regnum];
157 }
158
159 /* Utility functions returning useful register attributes stored in
160 the regcache descr. */
161
162 int
163 register_size (struct gdbarch *gdbarch, int regnum)
164 {
165 struct regcache_descr *descr = regcache_descr (gdbarch);
166 int size;
167
168 gdb_assert (regnum >= 0 && regnum < gdbarch_num_cooked_regs (gdbarch));
169 size = descr->sizeof_register[regnum];
170 return size;
171 }
172
173 /* See gdbsupport/common-regcache.h. */
174
175 int
176 regcache_register_size (const struct regcache *regcache, int n)
177 {
178 return register_size (regcache->arch (), n);
179 }
180
181 reg_buffer::reg_buffer (gdbarch *gdbarch, bool has_pseudo)
182 : m_has_pseudo (has_pseudo)
183 {
184 gdb_assert (gdbarch != NULL);
185 m_descr = regcache_descr (gdbarch);
186
187 if (has_pseudo)
188 {
189 m_registers.reset (new gdb_byte[m_descr->sizeof_cooked_registers] ());
190 m_register_status.reset
191 (new register_status[m_descr->nr_cooked_registers] ());
192 }
193 else
194 {
195 m_registers.reset (new gdb_byte[m_descr->sizeof_raw_registers] ());
196 m_register_status.reset
197 (new register_status[gdbarch_num_regs (gdbarch)] ());
198 }
199 }
200
201 regcache::regcache (process_stratum_target *target, gdbarch *gdbarch,
202 const address_space *aspace_)
203 /* The register buffers. A read/write register cache can only hold
204 [0 .. gdbarch_num_regs). */
205 : detached_regcache (gdbarch, false), m_aspace (aspace_), m_target (target)
206 {
207 m_ptid = minus_one_ptid;
208 }
209
210 readonly_detached_regcache::readonly_detached_regcache (regcache &src)
211 : readonly_detached_regcache (src.arch (),
212 [&src] (int regnum, gdb_byte *buf)
213 {
214 return src.cooked_read (regnum, buf);
215 })
216 {
217 }
218
219 gdbarch *
220 reg_buffer::arch () const
221 {
222 return m_descr->gdbarch;
223 }
224
225 /* Return a pointer to register REGNUM's buffer cache. */
226
227 gdb_byte *
228 reg_buffer::register_buffer (int regnum) const
229 {
230 return m_registers.get () + m_descr->register_offset[regnum];
231 }
232
233 void
234 reg_buffer::save (register_read_ftype cooked_read)
235 {
236 struct gdbarch *gdbarch = m_descr->gdbarch;
237 int regnum;
238
239 /* It should have pseudo registers. */
240 gdb_assert (m_has_pseudo);
241 /* Clear the dest. */
242 memset (m_registers.get (), 0, m_descr->sizeof_cooked_registers);
243 memset (m_register_status.get (), REG_UNKNOWN, m_descr->nr_cooked_registers);
244 /* Copy over any registers (identified by their membership in the
245 save_reggroup) and mark them as valid. The full [0 .. gdbarch_num_regs +
246 gdbarch_num_pseudo_regs) range is checked since some architectures need
247 to save/restore `cooked' registers that live in memory. */
248 for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
249 {
250 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
251 {
252 gdb_byte *dst_buf = register_buffer (regnum);
253 enum register_status status = cooked_read (regnum, dst_buf);
254
255 gdb_assert (status != REG_UNKNOWN);
256
257 if (status != REG_VALID)
258 memset (dst_buf, 0, register_size (gdbarch, regnum));
259
260 m_register_status[regnum] = status;
261 }
262 }
263 }
264
265 void
266 regcache::restore (readonly_detached_regcache *src)
267 {
268 struct gdbarch *gdbarch = m_descr->gdbarch;
269 int regnum;
270
271 gdb_assert (src != NULL);
272 gdb_assert (src->m_has_pseudo);
273
274 gdb_assert (gdbarch == src->arch ());
275
276 /* Copy over any registers, being careful to only restore those that
277 were both saved and need to be restored. The full [0 .. gdbarch_num_regs
278 + gdbarch_num_pseudo_regs) range is checked since some architectures need
279 to save/restore `cooked' registers that live in memory. */
280 for (regnum = 0; regnum < m_descr->nr_cooked_registers; regnum++)
281 {
282 if (gdbarch_register_reggroup_p (gdbarch, regnum, restore_reggroup))
283 {
284 if (src->m_register_status[regnum] == REG_VALID)
285 cooked_write (regnum, src->register_buffer (regnum));
286 }
287 }
288 }
289
290 /* See gdbsupport/common-regcache.h. */
291
292 enum register_status
293 reg_buffer::get_register_status (int regnum) const
294 {
295 assert_regnum (regnum);
296
297 return m_register_status[regnum];
298 }
299
300 void
301 reg_buffer::invalidate (int regnum)
302 {
303 assert_regnum (regnum);
304 m_register_status[regnum] = REG_UNKNOWN;
305 }
306
307 void
308 reg_buffer::assert_regnum (int regnum) const
309 {
310 gdb_assert (regnum >= 0);
311 if (m_has_pseudo)
312 gdb_assert (regnum < m_descr->nr_cooked_registers);
313 else
314 gdb_assert (regnum < gdbarch_num_regs (arch ()));
315 }
316
317 /* Type to map a ptid to a list of regcaches (one thread may have multiple
318 regcaches, associated to different gdbarches). */
319
320 using ptid_regcache_map
321 = std::unordered_multimap<ptid_t, regcache_up, hash_ptid>;
322
323 /* Type holding regcaches for a given pid. */
324
325 using pid_ptid_regcache_map = std::unordered_map<int, ptid_regcache_map>;
326
327 /* Type holding regcaches for a given target. */
328
329 using target_pid_ptid_regcache_map
330 = std::unordered_map<process_stratum_target *, pid_ptid_regcache_map>;
331
332 /* Global structure containing the existing regcaches. */
333
334 /* NOTE: this is a write-through cache. There is no "dirty" bit for
335 recording if the register values have been changed (eg. by the
336 user). Therefore all registers must be written back to the
337 target when appropriate. */
338 static target_pid_ptid_regcache_map regcaches;
339
340 struct regcache *
341 get_thread_arch_aspace_regcache (process_stratum_target *target,
342 ptid_t ptid, gdbarch *arch,
343 struct address_space *aspace)
344 {
345 gdb_assert (target != nullptr);
346
347 /* Find the map for this target. */
348 pid_ptid_regcache_map &pid_ptid_regc_map = regcaches[target];
349
350 /* Find the map for this pid. */
351 ptid_regcache_map &ptid_regc_map = pid_ptid_regc_map[ptid.pid ()];
352
353 /* Check first if a regcache for this arch already exists. */
354 auto range = ptid_regc_map.equal_range (ptid);
355 for (auto it = range.first; it != range.second; ++it)
356 {
357 if (it->second->arch () == arch)
358 return it->second.get ();
359 }
360
361 /* It does not exist, create it. */
362 regcache *new_regcache = new regcache (target, arch, aspace);
363 new_regcache->set_ptid (ptid);
364 /* Work around a problem with g++ 4.8 (PR96537): Call the regcache_up
365 constructor explictly instead of implicitly. */
366 ptid_regc_map.insert (std::make_pair (ptid, regcache_up (new_regcache)));
367
368 return new_regcache;
369 }
370
371 struct regcache *
372 get_thread_arch_regcache (process_stratum_target *target, ptid_t ptid,
373 struct gdbarch *gdbarch)
374 {
375 scoped_restore_current_inferior restore_current_inferior;
376 set_current_inferior (find_inferior_ptid (target, ptid));
377 address_space *aspace = target_thread_address_space (ptid);
378
379 return get_thread_arch_aspace_regcache (target, ptid, gdbarch, aspace);
380 }
381
382 static process_stratum_target *current_thread_target;
383 static ptid_t current_thread_ptid;
384 static struct gdbarch *current_thread_arch;
385
386 struct regcache *
387 get_thread_regcache (process_stratum_target *target, ptid_t ptid)
388 {
389 if (!current_thread_arch
390 || target != current_thread_target
391 || current_thread_ptid != ptid)
392 {
393 gdb_assert (ptid != null_ptid);
394
395 current_thread_ptid = ptid;
396 current_thread_target = target;
397
398 scoped_restore_current_inferior restore_current_inferior;
399 set_current_inferior (find_inferior_ptid (target, ptid));
400 current_thread_arch = target_thread_architecture (ptid);
401 }
402
403 return get_thread_arch_regcache (target, ptid, current_thread_arch);
404 }
405
406 /* See regcache.h. */
407
408 struct regcache *
409 get_thread_regcache (thread_info *thread)
410 {
411 return get_thread_regcache (thread->inf->process_target (),
412 thread->ptid);
413 }
414
415 struct regcache *
416 get_current_regcache (void)
417 {
418 return get_thread_regcache (inferior_thread ());
419 }
420
421 /* See gdbsupport/common-regcache.h. */
422
423 struct regcache *
424 get_thread_regcache_for_ptid (ptid_t ptid)
425 {
426 /* This function doesn't take a process_stratum_target parameter
427 because it's a gdbsupport/ routine implemented by both gdb and
428 gdbserver. It always refers to a ptid of the current target. */
429 process_stratum_target *proc_target = current_inferior ()->process_target ();
430 return get_thread_regcache (proc_target, ptid);
431 }
432
433 /* Observer for the target_changed event. */
434
435 static void
436 regcache_observer_target_changed (struct target_ops *target)
437 {
438 registers_changed ();
439 }
440
441 /* Update regcaches related to OLD_PTID to now use NEW_PTID. */
442 static void
443 regcache_thread_ptid_changed (process_stratum_target *target,
444 ptid_t old_ptid, ptid_t new_ptid)
445 {
446 /* Look up map for target. */
447 auto pid_ptid_regc_map_it = regcaches.find (target);
448 if (pid_ptid_regc_map_it == regcaches.end ())
449 return;
450
451 /* Look up map for pid. */
452 pid_ptid_regcache_map &pid_ptid_regc_map = pid_ptid_regc_map_it->second;
453 auto ptid_regc_map_it = pid_ptid_regc_map.find (old_ptid.pid ());
454 if (ptid_regc_map_it == pid_ptid_regc_map.end ())
455 return;
456
457 /* Update all regcaches belonging to old_ptid. */
458 ptid_regcache_map &ptid_regc_map = ptid_regc_map_it->second;
459 auto range = ptid_regc_map.equal_range (old_ptid);
460 for (auto it = range.first; it != range.second;)
461 {
462 regcache_up rc = std::move (it->second);
463 rc->set_ptid (new_ptid);
464
465 /* Remove old before inserting new, to avoid rehashing,
466 which would invalidate iterators. */
467 it = ptid_regc_map.erase (it);
468 ptid_regc_map.insert (std::make_pair (new_ptid, std::move (rc)));
469 }
470 }
471
472 /* Low level examining and depositing of registers.
473
474 The caller is responsible for making sure that the inferior is
475 stopped before calling the fetching routines, or it will get
476 garbage. (a change from GDB version 3, in which the caller got the
477 value from the last stop). */
478
479 /* REGISTERS_CHANGED ()
480
481 Indicate that registers may have changed, so invalidate the cache. */
482
483 void
484 registers_changed_ptid (process_stratum_target *target, ptid_t ptid)
485 {
486 if (target == nullptr)
487 {
488 /* Since there can be ptid clashes between targets, it's not valid to
489 pass a ptid without saying to which target it belongs. */
490 gdb_assert (ptid == minus_one_ptid);
491
492 /* Delete all the regcaches of all targets. */
493 regcaches.clear ();
494 }
495 else if (ptid.is_pid ())
496 {
497 /* Non-NULL target and pid ptid, delete all regcaches belonging
498 to this (TARGET, PID). */
499
500 /* Look up map for target. */
501 auto pid_ptid_regc_map_it = regcaches.find (target);
502 if (pid_ptid_regc_map_it != regcaches.end ())
503 {
504 pid_ptid_regcache_map &pid_ptid_regc_map
505 = pid_ptid_regc_map_it->second;
506
507 pid_ptid_regc_map.erase (ptid.pid ());
508 }
509 }
510 else if (ptid != minus_one_ptid)
511 {
512 /* Non-NULL target and non-minus_one_ptid, delete all regcaches belonging
513 to this (TARGET, PTID). */
514
515 /* Look up map for target. */
516 auto pid_ptid_regc_map_it = regcaches.find (target);
517 if (pid_ptid_regc_map_it != regcaches.end ())
518 {
519 pid_ptid_regcache_map &pid_ptid_regc_map
520 = pid_ptid_regc_map_it->second;
521
522 /* Look up map for pid. */
523 auto ptid_regc_map_it
524 = pid_ptid_regc_map.find (ptid.pid ());
525 if (ptid_regc_map_it != pid_ptid_regc_map.end ())
526 {
527 ptid_regcache_map &ptid_regc_map
528 = ptid_regc_map_it->second;
529
530 ptid_regc_map.erase (ptid);
531 }
532 }
533 }
534 else
535 {
536 /* Non-NULL target and minus_one_ptid, delete all regcaches
537 associated to this target. */
538 regcaches.erase (target);
539 }
540
541 if ((target == nullptr || current_thread_target == target)
542 && current_thread_ptid.matches (ptid))
543 {
544 current_thread_target = NULL;
545 current_thread_ptid = null_ptid;
546 current_thread_arch = NULL;
547 }
548
549 if ((target == nullptr || current_inferior ()->process_target () == target)
550 && inferior_ptid.matches (ptid))
551 {
552 /* We just deleted the regcache of the current thread. Need to
553 forget about any frames we have cached, too. */
554 reinit_frame_cache ();
555 }
556 }
557
558 /* See regcache.h. */
559
560 void
561 registers_changed_thread (thread_info *thread)
562 {
563 registers_changed_ptid (thread->inf->process_target (), thread->ptid);
564 }
565
566 void
567 registers_changed (void)
568 {
569 registers_changed_ptid (nullptr, minus_one_ptid);
570 }
571
572 void
573 regcache::raw_update (int regnum)
574 {
575 assert_regnum (regnum);
576
577 /* Make certain that the register cache is up-to-date with respect
578 to the current thread. This switching shouldn't be necessary
579 only there is still only one target side register cache. Sigh!
580 On the bright side, at least there is a regcache object. */
581
582 if (get_register_status (regnum) == REG_UNKNOWN)
583 {
584 target_fetch_registers (this, regnum);
585
586 /* A number of targets can't access the whole set of raw
587 registers (because the debug API provides no means to get at
588 them). */
589 if (m_register_status[regnum] == REG_UNKNOWN)
590 m_register_status[regnum] = REG_UNAVAILABLE;
591 }
592 }
593
594 enum register_status
595 readable_regcache::raw_read (int regnum, gdb_byte *buf)
596 {
597 gdb_assert (buf != NULL);
598 raw_update (regnum);
599
600 if (m_register_status[regnum] != REG_VALID)
601 memset (buf, 0, m_descr->sizeof_register[regnum]);
602 else
603 memcpy (buf, register_buffer (regnum),
604 m_descr->sizeof_register[regnum]);
605
606 return m_register_status[regnum];
607 }
608
609 enum register_status
610 regcache_raw_read_signed (struct regcache *regcache, int regnum, LONGEST *val)
611 {
612 gdb_assert (regcache != NULL);
613 return regcache->raw_read (regnum, val);
614 }
615
616 template<typename T, typename>
617 enum register_status
618 readable_regcache::raw_read (int regnum, T *val)
619 {
620 gdb_byte *buf;
621 enum register_status status;
622
623 assert_regnum (regnum);
624 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
625 status = raw_read (regnum, buf);
626 if (status == REG_VALID)
627 *val = extract_integer<T> (buf,
628 m_descr->sizeof_register[regnum],
629 gdbarch_byte_order (m_descr->gdbarch));
630 else
631 *val = 0;
632 return status;
633 }
634
635 enum register_status
636 regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
637 ULONGEST *val)
638 {
639 gdb_assert (regcache != NULL);
640 return regcache->raw_read (regnum, val);
641 }
642
643 void
644 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
645 {
646 gdb_assert (regcache != NULL);
647 regcache->raw_write (regnum, val);
648 }
649
650 template<typename T, typename>
651 void
652 regcache::raw_write (int regnum, T val)
653 {
654 gdb_byte *buf;
655
656 assert_regnum (regnum);
657 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
658 store_integer (buf, m_descr->sizeof_register[regnum],
659 gdbarch_byte_order (m_descr->gdbarch), val);
660 raw_write (regnum, buf);
661 }
662
663 void
664 regcache_raw_write_unsigned (struct regcache *regcache, int regnum,
665 ULONGEST val)
666 {
667 gdb_assert (regcache != NULL);
668 regcache->raw_write (regnum, val);
669 }
670
671 LONGEST
672 regcache_raw_get_signed (struct regcache *regcache, int regnum)
673 {
674 LONGEST value;
675 enum register_status status;
676
677 status = regcache_raw_read_signed (regcache, regnum, &value);
678 if (status == REG_UNAVAILABLE)
679 throw_error (NOT_AVAILABLE_ERROR,
680 _("Register %d is not available"), regnum);
681 return value;
682 }
683
684 enum register_status
685 readable_regcache::cooked_read (int regnum, gdb_byte *buf)
686 {
687 gdb_assert (regnum >= 0);
688 gdb_assert (regnum < m_descr->nr_cooked_registers);
689 if (regnum < num_raw_registers ())
690 return raw_read (regnum, buf);
691 else if (m_has_pseudo
692 && m_register_status[regnum] != REG_UNKNOWN)
693 {
694 if (m_register_status[regnum] == REG_VALID)
695 memcpy (buf, register_buffer (regnum),
696 m_descr->sizeof_register[regnum]);
697 else
698 memset (buf, 0, m_descr->sizeof_register[regnum]);
699
700 return m_register_status[regnum];
701 }
702 else if (gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
703 {
704 struct value *mark, *computed;
705 enum register_status result = REG_VALID;
706
707 mark = value_mark ();
708
709 computed = gdbarch_pseudo_register_read_value (m_descr->gdbarch,
710 this, regnum);
711 if (value_entirely_available (computed))
712 memcpy (buf, value_contents_raw (computed),
713 m_descr->sizeof_register[regnum]);
714 else
715 {
716 memset (buf, 0, m_descr->sizeof_register[regnum]);
717 result = REG_UNAVAILABLE;
718 }
719
720 value_free_to_mark (mark);
721
722 return result;
723 }
724 else
725 return gdbarch_pseudo_register_read (m_descr->gdbarch, this,
726 regnum, buf);
727 }
728
729 struct value *
730 readable_regcache::cooked_read_value (int regnum)
731 {
732 gdb_assert (regnum >= 0);
733 gdb_assert (regnum < m_descr->nr_cooked_registers);
734
735 if (regnum < num_raw_registers ()
736 || (m_has_pseudo && m_register_status[regnum] != REG_UNKNOWN)
737 || !gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
738 {
739 struct value *result;
740
741 result = allocate_value (register_type (m_descr->gdbarch, regnum));
742 VALUE_LVAL (result) = lval_register;
743 VALUE_REGNUM (result) = regnum;
744
745 /* It is more efficient in general to do this delegation in this
746 direction than in the other one, even though the value-based
747 API is preferred. */
748 if (cooked_read (regnum,
749 value_contents_raw (result)) == REG_UNAVAILABLE)
750 mark_value_bytes_unavailable (result, 0,
751 TYPE_LENGTH (value_type (result)));
752
753 return result;
754 }
755 else
756 return gdbarch_pseudo_register_read_value (m_descr->gdbarch,
757 this, regnum);
758 }
759
760 enum register_status
761 regcache_cooked_read_signed (struct regcache *regcache, int regnum,
762 LONGEST *val)
763 {
764 gdb_assert (regcache != NULL);
765 return regcache->cooked_read (regnum, val);
766 }
767
768 template<typename T, typename>
769 enum register_status
770 readable_regcache::cooked_read (int regnum, T *val)
771 {
772 enum register_status status;
773 gdb_byte *buf;
774
775 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
776 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
777 status = cooked_read (regnum, buf);
778 if (status == REG_VALID)
779 *val = extract_integer<T> (buf, m_descr->sizeof_register[regnum],
780 gdbarch_byte_order (m_descr->gdbarch));
781 else
782 *val = 0;
783 return status;
784 }
785
786 enum register_status
787 regcache_cooked_read_unsigned (struct regcache *regcache, int regnum,
788 ULONGEST *val)
789 {
790 gdb_assert (regcache != NULL);
791 return regcache->cooked_read (regnum, val);
792 }
793
794 void
795 regcache_cooked_write_signed (struct regcache *regcache, int regnum,
796 LONGEST val)
797 {
798 gdb_assert (regcache != NULL);
799 regcache->cooked_write (regnum, val);
800 }
801
802 template<typename T, typename>
803 void
804 regcache::cooked_write (int regnum, T val)
805 {
806 gdb_byte *buf;
807
808 gdb_assert (regnum >=0 && regnum < m_descr->nr_cooked_registers);
809 buf = (gdb_byte *) alloca (m_descr->sizeof_register[regnum]);
810 store_integer (buf, m_descr->sizeof_register[regnum],
811 gdbarch_byte_order (m_descr->gdbarch), val);
812 cooked_write (regnum, buf);
813 }
814
815 void
816 regcache_cooked_write_unsigned (struct regcache *regcache, int regnum,
817 ULONGEST val)
818 {
819 gdb_assert (regcache != NULL);
820 regcache->cooked_write (regnum, val);
821 }
822
823 void
824 regcache::raw_write (int regnum, const gdb_byte *buf)
825 {
826
827 gdb_assert (buf != NULL);
828 assert_regnum (regnum);
829
830 /* On the sparc, writing %g0 is a no-op, so we don't even want to
831 change the registers array if something writes to this register. */
832 if (gdbarch_cannot_store_register (arch (), regnum))
833 return;
834
835 /* If we have a valid copy of the register, and new value == old
836 value, then don't bother doing the actual store. */
837 if (get_register_status (regnum) == REG_VALID
838 && (memcmp (register_buffer (regnum), buf,
839 m_descr->sizeof_register[regnum]) == 0))
840 return;
841
842 target_prepare_to_store (this);
843 raw_supply (regnum, buf);
844
845 /* Invalidate the register after it is written, in case of a
846 failure. */
847 auto invalidator
848 = make_scope_exit ([&] { this->invalidate (regnum); });
849
850 target_store_registers (this, regnum);
851
852 /* The target did not throw an error so we can discard invalidating
853 the register. */
854 invalidator.release ();
855 }
856
857 void
858 regcache::cooked_write (int regnum, const gdb_byte *buf)
859 {
860 gdb_assert (regnum >= 0);
861 gdb_assert (regnum < m_descr->nr_cooked_registers);
862 if (regnum < num_raw_registers ())
863 raw_write (regnum, buf);
864 else
865 gdbarch_pseudo_register_write (m_descr->gdbarch, this,
866 regnum, buf);
867 }
868
869 /* See regcache.h. */
870
871 enum register_status
872 readable_regcache::read_part (int regnum, int offset, int len,
873 gdb_byte *out, bool is_raw)
874 {
875 int reg_size = register_size (arch (), regnum);
876
877 gdb_assert (out != NULL);
878 gdb_assert (offset >= 0 && offset <= reg_size);
879 gdb_assert (len >= 0 && offset + len <= reg_size);
880
881 if (offset == 0 && len == 0)
882 {
883 /* Nothing to do. */
884 return REG_VALID;
885 }
886
887 if (offset == 0 && len == reg_size)
888 {
889 /* Read the full register. */
890 return (is_raw) ? raw_read (regnum, out) : cooked_read (regnum, out);
891 }
892
893 enum register_status status;
894 gdb_byte *reg = (gdb_byte *) alloca (reg_size);
895
896 /* Read full register to buffer. */
897 status = (is_raw) ? raw_read (regnum, reg) : cooked_read (regnum, reg);
898 if (status != REG_VALID)
899 return status;
900
901 /* Copy out. */
902 memcpy (out, reg + offset, len);
903 return REG_VALID;
904 }
905
906 /* See regcache.h. */
907
908 void
909 reg_buffer::raw_collect_part (int regnum, int offset, int len,
910 gdb_byte *out) const
911 {
912 int reg_size = register_size (arch (), regnum);
913
914 gdb_assert (out != nullptr);
915 gdb_assert (offset >= 0 && offset <= reg_size);
916 gdb_assert (len >= 0 && offset + len <= reg_size);
917
918 if (offset == 0 && len == 0)
919 {
920 /* Nothing to do. */
921 return;
922 }
923
924 if (offset == 0 && len == reg_size)
925 {
926 /* Collect the full register. */
927 return raw_collect (regnum, out);
928 }
929
930 /* Read to buffer, then write out. */
931 gdb_byte *reg = (gdb_byte *) alloca (reg_size);
932 raw_collect (regnum, reg);
933 memcpy (out, reg + offset, len);
934 }
935
936 /* See regcache.h. */
937
938 enum register_status
939 regcache::write_part (int regnum, int offset, int len,
940 const gdb_byte *in, bool is_raw)
941 {
942 int reg_size = register_size (arch (), regnum);
943
944 gdb_assert (in != NULL);
945 gdb_assert (offset >= 0 && offset <= reg_size);
946 gdb_assert (len >= 0 && offset + len <= reg_size);
947
948 if (offset == 0 && len == 0)
949 {
950 /* Nothing to do. */
951 return REG_VALID;
952 }
953
954 if (offset == 0 && len == reg_size)
955 {
956 /* Write the full register. */
957 (is_raw) ? raw_write (regnum, in) : cooked_write (regnum, in);
958 return REG_VALID;
959 }
960
961 enum register_status status;
962 gdb_byte *reg = (gdb_byte *) alloca (reg_size);
963
964 /* Read existing register to buffer. */
965 status = (is_raw) ? raw_read (regnum, reg) : cooked_read (regnum, reg);
966 if (status != REG_VALID)
967 return status;
968
969 /* Update buffer, then write back to regcache. */
970 memcpy (reg + offset, in, len);
971 is_raw ? raw_write (regnum, reg) : cooked_write (regnum, reg);
972 return REG_VALID;
973 }
974
975 /* See regcache.h. */
976
977 void
978 reg_buffer::raw_supply_part (int regnum, int offset, int len,
979 const gdb_byte *in)
980 {
981 int reg_size = register_size (arch (), regnum);
982
983 gdb_assert (in != nullptr);
984 gdb_assert (offset >= 0 && offset <= reg_size);
985 gdb_assert (len >= 0 && offset + len <= reg_size);
986
987 if (offset == 0 && len == 0)
988 {
989 /* Nothing to do. */
990 return;
991 }
992
993 if (offset == 0 && len == reg_size)
994 {
995 /* Supply the full register. */
996 return raw_supply (regnum, in);
997 }
998
999 gdb_byte *reg = (gdb_byte *) alloca (reg_size);
1000
1001 /* Read existing value to buffer. */
1002 raw_collect (regnum, reg);
1003
1004 /* Write to buffer, then write out. */
1005 memcpy (reg + offset, in, len);
1006 raw_supply (regnum, reg);
1007 }
1008
1009 enum register_status
1010 readable_regcache::raw_read_part (int regnum, int offset, int len,
1011 gdb_byte *buf)
1012 {
1013 assert_regnum (regnum);
1014 return read_part (regnum, offset, len, buf, true);
1015 }
1016
1017 /* See regcache.h. */
1018
1019 void
1020 regcache::raw_write_part (int regnum, int offset, int len,
1021 const gdb_byte *buf)
1022 {
1023 assert_regnum (regnum);
1024 write_part (regnum, offset, len, buf, true);
1025 }
1026
1027 /* See regcache.h. */
1028
1029 enum register_status
1030 readable_regcache::cooked_read_part (int regnum, int offset, int len,
1031 gdb_byte *buf)
1032 {
1033 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
1034 return read_part (regnum, offset, len, buf, false);
1035 }
1036
1037 /* See regcache.h. */
1038
1039 void
1040 regcache::cooked_write_part (int regnum, int offset, int len,
1041 const gdb_byte *buf)
1042 {
1043 gdb_assert (regnum >= 0 && regnum < m_descr->nr_cooked_registers);
1044 write_part (regnum, offset, len, buf, false);
1045 }
1046
1047 /* See gdbsupport/common-regcache.h. */
1048
1049 void
1050 reg_buffer::raw_supply (int regnum, const void *buf)
1051 {
1052 void *regbuf;
1053 size_t size;
1054
1055 assert_regnum (regnum);
1056
1057 regbuf = register_buffer (regnum);
1058 size = m_descr->sizeof_register[regnum];
1059
1060 if (buf)
1061 {
1062 memcpy (regbuf, buf, size);
1063 m_register_status[regnum] = REG_VALID;
1064 }
1065 else
1066 {
1067 /* This memset not strictly necessary, but better than garbage
1068 in case the register value manages to escape somewhere (due
1069 to a bug, no less). */
1070 memset (regbuf, 0, size);
1071 m_register_status[regnum] = REG_UNAVAILABLE;
1072 }
1073 }
1074
1075 /* See regcache.h. */
1076
1077 void
1078 reg_buffer::raw_supply_integer (int regnum, const gdb_byte *addr,
1079 int addr_len, bool is_signed)
1080 {
1081 enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
1082 gdb_byte *regbuf;
1083 size_t regsize;
1084
1085 assert_regnum (regnum);
1086
1087 regbuf = register_buffer (regnum);
1088 regsize = m_descr->sizeof_register[regnum];
1089
1090 copy_integer_to_size (regbuf, regsize, addr, addr_len, is_signed,
1091 byte_order);
1092 m_register_status[regnum] = REG_VALID;
1093 }
1094
1095 /* See regcache.h. */
1096
1097 void
1098 reg_buffer::raw_supply_zeroed (int regnum)
1099 {
1100 void *regbuf;
1101 size_t size;
1102
1103 assert_regnum (regnum);
1104
1105 regbuf = register_buffer (regnum);
1106 size = m_descr->sizeof_register[regnum];
1107
1108 memset (regbuf, 0, size);
1109 m_register_status[regnum] = REG_VALID;
1110 }
1111
1112 /* See gdbsupport/common-regcache.h. */
1113
1114 void
1115 reg_buffer::raw_collect (int regnum, void *buf) const
1116 {
1117 const void *regbuf;
1118 size_t size;
1119
1120 gdb_assert (buf != NULL);
1121 assert_regnum (regnum);
1122
1123 regbuf = register_buffer (regnum);
1124 size = m_descr->sizeof_register[regnum];
1125 memcpy (buf, regbuf, size);
1126 }
1127
1128 /* See regcache.h. */
1129
1130 void
1131 reg_buffer::raw_collect_integer (int regnum, gdb_byte *addr, int addr_len,
1132 bool is_signed) const
1133 {
1134 enum bfd_endian byte_order = gdbarch_byte_order (m_descr->gdbarch);
1135 const gdb_byte *regbuf;
1136 size_t regsize;
1137
1138 assert_regnum (regnum);
1139
1140 regbuf = register_buffer (regnum);
1141 regsize = m_descr->sizeof_register[regnum];
1142
1143 copy_integer_to_size (addr, addr_len, regbuf, regsize, is_signed,
1144 byte_order);
1145 }
1146
1147 /* See regcache.h. */
1148
1149 void
1150 regcache::transfer_regset_register (struct regcache *out_regcache, int regnum,
1151 const gdb_byte *in_buf, gdb_byte *out_buf,
1152 int slot_size, int offs) const
1153 {
1154 struct gdbarch *gdbarch = arch ();
1155 int reg_size = std::min (register_size (gdbarch, regnum), slot_size);
1156
1157 /* Use part versions and reg_size to prevent possible buffer overflows when
1158 accessing the regcache. */
1159
1160 if (out_buf != nullptr)
1161 {
1162 raw_collect_part (regnum, 0, reg_size, out_buf + offs);
1163
1164 /* Ensure any additional space is cleared. */
1165 if (slot_size > reg_size)
1166 memset (out_buf + offs + reg_size, 0, slot_size - reg_size);
1167 }
1168 else if (in_buf != nullptr)
1169 out_regcache->raw_supply_part (regnum, 0, reg_size, in_buf + offs);
1170 else
1171 {
1172 /* Invalidate the register. */
1173 out_regcache->raw_supply (regnum, nullptr);
1174 }
1175 }
1176
1177 /* See regcache.h. */
1178
1179 void
1180 regcache::transfer_regset (const struct regset *regset,
1181 struct regcache *out_regcache,
1182 int regnum, const gdb_byte *in_buf,
1183 gdb_byte *out_buf, size_t size) const
1184 {
1185 const struct regcache_map_entry *map;
1186 int offs = 0, count;
1187
1188 for (map = (const struct regcache_map_entry *) regset->regmap;
1189 (count = map->count) != 0;
1190 map++)
1191 {
1192 int regno = map->regno;
1193 int slot_size = map->size;
1194
1195 if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
1196 slot_size = m_descr->sizeof_register[regno];
1197
1198 if (regno == REGCACHE_MAP_SKIP
1199 || (regnum != -1
1200 && (regnum < regno || regnum >= regno + count)))
1201 offs += count * slot_size;
1202
1203 else if (regnum == -1)
1204 for (; count--; regno++, offs += slot_size)
1205 {
1206 if (offs + slot_size > size)
1207 break;
1208
1209 transfer_regset_register (out_regcache, regno, in_buf, out_buf,
1210 slot_size, offs);
1211 }
1212 else
1213 {
1214 /* Transfer a single register and return. */
1215 offs += (regnum - regno) * slot_size;
1216 if (offs + slot_size > size)
1217 return;
1218
1219 transfer_regset_register (out_regcache, regnum, in_buf, out_buf,
1220 slot_size, offs);
1221 return;
1222 }
1223 }
1224 }
1225
1226 /* Supply register REGNUM from BUF to REGCACHE, using the register map
1227 in REGSET. If REGNUM is -1, do this for all registers in REGSET.
1228 If BUF is NULL, set the register(s) to "unavailable" status. */
1229
1230 void
1231 regcache_supply_regset (const struct regset *regset,
1232 struct regcache *regcache,
1233 int regnum, const void *buf, size_t size)
1234 {
1235 regcache->supply_regset (regset, regnum, (const gdb_byte *) buf, size);
1236 }
1237
1238 void
1239 regcache::supply_regset (const struct regset *regset,
1240 int regnum, const void *buf, size_t size)
1241 {
1242 transfer_regset (regset, this, regnum, (const gdb_byte *) buf, nullptr, size);
1243 }
1244
1245 /* Collect register REGNUM from REGCACHE to BUF, using the register
1246 map in REGSET. If REGNUM is -1, do this for all registers in
1247 REGSET. */
1248
1249 void
1250 regcache_collect_regset (const struct regset *regset,
1251 const struct regcache *regcache,
1252 int regnum, void *buf, size_t size)
1253 {
1254 regcache->collect_regset (regset, regnum, (gdb_byte *) buf, size);
1255 }
1256
1257 void
1258 regcache::collect_regset (const struct regset *regset,
1259 int regnum, void *buf, size_t size) const
1260 {
1261 transfer_regset (regset, nullptr, regnum, nullptr, (gdb_byte *) buf, size);
1262 }
1263
1264 /* See gdbsupport/common-regcache.h. */
1265
1266 bool
1267 reg_buffer::raw_compare (int regnum, const void *buf, int offset) const
1268 {
1269 gdb_assert (buf != NULL);
1270 assert_regnum (regnum);
1271
1272 const char *regbuf = (const char *) register_buffer (regnum);
1273 size_t size = m_descr->sizeof_register[regnum];
1274 gdb_assert (size >= offset);
1275
1276 return (memcmp (buf, regbuf + offset, size - offset) == 0);
1277 }
1278
1279 /* Special handling for register PC. */
1280
1281 CORE_ADDR
1282 regcache_read_pc (struct regcache *regcache)
1283 {
1284 struct gdbarch *gdbarch = regcache->arch ();
1285
1286 CORE_ADDR pc_val;
1287
1288 if (gdbarch_read_pc_p (gdbarch))
1289 pc_val = gdbarch_read_pc (gdbarch, regcache);
1290 /* Else use per-frame method on get_current_frame. */
1291 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1292 {
1293 ULONGEST raw_val;
1294
1295 if (regcache_cooked_read_unsigned (regcache,
1296 gdbarch_pc_regnum (gdbarch),
1297 &raw_val) == REG_UNAVAILABLE)
1298 throw_error (NOT_AVAILABLE_ERROR, _("PC register is not available"));
1299
1300 pc_val = gdbarch_addr_bits_remove (gdbarch, raw_val);
1301 }
1302 else
1303 internal_error (__FILE__, __LINE__,
1304 _("regcache_read_pc: Unable to find PC"));
1305 return pc_val;
1306 }
1307
1308 /* See gdbsupport/common-regcache.h. */
1309
1310 CORE_ADDR
1311 regcache_read_pc_protected (regcache *regcache)
1312 {
1313 CORE_ADDR pc;
1314 try
1315 {
1316 pc = regcache_read_pc (regcache);
1317 }
1318 catch (const gdb_exception_error &ex)
1319 {
1320 pc = 0;
1321 }
1322
1323 return pc;
1324 }
1325
1326 void
1327 regcache_write_pc (struct regcache *regcache, CORE_ADDR pc)
1328 {
1329 struct gdbarch *gdbarch = regcache->arch ();
1330
1331 if (gdbarch_write_pc_p (gdbarch))
1332 gdbarch_write_pc (gdbarch, regcache, pc);
1333 else if (gdbarch_pc_regnum (gdbarch) >= 0)
1334 regcache_cooked_write_unsigned (regcache,
1335 gdbarch_pc_regnum (gdbarch), pc);
1336 else
1337 internal_error (__FILE__, __LINE__,
1338 _("regcache_write_pc: Unable to update PC"));
1339
1340 /* Writing the PC (for instance, from "load") invalidates the
1341 current frame. */
1342 reinit_frame_cache ();
1343 }
1344
1345 int
1346 reg_buffer::num_raw_registers () const
1347 {
1348 return gdbarch_num_regs (arch ());
1349 }
1350
1351 void
1352 regcache::debug_print_register (const char *func, int regno)
1353 {
1354 struct gdbarch *gdbarch = arch ();
1355
1356 fprintf_unfiltered (gdb_stdlog, "%s ", func);
1357 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch)
1358 && gdbarch_register_name (gdbarch, regno) != NULL
1359 && gdbarch_register_name (gdbarch, regno)[0] != '\0')
1360 fprintf_unfiltered (gdb_stdlog, "(%s)",
1361 gdbarch_register_name (gdbarch, regno));
1362 else
1363 fprintf_unfiltered (gdb_stdlog, "(%d)", regno);
1364 if (regno >= 0 && regno < gdbarch_num_regs (gdbarch))
1365 {
1366 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1367 int size = register_size (gdbarch, regno);
1368 gdb_byte *buf = register_buffer (regno);
1369
1370 fprintf_unfiltered (gdb_stdlog, " = ");
1371 for (int i = 0; i < size; i++)
1372 {
1373 fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
1374 }
1375 if (size <= sizeof (LONGEST))
1376 {
1377 ULONGEST val = extract_unsigned_integer (buf, size, byte_order);
1378
1379 fprintf_unfiltered (gdb_stdlog, " %s %s",
1380 core_addr_to_string_nz (val), plongest (val));
1381 }
1382 }
1383 fprintf_unfiltered (gdb_stdlog, "\n");
1384 }
1385
1386 /* Implement 'maint flush register-cache' command. */
1387
1388 static void
1389 reg_flush_command (const char *command, int from_tty)
1390 {
1391 /* Force-flush the register cache. */
1392 registers_changed ();
1393 if (from_tty)
1394 printf_filtered (_("Register cache flushed.\n"));
1395 }
1396
1397 void
1398 register_dump::dump (ui_file *file)
1399 {
1400 auto descr = regcache_descr (m_gdbarch);
1401 int regnum;
1402 int footnote_nr = 0;
1403 int footnote_register_offset = 0;
1404 int footnote_register_type_name_null = 0;
1405 long register_offset = 0;
1406
1407 gdb_assert (descr->nr_cooked_registers
1408 == gdbarch_num_cooked_regs (m_gdbarch));
1409
1410 for (regnum = -1; regnum < descr->nr_cooked_registers; regnum++)
1411 {
1412 /* Name. */
1413 if (regnum < 0)
1414 fprintf_unfiltered (file, " %-10s", "Name");
1415 else
1416 {
1417 const char *p = gdbarch_register_name (m_gdbarch, regnum);
1418
1419 if (p == NULL)
1420 p = "";
1421 else if (p[0] == '\0')
1422 p = "''";
1423 fprintf_unfiltered (file, " %-10s", p);
1424 }
1425
1426 /* Number. */
1427 if (regnum < 0)
1428 fprintf_unfiltered (file, " %4s", "Nr");
1429 else
1430 fprintf_unfiltered (file, " %4d", regnum);
1431
1432 /* Relative number. */
1433 if (regnum < 0)
1434 fprintf_unfiltered (file, " %4s", "Rel");
1435 else if (regnum < gdbarch_num_regs (m_gdbarch))
1436 fprintf_unfiltered (file, " %4d", regnum);
1437 else
1438 fprintf_unfiltered (file, " %4d",
1439 (regnum - gdbarch_num_regs (m_gdbarch)));
1440
1441 /* Offset. */
1442 if (regnum < 0)
1443 fprintf_unfiltered (file, " %6s ", "Offset");
1444 else
1445 {
1446 fprintf_unfiltered (file, " %6ld",
1447 descr->register_offset[regnum]);
1448 if (register_offset != descr->register_offset[regnum]
1449 || (regnum > 0
1450 && (descr->register_offset[regnum]
1451 != (descr->register_offset[regnum - 1]
1452 + descr->sizeof_register[regnum - 1])))
1453 )
1454 {
1455 if (!footnote_register_offset)
1456 footnote_register_offset = ++footnote_nr;
1457 fprintf_unfiltered (file, "*%d", footnote_register_offset);
1458 }
1459 else
1460 fprintf_unfiltered (file, " ");
1461 register_offset = (descr->register_offset[regnum]
1462 + descr->sizeof_register[regnum]);
1463 }
1464
1465 /* Size. */
1466 if (regnum < 0)
1467 fprintf_unfiltered (file, " %5s ", "Size");
1468 else
1469 fprintf_unfiltered (file, " %5ld", descr->sizeof_register[regnum]);
1470
1471 /* Type. */
1472 {
1473 const char *t;
1474 std::string name_holder;
1475
1476 if (regnum < 0)
1477 t = "Type";
1478 else
1479 {
1480 static const char blt[] = "builtin_type";
1481
1482 t = register_type (m_gdbarch, regnum)->name ();
1483 if (t == NULL)
1484 {
1485 if (!footnote_register_type_name_null)
1486 footnote_register_type_name_null = ++footnote_nr;
1487 name_holder = string_printf ("*%d",
1488 footnote_register_type_name_null);
1489 t = name_holder.c_str ();
1490 }
1491 /* Chop a leading builtin_type. */
1492 if (startswith (t, blt))
1493 t += strlen (blt);
1494 }
1495 fprintf_unfiltered (file, " %-15s", t);
1496 }
1497
1498 /* Leading space always present. */
1499 fprintf_unfiltered (file, " ");
1500
1501 dump_reg (file, regnum);
1502
1503 fprintf_unfiltered (file, "\n");
1504 }
1505
1506 if (footnote_register_offset)
1507 fprintf_unfiltered (file, "*%d: Inconsistent register offsets.\n",
1508 footnote_register_offset);
1509 if (footnote_register_type_name_null)
1510 fprintf_unfiltered (file,
1511 "*%d: Register type's name NULL.\n",
1512 footnote_register_type_name_null);
1513 }
1514
1515 #if GDB_SELF_TEST
1516 #include "gdbsupport/selftest.h"
1517 #include "selftest-arch.h"
1518 #include "target-float.h"
1519
1520 namespace selftests {
1521
1522 static size_t
1523 regcaches_size ()
1524 {
1525 size_t size = 0;
1526
1527 for (auto pid_ptid_regc_map_it = regcaches.cbegin ();
1528 pid_ptid_regc_map_it != regcaches.cend ();
1529 ++pid_ptid_regc_map_it)
1530 {
1531 const pid_ptid_regcache_map &pid_ptid_regc_map
1532 = pid_ptid_regc_map_it->second;
1533
1534 for (auto ptid_regc_map_it = pid_ptid_regc_map.cbegin ();
1535 ptid_regc_map_it != pid_ptid_regc_map.cend ();
1536 ++ptid_regc_map_it)
1537 {
1538 const ptid_regcache_map &ptid_regc_map
1539 = ptid_regc_map_it->second;
1540
1541 size += ptid_regc_map.size ();
1542 }
1543 }
1544
1545 return size;
1546 }
1547
1548 /* Return the count of regcaches for (TARGET, PTID) in REGCACHES. */
1549
1550 static int
1551 regcache_count (process_stratum_target *target, ptid_t ptid)
1552 {
1553 /* Look up map for target. */
1554 auto pid_ptid_regc_map_it = regcaches.find (target);
1555 if (pid_ptid_regc_map_it != regcaches.end ())
1556 {
1557 pid_ptid_regcache_map &pid_ptid_regc_map = pid_ptid_regc_map_it->second;
1558
1559 /* Look map for pid. */
1560 auto ptid_regc_map_it = pid_ptid_regc_map.find (ptid.pid ());
1561 if (ptid_regc_map_it != pid_ptid_regc_map.end ())
1562 {
1563 ptid_regcache_map &ptid_regc_map = ptid_regc_map_it->second;
1564 auto range = ptid_regc_map.equal_range (ptid);
1565
1566 return std::distance (range.first, range.second);
1567 }
1568 }
1569
1570 return 0;
1571 };
1572
1573 /* Wrapper around get_thread_arch_aspace_regcache that does some self checks. */
1574
1575 static void
1576 get_thread_arch_aspace_regcache_and_check (process_stratum_target *target,
1577 ptid_t ptid)
1578 {
1579 /* We currently only test with a single gdbarch. Any gdbarch will do, so use
1580 the current inferior's gdbarch. Also use the current inferior's address
1581 space. */
1582 gdbarch *arch = current_inferior ()->gdbarch;
1583 address_space *aspace = current_inferior ()->aspace;
1584 regcache *regcache
1585 = get_thread_arch_aspace_regcache (target, ptid, arch, aspace);
1586
1587 SELF_CHECK (regcache != NULL);
1588 SELF_CHECK (regcache->target () == target);
1589 SELF_CHECK (regcache->ptid () == ptid);
1590 SELF_CHECK (regcache->arch () == arch);
1591 SELF_CHECK (regcache->aspace () == aspace);
1592 }
1593
1594 /* The data that the regcaches selftests must hold onto for the duration of the
1595 test. */
1596
1597 struct regcache_test_data
1598 {
1599 regcache_test_data ()
1600 {
1601 /* Ensure the regcaches container is empty at the start. */
1602 registers_changed ();
1603 }
1604
1605 ~regcache_test_data ()
1606 {
1607 /* Make sure to leave the global regcaches container empty. */
1608 registers_changed ();
1609 }
1610
1611 test_target_ops test_target1;
1612 test_target_ops test_target2;
1613 };
1614
1615 using regcache_test_data_up = std::unique_ptr<regcache_test_data>;
1616
1617 /* Set up a few regcaches from two different targets, for use in
1618 regcache-management tests.
1619
1620 Return a pointer, because the `regcache_test_data` type is not moveable. */
1621
1622 static regcache_test_data_up
1623 populate_regcaches_for_test ()
1624 {
1625 regcache_test_data_up data (new regcache_test_data);
1626 size_t expected_regcache_size = 0;
1627
1628 SELF_CHECK (regcaches_size () == 0);
1629
1630 /* Populate the regcache container with a few regcaches for the two test
1631 targets. */
1632 for (int pid : { 1, 2 })
1633 {
1634 for (long lwp : { 1, 2, 3 })
1635 {
1636 get_thread_arch_aspace_regcache_and_check
1637 (&data->test_target1, ptid_t (pid, lwp));
1638 expected_regcache_size++;
1639 SELF_CHECK (regcaches_size () == expected_regcache_size);
1640
1641 get_thread_arch_aspace_regcache_and_check
1642 (&data->test_target2, ptid_t (pid, lwp));
1643 expected_regcache_size++;
1644 SELF_CHECK (regcaches_size () == expected_regcache_size);
1645 }
1646 }
1647
1648 return data;
1649 }
1650
1651 static void
1652 get_thread_arch_aspace_regcache_test ()
1653 {
1654 /* populate_regcaches_for_test already tests most of the
1655 get_thread_arch_aspace_regcache functionality. */
1656 regcache_test_data_up data = populate_regcaches_for_test ();
1657 size_t regcaches_size_before = regcaches_size ();
1658
1659 /* Test that getting an existing regcache doesn't create a new one. */
1660 get_thread_arch_aspace_regcache_and_check (&data->test_target1, ptid_t (2, 2));
1661 SELF_CHECK (regcaches_size () == regcaches_size_before);
1662 }
1663
1664 /* Test marking all regcaches of all targets as changed. */
1665
1666 static void
1667 registers_changed_ptid_all_test ()
1668 {
1669 regcache_test_data_up data = populate_regcaches_for_test ();
1670
1671 registers_changed_ptid (nullptr, minus_one_ptid);
1672 SELF_CHECK (regcaches_size () == 0);
1673 }
1674
1675 /* Test marking regcaches of a specific target as changed. */
1676
1677 static void
1678 registers_changed_ptid_target_test ()
1679 {
1680 regcache_test_data_up data = populate_regcaches_for_test ();
1681
1682 registers_changed_ptid (&data->test_target1, minus_one_ptid);
1683 SELF_CHECK (regcaches_size () == 6);
1684
1685 /* Check that we deleted the regcache for the right target. */
1686 SELF_CHECK (regcache_count (&data->test_target1, ptid_t (2, 2)) == 0);
1687 SELF_CHECK (regcache_count (&data->test_target2, ptid_t (2, 2)) == 1);
1688 }
1689
1690 /* Test marking regcaches of a specific (target, pid) as changed. */
1691
1692 static void
1693 registers_changed_ptid_target_pid_test ()
1694 {
1695 regcache_test_data_up data = populate_regcaches_for_test ();
1696
1697 registers_changed_ptid (&data->test_target1, ptid_t (2));
1698 SELF_CHECK (regcaches_size () == 9);
1699
1700 /* Regcaches from target1 should not exist, while regcaches from target2
1701 should exist. */
1702 SELF_CHECK (regcache_count (&data->test_target1, ptid_t (2, 2)) == 0);
1703 SELF_CHECK (regcache_count (&data->test_target2, ptid_t (2, 2)) == 1);
1704 }
1705
1706 /* Test marking regcaches of a specific (target, ptid) as changed. */
1707
1708 static void
1709 registers_changed_ptid_target_ptid_test ()
1710 {
1711 regcache_test_data_up data = populate_regcaches_for_test ();
1712
1713 registers_changed_ptid (&data->test_target1, ptid_t (2, 2));
1714 SELF_CHECK (regcaches_size () == 11);
1715
1716 /* Check that we deleted the regcache for the right target. */
1717 SELF_CHECK (regcache_count (&data->test_target1, ptid_t (2, 2)) == 0);
1718 SELF_CHECK (regcache_count (&data->test_target2, ptid_t (2, 2)) == 1);
1719 }
1720
1721 class target_ops_no_register : public test_target_ops
1722 {
1723 public:
1724 target_ops_no_register ()
1725 : test_target_ops {}
1726 {}
1727
1728 void reset ()
1729 {
1730 fetch_registers_called = 0;
1731 store_registers_called = 0;
1732 xfer_partial_called = 0;
1733 }
1734
1735 void fetch_registers (regcache *regs, int regno) override;
1736 void store_registers (regcache *regs, int regno) override;
1737
1738 enum target_xfer_status xfer_partial (enum target_object object,
1739 const char *annex, gdb_byte *readbuf,
1740 const gdb_byte *writebuf,
1741 ULONGEST offset, ULONGEST len,
1742 ULONGEST *xfered_len) override;
1743
1744 unsigned int fetch_registers_called = 0;
1745 unsigned int store_registers_called = 0;
1746 unsigned int xfer_partial_called = 0;
1747 };
1748
1749 void
1750 target_ops_no_register::fetch_registers (regcache *regs, int regno)
1751 {
1752 /* Mark register available. */
1753 regs->raw_supply_zeroed (regno);
1754 this->fetch_registers_called++;
1755 }
1756
1757 void
1758 target_ops_no_register::store_registers (regcache *regs, int regno)
1759 {
1760 this->store_registers_called++;
1761 }
1762
1763 enum target_xfer_status
1764 target_ops_no_register::xfer_partial (enum target_object object,
1765 const char *annex, gdb_byte *readbuf,
1766 const gdb_byte *writebuf,
1767 ULONGEST offset, ULONGEST len,
1768 ULONGEST *xfered_len)
1769 {
1770 this->xfer_partial_called++;
1771
1772 *xfered_len = len;
1773 return TARGET_XFER_OK;
1774 }
1775
1776 class readwrite_regcache : public regcache
1777 {
1778 public:
1779 readwrite_regcache (process_stratum_target *target,
1780 struct gdbarch *gdbarch)
1781 : regcache (target, gdbarch, nullptr)
1782 {}
1783 };
1784
1785 /* Test regcache::cooked_read gets registers from raw registers and
1786 memory instead of target to_{fetch,store}_registers. */
1787
1788 static void
1789 cooked_read_test (struct gdbarch *gdbarch)
1790 {
1791 scoped_mock_context<target_ops_no_register> mockctx (gdbarch);
1792
1793 /* Test that read one raw register from regcache_no_target will go
1794 to the target layer. */
1795
1796 /* Find a raw register which size isn't zero. */
1797 int nonzero_regnum;
1798 for (nonzero_regnum = 0;
1799 nonzero_regnum < gdbarch_num_regs (gdbarch);
1800 nonzero_regnum++)
1801 {
1802 if (register_size (gdbarch, nonzero_regnum) != 0)
1803 break;
1804 }
1805
1806 readwrite_regcache readwrite (&mockctx.mock_target, gdbarch);
1807 gdb::def_vector<gdb_byte> buf (register_size (gdbarch, nonzero_regnum));
1808
1809 readwrite.raw_read (nonzero_regnum, buf.data ());
1810
1811 /* raw_read calls target_fetch_registers. */
1812 SELF_CHECK (mockctx.mock_target.fetch_registers_called > 0);
1813 mockctx.mock_target.reset ();
1814
1815 /* Mark all raw registers valid, so the following raw registers
1816 accesses won't go to target. */
1817 for (auto i = 0; i < gdbarch_num_regs (gdbarch); i++)
1818 readwrite.raw_update (i);
1819
1820 mockctx.mock_target.reset ();
1821 /* Then, read all raw and pseudo registers, and don't expect calling
1822 to_{fetch,store}_registers. */
1823 for (int regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++)
1824 {
1825 if (register_size (gdbarch, regnum) == 0)
1826 continue;
1827
1828 gdb::def_vector<gdb_byte> inner_buf (register_size (gdbarch, regnum));
1829
1830 SELF_CHECK (REG_VALID == readwrite.cooked_read (regnum,
1831 inner_buf.data ()));
1832
1833 SELF_CHECK (mockctx.mock_target.fetch_registers_called == 0);
1834 SELF_CHECK (mockctx.mock_target.store_registers_called == 0);
1835 SELF_CHECK (mockctx.mock_target.xfer_partial_called == 0);
1836
1837 mockctx.mock_target.reset ();
1838 }
1839
1840 readonly_detached_regcache readonly (readwrite);
1841
1842 /* GDB may go to target layer to fetch all registers and memory for
1843 readonly regcache. */
1844 mockctx.mock_target.reset ();
1845
1846 for (int regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++)
1847 {
1848 if (register_size (gdbarch, regnum) == 0)
1849 continue;
1850
1851 gdb::def_vector<gdb_byte> inner_buf (register_size (gdbarch, regnum));
1852 enum register_status status = readonly.cooked_read (regnum,
1853 inner_buf.data ());
1854
1855 if (regnum < gdbarch_num_regs (gdbarch))
1856 {
1857 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
1858
1859 if (bfd_arch == bfd_arch_frv || bfd_arch == bfd_arch_h8300
1860 || bfd_arch == bfd_arch_m32c || bfd_arch == bfd_arch_sh
1861 || bfd_arch == bfd_arch_alpha || bfd_arch == bfd_arch_v850
1862 || bfd_arch == bfd_arch_msp430 || bfd_arch == bfd_arch_mep
1863 || bfd_arch == bfd_arch_mips || bfd_arch == bfd_arch_v850_rh850
1864 || bfd_arch == bfd_arch_tic6x || bfd_arch == bfd_arch_mn10300
1865 || bfd_arch == bfd_arch_rl78 || bfd_arch == bfd_arch_score
1866 || bfd_arch == bfd_arch_riscv || bfd_arch == bfd_arch_csky)
1867 {
1868 /* Raw registers. If raw registers are not in save_reggroup,
1869 their status are unknown. */
1870 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
1871 SELF_CHECK (status == REG_VALID);
1872 else
1873 SELF_CHECK (status == REG_UNKNOWN);
1874 }
1875 else
1876 SELF_CHECK (status == REG_VALID);
1877 }
1878 else
1879 {
1880 if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
1881 SELF_CHECK (status == REG_VALID);
1882 else
1883 {
1884 /* If pseudo registers are not in save_reggroup, some of
1885 them can be computed from saved raw registers, but some
1886 of them are unknown. */
1887 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
1888
1889 if (bfd_arch == bfd_arch_frv
1890 || bfd_arch == bfd_arch_m32c
1891 || bfd_arch == bfd_arch_mep
1892 || bfd_arch == bfd_arch_sh)
1893 SELF_CHECK (status == REG_VALID || status == REG_UNKNOWN);
1894 else if (bfd_arch == bfd_arch_mips
1895 || bfd_arch == bfd_arch_h8300)
1896 SELF_CHECK (status == REG_UNKNOWN);
1897 else
1898 SELF_CHECK (status == REG_VALID);
1899 }
1900 }
1901
1902 SELF_CHECK (mockctx.mock_target.fetch_registers_called == 0);
1903 SELF_CHECK (mockctx.mock_target.store_registers_called == 0);
1904 SELF_CHECK (mockctx.mock_target.xfer_partial_called == 0);
1905
1906 mockctx.mock_target.reset ();
1907 }
1908 }
1909
1910 /* Test regcache::cooked_write by writing some expected contents to
1911 registers, and checking that contents read from registers and the
1912 expected contents are the same. */
1913
1914 static void
1915 cooked_write_test (struct gdbarch *gdbarch)
1916 {
1917 /* Error out if debugging something, because we're going to push the
1918 test target, which would pop any existing target. */
1919 if (current_top_target ()->stratum () >= process_stratum)
1920 error (_("target already pushed"));
1921
1922 /* Create a mock environment. A process_stratum target pushed. */
1923
1924 target_ops_no_register mock_target;
1925
1926 /* Push the process_stratum target so we can mock accessing
1927 registers. */
1928 current_inferior ()->push_target (&mock_target);
1929
1930 /* Pop it again on exit (return/exception). */
1931 struct on_exit
1932 {
1933 ~on_exit ()
1934 {
1935 pop_all_targets_at_and_above (process_stratum);
1936 }
1937 } pop_targets;
1938
1939 readwrite_regcache readwrite (&mock_target, gdbarch);
1940
1941 const int num_regs = gdbarch_num_cooked_regs (gdbarch);
1942
1943 for (auto regnum = 0; regnum < num_regs; regnum++)
1944 {
1945 if (register_size (gdbarch, regnum) == 0
1946 || gdbarch_cannot_store_register (gdbarch, regnum))
1947 continue;
1948
1949 auto bfd_arch = gdbarch_bfd_arch_info (gdbarch)->arch;
1950
1951 if (bfd_arch == bfd_arch_sparc
1952 /* SPARC64_CWP_REGNUM, SPARC64_PSTATE_REGNUM,
1953 SPARC64_ASI_REGNUM and SPARC64_CCR_REGNUM are hard to test. */
1954 && gdbarch_ptr_bit (gdbarch) == 64
1955 && (regnum >= gdbarch_num_regs (gdbarch)
1956 && regnum <= gdbarch_num_regs (gdbarch) + 4))
1957 continue;
1958
1959 std::vector<gdb_byte> expected (register_size (gdbarch, regnum), 0);
1960 std::vector<gdb_byte> buf (register_size (gdbarch, regnum), 0);
1961 const auto type = register_type (gdbarch, regnum);
1962
1963 if (type->code () == TYPE_CODE_FLT
1964 || type->code () == TYPE_CODE_DECFLOAT)
1965 {
1966 /* Generate valid float format. */
1967 target_float_from_string (expected.data (), type, "1.25");
1968 }
1969 else if (type->code () == TYPE_CODE_INT
1970 || type->code () == TYPE_CODE_ARRAY
1971 || type->code () == TYPE_CODE_PTR
1972 || type->code () == TYPE_CODE_UNION
1973 || type->code () == TYPE_CODE_STRUCT)
1974 {
1975 if (bfd_arch == bfd_arch_ia64
1976 || (regnum >= gdbarch_num_regs (gdbarch)
1977 && (bfd_arch == bfd_arch_xtensa
1978 || bfd_arch == bfd_arch_bfin
1979 || bfd_arch == bfd_arch_m32c
1980 /* m68hc11 pseudo registers are in memory. */
1981 || bfd_arch == bfd_arch_m68hc11
1982 || bfd_arch == bfd_arch_m68hc12
1983 || bfd_arch == bfd_arch_s390))
1984 || (bfd_arch == bfd_arch_frv
1985 /* FRV pseudo registers except iacc0. */
1986 && regnum > gdbarch_num_regs (gdbarch)))
1987 {
1988 /* Skip setting the expected values for some architecture
1989 registers. */
1990 }
1991 else if (bfd_arch == bfd_arch_rl78 && regnum == 40)
1992 {
1993 /* RL78_PC_REGNUM */
1994 for (auto j = 0; j < register_size (gdbarch, regnum) - 1; j++)
1995 expected[j] = j;
1996 }
1997 else
1998 {
1999 for (auto j = 0; j < register_size (gdbarch, regnum); j++)
2000 expected[j] = j;
2001 }
2002 }
2003 else if (type->code () == TYPE_CODE_FLAGS)
2004 {
2005 /* No idea how to test flags. */
2006 continue;
2007 }
2008 else
2009 {
2010 /* If we don't know how to create the expected value for the
2011 this type, make it fail. */
2012 SELF_CHECK (0);
2013 }
2014
2015 readwrite.cooked_write (regnum, expected.data ());
2016
2017 SELF_CHECK (readwrite.cooked_read (regnum, buf.data ()) == REG_VALID);
2018 SELF_CHECK (expected == buf);
2019 }
2020 }
2021
2022 /* Verify that when two threads with the same ptid exist (from two different
2023 targets) and one of them changes ptid, we only update the appropriate
2024 regcaches. */
2025
2026 static void
2027 regcache_thread_ptid_changed ()
2028 {
2029 /* This test relies on the global regcache list to initially be empty. */
2030 registers_changed ();
2031
2032 /* Any arch will do. */
2033 gdbarch *arch = current_inferior ()->gdbarch;
2034
2035 /* Prepare two targets with one thread each, with the same ptid. */
2036 scoped_mock_context<test_target_ops> target1 (arch);
2037 scoped_mock_context<test_target_ops> target2 (arch);
2038 target2.mock_inferior.next = &target1.mock_inferior;
2039
2040 ptid_t old_ptid (111, 222);
2041 ptid_t new_ptid (111, 333);
2042
2043 target1.mock_inferior.pid = old_ptid.pid ();
2044 target1.mock_thread.ptid = old_ptid;
2045 target2.mock_inferior.pid = old_ptid.pid ();
2046 target2.mock_thread.ptid = old_ptid;
2047
2048 gdb_assert (regcaches.empty ());
2049
2050 /* Populate the regcaches container. */
2051 get_thread_arch_aspace_regcache (&target1.mock_target, old_ptid, arch,
2052 nullptr);
2053 get_thread_arch_aspace_regcache (&target2.mock_target, old_ptid, arch,
2054 nullptr);
2055
2056 gdb_assert (regcaches.size () == 2);
2057 gdb_assert (regcache_count (&target1.mock_target, old_ptid) == 1);
2058 gdb_assert (regcache_count (&target1.mock_target, new_ptid) == 0);
2059 gdb_assert (regcache_count (&target2.mock_target, old_ptid) == 1);
2060 gdb_assert (regcache_count (&target2.mock_target, new_ptid) == 0);
2061
2062 thread_change_ptid (&target1.mock_target, old_ptid, new_ptid);
2063
2064 gdb_assert (regcaches.size () == 2);
2065 gdb_assert (regcache_count (&target1.mock_target, old_ptid) == 0);
2066 gdb_assert (regcache_count (&target1.mock_target, new_ptid) == 1);
2067 gdb_assert (regcache_count (&target2.mock_target, old_ptid) == 1);
2068 gdb_assert (regcache_count (&target2.mock_target, new_ptid) == 0);
2069
2070 /* Leave the regcache list empty. */
2071 registers_changed ();
2072 gdb_assert (regcaches.empty ());
2073 }
2074
2075 } // namespace selftests
2076 #endif /* GDB_SELF_TEST */
2077
2078 void _initialize_regcache ();
2079 void
2080 _initialize_regcache ()
2081 {
2082 struct cmd_list_element *c;
2083
2084 regcache_descr_handle
2085 = gdbarch_data_register_post_init (init_regcache_descr);
2086
2087 gdb::observers::target_changed.attach (regcache_observer_target_changed);
2088 gdb::observers::thread_ptid_changed.attach (regcache_thread_ptid_changed);
2089
2090 add_cmd ("register-cache", class_maintenance, reg_flush_command,
2091 _("Force gdb to flush its register and frame cache."),
2092 &maintenanceflushlist);
2093 c = add_com_alias ("flushregs", "maintenance flush register-cache",
2094 class_maintenance, 0);
2095 deprecate_cmd (c, "maintenance flush register-cache");
2096
2097 #if GDB_SELF_TEST
2098 selftests::register_test ("get_thread_arch_aspace_regcache",
2099 selftests::get_thread_arch_aspace_regcache_test);
2100 selftests::register_test ("registers_changed_ptid_all",
2101 selftests::registers_changed_ptid_all_test);
2102 selftests::register_test ("registers_changed_ptid_target",
2103 selftests::registers_changed_ptid_target_test);
2104 selftests::register_test ("registers_changed_ptid_target_pid",
2105 selftests::registers_changed_ptid_target_pid_test);
2106 selftests::register_test ("registers_changed_ptid_target_ptid",
2107 selftests::registers_changed_ptid_target_ptid_test);
2108
2109 selftests::register_test_foreach_arch ("regcache::cooked_read_test",
2110 selftests::cooked_read_test);
2111 selftests::register_test_foreach_arch ("regcache::cooked_write_test",
2112 selftests::cooked_write_test);
2113 selftests::register_test ("regcache_thread_ptid_changed",
2114 selftests::regcache_thread_ptid_changed);
2115 #endif
2116 }