gdb/gdbserver:
[deliverable/binutils-gdb.git] / gdb / alpha-mdebug-tdep.c
CommitLineData
d2427a71 1/* Target-dependent mdebug code for the ALPHA architecture.
0b302171 2 Copyright (C) 1993-2003, 2007-2012 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
RH
25#include "block.h"
26#include "gdb_assert.h"
62f6180c 27#include "gdb_string.h"
0cd9ab92 28#include "trad-frame.h"
d2427a71 29
d2427a71 30#include "alpha-tdep.h"
5f6a2351 31#include "mdebugread.h"
d2427a71
RH
32
33/* FIXME: Some of this code should perhaps be merged with mips. */
34
35/* *INDENT-OFF* */
36/* Layout of a stack frame on the alpha:
37
38 | |
39 pdr members: | 7th ... nth arg, |
40 | `pushed' by caller. |
41 | |
42----------------|-------------------------------|<-- old_sp == vfp
43 ^ ^ ^ ^ | |
44 | | | | | |
45 | |localoff | Copies of 1st .. 6th |
46 | | | | | argument if necessary. |
47 | | | v | |
42efa47a 48 | | | --- |-------------------------------|<-- LOCALS_ADDRESS
d2427a71
RH
49 | | | | |
50 | | | | Locals and temporaries. |
51 | | | | |
52 | | | |-------------------------------|
53 | | | | |
54 |-fregoffset | Saved float registers. |
55 | | | | F9 |
56 | | | | . |
57 | | | | . |
58 | | | | F2 |
59 | | v | |
60 | | -------|-------------------------------|
61 | | | |
62 | | | Saved registers. |
63 | | | S6 |
64 |-regoffset | . |
65 | | | . |
66 | | | S0 |
67 | | | pdr.pcreg |
68 | v | |
69 | ----------|-------------------------------|
70 | | |
71 frameoffset | Argument build area, gets |
72 | | 7th ... nth arg for any |
73 | | called procedure. |
74 v | |
75 -------------|-------------------------------|<-- sp
76 | |
77*/
78/* *INDENT-ON* */
79
80#define PROC_LOW_ADDR(proc) ((proc)->pdr.adr)
81#define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
82#define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
83#define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
84#define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
85#define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
86#define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
87#define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
88#define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
89\f
90/* Locate the mdebug PDR for the given PC. Return null if one can't
91 be found; you'll have to fall back to other methods in that case. */
92
5f6a2351 93static struct mdebug_extra_func_info *
d2427a71
RH
94find_proc_desc (CORE_ADDR pc)
95{
96 struct block *b = block_for_pc (pc);
5f6a2351 97 struct mdebug_extra_func_info *proc_desc = NULL;
d2427a71 98 struct symbol *sym = NULL;
2c02bd72 99 const char *sh_name = NULL;
d2427a71
RH
100
101 if (b)
102 {
103 CORE_ADDR startaddr;
62f6180c 104 find_pc_partial_function (pc, &sh_name, &startaddr, NULL);
d2427a71
RH
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
2570f2b7 112 sym = lookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, 0);
d2427a71
RH
113 }
114
115 if (sym)
116 {
37049e31 117 proc_desc = (struct mdebug_extra_func_info *) SYMBOL_VALUE_BYTES (sym);
d2427a71 118
62f6180c
UW
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
d2427a71
RH
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
3a48e6ff
JG
138/* Return a non-zero result if the function is frameless; zero otherwise. */
139
140static int
141alpha_mdebug_frameless (struct mdebug_extra_func_info *proc_desc)
142{
143 return (PROC_FRAME_REG (proc_desc) == ALPHA_SP_REGNUM
144 && PROC_FRAME_OFFSET (proc_desc) == 0);
145}
146
d2427a71
RH
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
0963b4bd
MS
151alpha_mdebug_after_prologue (CORE_ADDR pc,
152 struct mdebug_extra_func_info *proc_desc)
d2427a71
RH
153{
154 if (proc_desc)
155 {
156 /* If function is frameless, then we need to do it the hard way. I
0963b4bd 157 strongly suspect that frameless always means prologueless... */
3a48e6ff 158 if (alpha_mdebug_frameless (proc_desc))
d2427a71
RH
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
0963b4bd
MS
169alpha_mdebug_in_prologue (CORE_ADDR pc,
170 struct mdebug_extra_func_info *proc_desc)
d2427a71
RH
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\f
177/* Frame unwinder that reads mdebug PDRs. */
178
179struct alpha_mdebug_unwind_cache
180{
5f6a2351 181 struct mdebug_extra_func_info *proc_desc;
d2427a71 182 CORE_ADDR vfp;
0cd9ab92 183 struct trad_frame_saved_reg *saved_regs;
d2427a71
RH
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 *
6834c9bb 190alpha_mdebug_frame_unwind_cache (struct frame_info *this_frame,
d2427a71
RH
191 void **this_prologue_cache)
192{
193 struct alpha_mdebug_unwind_cache *info;
5f6a2351 194 struct mdebug_extra_func_info *proc_desc;
d2427a71
RH
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 *this_prologue_cache;
202
203 info = FRAME_OBSTACK_ZALLOC (struct alpha_mdebug_unwind_cache);
204 *this_prologue_cache = info;
88828b32 205 pc = get_frame_address_in_block (this_frame);
d2427a71
RH
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
0cd9ab92 214 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
d2427a71
RH
215
216 /* The VFP of the frame is at FRAME_REG+FRAME_OFFSET. */
6834c9bb 217 vfp = get_frame_register_unsigned (this_frame, PROC_FRAME_REG (proc_desc));
d2427a71
RH
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 {
0963b4bd 231 /* Clear bit for RA so we don't save it again later. */
d2427a71
RH
232 mask &= ~(1 << returnreg);
233
0cd9ab92 234 info->saved_regs[returnreg].addr = reg_position;
d2427a71
RH
235 reg_position += 8;
236 }
237
238 for (ireg = 0; ireg <= 31; ++ireg)
239 if (mask & (1 << ireg))
240 {
0cd9ab92 241 info->saved_regs[ireg].addr = reg_position;
d2427a71
RH
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 {
0cd9ab92 251 info->saved_regs[ALPHA_FP0_REGNUM + ireg].addr = reg_position;
d2427a71
RH
252 reg_position += 8;
253 }
254
0cd9ab92
UW
255 /* The stack pointer of the previous frame is computed by popping
256 the current stack frame. */
257 if (!trad_frame_addr_p (info->saved_regs, ALPHA_SP_REGNUM))
258 trad_frame_set_value (info->saved_regs, ALPHA_SP_REGNUM, vfp);
259
d2427a71
RH
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
6834c9bb 267alpha_mdebug_frame_this_id (struct frame_info *this_frame,
d2427a71
RH
268 void **this_prologue_cache,
269 struct frame_id *this_id)
270{
271 struct alpha_mdebug_unwind_cache *info
6834c9bb 272 = alpha_mdebug_frame_unwind_cache (this_frame, this_prologue_cache);
d2427a71 273
6834c9bb 274 *this_id = frame_id_build (info->vfp, get_frame_func (this_frame));
d2427a71
RH
275}
276
277/* Retrieve the value of REGNUM in FRAME. Don't give up! */
278
6834c9bb
JB
279static struct value *
280alpha_mdebug_frame_prev_register (struct frame_info *this_frame,
281 void **this_prologue_cache, int regnum)
d2427a71
RH
282{
283 struct alpha_mdebug_unwind_cache *info
6834c9bb 284 = alpha_mdebug_frame_unwind_cache (this_frame, this_prologue_cache);
d2427a71 285
d2427a71
RH
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. */
087779b1 289 if (regnum == ALPHA_PC_REGNUM)
d2427a71
RH
290 regnum = PROC_PC_REG (info->proc_desc);
291
0cd9ab92 292 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
d2427a71
RH
293}
294
3a48e6ff
JG
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
299alpha_mdebug_max_frame_size_exceeded (struct mdebug_extra_func_info *proc_desc)
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
306 && !alpha_mdebug_frameless (proc_desc));
307}
308
6834c9bb
JB
309static int
310alpha_mdebug_frame_sniffer (const struct frame_unwind *self,
311 struct frame_info *this_frame,
312 void **this_cache)
d2427a71 313{
6834c9bb 314 CORE_ADDR pc = get_frame_address_in_block (this_frame);
5f6a2351 315 struct mdebug_extra_func_info *proc_desc;
d2427a71
RH
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)
6834c9bb 321 return 0;
d2427a71 322
fbe586ae
RH
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))
6834c9bb 326 return 0;
fbe586ae 327
3a48e6ff
JG
328 /* If the maximum debuggable frame size has been exceeded, the
329 proc desc is bogus. Fall back on the heuristic unwinder. */
330 if (alpha_mdebug_max_frame_size_exceeded (proc_desc))
331 return 0;
332
6834c9bb 333 return 1;
d2427a71
RH
334}
335
6834c9bb
JB
336static const struct frame_unwind alpha_mdebug_frame_unwind = {
337 NORMAL_FRAME,
8fbca658 338 default_frame_unwind_stop_reason,
6834c9bb
JB
339 alpha_mdebug_frame_this_id,
340 alpha_mdebug_frame_prev_register,
341 NULL,
342 alpha_mdebug_frame_sniffer
343};
344
d2427a71 345static CORE_ADDR
6834c9bb 346alpha_mdebug_frame_base_address (struct frame_info *this_frame,
d2427a71
RH
347 void **this_prologue_cache)
348{
349 struct alpha_mdebug_unwind_cache *info
6834c9bb 350 = alpha_mdebug_frame_unwind_cache (this_frame, this_prologue_cache);
d2427a71 351
fbe586ae 352 return info->vfp;
d2427a71
RH
353}
354
355static CORE_ADDR
6834c9bb 356alpha_mdebug_frame_locals_address (struct frame_info *this_frame,
d2427a71
RH
357 void **this_prologue_cache)
358{
359 struct alpha_mdebug_unwind_cache *info
6834c9bb 360 = alpha_mdebug_frame_unwind_cache (this_frame, this_prologue_cache);
d2427a71 361
fbe586ae 362 return info->vfp - PROC_LOCALOFF (info->proc_desc);
d2427a71
RH
363}
364
365static CORE_ADDR
6834c9bb 366alpha_mdebug_frame_args_address (struct frame_info *this_frame,
d2427a71
RH
367 void **this_prologue_cache)
368{
369 struct alpha_mdebug_unwind_cache *info
6834c9bb 370 = alpha_mdebug_frame_unwind_cache (this_frame, this_prologue_cache);
d2427a71 371
fbe586ae 372 return info->vfp - ALPHA_NUM_ARG_REGS * 8;
d2427a71
RH
373}
374
375static const struct frame_base alpha_mdebug_frame_base = {
376 &alpha_mdebug_frame_unwind,
377 alpha_mdebug_frame_base_address,
378 alpha_mdebug_frame_locals_address,
379 alpha_mdebug_frame_args_address
380};
381
382static const struct frame_base *
6834c9bb 383alpha_mdebug_frame_base_sniffer (struct frame_info *this_frame)
d2427a71 384{
6834c9bb 385 CORE_ADDR pc = get_frame_address_in_block (this_frame);
5f6a2351 386 struct mdebug_extra_func_info *proc_desc;
d2427a71
RH
387
388 /* If this PC does not map to a PDR, then clearly this isn't an
389 mdebug frame. */
390 proc_desc = find_proc_desc (pc);
391 if (proc_desc == NULL)
392 return NULL;
393
3a48e6ff
JG
394 /* If the maximum debuggable frame size has been exceeded, the
395 proc desc is bogus. Fall back on the heuristic unwinder. */
396 if (alpha_mdebug_max_frame_size_exceeded (proc_desc))
397 return 0;
398
d2427a71
RH
399 return &alpha_mdebug_frame_base;
400}
401
402\f
403void
404alpha_mdebug_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
405{
406 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
407
6834c9bb 408 frame_unwind_append_unwinder (gdbarch, &alpha_mdebug_frame_unwind);
336d1bba 409 frame_base_append_sniffer (gdbarch, alpha_mdebug_frame_base_sniffer);
d2427a71 410}
This page took 0.656183 seconds and 4 git commands to generate.