1 /* Traditional frame unwind support, for GDB the GNU Debugger. 2 3 Copyright (C) 2003-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 #ifndef TRAD_FRAME_H 21 #define TRAD_FRAME_H 22 23 #include "frame.h" /* For "struct frame_id". */ 24 25 class frame_info_ptr; 26 struct regcache_map_entry; 27 struct trad_frame_cache; 28 29 /* A simple, or traditional frame cache. 30 31 The entire cache is populated in a single pass and then generic 32 routines are used to extract the various cache values. */ 33 34 struct trad_frame_cache *trad_frame_cache_zalloc (frame_info_ptr); 35 36 /* This frame's ID. */ 37 void trad_frame_set_id (struct trad_frame_cache *this_trad_cache, 38 struct frame_id this_id); 39 void trad_frame_get_id (struct trad_frame_cache *this_trad_cache, 40 struct frame_id *this_id); 41 void trad_frame_set_this_base (struct trad_frame_cache *this_trad_cache, 42 CORE_ADDR this_base); 43 CORE_ADDR trad_frame_get_this_base (struct trad_frame_cache *this_trad_cache); 44 45 void trad_frame_set_reg_realreg (struct trad_frame_cache *this_trad_cache, 46 int regnum, int realreg); 47 void trad_frame_set_reg_addr (struct trad_frame_cache *this_trad_cache, 48 int regnum, CORE_ADDR addr); 49 void trad_frame_set_reg_regmap (struct trad_frame_cache *this_trad_cache, 50 const struct regcache_map_entry *regmap, 51 CORE_ADDR addr, size_t size); 52 void trad_frame_set_reg_value (struct trad_frame_cache *this_cache, 53 int regnum, LONGEST val); 54 55 /* Given the cache in THIS_TRAD_CACHE, set the value of REGNUM to the bytes 56 contained in BYTES with size SIZE. */ 57 void trad_frame_set_reg_value_bytes (struct trad_frame_cache *this_trad_cache, 58 int regnum, 59 gdb::array_view<const gdb_byte> bytes); 60 61 struct value *trad_frame_get_register (struct trad_frame_cache *this_trad_cache, 62 frame_info_ptr this_frame, 63 int regnum); 64 65 /* Describes the kind of encoding a stored register has. */ 66 enum class trad_frame_saved_reg_kind 67 { 68 /* Register value is unknown. */ 69 UNKNOWN = 0, 70 /* Register value is a constant. */ 71 VALUE, 72 /* Register value is in another register. */ 73 REALREG, 74 /* Register value is at an address. */ 75 ADDR, 76 /* Register value is a sequence of bytes. */ 77 VALUE_BYTES 78 }; 79 80 /* A struct that describes a saved register in a frame. */ 81 82 struct trad_frame_saved_reg 83 { 84 /* Setters */ 85 86 /* Encode that the saved register's value is constant VAL in the 87 trad-frame. */ 88 void set_value (LONGEST val) 89 { 90 m_kind = trad_frame_saved_reg_kind::VALUE; 91 m_reg.value = val; 92 } 93 94 /* Encode that the saved register's value is stored in register REALREG. */ 95 void set_realreg (int realreg) 96 { 97 m_kind = trad_frame_saved_reg_kind::REALREG; 98 m_reg.realreg = realreg; 99 } 100 101 /* Encode that the saved register's value is stored in memory at ADDR. */ 102 void set_addr (LONGEST addr) 103 { 104 m_kind = trad_frame_saved_reg_kind::ADDR; 105 m_reg.addr = addr; 106 } 107 108 /* Encode that the saved register's value is unknown. */ 109 void set_unknown () 110 { 111 m_kind = trad_frame_saved_reg_kind::UNKNOWN; 112 } 113 114 /* Encode that the saved register's value is stored as a sequence of bytes. 115 This is useful when the value is larger than what primitive types 116 can hold. */ 117 void set_value_bytes (gdb::array_view<const gdb_byte> bytes) 118 { 119 /* Allocate the space and copy the data bytes. */ 120 gdb_byte *data = FRAME_OBSTACK_CALLOC (bytes.size (), gdb_byte); 121 memcpy (data, bytes.data (), bytes.size ()); 122 123 m_kind = trad_frame_saved_reg_kind::VALUE_BYTES; 124 m_reg.value_bytes = data; 125 } 126 127 /* Getters */ 128 129 LONGEST value () const 130 { 131 gdb_assert (m_kind == trad_frame_saved_reg_kind::VALUE); 132 return m_reg.value; 133 } 134 135 int realreg () const 136 { 137 gdb_assert (m_kind == trad_frame_saved_reg_kind::REALREG); 138 return m_reg.realreg; 139 } 140 141 LONGEST addr () const 142 { 143 gdb_assert (m_kind == trad_frame_saved_reg_kind::ADDR); 144 return m_reg.addr; 145 } 146 147 const gdb_byte *value_bytes () const 148 { 149 gdb_assert (m_kind == trad_frame_saved_reg_kind::VALUE_BYTES); 150 return m_reg.value_bytes; 151 } 152 153 /* Convenience functions, return true if the register has been 154 encoded as specified. Return false otherwise. */ 155 bool is_value () const 156 { 157 return m_kind == trad_frame_saved_reg_kind::VALUE; 158 } 159 160 bool is_realreg () const 161 { 162 return m_kind == trad_frame_saved_reg_kind::REALREG; 163 } 164 165 bool is_addr () const 166 { 167 return m_kind == trad_frame_saved_reg_kind::ADDR; 168 } 169 170 bool is_unknown () const 171 { 172 return m_kind == trad_frame_saved_reg_kind::UNKNOWN; 173 } 174 175 bool is_value_bytes () const 176 { 177 return m_kind == trad_frame_saved_reg_kind::VALUE_BYTES; 178 } 179 180 private: 181 182 trad_frame_saved_reg_kind m_kind; 183 184 union { 185 LONGEST value; 186 int realreg; 187 LONGEST addr; 188 const gdb_byte *value_bytes; 189 } m_reg; 190 }; 191 192 /* Reset the saved regs cache, setting register values to REALREG. */ 193 void trad_frame_reset_saved_regs (struct gdbarch *gdbarch, 194 trad_frame_saved_reg *regs); 195 196 /* Return a freshly allocated (and initialized) trad_frame array. */ 197 trad_frame_saved_reg *trad_frame_alloc_saved_regs (frame_info_ptr); 198 trad_frame_saved_reg *trad_frame_alloc_saved_regs (struct gdbarch *); 199 200 /* Given the trad_frame info, return the location of the specified 201 register. */ 202 struct value *trad_frame_get_prev_register (frame_info_ptr this_frame, 203 trad_frame_saved_reg this_saved_regs[], 204 int regnum); 205 206 #endif 207