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