]>
Commit | Line | Data |
---|---|---|
d2427a71 | 1 | /* Target-dependent mdebug code for the ALPHA architecture. |
1d506c26 | 2 | Copyright (C) 1993-2024 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" | |
d55e5aa6 | 20 | #include "frame.h" |
4de283e4 TT |
21 | #include "frame-unwind.h" |
22 | #include "frame-base.h" | |
d55e5aa6 | 23 | #include "symtab.h" |
4de283e4 TT |
24 | #include "gdbcore.h" |
25 | #include "block.h" | |
d55e5aa6 | 26 | #include "trad-frame.h" |
d2427a71 | 27 | |
4de283e4 TT |
28 | #include "alpha-tdep.h" |
29 | #include "mdebugread.h" | |
0d12e84c | 30 | #include "gdbarch.h" |
4de283e4 | 31 | |
d2427a71 RH |
32 | /* FIXME: Some of this code should perhaps be merged with mips. */ |
33 | ||
d2427a71 RH |
34 | /* Layout of a stack frame on the alpha: |
35 | ||
dda83cd7 | 36 | | | |
d2427a71 | 37 | pdr members: | 7th ... nth arg, | |
dda83cd7 SM |
38 | | `pushed' by caller. | |
39 | | | | |
d2427a71 RH |
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 | |
dda83cd7 | 74 | | | |
d2427a71 | 75 | */ |
d2427a71 RH |
76 | |
77 | #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) | |
78 | #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset) | |
79 | #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg) | |
80 | #define PROC_REG_MASK(proc) ((proc)->pdr.regmask) | |
81 | #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask) | |
82 | #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset) | |
83 | #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset) | |
84 | #define PROC_PC_REG(proc) ((proc)->pdr.pcreg) | |
85 | #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff) | |
86 | \f | |
87 | /* Locate the mdebug PDR for the given PC. Return null if one can't | |
88 | be found; you'll have to fall back to other methods in that case. */ | |
89 | ||
5f6a2351 | 90 | static struct mdebug_extra_func_info * |
d2427a71 RH |
91 | find_proc_desc (CORE_ADDR pc) |
92 | { | |
3977b71f | 93 | const struct block *b = block_for_pc (pc); |
5f6a2351 | 94 | struct mdebug_extra_func_info *proc_desc = NULL; |
d2427a71 | 95 | struct symbol *sym = NULL; |
2c02bd72 | 96 | const char *sh_name = NULL; |
d2427a71 RH |
97 | |
98 | if (b) | |
99 | { | |
100 | CORE_ADDR startaddr; | |
62f6180c | 101 | find_pc_partial_function (pc, &sh_name, &startaddr, NULL); |
d2427a71 | 102 | |
4b8791e1 | 103 | if (startaddr > b->start ()) |
d2427a71 RH |
104 | /* This is the "pathological" case referred to in a comment in |
105 | print_frame_info. It might be better to move this check into | |
106 | symbol reading. */ | |
107 | sym = NULL; | |
108 | else | |
835a09d9 PMR |
109 | sym = lookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, LABEL_DOMAIN, |
110 | 0).symbol; | |
d2427a71 RH |
111 | } |
112 | ||
113 | if (sym) | |
114 | { | |
4aeddc50 | 115 | proc_desc = (struct mdebug_extra_func_info *) sym->value_bytes (); |
d2427a71 | 116 | |
62f6180c | 117 | /* Correct incorrect setjmp procedure descriptor from the library |
dda83cd7 | 118 | to make backtrace through setjmp work. */ |
62f6180c UW |
119 | if (proc_desc->pdr.pcreg == 0 |
120 | && strcmp (sh_name, "setjmp") == 0) | |
121 | { | |
122 | proc_desc->pdr.pcreg = ALPHA_RA_REGNUM; | |
123 | proc_desc->pdr.regmask = 0x80000000; | |
124 | proc_desc->pdr.regoffset = -4; | |
125 | } | |
126 | ||
d2427a71 RH |
127 | /* If we never found a PDR for this function in symbol reading, |
128 | then examine prologues to find the information. */ | |
129 | if (proc_desc->pdr.framereg == -1) | |
130 | proc_desc = NULL; | |
131 | } | |
132 | ||
133 | return proc_desc; | |
134 | } | |
135 | ||
3a48e6ff JG |
136 | /* Return a non-zero result if the function is frameless; zero otherwise. */ |
137 | ||
138 | static int | |
139 | alpha_mdebug_frameless (struct mdebug_extra_func_info *proc_desc) | |
140 | { | |
141 | return (PROC_FRAME_REG (proc_desc) == ALPHA_SP_REGNUM | |
142 | && PROC_FRAME_OFFSET (proc_desc) == 0); | |
143 | } | |
144 | ||
d2427a71 RH |
145 | /* This returns the PC of the first inst after the prologue. If we can't |
146 | find the prologue, then return 0. */ | |
147 | ||
148 | static CORE_ADDR | |
0963b4bd MS |
149 | alpha_mdebug_after_prologue (CORE_ADDR pc, |
150 | struct mdebug_extra_func_info *proc_desc) | |
d2427a71 RH |
151 | { |
152 | if (proc_desc) | |
153 | { | |
154 | /* If function is frameless, then we need to do it the hard way. I | |
dda83cd7 | 155 | strongly suspect that frameless always means prologueless... */ |
3a48e6ff | 156 | if (alpha_mdebug_frameless (proc_desc)) |
d2427a71 RH |
157 | return 0; |
158 | } | |
159 | ||
160 | return alpha_after_prologue (pc); | |
161 | } | |
162 | ||
163 | /* Return non-zero if we *might* be in a function prologue. Return zero | |
164 | if we are definitively *not* in a function prologue. */ | |
165 | ||
166 | static int | |
0963b4bd MS |
167 | alpha_mdebug_in_prologue (CORE_ADDR pc, |
168 | struct mdebug_extra_func_info *proc_desc) | |
d2427a71 RH |
169 | { |
170 | CORE_ADDR after_prologue_pc = alpha_mdebug_after_prologue (pc, proc_desc); | |
171 | return (after_prologue_pc == 0 || pc < after_prologue_pc); | |
172 | } | |
173 | ||
174 | \f | |
175 | /* Frame unwinder that reads mdebug PDRs. */ | |
176 | ||
177 | struct alpha_mdebug_unwind_cache | |
178 | { | |
5f6a2351 | 179 | struct mdebug_extra_func_info *proc_desc; |
d2427a71 | 180 | CORE_ADDR vfp; |
098caef4 | 181 | trad_frame_saved_reg *saved_regs; |
d2427a71 RH |
182 | }; |
183 | ||
184 | /* Extract all of the information about the frame from PROC_DESC | |
185 | and store the resulting register save locations in the structure. */ | |
186 | ||
187 | static struct alpha_mdebug_unwind_cache * | |
bd2b40ac | 188 | alpha_mdebug_frame_unwind_cache (frame_info_ptr this_frame, |
d2427a71 RH |
189 | void **this_prologue_cache) |
190 | { | |
191 | struct alpha_mdebug_unwind_cache *info; | |
5f6a2351 | 192 | struct mdebug_extra_func_info *proc_desc; |
d2427a71 RH |
193 | ULONGEST vfp; |
194 | CORE_ADDR pc, reg_position; | |
195 | unsigned long mask; | |
196 | int ireg, returnreg; | |
197 | ||
198 | if (*this_prologue_cache) | |
9a3c8263 | 199 | return (struct alpha_mdebug_unwind_cache *) *this_prologue_cache; |
d2427a71 RH |
200 | |
201 | info = FRAME_OBSTACK_ZALLOC (struct alpha_mdebug_unwind_cache); | |
202 | *this_prologue_cache = info; | |
88828b32 | 203 | pc = get_frame_address_in_block (this_frame); |
d2427a71 RH |
204 | |
205 | /* ??? We don't seem to be able to cache the lookup of the PDR | |
206 | from alpha_mdebug_frame_p. It'd be nice if we could change | |
207 | the arguments to that function. Oh well. */ | |
208 | proc_desc = find_proc_desc (pc); | |
209 | info->proc_desc = proc_desc; | |
210 | gdb_assert (proc_desc != NULL); | |
211 | ||
0cd9ab92 | 212 | info->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
d2427a71 RH |
213 | |
214 | /* The VFP of the frame is at FRAME_REG+FRAME_OFFSET. */ | |
6834c9bb | 215 | vfp = get_frame_register_unsigned (this_frame, PROC_FRAME_REG (proc_desc)); |
d2427a71 RH |
216 | vfp += PROC_FRAME_OFFSET (info->proc_desc); |
217 | info->vfp = vfp; | |
218 | ||
219 | /* Fill in the offsets for the registers which gen_mask says were saved. */ | |
220 | ||
221 | reg_position = vfp + PROC_REG_OFFSET (proc_desc); | |
222 | mask = PROC_REG_MASK (proc_desc); | |
223 | returnreg = PROC_PC_REG (proc_desc); | |
224 | ||
225 | /* Note that RA is always saved first, regardless of its actual | |
226 | register number. */ | |
227 | if (mask & (1 << returnreg)) | |
228 | { | |
0963b4bd | 229 | /* Clear bit for RA so we don't save it again later. */ |
d2427a71 RH |
230 | mask &= ~(1 << returnreg); |
231 | ||
098caef4 | 232 | info->saved_regs[returnreg].set_addr (reg_position); |
d2427a71 RH |
233 | reg_position += 8; |
234 | } | |
235 | ||
236 | for (ireg = 0; ireg <= 31; ++ireg) | |
237 | if (mask & (1 << ireg)) | |
238 | { | |
098caef4 | 239 | info->saved_regs[ireg].set_addr (reg_position); |
d2427a71 RH |
240 | reg_position += 8; |
241 | } | |
242 | ||
243 | reg_position = vfp + PROC_FREG_OFFSET (proc_desc); | |
244 | mask = PROC_FREG_MASK (proc_desc); | |
245 | ||
246 | for (ireg = 0; ireg <= 31; ++ireg) | |
247 | if (mask & (1 << ireg)) | |
248 | { | |
098caef4 | 249 | info->saved_regs[ALPHA_FP0_REGNUM + ireg].set_addr (reg_position); |
d2427a71 RH |
250 | reg_position += 8; |
251 | } | |
252 | ||
0cd9ab92 UW |
253 | /* The stack pointer of the previous frame is computed by popping |
254 | the current stack frame. */ | |
a9a87d35 LM |
255 | if (!info->saved_regs[ALPHA_SP_REGNUM].is_addr ()) |
256 | info->saved_regs[ALPHA_SP_REGNUM].set_value (vfp); | |
0cd9ab92 | 257 | |
d2427a71 RH |
258 | return info; |
259 | } | |
260 | ||
261 | /* Given a GDB frame, determine the address of the calling function's | |
262 | frame. This will be used to create a new GDB frame struct. */ | |
263 | ||
264 | static void | |
bd2b40ac | 265 | alpha_mdebug_frame_this_id (frame_info_ptr this_frame, |
d2427a71 RH |
266 | void **this_prologue_cache, |
267 | struct frame_id *this_id) | |
268 | { | |
269 | struct alpha_mdebug_unwind_cache *info | |
6834c9bb | 270 | = alpha_mdebug_frame_unwind_cache (this_frame, this_prologue_cache); |
d2427a71 | 271 | |
6834c9bb | 272 | *this_id = frame_id_build (info->vfp, get_frame_func (this_frame)); |
d2427a71 RH |
273 | } |
274 | ||
275 | /* Retrieve the value of REGNUM in FRAME. Don't give up! */ | |
276 | ||
6834c9bb | 277 | static struct value * |
bd2b40ac | 278 | alpha_mdebug_frame_prev_register (frame_info_ptr this_frame, |
6834c9bb | 279 | void **this_prologue_cache, int regnum) |
d2427a71 RH |
280 | { |
281 | struct alpha_mdebug_unwind_cache *info | |
6834c9bb | 282 | = alpha_mdebug_frame_unwind_cache (this_frame, this_prologue_cache); |
d2427a71 | 283 | |
d2427a71 RH |
284 | /* The PC of the previous frame is stored in the link register of |
285 | the current frame. Frob regnum so that we pull the value from | |
286 | the correct place. */ | |
087779b1 | 287 | if (regnum == ALPHA_PC_REGNUM) |
d2427a71 RH |
288 | regnum = PROC_PC_REG (info->proc_desc); |
289 | ||
0cd9ab92 | 290 | return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); |
d2427a71 RH |
291 | } |
292 | ||
3a48e6ff JG |
293 | /* Return a non-zero result if the size of the stack frame exceeds the |
294 | maximum debuggable frame size (512 Kbytes); zero otherwise. */ | |
295 | ||
296 | static int | |
297 | alpha_mdebug_max_frame_size_exceeded (struct mdebug_extra_func_info *proc_desc) | |
298 | { | |
299 | /* If frame offset is null, we can be in two cases: either the | |
300 | function is frameless (the stack frame is null) or its | |
301 | frame exceeds the maximum debuggable frame size (512 Kbytes). */ | |
302 | ||
303 | return (PROC_FRAME_OFFSET (proc_desc) == 0 | |
304 | && !alpha_mdebug_frameless (proc_desc)); | |
305 | } | |
306 | ||
6834c9bb JB |
307 | static int |
308 | alpha_mdebug_frame_sniffer (const struct frame_unwind *self, | |
bd2b40ac | 309 | frame_info_ptr this_frame, |
dda83cd7 | 310 | void **this_cache) |
d2427a71 | 311 | { |
6834c9bb | 312 | CORE_ADDR pc = get_frame_address_in_block (this_frame); |
5f6a2351 | 313 | struct mdebug_extra_func_info *proc_desc; |
d2427a71 RH |
314 | |
315 | /* If this PC does not map to a PDR, then clearly this isn't an | |
316 | mdebug frame. */ | |
317 | proc_desc = find_proc_desc (pc); | |
318 | if (proc_desc == NULL) | |
6834c9bb | 319 | return 0; |
d2427a71 | 320 | |
fbe586ae RH |
321 | /* If we're in the prologue, the PDR for this frame is not yet valid. |
322 | Say no here and we'll fall back on the heuristic unwinder. */ | |
323 | if (alpha_mdebug_in_prologue (pc, proc_desc)) | |
6834c9bb | 324 | return 0; |
fbe586ae | 325 | |
3a48e6ff JG |
326 | /* If the maximum debuggable frame size has been exceeded, the |
327 | proc desc is bogus. Fall back on the heuristic unwinder. */ | |
328 | if (alpha_mdebug_max_frame_size_exceeded (proc_desc)) | |
329 | return 0; | |
330 | ||
6834c9bb | 331 | return 1; |
d2427a71 RH |
332 | } |
333 | ||
a154d838 SM |
334 | static const struct frame_unwind alpha_mdebug_frame_unwind = |
335 | { | |
336 | "alpha mdebug", | |
6834c9bb | 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 | 345 | static CORE_ADDR |
bd2b40ac | 346 | alpha_mdebug_frame_base_address (frame_info_ptr 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 | ||
355 | static CORE_ADDR | |
bd2b40ac | 356 | alpha_mdebug_frame_locals_address (frame_info_ptr 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 | ||
365 | static CORE_ADDR | |
bd2b40ac | 366 | alpha_mdebug_frame_args_address (frame_info_ptr 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 | ||
375 | static 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 | ||
382 | static const struct frame_base * | |
bd2b40ac | 383 | alpha_mdebug_frame_base_sniffer (frame_info_ptr 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 | |
403 | void | |
404 | alpha_mdebug_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) | |
405 | { | |
6834c9bb | 406 | frame_unwind_append_unwinder (gdbarch, &alpha_mdebug_frame_unwind); |
336d1bba | 407 | frame_base_append_sniffer (gdbarch, alpha_mdebug_frame_base_sniffer); |
d2427a71 | 408 | } |