GDB (xrefs)
Loading...
Searching...
No Matches
trad-frame.c
Go to the documentation of this file.
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#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"
27#include "gdbarch.h"
28#include "gdbsupport/traits.h"
29
37
38struct trad_frame_cache *
40{
41 struct trad_frame_cache *this_trad_cache;
42
43 this_trad_cache = FRAME_OBSTACK_ZALLOC (struct trad_frame_cache);
45 this_trad_cache->this_frame = this_frame;
46 return this_trad_cache;
47}
48
49/* See trad-frame.h. */
50
51void
54{
55 int numregs = gdbarch_num_cooked_regs (gdbarch);
56
57 for (int regnum = 0; regnum < numregs; regnum++)
58 regs[regnum].set_realreg (regnum);
59}
60
63{
64#ifdef HAVE_IS_TRIVIALLY_CONSTRUCTIBLE
65 gdb_static_assert (std::is_trivially_constructible<trad_frame_saved_reg>::value);
66#endif
67
68 int numregs = gdbarch_num_cooked_regs (gdbarch);
69 trad_frame_saved_reg *this_saved_regs
71
72 /* For backwards compatibility, initialize all the register values to
73 REALREG, with register 0 stored in 0, register 1 stored in 1 and so
74 on. */
75 trad_frame_reset_saved_regs (gdbarch, this_saved_regs);
76
77 return this_saved_regs;
78}
79
80/* A traditional frame is unwound by analysing the function prologue
81 and using the information gathered to track registers. For
82 non-optimized frames, the technique is reliable (just need to check
83 for all potential instruction sequences). */
84
92
93void
95 int regnum, LONGEST val)
96{
97 /* External interface for users of trad_frame_cache
98 (who cannot access the prev_regs object directly). */
99 this_trad_cache->prev_regs[regnum].set_value (val);
100}
101
102void
104 int regnum, int realreg)
105{
106 this_trad_cache->prev_regs[regnum].set_realreg (realreg);
107}
108
109void
111 int regnum, CORE_ADDR addr)
112{
113 this_trad_cache->prev_regs[regnum].set_addr (addr);
114}
115
116void
118 const struct regcache_map_entry *regmap,
119 CORE_ADDR addr, size_t size)
120{
121 struct gdbarch *gdbarch = get_frame_arch (this_trad_cache->this_frame);
122 int offs = 0, count;
123
124 for (; (count = regmap->count) != 0; regmap++)
125 {
126 int regno = regmap->regno;
127 int slot_size = regmap->size;
128
129 if (slot_size == 0 && regno != REGCACHE_MAP_SKIP)
130 slot_size = register_size (gdbarch, regno);
131
132 if (offs + slot_size > size)
133 break;
134
135 if (regno == REGCACHE_MAP_SKIP)
136 offs += count * slot_size;
137 else
138 for (; count--; regno++, offs += slot_size)
139 {
140 /* Mimic the semantics of regcache::transfer_regset if a
141 register slot's size does not match the size of a
142 register.
143
144 If a register slot is larger than a register, assume
145 the register's value is stored in the first N bytes of
146 the slot and ignore the remaining bytes.
147
148 If the register slot is smaller than the register,
149 assume that the slot contains the low N bytes of the
150 register's value. Since trad_frame assumes that
151 registers stored by address are sized according to the
152 register, read the low N bytes and zero-extend them to
153 generate a register value. */
154 if (slot_size >= register_size (gdbarch, regno))
155 trad_frame_set_reg_addr (this_trad_cache, regno, addr + offs);
156 else
157 {
158 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
159 gdb_byte buf[slot_size];
160
161 if (target_read_memory (addr + offs, buf, sizeof buf) == 0)
162 {
163 LONGEST val
164 = extract_unsigned_integer (buf, sizeof buf, byte_order);
165 trad_frame_set_reg_value (this_trad_cache, regno, val);
166 }
167 }
168 }
169 }
170}
171
172/* See trad-frame.h. */
173
174void
176 int regnum,
177 gdb::array_view<const gdb_byte> bytes)
178{
179 /* External interface for users of trad_frame_cache
180 (who cannot access the prev_regs object directly). */
181 this_trad_cache->prev_regs[regnum].set_value_bytes (bytes);
182}
183
184
185
186struct value *
188 trad_frame_saved_reg this_saved_regs[],
189 int regnum)
190{
191 if (this_saved_regs[regnum].is_addr ())
192 /* The register was saved in memory. */
193 return frame_unwind_got_memory (this_frame, regnum,
194 this_saved_regs[regnum].addr ());
195 else if (this_saved_regs[regnum].is_realreg ())
196 return frame_unwind_got_register (this_frame, regnum,
197 this_saved_regs[regnum].realreg ());
198 else if (this_saved_regs[regnum].is_value ())
199 /* The register's value is available. */
200 return frame_unwind_got_constant (this_frame, regnum,
201 this_saved_regs[regnum].value ());
202 else if (this_saved_regs[regnum].is_value_bytes ())
203 /* The register's value is available as a sequence of bytes. */
204 return frame_unwind_got_bytes (this_frame, regnum,
205 this_saved_regs[regnum].value_bytes ());
206 else
207 return frame_unwind_got_optimized (this_frame, regnum);
208}
209
210struct value *
212 frame_info_ptr this_frame,
213 int regnum)
214{
215 return trad_frame_get_prev_register (this_frame, this_trad_cache->prev_regs,
216 regnum);
217}
218
219void
220trad_frame_set_id (struct trad_frame_cache *this_trad_cache,
221 struct frame_id this_id)
222{
223 this_trad_cache->this_id = this_id;
224}
225
226void
227trad_frame_get_id (struct trad_frame_cache *this_trad_cache,
228 struct frame_id *this_id)
229{
230 (*this_id) = this_trad_cache->this_id;
231}
232
233void
235 CORE_ADDR this_base)
236{
237 this_trad_cache->this_base = this_base;
238}
239
240CORE_ADDR
242{
243 return this_trad_cache->this_base;
244}
int regnum
gdb_static_assert(sizeof(splay_tree_key) >=sizeof(CORE_ADDR *))
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
Definition defs.h:480
struct value * frame_unwind_got_memory(frame_info_ptr frame, int regnum, CORE_ADDR addr)
struct value * frame_unwind_got_optimized(frame_info_ptr frame, int regnum)
struct value * frame_unwind_got_register(frame_info_ptr frame, int regnum, int new_regnum)
struct value * frame_unwind_got_bytes(frame_info_ptr frame, int regnum, const gdb_byte *buf)
struct value * frame_unwind_got_constant(frame_info_ptr frame, int regnum, ULONGEST val)
struct gdbarch * get_frame_arch(frame_info_ptr this_frame)
Definition frame.c:3027
#define FRAME_OBSTACK_CALLOC(NUMBER, TYPE)
Definition frame.h:827
#define FRAME_OBSTACK_ZALLOC(TYPE)
Definition frame.h:825
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
Definition gdbarch.c:1396
static int gdbarch_num_cooked_regs(gdbarch *arch)
Definition gdbarch.h:390
size_t size
Definition go32-nat.c:239
static int regmap[]
int register_size(struct gdbarch *gdbarch, int regnum)
Definition regcache.c:170
@ REGCACHE_MAP_SKIP
Definition regcache.h:121
Definition regcache.h:111
struct frame_id this_id
Definition trad-frame.c:35
CORE_ADDR this_base
Definition trad-frame.c:33
trad_frame_saved_reg * prev_regs
Definition trad-frame.c:34
frame_info_ptr this_frame
Definition trad-frame.c:32
void set_value_bytes(gdb::array_view< const gdb_byte > bytes)
Definition trad-frame.h:117
void set_realreg(int realreg)
Definition trad-frame.h:95
void set_addr(LONGEST addr)
Definition trad-frame.h:102
void set_value(LONGEST val)
Definition trad-frame.h:88
Definition value.h:130
int target_read_memory(CORE_ADDR memaddr, gdb_byte *myaddr, ssize_t len)
Definition target.c:1785
trad_frame_saved_reg * trad_frame_alloc_saved_regs(struct gdbarch *gdbarch)
Definition trad-frame.c:62
void trad_frame_set_reg_realreg(struct trad_frame_cache *this_trad_cache, int regnum, int realreg)
Definition trad-frame.c:103
void trad_frame_set_reg_value_bytes(struct trad_frame_cache *this_trad_cache, int regnum, gdb::array_view< const gdb_byte > bytes)
Definition trad-frame.c:175
struct value * trad_frame_get_prev_register(frame_info_ptr this_frame, trad_frame_saved_reg this_saved_regs[], int regnum)
Definition trad-frame.c:187
struct trad_frame_cache * trad_frame_cache_zalloc(frame_info_ptr this_frame)
Definition trad-frame.c:39
void trad_frame_set_reg_addr(struct trad_frame_cache *this_trad_cache, int regnum, CORE_ADDR addr)
Definition trad-frame.c:110
void trad_frame_set_reg_regmap(struct trad_frame_cache *this_trad_cache, const struct regcache_map_entry *regmap, CORE_ADDR addr, size_t size)
Definition trad-frame.c:117
void trad_frame_reset_saved_regs(struct gdbarch *gdbarch, trad_frame_saved_reg *regs)
Definition trad-frame.c:52
void trad_frame_get_id(struct trad_frame_cache *this_trad_cache, struct frame_id *this_id)
Definition trad-frame.c:227
void trad_frame_set_id(struct trad_frame_cache *this_trad_cache, struct frame_id this_id)
Definition trad-frame.c:220
CORE_ADDR trad_frame_get_this_base(struct trad_frame_cache *this_trad_cache)
Definition trad-frame.c:241
void trad_frame_set_this_base(struct trad_frame_cache *this_trad_cache, CORE_ADDR this_base)
Definition trad-frame.c:234
void trad_frame_set_reg_value(struct trad_frame_cache *this_trad_cache, int regnum, LONGEST val)
Definition trad-frame.c:94
struct value * trad_frame_get_register(struct trad_frame_cache *this_trad_cache, frame_info_ptr this_frame, int regnum)
Definition trad-frame.c:211