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