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"
29 #include "gdb_assert.h"
31 #include "alpha-tdep.h"
32 #include "mdebugread.h"
34 /* FIXME: Some of this code should perhaps be merged with mips. */
37 /* Layout of a stack frame on the alpha:
40 pdr members: | 7th ... nth arg, |
41 | `pushed' by caller. |
43 ----------------|-------------------------------|<-- old_sp == vfp
46 | |localoff | Copies of 1st .. 6th |
47 | | | | | argument if necessary. |
49 | | | --- |-------------------------------|<-- LOCALS_ADDRESS
51 | | | | Locals and temporaries. |
53 | | | |-------------------------------|
55 |-fregoffset | Saved float registers. |
61 | | -------|-------------------------------|
63 | | | Saved registers. |
70 | ----------|-------------------------------|
72 frameoffset | Argument build area, gets |
73 | | 7th ... nth arg for any |
74 | | called procedure. |
76 -------------|-------------------------------|<-- sp
81 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr)
82 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
83 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
84 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
85 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
86 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
87 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
88 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
89 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
91 /* Locate the mdebug PDR for the given PC. Return null if one can't
92 be found; you'll have to fall back to other methods in that case. */
94 static struct mdebug_extra_func_info
*
95 find_proc_desc (CORE_ADDR pc
)
97 struct block
*b
= block_for_pc (pc
);
98 struct mdebug_extra_func_info
*proc_desc
= NULL
;
99 struct symbol
*sym
= NULL
;
104 find_pc_partial_function (pc
, NULL
, &startaddr
, NULL
);
106 if (startaddr
> BLOCK_START (b
))
107 /* This is the "pathological" case referred to in a comment in
108 print_frame_info. It might be better to move this check into
112 sym
= lookup_symbol (MDEBUG_EFI_SYMBOL_NAME
, b
, LABEL_DOMAIN
, 0, NULL
);
117 proc_desc
= (struct mdebug_extra_func_info
*) SYMBOL_VALUE (sym
);
119 /* If we never found a PDR for this function in symbol reading,
120 then examine prologues to find the information. */
121 if (proc_desc
->pdr
.framereg
== -1)
128 /* This returns the PC of the first inst after the prologue. If we can't
129 find the prologue, then return 0. */
132 alpha_mdebug_after_prologue (CORE_ADDR pc
, struct mdebug_extra_func_info
*proc_desc
)
136 /* If function is frameless, then we need to do it the hard way. I
137 strongly suspect that frameless always means prologueless... */
138 if (PROC_FRAME_REG (proc_desc
) == ALPHA_SP_REGNUM
139 && PROC_FRAME_OFFSET (proc_desc
) == 0)
143 return alpha_after_prologue (pc
);
146 /* Return non-zero if we *might* be in a function prologue. Return zero
147 if we are definitively *not* in a function prologue. */
150 alpha_mdebug_in_prologue (CORE_ADDR pc
, struct mdebug_extra_func_info
*proc_desc
)
152 CORE_ADDR after_prologue_pc
= alpha_mdebug_after_prologue (pc
, proc_desc
);
153 return (after_prologue_pc
== 0 || pc
< after_prologue_pc
);
157 /* Frame unwinder that reads mdebug PDRs. */
159 struct alpha_mdebug_unwind_cache
161 struct mdebug_extra_func_info
*proc_desc
;
163 CORE_ADDR
*saved_regs
;
166 /* Extract all of the information about the frame from PROC_DESC
167 and store the resulting register save locations in the structure. */
169 static struct alpha_mdebug_unwind_cache
*
170 alpha_mdebug_frame_unwind_cache (struct frame_info
*next_frame
,
171 void **this_prologue_cache
)
173 struct alpha_mdebug_unwind_cache
*info
;
174 struct mdebug_extra_func_info
*proc_desc
;
176 CORE_ADDR pc
, reg_position
;
180 if (*this_prologue_cache
)
181 return *this_prologue_cache
;
183 info
= FRAME_OBSTACK_ZALLOC (struct alpha_mdebug_unwind_cache
);
184 *this_prologue_cache
= info
;
185 pc
= frame_pc_unwind (next_frame
);
187 /* ??? We don't seem to be able to cache the lookup of the PDR
188 from alpha_mdebug_frame_p. It'd be nice if we could change
189 the arguments to that function. Oh well. */
190 proc_desc
= find_proc_desc (pc
);
191 info
->proc_desc
= proc_desc
;
192 gdb_assert (proc_desc
!= NULL
);
194 info
->saved_regs
= frame_obstack_zalloc (SIZEOF_FRAME_SAVED_REGS
);
196 /* The VFP of the frame is at FRAME_REG+FRAME_OFFSET. */
197 frame_unwind_unsigned_register (next_frame
, PROC_FRAME_REG (proc_desc
), &vfp
);
198 vfp
+= PROC_FRAME_OFFSET (info
->proc_desc
);
201 /* Fill in the offsets for the registers which gen_mask says were saved. */
203 reg_position
= vfp
+ PROC_REG_OFFSET (proc_desc
);
204 mask
= PROC_REG_MASK (proc_desc
);
205 returnreg
= PROC_PC_REG (proc_desc
);
207 /* Note that RA is always saved first, regardless of its actual
209 if (mask
& (1 << returnreg
))
211 /* Clear bit for RA so we don't save it again later. */
212 mask
&= ~(1 << returnreg
);
214 info
->saved_regs
[returnreg
] = reg_position
;
218 for (ireg
= 0; ireg
<= 31; ++ireg
)
219 if (mask
& (1 << ireg
))
221 info
->saved_regs
[ireg
] = reg_position
;
225 reg_position
= vfp
+ PROC_FREG_OFFSET (proc_desc
);
226 mask
= PROC_FREG_MASK (proc_desc
);
228 for (ireg
= 0; ireg
<= 31; ++ireg
)
229 if (mask
& (1 << ireg
))
231 info
->saved_regs
[ALPHA_FP0_REGNUM
+ ireg
] = reg_position
;
238 /* Given a GDB frame, determine the address of the calling function's
239 frame. This will be used to create a new GDB frame struct. */
242 alpha_mdebug_frame_this_id (struct frame_info
*next_frame
,
243 void **this_prologue_cache
,
244 struct frame_id
*this_id
)
246 struct alpha_mdebug_unwind_cache
*info
247 = alpha_mdebug_frame_unwind_cache (next_frame
, this_prologue_cache
);
249 *this_id
= frame_id_build (info
->vfp
, frame_func_unwind (next_frame
));
252 /* Retrieve the value of REGNUM in FRAME. Don't give up! */
255 alpha_mdebug_frame_prev_register (struct frame_info
*next_frame
,
256 void **this_prologue_cache
,
257 int regnum
, int *optimizedp
,
258 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
259 int *realnump
, void *bufferp
)
261 struct alpha_mdebug_unwind_cache
*info
262 = alpha_mdebug_frame_unwind_cache (next_frame
, this_prologue_cache
);
264 /* The PC of the previous frame is stored in the link register of
265 the current frame. Frob regnum so that we pull the value from
266 the correct place. */
267 if (regnum
== ALPHA_PC_REGNUM
)
268 regnum
= PROC_PC_REG (info
->proc_desc
);
270 /* For all registers known to be saved in the current frame,
271 do the obvious and pull the value out. */
272 if (info
->saved_regs
[regnum
])
275 *lvalp
= lval_memory
;
276 *addrp
= info
->saved_regs
[regnum
];
279 get_frame_memory (next_frame
, *addrp
, bufferp
, ALPHA_REGISTER_SIZE
);
283 /* The stack pointer of the previous frame is computed by popping
284 the current stack frame. */
285 if (regnum
== ALPHA_SP_REGNUM
)
292 store_unsigned_integer (bufferp
, ALPHA_REGISTER_SIZE
, info
->vfp
);
296 /* Otherwise assume the next frame has the same register value. */
297 frame_register (next_frame
, regnum
, optimizedp
, lvalp
, addrp
,
301 static const struct frame_unwind alpha_mdebug_frame_unwind
= {
303 alpha_mdebug_frame_this_id
,
304 alpha_mdebug_frame_prev_register
307 const struct frame_unwind
*
308 alpha_mdebug_frame_sniffer (struct frame_info
*next_frame
)
310 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
311 struct mdebug_extra_func_info
*proc_desc
;
313 /* If this PC does not map to a PDR, then clearly this isn't an
315 proc_desc
= find_proc_desc (pc
);
316 if (proc_desc
== NULL
)
319 /* If we're in the prologue, the PDR for this frame is not yet valid.
320 Say no here and we'll fall back on the heuristic unwinder. */
321 if (alpha_mdebug_in_prologue (pc
, proc_desc
))
324 return &alpha_mdebug_frame_unwind
;
328 alpha_mdebug_frame_base_address (struct frame_info
*next_frame
,
329 void **this_prologue_cache
)
331 struct alpha_mdebug_unwind_cache
*info
332 = alpha_mdebug_frame_unwind_cache (next_frame
, this_prologue_cache
);
338 alpha_mdebug_frame_locals_address (struct frame_info
*next_frame
,
339 void **this_prologue_cache
)
341 struct alpha_mdebug_unwind_cache
*info
342 = alpha_mdebug_frame_unwind_cache (next_frame
, this_prologue_cache
);
344 return info
->vfp
- PROC_LOCALOFF (info
->proc_desc
);
348 alpha_mdebug_frame_args_address (struct frame_info
*next_frame
,
349 void **this_prologue_cache
)
351 struct alpha_mdebug_unwind_cache
*info
352 = alpha_mdebug_frame_unwind_cache (next_frame
, this_prologue_cache
);
354 return info
->vfp
- ALPHA_NUM_ARG_REGS
* 8;
357 static const struct frame_base alpha_mdebug_frame_base
= {
358 &alpha_mdebug_frame_unwind
,
359 alpha_mdebug_frame_base_address
,
360 alpha_mdebug_frame_locals_address
,
361 alpha_mdebug_frame_args_address
364 static const struct frame_base
*
365 alpha_mdebug_frame_base_sniffer (struct frame_info
*next_frame
)
367 CORE_ADDR pc
= frame_pc_unwind (next_frame
);
368 struct mdebug_extra_func_info
*proc_desc
;
370 /* If this PC does not map to a PDR, then clearly this isn't an
372 proc_desc
= find_proc_desc (pc
);
373 if (proc_desc
== NULL
)
376 return &alpha_mdebug_frame_base
;
381 alpha_mdebug_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
383 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
385 frame_unwind_append_sniffer (gdbarch
, alpha_mdebug_frame_sniffer
);
386 frame_base_append_sniffer (gdbarch
, alpha_mdebug_frame_base_sniffer
);