GDB (xrefs)
Loading...
Searching...
No Matches
alpha-mdebug-tdep.c
Go to the documentation of this file.
1/* Target-dependent mdebug code for the ALPHA architecture.
2 Copyright (C) 1993-2023 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#include "defs.h"
20#include "frame.h"
21#include "frame-unwind.h"
22#include "frame-base.h"
23#include "symtab.h"
24#include "gdbcore.h"
25#include "block.h"
26#include "trad-frame.h"
27
28#include "alpha-tdep.h"
29#include "mdebugread.h"
30#include "gdbarch.h"
31
32/* FIXME: Some of this code should perhaps be merged with mips. */
33
34/* *INDENT-OFF* */
35/* Layout of a stack frame on the alpha:
36
37 | |
38 pdr members: | 7th ... nth arg, |
39 | `pushed' by caller. |
40 | |
41----------------|-------------------------------|<-- old_sp == vfp
42 ^ ^ ^ ^ | |
43 | | | | | |
44 | |localoff | Copies of 1st .. 6th |
45 | | | | | argument if necessary. |
46 | | | v | |
47 | | | --- |-------------------------------|<-- LOCALS_ADDRESS
48 | | | | |
49 | | | | Locals and temporaries. |
50 | | | | |
51 | | | |-------------------------------|
52 | | | | |
53 |-fregoffset | Saved float registers. |
54 | | | | F9 |
55 | | | | . |
56 | | | | . |
57 | | | | F2 |
58 | | v | |
59 | | -------|-------------------------------|
60 | | | |
61 | | | Saved registers. |
62 | | | S6 |
63 |-regoffset | . |
64 | | | . |
65 | | | S0 |
66 | | | pdr.pcreg |
67 | v | |
68 | ----------|-------------------------------|
69 | | |
70 frameoffset | Argument build area, gets |
71 | | 7th ... nth arg for any |
72 | | called procedure. |
73 v | |
74 -------------|-------------------------------|<-- sp
75 | |
76*/
77/* *INDENT-ON* */
78
79#define PROC_LOW_ADDR(proc) ((proc)->pdr.adr)
80#define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
81#define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
82#define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
83#define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
84#define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
85#define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
86#define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
87#define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
88
89/* Locate the mdebug PDR for the given PC. Return null if one can't
90 be found; you'll have to fall back to other methods in that case. */
91
92static struct mdebug_extra_func_info *
93find_proc_desc (CORE_ADDR pc)
94{
95 const struct block *b = block_for_pc (pc);
96 struct mdebug_extra_func_info *proc_desc = NULL;
97 struct symbol *sym = NULL;
98 const char *sh_name = NULL;
99
100 if (b)
101 {
102 CORE_ADDR startaddr;
103 find_pc_partial_function (pc, &sh_name, &startaddr, NULL);
104
105 if (startaddr > b->start ())
106 /* This is the "pathological" case referred to in a comment in
107 print_frame_info. It might be better to move this check into
108 symbol reading. */
109 sym = NULL;
110 else
112 0).symbol;
113 }
114
115 if (sym)
116 {
117 proc_desc = (struct mdebug_extra_func_info *) sym->value_bytes ();
118
119 /* Correct incorrect setjmp procedure descriptor from the library
120 to make backtrace through setjmp work. */
121 if (proc_desc->pdr.pcreg == 0
122 && strcmp (sh_name, "setjmp") == 0)
123 {
124 proc_desc->pdr.pcreg = ALPHA_RA_REGNUM;
125 proc_desc->pdr.regmask = 0x80000000;
126 proc_desc->pdr.regoffset = -4;
127 }
128
129 /* If we never found a PDR for this function in symbol reading,
130 then examine prologues to find the information. */
131 if (proc_desc->pdr.framereg == -1)
132 proc_desc = NULL;
133 }
134
135 return proc_desc;
136}
137
138/* Return a non-zero result if the function is frameless; zero otherwise. */
139
140static int
142{
143 return (PROC_FRAME_REG (proc_desc) == ALPHA_SP_REGNUM
144 && PROC_FRAME_OFFSET (proc_desc) == 0);
145}
146
147/* This returns the PC of the first inst after the prologue. If we can't
148 find the prologue, then return 0. */
149
150static CORE_ADDR
152 struct mdebug_extra_func_info *proc_desc)
153{
154 if (proc_desc)
155 {
156 /* If function is frameless, then we need to do it the hard way. I
157 strongly suspect that frameless always means prologueless... */
158 if (alpha_mdebug_frameless (proc_desc))
159 return 0;
160 }
161
162 return alpha_after_prologue (pc);
163}
164
165/* Return non-zero if we *might* be in a function prologue. Return zero
166 if we are definitively *not* in a function prologue. */
167
168static int
170 struct mdebug_extra_func_info *proc_desc)
171{
172 CORE_ADDR after_prologue_pc = alpha_mdebug_after_prologue (pc, proc_desc);
173 return (after_prologue_pc == 0 || pc < after_prologue_pc);
174}
175
176
177/* Frame unwinder that reads mdebug PDRs. */
178
180{
182 CORE_ADDR vfp;
184};
185
186/* Extract all of the information about the frame from PROC_DESC
187 and store the resulting register save locations in the structure. */
188
189static struct alpha_mdebug_unwind_cache *
191 void **this_prologue_cache)
192{
193 struct alpha_mdebug_unwind_cache *info;
194 struct mdebug_extra_func_info *proc_desc;
195 ULONGEST vfp;
196 CORE_ADDR pc, reg_position;
197 unsigned long mask;
198 int ireg, returnreg;
199
200 if (*this_prologue_cache)
201 return (struct alpha_mdebug_unwind_cache *) *this_prologue_cache;
202
204 *this_prologue_cache = info;
205 pc = get_frame_address_in_block (this_frame);
206
207 /* ??? We don't seem to be able to cache the lookup of the PDR
208 from alpha_mdebug_frame_p. It'd be nice if we could change
209 the arguments to that function. Oh well. */
210 proc_desc = find_proc_desc (pc);
211 info->proc_desc = proc_desc;
212 gdb_assert (proc_desc != NULL);
213
214 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
215
216 /* The VFP of the frame is at FRAME_REG+FRAME_OFFSET. */
217 vfp = get_frame_register_unsigned (this_frame, PROC_FRAME_REG (proc_desc));
218 vfp += PROC_FRAME_OFFSET (info->proc_desc);
219 info->vfp = vfp;
220
221 /* Fill in the offsets for the registers which gen_mask says were saved. */
222
223 reg_position = vfp + PROC_REG_OFFSET (proc_desc);
224 mask = PROC_REG_MASK (proc_desc);
225 returnreg = PROC_PC_REG (proc_desc);
226
227 /* Note that RA is always saved first, regardless of its actual
228 register number. */
229 if (mask & (1 << returnreg))
230 {
231 /* Clear bit for RA so we don't save it again later. */
232 mask &= ~(1 << returnreg);
233
234 info->saved_regs[returnreg].set_addr (reg_position);
235 reg_position += 8;
236 }
237
238 for (ireg = 0; ireg <= 31; ++ireg)
239 if (mask & (1 << ireg))
240 {
241 info->saved_regs[ireg].set_addr (reg_position);
242 reg_position += 8;
243 }
244
245 reg_position = vfp + PROC_FREG_OFFSET (proc_desc);
246 mask = PROC_FREG_MASK (proc_desc);
247
248 for (ireg = 0; ireg <= 31; ++ireg)
249 if (mask & (1 << ireg))
250 {
251 info->saved_regs[ALPHA_FP0_REGNUM + ireg].set_addr (reg_position);
252 reg_position += 8;
253 }
254
255 /* The stack pointer of the previous frame is computed by popping
256 the current stack frame. */
257 if (!info->saved_regs[ALPHA_SP_REGNUM].is_addr ())
258 info->saved_regs[ALPHA_SP_REGNUM].set_value (vfp);
259
260 return info;
261}
262
263/* Given a GDB frame, determine the address of the calling function's
264 frame. This will be used to create a new GDB frame struct. */
265
266static void
268 void **this_prologue_cache,
269 struct frame_id *this_id)
270{
271 struct alpha_mdebug_unwind_cache *info
272 = alpha_mdebug_frame_unwind_cache (this_frame, this_prologue_cache);
273
274 *this_id = frame_id_build (info->vfp, get_frame_func (this_frame));
275}
276
277/* Retrieve the value of REGNUM in FRAME. Don't give up! */
278
279static struct value *
281 void **this_prologue_cache, int regnum)
282{
283 struct alpha_mdebug_unwind_cache *info
284 = alpha_mdebug_frame_unwind_cache (this_frame, this_prologue_cache);
285
286 /* The PC of the previous frame is stored in the link register of
287 the current frame. Frob regnum so that we pull the value from
288 the correct place. */
289 if (regnum == ALPHA_PC_REGNUM)
290 regnum = PROC_PC_REG (info->proc_desc);
291
292 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
293}
294
295/* Return a non-zero result if the size of the stack frame exceeds the
296 maximum debuggable frame size (512 Kbytes); zero otherwise. */
297
298static int
300{
301 /* If frame offset is null, we can be in two cases: either the
302 function is frameless (the stack frame is null) or its
303 frame exceeds the maximum debuggable frame size (512 Kbytes). */
304
305 return (PROC_FRAME_OFFSET (proc_desc) == 0
307}
308
309static int
311 frame_info_ptr this_frame,
312 void **this_cache)
313{
314 CORE_ADDR pc = get_frame_address_in_block (this_frame);
315 struct mdebug_extra_func_info *proc_desc;
316
317 /* If this PC does not map to a PDR, then clearly this isn't an
318 mdebug frame. */
319 proc_desc = find_proc_desc (pc);
320 if (proc_desc == NULL)
321 return 0;
322
323 /* If we're in the prologue, the PDR for this frame is not yet valid.
324 Say no here and we'll fall back on the heuristic unwinder. */
325 if (alpha_mdebug_in_prologue (pc, proc_desc))
326 return 0;
327
328 /* If the maximum debuggable frame size has been exceeded, the
329 proc desc is bogus. Fall back on the heuristic unwinder. */
331 return 0;
332
333 return 1;
334}
335
337{
338 "alpha mdebug",
343 NULL,
345};
346
347static CORE_ADDR
349 void **this_prologue_cache)
350{
351 struct alpha_mdebug_unwind_cache *info
352 = alpha_mdebug_frame_unwind_cache (this_frame, this_prologue_cache);
353
354 return info->vfp;
355}
356
357static CORE_ADDR
359 void **this_prologue_cache)
360{
361 struct alpha_mdebug_unwind_cache *info
362 = alpha_mdebug_frame_unwind_cache (this_frame, this_prologue_cache);
363
364 return info->vfp - PROC_LOCALOFF (info->proc_desc);
365}
366
367static CORE_ADDR
369 void **this_prologue_cache)
370{
371 struct alpha_mdebug_unwind_cache *info
372 = alpha_mdebug_frame_unwind_cache (this_frame, this_prologue_cache);
373
374 return info->vfp - ALPHA_NUM_ARG_REGS * 8;
375}
376
377static const struct frame_base alpha_mdebug_frame_base = {
382};
383
384static const struct frame_base *
386{
387 CORE_ADDR pc = get_frame_address_in_block (this_frame);
388 struct mdebug_extra_func_info *proc_desc;
389
390 /* If this PC does not map to a PDR, then clearly this isn't an
391 mdebug frame. */
392 proc_desc = find_proc_desc (pc);
393 if (proc_desc == NULL)
394 return NULL;
395
396 /* If the maximum debuggable frame size has been exceeded, the
397 proc desc is bogus. Fall back on the heuristic unwinder. */
399 return 0;
400
402}
403
404
405void
407{
410}
int regnum
#define PROC_FREG_OFFSET(proc)
void alpha_mdebug_init_abi(struct gdbarch_info info, struct gdbarch *gdbarch)
static CORE_ADDR alpha_mdebug_after_prologue(CORE_ADDR pc, struct mdebug_extra_func_info *proc_desc)
static int alpha_mdebug_max_frame_size_exceeded(struct mdebug_extra_func_info *proc_desc)
#define PROC_REG_MASK(proc)
static CORE_ADDR alpha_mdebug_frame_args_address(frame_info_ptr this_frame, void **this_prologue_cache)
#define PROC_FREG_MASK(proc)
#define PROC_LOCALOFF(proc)
static CORE_ADDR alpha_mdebug_frame_locals_address(frame_info_ptr this_frame, void **this_prologue_cache)
static const struct frame_base * alpha_mdebug_frame_base_sniffer(frame_info_ptr this_frame)
static CORE_ADDR alpha_mdebug_frame_base_address(frame_info_ptr this_frame, void **this_prologue_cache)
static int alpha_mdebug_frameless(struct mdebug_extra_func_info *proc_desc)
static struct value * alpha_mdebug_frame_prev_register(frame_info_ptr this_frame, void **this_prologue_cache, int regnum)
static int alpha_mdebug_frame_sniffer(const struct frame_unwind *self, frame_info_ptr this_frame, void **this_cache)
static void alpha_mdebug_frame_this_id(frame_info_ptr this_frame, void **this_prologue_cache, struct frame_id *this_id)
#define PROC_FRAME_OFFSET(proc)
static struct alpha_mdebug_unwind_cache * alpha_mdebug_frame_unwind_cache(frame_info_ptr this_frame, void **this_prologue_cache)
#define PROC_PC_REG(proc)
#define PROC_FRAME_REG(proc)
static const struct frame_unwind alpha_mdebug_frame_unwind
static const struct frame_base alpha_mdebug_frame_base
static int alpha_mdebug_in_prologue(CORE_ADDR pc, struct mdebug_extra_func_info *proc_desc)
static struct mdebug_extra_func_info * find_proc_desc(CORE_ADDR pc)
#define PROC_REG_OFFSET(proc)
#define ALPHA_PC_REGNUM
Definition alpha-tdep.h:52
#define ALPHA_SP_REGNUM
Definition alpha-tdep.h:47
#define ALPHA_FP0_REGNUM
Definition alpha-tdep.h:49
#define ALPHA_NUM_ARG_REGS
Definition alpha-tdep.h:70
CORE_ADDR alpha_after_prologue(CORE_ADDR pc)
#define ALPHA_RA_REGNUM
Definition alpha-tdep.h:44
const struct block * block_for_pc(CORE_ADDR pc)
Definition block.c:283
bool find_pc_partial_function(CORE_ADDR pc, const char **name, CORE_ADDR *address, CORE_ADDR *endaddr, const struct block **block)
Definition blockframe.c:373
void frame_base_append_sniffer(struct gdbarch *gdbarch, frame_base_sniffer_ftype *sniffer)
Definition frame-base.c:81
enum unwind_stop_reason default_frame_unwind_stop_reason(frame_info_ptr this_frame, void **this_cache)
void frame_unwind_append_unwinder(struct gdbarch *gdbarch, const struct frame_unwind *unwinder)
ULONGEST get_frame_register_unsigned(frame_info_ptr frame, int regnum)
Definition frame.c:1351
struct frame_id frame_id_build(CORE_ADDR stack_addr, CORE_ADDR code_addr)
Definition frame.c:713
CORE_ADDR get_frame_func(frame_info_ptr this_frame)
Definition frame.c:1050
CORE_ADDR get_frame_address_in_block(frame_info_ptr this_frame)
Definition frame.c:2622
@ NORMAL_FRAME
Definition frame.h:179
#define FRAME_OBSTACK_ZALLOC(TYPE)
Definition frame.h:608
#define MDEBUG_EFI_SYMBOL_NAME
Definition mdebugread.h:38
struct mdebug_extra_func_info * proc_desc
trad_frame_saved_reg * saved_regs
struct symbol * symbol
Definition symtab.h:1494
Definition block.h:109
CORE_ADDR start() const
Definition block.h:111
const gdb_byte * value_bytes() const
Definition symtab.h:1328
Definition value.c:181
struct block_symbol lookup_symbol(const char *name, const struct block *block, domain_enum domain, struct field_of_this_result *is_a_field_of_this)
Definition symtab.c:1967
@ LABEL_DOMAIN
Definition symtab.h:895
trad_frame_saved_reg * trad_frame_alloc_saved_regs(struct gdbarch *gdbarch)
Definition trad-frame.c:62
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