Debian Codegraph @

gdbserver/regcache.h

raw
1 /* Register support routines for the remote server for GDB.
2 Copyright (C) 2001-2025 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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/>. */
18
19 #ifndef GDBSERVER_REGCACHE_H
20 #define GDBSERVER_REGCACHE_H
21
22 #include "gdbsupport/common-regcache.h"
23 #include <memory>
24
25 struct thread_info;
26 struct target_desc;
27
28 /* The data for the register cache. Note that we have one per
29 inferior; this is primarily for simplicity, as the performance
30 benefit is minimal. */
31
32 struct regcache : public reg_buffer_common
33 {
34 /* The regcache's target description. */
35 const struct target_desc *tdesc = nullptr;
36
37 /* Whether the REGISTERS buffer's contents are fetched. If false,
38 we haven't fetched the registers from the target yet. Note that
39 this register cache is _not_ pass-through, unlike GDB's. Also,
40 note that "fetched" here is unrelated to whether the registers
41 are available in a traceframe. For that, check REGISTER_STATUS
42 below. */
43 bool registers_fetched = false;
44 bool registers_owned = false;
45 unsigned char *registers = nullptr;
46 #ifndef IN_PROCESS_AGENT
47 /* Construct a regcache using the register layout described by TDESC.
48
49 The regcache dynamically allocates its register buffer. */
50 regcache (const target_desc *tdesc);
51
52 /* Destructor. */
53 ~regcache ();
54 #endif
55
56 /* Construct a regcache using the register layout described by TDESC
57 and REGBUF as the register buffer.
58
59 The regcache does *not* take ownership of the buffer. */
60 regcache (const target_desc *tdesc, unsigned char *regbuf);
61
62 DISABLE_COPY_AND_ASSIGN (regcache);
63
64 /* Clear the register values to all zeros and set the register
65 statuses to STATUS. */
66 void reset (enum register_status status);
67
68 /* See gdbsupport/common-regcache.h. */
69 enum register_status get_register_status (int regnum) const override;
70
71 /* Set the status of register REGNUM to STATUS. */
72 void set_register_status (int regnum, enum register_status status);
73
74 /* See gdbsupport/common-regcache.h. */
75 int register_size (int regnum) const override;
76
77 /* See gdbsupport/common-regcache.h. */
78 void raw_supply (int regnum, gdb::array_view<const gdb_byte> src) override;
79
80 /* See gdbsupport/common-regcache.h. */
81 void raw_supply_part_zeroed (int regnum, int offset, size_t size) override;
82
83 /* See gdbsupport/common-regcache.h. */
84 void raw_collect (int regnum, gdb::array_view<gdb_byte> dst) const override;
85
86 /* See gdbsupport/common-regcache.h. */
87 bool raw_compare (int regnum, const void *buf, int offset) const override;
88
89 /* Copy the contents of SRC into this regcache. */
90 void copy_from (regcache *src);
91
92 private:
93
94 #ifndef IN_PROCESS_AGENT
95 /* See gdbsupport/common-regcache.h. */
96 std::unique_ptr<enum register_status[]> m_register_status;
97 #endif
98 };
99
100 regcache *get_thread_regcache (thread_info *thread, bool fetch = true);
101
102 /* Invalidate cached registers for one thread. */
103
104 void regcache_invalidate_thread (thread_info *);
105
106 /* Invalidate cached registers for all threads of the given process. */
107
108 void regcache_invalidate_pid (int pid);
109
110 /* Invalidate cached registers for all threads of the current
111 process. */
112
113 void regcache_invalidate (void);
114
115 /* Invalidate and release the register cache of all threads of the
116 current process. */
117
118 void regcache_release (void);
119
120 /* Convert all registers to a string in the currently specified remote
121 format. */
122
123 void registers_to_string (struct regcache *regcache, char *buf);
124
125 /* Convert a string to register values and fill our register cache. */
126
127 void registers_from_string (struct regcache *regcache, char *buf);
128
129 /* For regcache_read_pc see gdbsupport/common-regcache.h. */
130
131 void regcache_write_pc (struct regcache *regcache, CORE_ADDR pc);
132
133 int register_cache_size (const struct target_desc *tdesc);
134
135 int register_size (const struct target_desc *tdesc, int n);
136
137 /* No throw version of find_regno. If NAME is not a known register, return
138 an empty value. */
139 std::optional<int> find_regno_no_throw (const struct target_desc *tdesc,
140 const char *name);
141
142 int find_regno (const struct target_desc *tdesc, const char *name);
143
144 void supply_register (struct regcache *regcache, int n, const void *buf);
145
146 void supply_register_zeroed (struct regcache *regcache, int n);
147
148 void supply_register_by_name (struct regcache *regcache,
149 const char *name, const void *buf);
150
151 void supply_register_by_name_zeroed (struct regcache *regcache,
152 const char *name);
153
154 void supply_regblock (struct regcache *regcache, const void *buf);
155
156 void collect_register (struct regcache *regcache, int n, void *buf);
157
158 void collect_register_as_string (struct regcache *regcache, int n, char *buf);
159
160 void collect_register_by_name (struct regcache *regcache,
161 const char *name, void *buf);
162
163 /* Read a raw register as an unsigned integer. Convenience wrapper
164 around regcache_raw_get_unsigned that takes a register name instead
165 of a register number. */
166
167 ULONGEST regcache_raw_get_unsigned_by_name (struct regcache *regcache,
168 const char *name);
169
170 #endif /* GDBSERVER_REGCACHE_H */