[PATCH 7/57][Arm][GAS] Add support for MVE instructions: vstr/vldr
[binutils-gdb.git] / gdb / trad-frame.c
blobd9114753c5e2ba9ab00e9f188bdccc7bdfae43a2
1 /* Traditional frame unwind support, for GDB the GNU Debugger.
3 Copyright (C) 2003-2019 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #include "defs.h"
21 #include "frame.h"
22 #include "trad-frame.h"
23 #include "regcache.h"
24 #include "frame-unwind.h"
25 #include "target.h"
26 #include "value.h"
28 struct trad_frame_cache
30 struct frame_info *this_frame;
31 CORE_ADDR this_base;
32 struct trad_frame_saved_reg *prev_regs;
33 struct frame_id this_id;
36 struct trad_frame_cache *
37 trad_frame_cache_zalloc (struct frame_info *this_frame)
39 struct trad_frame_cache *this_trad_cache;
41 this_trad_cache = FRAME_OBSTACK_ZALLOC (struct trad_frame_cache);
42 this_trad_cache->prev_regs = trad_frame_alloc_saved_regs (this_frame);
43 this_trad_cache->this_frame = this_frame;
44 return this_trad_cache;
47 /* See trad-frame.h. */
49 void
50 trad_frame_reset_saved_regs (struct gdbarch *gdbarch,
51 struct trad_frame_saved_reg *regs)
53 int numregs = gdbarch_num_cooked_regs (gdbarch);
54 for (int regnum = 0; regnum < numregs; regnum++)
56 regs[regnum].realreg = regnum;
57 regs[regnum].addr = -1;
61 struct trad_frame_saved_reg *
62 trad_frame_alloc_saved_regs (struct gdbarch *gdbarch)
64 int numregs = gdbarch_num_cooked_regs (gdbarch);
65 struct trad_frame_saved_reg *this_saved_regs
66 = FRAME_OBSTACK_CALLOC (numregs, struct trad_frame_saved_reg);
68 trad_frame_reset_saved_regs (gdbarch, this_saved_regs);
69 return this_saved_regs;
72 /* A traditional frame is unwound by analysing the function prologue
73 and using the information gathered to track registers. For
74 non-optimized frames, the technique is reliable (just need to check
75 for all potential instruction sequences). */
77 struct trad_frame_saved_reg *
78 trad_frame_alloc_saved_regs (struct frame_info *this_frame)
80 struct gdbarch *gdbarch = get_frame_arch (this_frame);
82 return trad_frame_alloc_saved_regs (gdbarch);
85 enum { TF_REG_VALUE = -1, TF_REG_UNKNOWN = -2 };
87 int
88 trad_frame_value_p (struct trad_frame_saved_reg this_saved_regs[], int regnum)
90 return (this_saved_regs[regnum].realreg == TF_REG_VALUE);
93 int
94 trad_frame_addr_p (struct trad_frame_saved_reg this_saved_regs[], int regnum)
96 return (this_saved_regs[regnum].realreg >= 0
97 && this_saved_regs[regnum].addr != -1);
101 trad_frame_realreg_p (struct trad_frame_saved_reg this_saved_regs[],
102 int regnum)
104 return (this_saved_regs[regnum].realreg >= 0
105 && this_saved_regs[regnum].addr == -1);
108 void
109 trad_frame_set_value (struct trad_frame_saved_reg this_saved_regs[],
110 int regnum, LONGEST val)
112 /* Make the REALREG invalid, indicating that the ADDR contains the
113 register's value. */
114 this_saved_regs[regnum].realreg = TF_REG_VALUE;
115 this_saved_regs[regnum].addr = val;
118 /* See trad-frame.h. */
120 void
121 trad_frame_set_realreg (struct trad_frame_saved_reg this_saved_regs[],
122 int regnum, int realreg)
124 this_saved_regs[regnum].realreg = realreg;
125 this_saved_regs[regnum].addr = -1;
128 /* See trad-frame.h. */
130 void
131 trad_frame_set_addr (struct trad_frame_saved_reg this_saved_regs[],
132 int regnum, CORE_ADDR addr)
134 this_saved_regs[regnum].realreg = regnum;
135 this_saved_regs[regnum].addr = addr;
138 void
139 trad_frame_set_reg_value (struct trad_frame_cache *this_trad_cache,
140 int regnum, LONGEST val)
142 /* External interface for users of trad_frame_cache
143 (who cannot access the prev_regs object directly). */
144 trad_frame_set_value (this_trad_cache->prev_regs, regnum, val);
147 void
148 trad_frame_set_reg_realreg (struct trad_frame_cache *this_trad_cache,
149 int regnum, int realreg)
151 trad_frame_set_realreg (this_trad_cache->prev_regs, regnum, realreg);
154 void
155 trad_frame_set_reg_addr (struct trad_frame_cache *this_trad_cache,
156 int regnum, CORE_ADDR addr)
158 trad_frame_set_addr (this_trad_cache->prev_regs, regnum, addr);
161 void
162 trad_frame_set_reg_regmap (struct trad_frame_cache *this_trad_cache,
163 const struct regcache_map_entry *regmap,
164 CORE_ADDR addr, size_t size)
166 struct gdbarch *gdbarch = get_frame_arch (this_trad_cache->this_frame);
167 int offs = 0, count;
169 for (; (count = regmap->count) != 0; regmap++)
171 int regno = regmap->regno;
172 int slot_size = regmap->size;
174 if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
175 slot_size = register_size (gdbarch, regno);
177 if (offs + slot_size > size)
178 break;
180 if (regno == REGCACHE_MAP_SKIP)
181 offs += count * slot_size;
182 else
183 for (; count--; regno++, offs += slot_size)
185 /* Mimic the semantics of regcache::transfer_regset if a
186 register slot's size does not match the size of a
187 register.
189 If a register slot is larger than a register, assume
190 the register's value is stored in the first N bytes of
191 the slot and ignore the remaining bytes.
193 If the register slot is smaller than the register,
194 assume that the slot contains the low N bytes of the
195 register's value. Since trad_frame assumes that
196 registers stored by address are sized according to the
197 register, read the low N bytes and zero-extend them to
198 generate a register value. */
199 if (slot_size >= register_size (gdbarch, regno))
200 trad_frame_set_reg_addr (this_trad_cache, regno, addr + offs);
201 else
203 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
204 gdb_byte buf[slot_size];
206 if (target_read_memory (addr + offs, buf, sizeof buf) == 0)
208 LONGEST val
209 = extract_unsigned_integer (buf, sizeof buf, byte_order);
210 trad_frame_set_reg_value (this_trad_cache, regno, val);
217 void
218 trad_frame_set_unknown (struct trad_frame_saved_reg this_saved_regs[],
219 int regnum)
221 /* Make the REALREG invalid, indicating that the value is not known. */
222 this_saved_regs[regnum].realreg = TF_REG_UNKNOWN;
223 this_saved_regs[regnum].addr = -1;
226 struct value *
227 trad_frame_get_prev_register (struct frame_info *this_frame,
228 struct trad_frame_saved_reg this_saved_regs[],
229 int regnum)
231 if (trad_frame_addr_p (this_saved_regs, regnum))
232 /* The register was saved in memory. */
233 return frame_unwind_got_memory (this_frame, regnum,
234 this_saved_regs[regnum].addr);
235 else if (trad_frame_realreg_p (this_saved_regs, regnum))
236 return frame_unwind_got_register (this_frame, regnum,
237 this_saved_regs[regnum].realreg);
238 else if (trad_frame_value_p (this_saved_regs, regnum))
239 /* The register's value is available. */
240 return frame_unwind_got_constant (this_frame, regnum,
241 this_saved_regs[regnum].addr);
242 else
243 return frame_unwind_got_optimized (this_frame, regnum);
246 struct value *
247 trad_frame_get_register (struct trad_frame_cache *this_trad_cache,
248 struct frame_info *this_frame,
249 int regnum)
251 return trad_frame_get_prev_register (this_frame, this_trad_cache->prev_regs,
252 regnum);
255 void
256 trad_frame_set_id (struct trad_frame_cache *this_trad_cache,
257 struct frame_id this_id)
259 this_trad_cache->this_id = this_id;
262 void
263 trad_frame_get_id (struct trad_frame_cache *this_trad_cache,
264 struct frame_id *this_id)
266 (*this_id) = this_trad_cache->this_id;
269 void
270 trad_frame_set_this_base (struct trad_frame_cache *this_trad_cache,
271 CORE_ADDR this_base)
273 this_trad_cache->this_base = this_base;
276 CORE_ADDR
277 trad_frame_get_this_base (struct trad_frame_cache *this_trad_cache)
279 return this_trad_cache->this_base;