1 /* Register support routines for the remote server for GDB.
2 Copyright (C) 2001-2024 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #ifndef GDBSERVER_REGCACHE_H
20 #define GDBSERVER_REGCACHE_H
22 #include "gdbsupport/common-regcache.h"
27 /* The data for the register cache. Note that we have one per
28 inferior; this is primarily for simplicity, as the performance
29 benefit is minimal. */
31 struct regcache
: public reg_buffer_common
33 /* The regcache's target description. */
34 const struct target_desc
*tdesc
= nullptr;
36 /* Whether the REGISTERS buffer's contents are valid. If false, we
37 haven't fetched the registers from the target yet. Not that this
38 register cache is _not_ pass-through, unlike GDB's. Note that
39 "valid" here is unrelated to whether the registers are available
40 in a traceframe. For that, check REGISTER_STATUS below. */
41 int registers_valid
= 0;
42 int registers_owned
= 0;
43 unsigned char *registers
= nullptr;
44 #ifndef IN_PROCESS_AGENT
45 /* One of REG_UNAVAILABLE or REG_VALID. */
46 unsigned char *register_status
= nullptr;
49 /* See gdbsupport/common-regcache.h. */
50 enum register_status
get_register_status (int regnum
) const override
;
52 /* See gdbsupport/common-regcache.h. */
53 void raw_supply (int regnum
, gdb::array_view
<const gdb_byte
> src
) override
;
55 /* See gdbsupport/common-regcache.h. */
56 void raw_supply_part_zeroed (int regnum
, int offset
, size_t size
) override
;
58 /* See gdbsupport/common-regcache.h. */
59 void raw_collect (int regnum
, gdb::array_view
<gdb_byte
> dst
) const override
;
61 /* See gdbsupport/common-regcache.h. */
62 bool raw_compare (int regnum
, const void *buf
, int offset
) const override
;
65 struct regcache
*init_register_cache (struct regcache
*regcache
,
66 const struct target_desc
*tdesc
,
67 unsigned char *regbuf
);
69 void regcache_cpy (struct regcache
*dst
, struct regcache
*src
);
71 /* Create a new register cache for INFERIOR. */
73 struct regcache
*new_register_cache (const struct target_desc
*tdesc
);
75 struct regcache
*get_thread_regcache (struct thread_info
*thread
, int fetch
);
77 /* Release all memory associated with the register cache for INFERIOR. */
79 void free_register_cache (struct regcache
*regcache
);
81 /* Invalidate cached registers for one thread. */
83 void regcache_invalidate_thread (struct thread_info
*);
85 /* Invalidate cached registers for all threads of the given process. */
87 void regcache_invalidate_pid (int pid
);
89 /* Invalidate cached registers for all threads of the current
92 void regcache_invalidate (void);
94 /* Invalidate and release the register cache of all threads of the
97 void regcache_release (void);
99 /* Convert all registers to a string in the currently specified remote
102 void registers_to_string (struct regcache
*regcache
, char *buf
);
104 /* Convert a string to register values and fill our register cache. */
106 void registers_from_string (struct regcache
*regcache
, char *buf
);
108 /* For regcache_read_pc see gdbsupport/common-regcache.h. */
110 void regcache_write_pc (struct regcache
*regcache
, CORE_ADDR pc
);
112 int register_cache_size (const struct target_desc
*tdesc
);
114 int register_size (const struct target_desc
*tdesc
, int n
);
116 /* No throw version of find_regno. If NAME is not a known register, return
118 std::optional
<int> find_regno_no_throw (const struct target_desc
*tdesc
,
121 int find_regno (const struct target_desc
*tdesc
, const char *name
);
123 void supply_register (struct regcache
*regcache
, int n
, const void *buf
);
125 void supply_register_zeroed (struct regcache
*regcache
, int n
);
127 void supply_register_by_name (struct regcache
*regcache
,
128 const char *name
, const void *buf
);
130 void supply_register_by_name_zeroed (struct regcache
*regcache
,
133 void supply_regblock (struct regcache
*regcache
, const void *buf
);
135 void collect_register (struct regcache
*regcache
, int n
, void *buf
);
137 void collect_register_as_string (struct regcache
*regcache
, int n
, char *buf
);
139 void collect_register_by_name (struct regcache
*regcache
,
140 const char *name
, void *buf
);
142 /* Read a raw register as an unsigned integer. Convenience wrapper
143 around regcache_raw_get_unsigned that takes a register name instead
144 of a register number. */
146 ULONGEST
regcache_raw_get_unsigned_by_name (struct regcache
*regcache
,
149 #endif /* GDBSERVER_REGCACHE_H */