1 /* Register support routines for the remote server for GDB. 2 Copyright (C) 2001-2024 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 24 struct thread_info; 25 struct target_desc; 26 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. */ 30 31 struct regcache : public reg_buffer_common 32 { 33 /* The regcache's target description. */ 34 const struct target_desc *tdesc = nullptr; 35 36 /* Whether the REGISTERS buffer's contents are fetched. If false, 37 we haven't fetched the registers from the target yet. Note that 38 this register cache is _not_ pass-through, unlike GDB's. Also, 39 note that "fetched" here is unrelated to whether the registers 40 are available in a traceframe. For that, check REGISTER_STATUS 41 below. */ 42 bool registers_fetched = false; 43 bool registers_owned = false; 44 unsigned char *registers = nullptr; 45 #ifndef IN_PROCESS_AGENT 46 /* One of REG_UNAVAILABLE or REG_VALID. */ 47 unsigned char *register_status = nullptr; 48 #endif 49 50 /* See gdbsupport/common-regcache.h. */ 51 enum register_status get_register_status (int regnum) const override; 52 53 /* See gdbsupport/common-regcache.h. */ 54 void raw_supply (int regnum, gdb::array_view<const gdb_byte> src) override; 55 56 /* See gdbsupport/common-regcache.h. */ 57 void raw_supply_part_zeroed (int regnum, int offset, size_t size) override; 58 59 /* See gdbsupport/common-regcache.h. */ 60 void raw_collect (int regnum, gdb::array_view<gdb_byte> dst) const override; 61 62 /* See gdbsupport/common-regcache.h. */ 63 bool raw_compare (int regnum, const void *buf, int offset) const override; 64 65 /* Copy the contents of SRC into this regcache. */ 66 void copy_from (regcache *src); 67 }; 68 69 struct regcache *init_register_cache (struct regcache *regcache, 70 const struct target_desc *tdesc, 71 unsigned char *regbuf); 72 73 /* Create a new register cache for INFERIOR. */ 74 75 struct regcache *new_register_cache (const struct target_desc *tdesc); 76 77 regcache *get_thread_regcache (thread_info *thread, bool fetch = true); 78 79 /* Release all memory associated with the register cache for INFERIOR. */ 80 81 void free_register_cache (struct regcache *regcache); 82 83 /* Invalidate cached registers for one thread. */ 84 85 void regcache_invalidate_thread (thread_info *); 86 87 /* Invalidate cached registers for all threads of the given process. */ 88 89 void regcache_invalidate_pid (int pid); 90 91 /* Invalidate cached registers for all threads of the current 92 process. */ 93 94 void regcache_invalidate (void); 95 96 /* Invalidate and release the register cache of all threads of the 97 current process. */ 98 99 void regcache_release (void); 100 101 /* Convert all registers to a string in the currently specified remote 102 format. */ 103 104 void registers_to_string (struct regcache *regcache, char *buf); 105 106 /* Convert a string to register values and fill our register cache. */ 107 108 void registers_from_string (struct regcache *regcache, char *buf); 109 110 /* For regcache_read_pc see gdbsupport/common-regcache.h. */ 111 112 void regcache_write_pc (struct regcache *regcache, CORE_ADDR pc); 113 114 int register_cache_size (const struct target_desc *tdesc); 115 116 int register_size (const struct target_desc *tdesc, int n); 117 118 /* No throw version of find_regno. If NAME is not a known register, return 119 an empty value. */ 120 std::optional<int> find_regno_no_throw (const struct target_desc *tdesc, 121 const char *name); 122 123 int find_regno (const struct target_desc *tdesc, const char *name); 124 125 void supply_register (struct regcache *regcache, int n, const void *buf); 126 127 void supply_register_zeroed (struct regcache *regcache, int n); 128 129 void supply_register_by_name (struct regcache *regcache, 130 const char *name, const void *buf); 131 132 void supply_register_by_name_zeroed (struct regcache *regcache, 133 const char *name); 134 135 void supply_regblock (struct regcache *regcache, const void *buf); 136 137 void collect_register (struct regcache *regcache, int n, void *buf); 138 139 void collect_register_as_string (struct regcache *regcache, int n, char *buf); 140 141 void collect_register_by_name (struct regcache *regcache, 142 const char *name, void *buf); 143 144 /* Read a raw register as an unsigned integer. Convenience wrapper 145 around regcache_raw_get_unsigned that takes a register name instead 146 of a register number. */ 147 148 ULONGEST regcache_raw_get_unsigned_by_name (struct regcache *regcache, 149 const char *name); 150 151 #endif /* GDBSERVER_REGCACHE_H */ 152