Commit | Line | Data |
---|---|---|
d2427a71 | 1 | /* Target-dependent mdebug code for the ALPHA architecture. |
6aba47ca DJ |
2 | Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
3 | 2003, 2007 Free Software Foundation, Inc. | |
d2427a71 RH |
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 2 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, write to the Free Software | |
197e01b6 EZ |
19 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | Boston, MA 02110-1301, USA. */ | |
d2427a71 RH |
21 | |
22 | #include "defs.h" | |
23 | #include "frame.h" | |
24 | #include "frame-unwind.h" | |
25 | #include "frame-base.h" | |
d2427a71 | 26 | #include "symtab.h" |
d2427a71 | 27 | #include "gdbcore.h" |
d2427a71 RH |
28 | #include "block.h" |
29 | #include "gdb_assert.h" | |
30 | ||
d2427a71 | 31 | #include "alpha-tdep.h" |
5f6a2351 | 32 | #include "mdebugread.h" |
d2427a71 RH |
33 | |
34 | /* FIXME: Some of this code should perhaps be merged with mips. */ | |
35 | ||
36 | /* *INDENT-OFF* */ | |
37 | /* Layout of a stack frame on the alpha: | |
38 | ||
39 | | | | |
40 | pdr members: | 7th ... nth arg, | | |
41 | | `pushed' by caller. | | |
42 | | | | |
43 | ----------------|-------------------------------|<-- old_sp == vfp | |
44 | ^ ^ ^ ^ | | | |
45 | | | | | | | | |
46 | | |localoff | Copies of 1st .. 6th | | |
47 | | | | | | argument if necessary. | | |
48 | | | | v | | | |
42efa47a | 49 | | | | --- |-------------------------------|<-- LOCALS_ADDRESS |
d2427a71 RH |
50 | | | | | | |
51 | | | | | Locals and temporaries. | | |
52 | | | | | | | |
53 | | | | |-------------------------------| | |
54 | | | | | | | |
55 | |-fregoffset | Saved float registers. | | |
56 | | | | | F9 | | |
57 | | | | | . | | |
58 | | | | | . | | |
59 | | | | | F2 | | |
60 | | | v | | | |
61 | | | -------|-------------------------------| | |
62 | | | | | | |
63 | | | | Saved registers. | | |
64 | | | | S6 | | |
65 | |-regoffset | . | | |
66 | | | | . | | |
67 | | | | S0 | | |
68 | | | | pdr.pcreg | | |
69 | | v | | | |
70 | | ----------|-------------------------------| | |
71 | | | | | |
72 | frameoffset | Argument build area, gets | | |
73 | | | 7th ... nth arg for any | | |
74 | | | called procedure. | | |
75 | v | | | |
76 | -------------|-------------------------------|<-- sp | |
77 | | | | |
78 | */ | |
79 | /* *INDENT-ON* */ | |
80 | ||
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) | |
90 | \f | |
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. */ | |
93 | ||
5f6a2351 | 94 | static struct mdebug_extra_func_info * |
d2427a71 RH |
95 | find_proc_desc (CORE_ADDR pc) |
96 | { | |
97 | struct block *b = block_for_pc (pc); | |
5f6a2351 | 98 | struct mdebug_extra_func_info *proc_desc = NULL; |
d2427a71 RH |
99 | struct symbol *sym = NULL; |
100 | ||
101 | if (b) | |
102 | { | |
103 | CORE_ADDR startaddr; | |
104 | find_pc_partial_function (pc, NULL, &startaddr, NULL); | |
105 | ||
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 | |
109 | symbol reading. */ | |
110 | sym = NULL; | |
111 | else | |
f92761ec | 112 | sym = lookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, 0, NULL); |
d2427a71 RH |
113 | } |
114 | ||
115 | if (sym) | |
116 | { | |
5f6a2351 | 117 | proc_desc = (struct mdebug_extra_func_info *) SYMBOL_VALUE (sym); |
d2427a71 RH |
118 | |
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) | |
122 | proc_desc = NULL; | |
123 | } | |
124 | ||
125 | return proc_desc; | |
126 | } | |
127 | ||
128 | /* This returns the PC of the first inst after the prologue. If we can't | |
129 | find the prologue, then return 0. */ | |
130 | ||
131 | static CORE_ADDR | |
5f6a2351 | 132 | alpha_mdebug_after_prologue (CORE_ADDR pc, struct mdebug_extra_func_info *proc_desc) |
d2427a71 RH |
133 | { |
134 | if (proc_desc) | |
135 | { | |
136 | /* If function is frameless, then we need to do it the hard way. I | |
137 | strongly suspect that frameless always means prologueless... */ | |
087779b1 | 138 | if (PROC_FRAME_REG (proc_desc) == ALPHA_SP_REGNUM |
d2427a71 RH |
139 | && PROC_FRAME_OFFSET (proc_desc) == 0) |
140 | return 0; | |
141 | } | |
142 | ||
143 | return alpha_after_prologue (pc); | |
144 | } | |
145 | ||
146 | /* Return non-zero if we *might* be in a function prologue. Return zero | |
147 | if we are definitively *not* in a function prologue. */ | |
148 | ||
149 | static int | |
5f6a2351 | 150 | alpha_mdebug_in_prologue (CORE_ADDR pc, struct mdebug_extra_func_info *proc_desc) |
d2427a71 RH |
151 | { |
152 | CORE_ADDR after_prologue_pc = alpha_mdebug_after_prologue (pc, proc_desc); | |
153 | return (after_prologue_pc == 0 || pc < after_prologue_pc); | |
154 | } | |
155 | ||
156 | \f | |
157 | /* Frame unwinder that reads mdebug PDRs. */ | |
158 | ||
159 | struct alpha_mdebug_unwind_cache | |
160 | { | |
5f6a2351 | 161 | struct mdebug_extra_func_info *proc_desc; |
d2427a71 RH |
162 | CORE_ADDR vfp; |
163 | CORE_ADDR *saved_regs; | |
d2427a71 RH |
164 | }; |
165 | ||
166 | /* Extract all of the information about the frame from PROC_DESC | |
167 | and store the resulting register save locations in the structure. */ | |
168 | ||
169 | static struct alpha_mdebug_unwind_cache * | |
170 | alpha_mdebug_frame_unwind_cache (struct frame_info *next_frame, | |
171 | void **this_prologue_cache) | |
172 | { | |
173 | struct alpha_mdebug_unwind_cache *info; | |
5f6a2351 | 174 | struct mdebug_extra_func_info *proc_desc; |
d2427a71 RH |
175 | ULONGEST vfp; |
176 | CORE_ADDR pc, reg_position; | |
177 | unsigned long mask; | |
178 | int ireg, returnreg; | |
179 | ||
180 | if (*this_prologue_cache) | |
181 | return *this_prologue_cache; | |
182 | ||
183 | info = FRAME_OBSTACK_ZALLOC (struct alpha_mdebug_unwind_cache); | |
184 | *this_prologue_cache = info; | |
185 | pc = frame_pc_unwind (next_frame); | |
186 | ||
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); | |
193 | ||
d2427a71 RH |
194 | info->saved_regs = frame_obstack_zalloc (SIZEOF_FRAME_SAVED_REGS); |
195 | ||
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); | |
199 | info->vfp = vfp; | |
200 | ||
201 | /* Fill in the offsets for the registers which gen_mask says were saved. */ | |
202 | ||
203 | reg_position = vfp + PROC_REG_OFFSET (proc_desc); | |
204 | mask = PROC_REG_MASK (proc_desc); | |
205 | returnreg = PROC_PC_REG (proc_desc); | |
206 | ||
207 | /* Note that RA is always saved first, regardless of its actual | |
208 | register number. */ | |
209 | if (mask & (1 << returnreg)) | |
210 | { | |
211 | /* Clear bit for RA so we don't save it again later. */ | |
212 | mask &= ~(1 << returnreg); | |
213 | ||
214 | info->saved_regs[returnreg] = reg_position; | |
215 | reg_position += 8; | |
216 | } | |
217 | ||
218 | for (ireg = 0; ireg <= 31; ++ireg) | |
219 | if (mask & (1 << ireg)) | |
220 | { | |
221 | info->saved_regs[ireg] = reg_position; | |
222 | reg_position += 8; | |
223 | } | |
224 | ||
225 | reg_position = vfp + PROC_FREG_OFFSET (proc_desc); | |
226 | mask = PROC_FREG_MASK (proc_desc); | |
227 | ||
228 | for (ireg = 0; ireg <= 31; ++ireg) | |
229 | if (mask & (1 << ireg)) | |
230 | { | |
087779b1 | 231 | info->saved_regs[ALPHA_FP0_REGNUM + ireg] = reg_position; |
d2427a71 RH |
232 | reg_position += 8; |
233 | } | |
234 | ||
235 | return info; | |
236 | } | |
237 | ||
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. */ | |
240 | ||
241 | static void | |
242 | alpha_mdebug_frame_this_id (struct frame_info *next_frame, | |
243 | void **this_prologue_cache, | |
244 | struct frame_id *this_id) | |
245 | { | |
246 | struct alpha_mdebug_unwind_cache *info | |
247 | = alpha_mdebug_frame_unwind_cache (next_frame, this_prologue_cache); | |
248 | ||
93d42b30 DJ |
249 | *this_id = frame_id_build (info->vfp, |
250 | frame_func_unwind (next_frame, NORMAL_FRAME)); | |
d2427a71 RH |
251 | } |
252 | ||
253 | /* Retrieve the value of REGNUM in FRAME. Don't give up! */ | |
254 | ||
255 | static void | |
256 | alpha_mdebug_frame_prev_register (struct frame_info *next_frame, | |
257 | void **this_prologue_cache, | |
258 | int regnum, int *optimizedp, | |
259 | enum lval_type *lvalp, CORE_ADDR *addrp, | |
5b819568 | 260 | int *realnump, gdb_byte *bufferp) |
d2427a71 RH |
261 | { |
262 | struct alpha_mdebug_unwind_cache *info | |
263 | = alpha_mdebug_frame_unwind_cache (next_frame, this_prologue_cache); | |
264 | ||
d2427a71 RH |
265 | /* The PC of the previous frame is stored in the link register of |
266 | the current frame. Frob regnum so that we pull the value from | |
267 | the correct place. */ | |
087779b1 | 268 | if (regnum == ALPHA_PC_REGNUM) |
d2427a71 RH |
269 | regnum = PROC_PC_REG (info->proc_desc); |
270 | ||
271 | /* For all registers known to be saved in the current frame, | |
272 | do the obvious and pull the value out. */ | |
273 | if (info->saved_regs[regnum]) | |
274 | { | |
275 | *optimizedp = 0; | |
276 | *lvalp = lval_memory; | |
277 | *addrp = info->saved_regs[regnum]; | |
278 | *realnump = -1; | |
279 | if (bufferp != NULL) | |
b21fd293 | 280 | get_frame_memory (next_frame, *addrp, bufferp, ALPHA_REGISTER_SIZE); |
d2427a71 RH |
281 | return; |
282 | } | |
283 | ||
284 | /* The stack pointer of the previous frame is computed by popping | |
285 | the current stack frame. */ | |
087779b1 | 286 | if (regnum == ALPHA_SP_REGNUM) |
d2427a71 RH |
287 | { |
288 | *optimizedp = 0; | |
289 | *lvalp = not_lval; | |
290 | *addrp = 0; | |
291 | *realnump = -1; | |
292 | if (bufferp != NULL) | |
293 | store_unsigned_integer (bufferp, ALPHA_REGISTER_SIZE, info->vfp); | |
294 | return; | |
295 | } | |
296 | ||
297 | /* Otherwise assume the next frame has the same register value. */ | |
5efde112 DJ |
298 | *optimizedp = 0; |
299 | *lvalp = lval_register; | |
300 | *addrp = 0; | |
301 | *realnump = regnum; | |
302 | if (bufferp) | |
303 | frame_unwind_register (next_frame, *realnump, bufferp); | |
d2427a71 RH |
304 | } |
305 | ||
306 | static const struct frame_unwind alpha_mdebug_frame_unwind = { | |
307 | NORMAL_FRAME, | |
308 | alpha_mdebug_frame_this_id, | |
309 | alpha_mdebug_frame_prev_register | |
310 | }; | |
311 | ||
312 | const struct frame_unwind * | |
336d1bba | 313 | alpha_mdebug_frame_sniffer (struct frame_info *next_frame) |
d2427a71 | 314 | { |
93d42b30 | 315 | CORE_ADDR pc = frame_unwind_address_in_block (next_frame, NORMAL_FRAME); |
5f6a2351 | 316 | struct mdebug_extra_func_info *proc_desc; |
d2427a71 RH |
317 | |
318 | /* If this PC does not map to a PDR, then clearly this isn't an | |
319 | mdebug frame. */ | |
320 | proc_desc = find_proc_desc (pc); | |
321 | if (proc_desc == NULL) | |
322 | return NULL; | |
323 | ||
fbe586ae RH |
324 | /* If we're in the prologue, the PDR for this frame is not yet valid. |
325 | Say no here and we'll fall back on the heuristic unwinder. */ | |
326 | if (alpha_mdebug_in_prologue (pc, proc_desc)) | |
327 | return NULL; | |
328 | ||
d2427a71 RH |
329 | return &alpha_mdebug_frame_unwind; |
330 | } | |
331 | ||
332 | static CORE_ADDR | |
333 | alpha_mdebug_frame_base_address (struct frame_info *next_frame, | |
334 | void **this_prologue_cache) | |
335 | { | |
336 | struct alpha_mdebug_unwind_cache *info | |
337 | = alpha_mdebug_frame_unwind_cache (next_frame, this_prologue_cache); | |
338 | ||
fbe586ae | 339 | return info->vfp; |
d2427a71 RH |
340 | } |
341 | ||
342 | static CORE_ADDR | |
343 | alpha_mdebug_frame_locals_address (struct frame_info *next_frame, | |
344 | void **this_prologue_cache) | |
345 | { | |
346 | struct alpha_mdebug_unwind_cache *info | |
347 | = alpha_mdebug_frame_unwind_cache (next_frame, this_prologue_cache); | |
d2427a71 | 348 | |
fbe586ae | 349 | return info->vfp - PROC_LOCALOFF (info->proc_desc); |
d2427a71 RH |
350 | } |
351 | ||
352 | static CORE_ADDR | |
353 | alpha_mdebug_frame_args_address (struct frame_info *next_frame, | |
354 | void **this_prologue_cache) | |
355 | { | |
356 | struct alpha_mdebug_unwind_cache *info | |
357 | = alpha_mdebug_frame_unwind_cache (next_frame, this_prologue_cache); | |
d2427a71 | 358 | |
fbe586ae | 359 | return info->vfp - ALPHA_NUM_ARG_REGS * 8; |
d2427a71 RH |
360 | } |
361 | ||
362 | static const struct frame_base alpha_mdebug_frame_base = { | |
363 | &alpha_mdebug_frame_unwind, | |
364 | alpha_mdebug_frame_base_address, | |
365 | alpha_mdebug_frame_locals_address, | |
366 | alpha_mdebug_frame_args_address | |
367 | }; | |
368 | ||
369 | static const struct frame_base * | |
336d1bba | 370 | alpha_mdebug_frame_base_sniffer (struct frame_info *next_frame) |
d2427a71 | 371 | { |
93d42b30 | 372 | CORE_ADDR pc = frame_unwind_address_in_block (next_frame, NORMAL_FRAME); |
5f6a2351 | 373 | struct mdebug_extra_func_info *proc_desc; |
d2427a71 RH |
374 | |
375 | /* If this PC does not map to a PDR, then clearly this isn't an | |
376 | mdebug frame. */ | |
377 | proc_desc = find_proc_desc (pc); | |
378 | if (proc_desc == NULL) | |
379 | return NULL; | |
380 | ||
381 | return &alpha_mdebug_frame_base; | |
382 | } | |
383 | ||
384 | \f | |
385 | void | |
386 | alpha_mdebug_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
387 | { | |
388 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
389 | ||
336d1bba AC |
390 | frame_unwind_append_sniffer (gdbarch, alpha_mdebug_frame_sniffer); |
391 | frame_base_append_sniffer (gdbarch, alpha_mdebug_frame_base_sniffer); | |
d2427a71 | 392 | } |