1 /* Target-dependent mdebug code for the ALPHA architecture.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 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 2 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "frame-unwind.h"
25 #include "frame-base.h"
34 #include "gdb_string.h"
38 #include "arch-utils.h"
41 #include "gdb_assert.h"
45 #include "alpha-tdep.h"
47 /* FIXME: Some of this code should perhaps be merged with mips. */
50 /* Layout of a stack frame on the alpha:
53 pdr members: | 7th ... nth arg, |
54 | `pushed' by caller. |
56 ----------------|-------------------------------|<-- old_sp == vfp
59 | |localoff | Copies of 1st .. 6th |
60 | | | | | argument if necessary. |
62 | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
64 | | | | Locals and temporaries. |
66 | | | |-------------------------------|
68 |-fregoffset | Saved float registers. |
74 | | -------|-------------------------------|
76 | | | Saved registers. |
83 | ----------|-------------------------------|
85 frameoffset | Argument build area, gets |
86 | | 7th ... nth arg for any |
87 | | called procedure. |
89 -------------|-------------------------------|<-- sp
94 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr)
95 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
96 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
97 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
98 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
99 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
100 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
101 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
102 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
104 /* Locate the mdebug PDR for the given PC. Return null if one can't
105 be found; you'll have to fall back to other methods in that case. */
107 static alpha_extra_func_info_t
108 find_proc_desc (CORE_ADDR pc
)
110 struct block
*b
= block_for_pc (pc
);
111 alpha_extra_func_info_t proc_desc
= NULL
;
112 struct symbol
*sym
= NULL
;
117 find_pc_partial_function (pc
, NULL
, &startaddr
, NULL
);
119 if (startaddr
> BLOCK_START (b
))
120 /* This is the "pathological" case referred to in a comment in
121 print_frame_info. It might be better to move this check into
125 sym
= lookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_DOMAIN
, 0, NULL
);
130 proc_desc
= (alpha_extra_func_info_t
) SYMBOL_VALUE (sym
);
132 /* If we never found a PDR for this function in symbol reading,
133 then examine prologues to find the information. */
134 if (proc_desc
->pdr
.framereg
== -1)
141 /* This returns the PC of the first inst after the prologue. If we can't
142 find the prologue, then return 0. */
145 alpha_mdebug_after_prologue (CORE_ADDR pc
, alpha_extra_func_info_t proc_desc
)
149 /* If function is frameless, then we need to do it the hard way. I
150 strongly suspect that frameless always means prologueless... */
151 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
152 && PROC_FRAME_OFFSET (proc_desc
) == 0)
156 return alpha_after_prologue (pc
);
159 /* Return non-zero if we *might* be in a function prologue. Return zero
160 if we are definitively *not* in a function prologue. */
163 alpha_mdebug_in_prologue (CORE_ADDR pc
, alpha_extra_func_info_t proc_desc
)
165 CORE_ADDR after_prologue_pc
= alpha_mdebug_after_prologue (pc
, proc_desc
);
166 return (after_prologue_pc
== 0 || pc
< after_prologue_pc
);
170 /* Frame unwinder that reads mdebug PDRs. */
172 struct alpha_mdebug_unwind_cache
174 alpha_extra_func_info_t proc_desc
;
176 CORE_ADDR
*saved_regs
;
179 /* Extract all of the information about the frame from PROC_DESC
180 and store the resulting register save locations in the structure. */
182 static struct alpha_mdebug_unwind_cache
*
183 alpha_mdebug_frame_unwind_cache (struct frame_info
*next_frame
,
184 void **this_prologue_cache
)
186 struct alpha_mdebug_unwind_cache
*info
;
187 alpha_extra_func_info_t proc_desc
;
189 CORE_ADDR pc
, reg_position
;
193 if (*this_prologue_cache
)
194 return *this_prologue_cache
;
196 info
= FRAME_OBSTACK_ZALLOC (struct alpha_mdebug_unwind_cache
);
197 *this_prologue_cache
= info
;
198 pc
= frame_pc_unwind (next_frame
);
200 /* ??? We don't seem to be able to cache the lookup of the PDR
201 from alpha_mdebug_frame_p. It'd be nice if we could change
202 the arguments to that function. Oh well. */
203 proc_desc
= find_proc_desc (pc
);
204 info
->proc_desc
= proc_desc
;
205 gdb_assert (proc_desc
!= NULL
);
207 info
->saved_regs
= frame_obstack_zalloc (SIZEOF_FRAME_SAVED_REGS
);
209 /* The VFP of the frame is at FRAME_REG+FRAME_OFFSET. */
210 frame_unwind_unsigned_register (next_frame
, PROC_FRAME_REG (proc_desc
), &vfp
);
211 vfp
+= PROC_FRAME_OFFSET (info
->proc_desc
);
214 /* Fill in the offsets for the registers which gen_mask says were saved. */
216 reg_position
= vfp
+ PROC_REG_OFFSET (proc_desc
);
217 mask
= PROC_REG_MASK (proc_desc
);
218 returnreg
= PROC_PC_REG (proc_desc
);
220 /* Note that RA is always saved first, regardless of its actual
222 if (mask
& (1 << returnreg
))
224 /* Clear bit for RA so we don't save it again later. */
225 mask
&= ~(1 << returnreg
);
227 info
->saved_regs
[returnreg
] = reg_position
;
231 for (ireg
= 0; ireg
<= 31; ++ireg
)
232 if (mask
& (1 << ireg
))
234 info
->saved_regs
[ireg
] = reg_position
;
238 reg_position
= vfp
+ PROC_FREG_OFFSET (proc_desc
);
239 mask
= PROC_FREG_MASK (proc_desc
);
241 for (ireg
= 0; ireg
<= 31; ++ireg
)
242 if (mask
& (1 << ireg
))
244 info
->saved_regs
[FP0_REGNUM
+ ireg
] = reg_position
;
251 /* Given a GDB frame, determine the address of the calling function's
252 frame. This will be used to create a new GDB frame struct. */
255 alpha_mdebug_frame_this_id (struct frame_info
*next_frame
,
256 void **this_prologue_cache
,
257 struct frame_id
*this_id
)
259 struct alpha_mdebug_unwind_cache
*info
260 = alpha_mdebug_frame_unwind_cache (next_frame
, this_prologue_cache
);
262 *this_id
= frame_id_build (info
->vfp
, frame_func_unwind (next_frame
));
265 /* Retrieve the value of REGNUM in FRAME. Don't give up! */
268 alpha_mdebug_frame_prev_register (struct frame_info
*next_frame
,
269 void **this_prologue_cache
,
270 int regnum
, int *optimizedp
,
271 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
272 int *realnump
, void *bufferp
)
274 struct alpha_mdebug_unwind_cache
*info
275 = alpha_mdebug_frame_unwind_cache (next_frame
, this_prologue_cache
);
277 /* The PC of the previous frame is stored in the link register of
278 the current frame. Frob regnum so that we pull the value from
279 the correct place. */
280 if (regnum
== PC_REGNUM
)
281 regnum
= PROC_PC_REG (info
->proc_desc
);
283 /* For all registers known to be saved in the current frame,
284 do the obvious and pull the value out. */
285 if (info
->saved_regs
[regnum
])
288 *lvalp
= lval_memory
;
289 *addrp
= info
->saved_regs
[regnum
];
292 read_memory (*addrp
, bufferp
, ALPHA_REGISTER_SIZE
);
296 /* The stack pointer of the previous frame is computed by popping
297 the current stack frame. */
298 if (regnum
== SP_REGNUM
)
305 store_unsigned_integer (bufferp
, ALPHA_REGISTER_SIZE
, info
->vfp
);
309 /* Otherwise assume the next frame has the same register value. */
310 frame_register (next_frame
, regnum
, optimizedp
, lvalp
, addrp
,
314 static const struct frame_unwind alpha_mdebug_frame_unwind
= {
316 alpha_mdebug_frame_this_id
,
317 alpha_mdebug_frame_prev_register
320 const struct frame_unwind
*
321 alpha_mdebug_frame_p (CORE_ADDR pc
)
323 alpha_extra_func_info_t proc_desc
;
325 /* If this PC does not map to a PDR, then clearly this isn't an
327 proc_desc
= find_proc_desc (pc
);
328 if (proc_desc
== NULL
)
331 /* If we're in the prologue, the PDR for this frame is not yet valid.
332 Say no here and we'll fall back on the heuristic unwinder. */
333 if (alpha_mdebug_in_prologue (pc
, proc_desc
))
336 return &alpha_mdebug_frame_unwind
;
340 alpha_mdebug_frame_base_address (struct frame_info
*next_frame
,
341 void **this_prologue_cache
)
343 struct alpha_mdebug_unwind_cache
*info
344 = alpha_mdebug_frame_unwind_cache (next_frame
, this_prologue_cache
);
350 alpha_mdebug_frame_locals_address (struct frame_info
*next_frame
,
351 void **this_prologue_cache
)
353 struct alpha_mdebug_unwind_cache
*info
354 = alpha_mdebug_frame_unwind_cache (next_frame
, this_prologue_cache
);
356 return info
->vfp
- PROC_LOCALOFF (info
->proc_desc
);
360 alpha_mdebug_frame_args_address (struct frame_info
*next_frame
,
361 void **this_prologue_cache
)
363 struct alpha_mdebug_unwind_cache
*info
364 = alpha_mdebug_frame_unwind_cache (next_frame
, this_prologue_cache
);
366 return info
->vfp
- ALPHA_NUM_ARG_REGS
* 8;
369 static const struct frame_base alpha_mdebug_frame_base
= {
370 &alpha_mdebug_frame_unwind
,
371 alpha_mdebug_frame_base_address
,
372 alpha_mdebug_frame_locals_address
,
373 alpha_mdebug_frame_args_address
376 static const struct frame_base
*
377 alpha_mdebug_frame_base_p (CORE_ADDR pc
)
379 alpha_extra_func_info_t proc_desc
;
381 /* If this PC does not map to a PDR, then clearly this isn't an
383 proc_desc
= find_proc_desc (pc
);
384 if (proc_desc
== NULL
)
387 return &alpha_mdebug_frame_base
;
392 alpha_mdebug_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
394 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
396 frame_unwind_append_predicate (gdbarch
, alpha_mdebug_frame_p
);
397 frame_base_append_predicate (gdbarch
, alpha_mdebug_frame_base_p
);