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