]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger. |
ec32e4be | 2 | Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
b6ba6518 | 3 | Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
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. | |
c906108c | 11 | |
c5aa993b JM |
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. | |
c906108c | 16 | |
c5aa993b JM |
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. */ | |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include "frame.h" | |
24 | #include "inferior.h" | |
25 | #include "symtab.h" | |
26 | #include "value.h" | |
27 | #include "gdbcmd.h" | |
28 | #include "gdbcore.h" | |
29 | #include "dis-asm.h" | |
30 | #include "symfile.h" | |
31 | #include "objfiles.h" | |
32 | #include "gdb_string.h" | |
c5f0f3d0 | 33 | #include "linespec.h" |
4e052eda | 34 | #include "regcache.h" |
d16aafd8 | 35 | #include "doublest.h" |
dc129d82 JT |
36 | #include "arch-utils.h" |
37 | ||
38 | #include "elf-bfd.h" | |
39 | ||
40 | #include "alpha-tdep.h" | |
41 | ||
42 | static gdbarch_init_ftype alpha_gdbarch_init; | |
43 | ||
44 | static gdbarch_register_name_ftype alpha_register_name; | |
45 | static gdbarch_register_raw_size_ftype alpha_register_raw_size; | |
46 | static gdbarch_register_virtual_size_ftype alpha_register_virtual_size; | |
47 | static gdbarch_register_virtual_type_ftype alpha_register_virtual_type; | |
48 | static gdbarch_register_byte_ftype alpha_register_byte; | |
49 | static gdbarch_cannot_fetch_register_ftype alpha_cannot_fetch_register; | |
50 | static gdbarch_cannot_store_register_ftype alpha_cannot_store_register; | |
51 | static gdbarch_register_convertible_ftype alpha_register_convertible; | |
52 | static gdbarch_register_convert_to_virtual_ftype | |
53 | alpha_register_convert_to_virtual; | |
54 | static gdbarch_register_convert_to_raw_ftype alpha_register_convert_to_raw; | |
55 | static gdbarch_store_struct_return_ftype alpha_store_struct_return; | |
26e9b323 | 56 | static gdbarch_deprecated_extract_return_value_ftype alpha_extract_return_value; |
dc129d82 | 57 | static gdbarch_store_return_value_ftype alpha_store_return_value; |
26e9b323 | 58 | static gdbarch_deprecated_extract_struct_value_address_ftype |
dc129d82 JT |
59 | alpha_extract_struct_value_address; |
60 | static gdbarch_use_struct_convention_ftype alpha_use_struct_convention; | |
61 | ||
95b80706 JT |
62 | static gdbarch_breakpoint_from_pc_ftype alpha_breakpoint_from_pc; |
63 | ||
dc129d82 JT |
64 | static gdbarch_frame_args_address_ftype alpha_frame_args_address; |
65 | static gdbarch_frame_locals_address_ftype alpha_frame_locals_address; | |
66 | ||
67 | static gdbarch_skip_prologue_ftype alpha_skip_prologue; | |
68 | static gdbarch_get_saved_register_ftype alpha_get_saved_register; | |
69 | static gdbarch_saved_pc_after_call_ftype alpha_saved_pc_after_call; | |
70 | static gdbarch_frame_chain_ftype alpha_frame_chain; | |
71 | static gdbarch_frame_saved_pc_ftype alpha_frame_saved_pc; | |
72 | static gdbarch_frame_init_saved_regs_ftype alpha_frame_init_saved_regs; | |
73 | ||
74 | static gdbarch_push_arguments_ftype alpha_push_arguments; | |
75 | static gdbarch_push_dummy_frame_ftype alpha_push_dummy_frame; | |
76 | static gdbarch_pop_frame_ftype alpha_pop_frame; | |
77 | static gdbarch_fix_call_dummy_ftype alpha_fix_call_dummy; | |
78 | static gdbarch_init_frame_pc_first_ftype alpha_init_frame_pc_first; | |
79 | static gdbarch_init_extra_frame_info_ftype alpha_init_extra_frame_info; | |
c906108c | 80 | |
accc6d1f JT |
81 | static gdbarch_get_longjmp_target_ftype alpha_get_longjmp_target; |
82 | ||
140f9984 JT |
83 | struct frame_extra_info |
84 | { | |
85 | alpha_extra_func_info_t proc_desc; | |
86 | int localoff; | |
87 | int pc_reg; | |
88 | }; | |
89 | ||
c906108c SS |
90 | /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */ |
91 | ||
92 | /* Prototypes for local functions. */ | |
93 | ||
140f9984 JT |
94 | static void alpha_find_saved_regs (struct frame_info *); |
95 | ||
a14ed312 | 96 | static alpha_extra_func_info_t push_sigtramp_desc (CORE_ADDR low_addr); |
c906108c | 97 | |
a14ed312 | 98 | static CORE_ADDR read_next_frame_reg (struct frame_info *, int); |
c906108c | 99 | |
a14ed312 | 100 | static CORE_ADDR heuristic_proc_start (CORE_ADDR); |
c906108c | 101 | |
a14ed312 KB |
102 | static alpha_extra_func_info_t heuristic_proc_desc (CORE_ADDR, |
103 | CORE_ADDR, | |
104 | struct frame_info *); | |
c906108c | 105 | |
a14ed312 KB |
106 | static alpha_extra_func_info_t find_proc_desc (CORE_ADDR, |
107 | struct frame_info *); | |
c906108c SS |
108 | |
109 | #if 0 | |
a14ed312 | 110 | static int alpha_in_lenient_prologue (CORE_ADDR, CORE_ADDR); |
c906108c SS |
111 | #endif |
112 | ||
a14ed312 | 113 | static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *); |
c906108c | 114 | |
a14ed312 KB |
115 | static CORE_ADDR after_prologue (CORE_ADDR pc, |
116 | alpha_extra_func_info_t proc_desc); | |
c906108c | 117 | |
a14ed312 KB |
118 | static int alpha_in_prologue (CORE_ADDR pc, |
119 | alpha_extra_func_info_t proc_desc); | |
c906108c | 120 | |
a14ed312 | 121 | static int alpha_about_to_return (CORE_ADDR pc); |
392a587b | 122 | |
a14ed312 | 123 | void _initialize_alpha_tdep (void); |
392a587b | 124 | |
c906108c SS |
125 | /* Heuristic_proc_start may hunt through the text section for a long |
126 | time across a 2400 baud serial line. Allows the user to limit this | |
127 | search. */ | |
128 | static unsigned int heuristic_fence_post = 0; | |
c5aa993b | 129 | /* *INDENT-OFF* */ |
c906108c SS |
130 | /* Layout of a stack frame on the alpha: |
131 | ||
132 | | | | |
133 | pdr members: | 7th ... nth arg, | | |
134 | | `pushed' by caller. | | |
135 | | | | |
136 | ----------------|-------------------------------|<-- old_sp == vfp | |
137 | ^ ^ ^ ^ | | | |
138 | | | | | | | | |
139 | | |localoff | Copies of 1st .. 6th | | |
140 | | | | | | argument if necessary. | | |
141 | | | | v | | | |
142 | | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS | |
143 | | | | | | | |
144 | | | | | Locals and temporaries. | | |
145 | | | | | | | |
146 | | | | |-------------------------------| | |
147 | | | | | | | |
148 | |-fregoffset | Saved float registers. | | |
149 | | | | | F9 | | |
150 | | | | | . | | |
151 | | | | | . | | |
152 | | | | | F2 | | |
153 | | | v | | | |
154 | | | -------|-------------------------------| | |
155 | | | | | | |
156 | | | | Saved registers. | | |
157 | | | | S6 | | |
158 | |-regoffset | . | | |
159 | | | | . | | |
160 | | | | S0 | | |
161 | | | | pdr.pcreg | | |
162 | | v | | | |
163 | | ----------|-------------------------------| | |
164 | | | | | |
165 | frameoffset | Argument build area, gets | | |
166 | | | 7th ... nth arg for any | | |
167 | | | called procedure. | | |
168 | v | | | |
169 | -------------|-------------------------------|<-- sp | |
170 | | | | |
171 | */ | |
c5aa993b JM |
172 | /* *INDENT-ON* */ |
173 | ||
c5aa993b | 174 | #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */ |
b83266a0 SS |
175 | /* These next two fields are kind of being hijacked. I wonder if |
176 | iline is too small for the values it needs to hold, if GDB is | |
177 | running on a 32-bit host. */ | |
c5aa993b JM |
178 | #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */ |
179 | #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.cbLineOffset) /*CALL_DUMMY frame */ | |
c906108c SS |
180 | #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset) |
181 | #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg) | |
182 | #define PROC_REG_MASK(proc) ((proc)->pdr.regmask) | |
183 | #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask) | |
184 | #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset) | |
185 | #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset) | |
186 | #define PROC_PC_REG(proc) ((proc)->pdr.pcreg) | |
187 | #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff) | |
188 | #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym) | |
189 | #define _PROC_MAGIC_ 0x0F0F0F0F | |
190 | #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_) | |
191 | #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_) | |
192 | ||
193 | struct linked_proc_info | |
c5aa993b JM |
194 | { |
195 | struct alpha_extra_func_info info; | |
196 | struct linked_proc_info *next; | |
197 | } | |
198 | *linked_proc_desc_table = NULL; | |
c906108c | 199 | \f |
36a6271d JT |
200 | static CORE_ADDR |
201 | alpha_frame_past_sigtramp_frame (struct frame_info *frame, CORE_ADDR pc) | |
c906108c | 202 | { |
36a6271d JT |
203 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
204 | ||
205 | if (tdep->skip_sigtramp_frame != NULL) | |
206 | return (tdep->skip_sigtramp_frame (frame, pc)); | |
207 | ||
208 | return (0); | |
209 | } | |
210 | ||
211 | static LONGEST | |
212 | alpha_dynamic_sigtramp_offset (CORE_ADDR pc) | |
213 | { | |
214 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
215 | ||
216 | /* Must be provided by OS/ABI variant code if supported. */ | |
217 | if (tdep->dynamic_sigtramp_offset != NULL) | |
218 | return (tdep->dynamic_sigtramp_offset (pc)); | |
219 | ||
220 | return (-1); | |
221 | } | |
222 | ||
223 | #define ALPHA_PROC_SIGTRAMP_MAGIC 0x0e0f0f0f | |
224 | ||
225 | /* Return TRUE if the procedure descriptor PROC is a procedure | |
226 | descriptor that refers to a dynamically generated signal | |
227 | trampoline routine. */ | |
228 | static int | |
229 | alpha_proc_desc_is_dyn_sigtramp (struct alpha_extra_func_info *proc) | |
230 | { | |
231 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
232 | ||
233 | if (tdep->dynamic_sigtramp_offset != NULL) | |
234 | return (proc->pdr.isym == ALPHA_PROC_SIGTRAMP_MAGIC); | |
235 | ||
236 | return (0); | |
237 | } | |
238 | ||
239 | static void | |
240 | alpha_set_proc_desc_is_dyn_sigtramp (struct alpha_extra_func_info *proc) | |
241 | { | |
242 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
243 | ||
244 | if (tdep->dynamic_sigtramp_offset != NULL) | |
245 | proc->pdr.isym = ALPHA_PROC_SIGTRAMP_MAGIC; | |
c906108c | 246 | } |
c5aa993b | 247 | |
c906108c SS |
248 | /* Dynamically create a signal-handler caller procedure descriptor for |
249 | the signal-handler return code starting at address LOW_ADDR. The | |
250 | descriptor is added to the linked_proc_desc_table. */ | |
251 | ||
252 | static alpha_extra_func_info_t | |
fba45db2 | 253 | push_sigtramp_desc (CORE_ADDR low_addr) |
c906108c SS |
254 | { |
255 | struct linked_proc_info *link; | |
256 | alpha_extra_func_info_t proc_desc; | |
257 | ||
258 | link = (struct linked_proc_info *) | |
259 | xmalloc (sizeof (struct linked_proc_info)); | |
260 | link->next = linked_proc_desc_table; | |
261 | linked_proc_desc_table = link; | |
262 | ||
263 | proc_desc = &link->info; | |
264 | ||
265 | proc_desc->numargs = 0; | |
c5aa993b JM |
266 | PROC_LOW_ADDR (proc_desc) = low_addr; |
267 | PROC_HIGH_ADDR (proc_desc) = low_addr + 3 * 4; | |
268 | PROC_DUMMY_FRAME (proc_desc) = 0; | |
269 | PROC_FRAME_OFFSET (proc_desc) = 0x298; /* sizeof(struct sigcontext_struct) */ | |
270 | PROC_FRAME_REG (proc_desc) = SP_REGNUM; | |
271 | PROC_REG_MASK (proc_desc) = 0xffff; | |
272 | PROC_FREG_MASK (proc_desc) = 0xffff; | |
273 | PROC_PC_REG (proc_desc) = 26; | |
274 | PROC_LOCALOFF (proc_desc) = 0; | |
36a6271d | 275 | alpha_set_proc_desc_is_dyn_sigtramp (proc_desc); |
c906108c SS |
276 | return (proc_desc); |
277 | } | |
c906108c | 278 | \f |
c5aa993b | 279 | |
fa88f677 | 280 | static const char * |
636a6dfc JT |
281 | alpha_register_name (int regno) |
282 | { | |
283 | static char *register_names[] = | |
284 | { | |
285 | "v0", "t0", "t1", "t2", "t3", "t4", "t5", "t6", | |
286 | "t7", "s0", "s1", "s2", "s3", "s4", "s5", "fp", | |
287 | "a0", "a1", "a2", "a3", "a4", "a5", "t8", "t9", | |
288 | "t10", "t11", "ra", "t12", "at", "gp", "sp", "zero", | |
289 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", | |
290 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", | |
291 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", | |
292 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "fpcr", | |
293 | "pc", "vfp", | |
294 | }; | |
295 | ||
296 | if (regno < 0) | |
297 | return (NULL); | |
298 | if (regno >= (sizeof(register_names) / sizeof(*register_names))) | |
299 | return (NULL); | |
300 | return (register_names[regno]); | |
301 | } | |
d734c450 | 302 | |
dc129d82 | 303 | static int |
d734c450 JT |
304 | alpha_cannot_fetch_register (int regno) |
305 | { | |
dc129d82 | 306 | return (regno == FP_REGNUM || regno == ALPHA_ZERO_REGNUM); |
d734c450 JT |
307 | } |
308 | ||
dc129d82 | 309 | static int |
d734c450 JT |
310 | alpha_cannot_store_register (int regno) |
311 | { | |
dc129d82 | 312 | return (regno == FP_REGNUM || regno == ALPHA_ZERO_REGNUM); |
d734c450 JT |
313 | } |
314 | ||
dc129d82 | 315 | static int |
d734c450 JT |
316 | alpha_register_convertible (int regno) |
317 | { | |
318 | return (regno >= FP0_REGNUM && regno <= FP0_REGNUM + 31); | |
319 | } | |
0d056799 | 320 | |
dc129d82 | 321 | static struct type * |
0d056799 JT |
322 | alpha_register_virtual_type (int regno) |
323 | { | |
324 | return ((regno >= FP0_REGNUM && regno < (FP0_REGNUM+31)) | |
325 | ? builtin_type_double : builtin_type_long); | |
326 | } | |
f8453e34 | 327 | |
dc129d82 | 328 | static int |
f8453e34 JT |
329 | alpha_register_byte (int regno) |
330 | { | |
331 | return (regno * 8); | |
332 | } | |
333 | ||
dc129d82 | 334 | static int |
f8453e34 JT |
335 | alpha_register_raw_size (int regno) |
336 | { | |
337 | return 8; | |
338 | } | |
339 | ||
dc129d82 | 340 | static int |
f8453e34 JT |
341 | alpha_register_virtual_size (int regno) |
342 | { | |
343 | return 8; | |
344 | } | |
636a6dfc JT |
345 | \f |
346 | ||
5868c862 JT |
347 | static CORE_ADDR |
348 | alpha_sigcontext_addr (struct frame_info *fi) | |
349 | { | |
350 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
351 | ||
352 | if (tdep->sigcontext_addr) | |
353 | return (tdep->sigcontext_addr (fi)); | |
354 | ||
355 | return (0); | |
356 | } | |
357 | ||
c906108c SS |
358 | /* Guaranteed to set frame->saved_regs to some values (it never leaves it |
359 | NULL). */ | |
360 | ||
140f9984 | 361 | static void |
fba45db2 | 362 | alpha_find_saved_regs (struct frame_info *frame) |
c906108c SS |
363 | { |
364 | int ireg; | |
365 | CORE_ADDR reg_position; | |
366 | unsigned long mask; | |
367 | alpha_extra_func_info_t proc_desc; | |
368 | int returnreg; | |
369 | ||
370 | frame_saved_regs_zalloc (frame); | |
371 | ||
372 | /* If it is the frame for __sigtramp, the saved registers are located | |
373 | in a sigcontext structure somewhere on the stack. __sigtramp | |
374 | passes a pointer to the sigcontext structure on the stack. | |
375 | If the stack layout for __sigtramp changes, or if sigcontext offsets | |
376 | change, we might have to update this code. */ | |
377 | #ifndef SIGFRAME_PC_OFF | |
378 | #define SIGFRAME_PC_OFF (2 * 8) | |
379 | #define SIGFRAME_REGSAVE_OFF (4 * 8) | |
380 | #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8) | |
381 | #endif | |
382 | if (frame->signal_handler_caller) | |
383 | { | |
384 | CORE_ADDR sigcontext_addr; | |
385 | ||
5868c862 JT |
386 | sigcontext_addr = alpha_sigcontext_addr (frame); |
387 | if (sigcontext_addr == 0) | |
388 | { | |
389 | /* Don't know where the sigcontext is; just bail. */ | |
390 | return; | |
391 | } | |
c906108c SS |
392 | for (ireg = 0; ireg < 32; ireg++) |
393 | { | |
c5aa993b JM |
394 | reg_position = sigcontext_addr + SIGFRAME_REGSAVE_OFF + ireg * 8; |
395 | frame->saved_regs[ireg] = reg_position; | |
c906108c SS |
396 | } |
397 | for (ireg = 0; ireg < 32; ireg++) | |
398 | { | |
c5aa993b JM |
399 | reg_position = sigcontext_addr + SIGFRAME_FPREGSAVE_OFF + ireg * 8; |
400 | frame->saved_regs[FP0_REGNUM + ireg] = reg_position; | |
c906108c SS |
401 | } |
402 | frame->saved_regs[PC_REGNUM] = sigcontext_addr + SIGFRAME_PC_OFF; | |
403 | return; | |
404 | } | |
405 | ||
140f9984 | 406 | proc_desc = frame->extra_info->proc_desc; |
c906108c SS |
407 | if (proc_desc == NULL) |
408 | /* I'm not sure how/whether this can happen. Normally when we can't | |
409 | find a proc_desc, we "synthesize" one using heuristic_proc_desc | |
410 | and set the saved_regs right away. */ | |
411 | return; | |
412 | ||
413 | /* Fill in the offsets for the registers which gen_mask says | |
414 | were saved. */ | |
415 | ||
416 | reg_position = frame->frame + PROC_REG_OFFSET (proc_desc); | |
417 | mask = PROC_REG_MASK (proc_desc); | |
418 | ||
419 | returnreg = PROC_PC_REG (proc_desc); | |
420 | ||
421 | /* Note that RA is always saved first, regardless of its actual | |
422 | register number. */ | |
423 | if (mask & (1 << returnreg)) | |
424 | { | |
425 | frame->saved_regs[returnreg] = reg_position; | |
426 | reg_position += 8; | |
c5aa993b JM |
427 | mask &= ~(1 << returnreg); /* Clear bit for RA so we |
428 | don't save again later. */ | |
c906108c SS |
429 | } |
430 | ||
c5aa993b | 431 | for (ireg = 0; ireg <= 31; ++ireg) |
c906108c SS |
432 | if (mask & (1 << ireg)) |
433 | { | |
434 | frame->saved_regs[ireg] = reg_position; | |
435 | reg_position += 8; | |
436 | } | |
437 | ||
438 | /* Fill in the offsets for the registers which float_mask says | |
439 | were saved. */ | |
440 | ||
441 | reg_position = frame->frame + PROC_FREG_OFFSET (proc_desc); | |
442 | mask = PROC_FREG_MASK (proc_desc); | |
443 | ||
c5aa993b | 444 | for (ireg = 0; ireg <= 31; ++ireg) |
c906108c SS |
445 | if (mask & (1 << ireg)) |
446 | { | |
c5aa993b | 447 | frame->saved_regs[FP0_REGNUM + ireg] = reg_position; |
c906108c SS |
448 | reg_position += 8; |
449 | } | |
450 | ||
451 | frame->saved_regs[PC_REGNUM] = frame->saved_regs[returnreg]; | |
452 | } | |
453 | ||
dc129d82 | 454 | static void |
140f9984 JT |
455 | alpha_frame_init_saved_regs (struct frame_info *fi) |
456 | { | |
457 | if (fi->saved_regs == NULL) | |
458 | alpha_find_saved_regs (fi); | |
459 | fi->saved_regs[SP_REGNUM] = fi->frame; | |
460 | } | |
461 | ||
dc129d82 | 462 | static void |
0d056799 JT |
463 | alpha_init_frame_pc_first (int fromleaf, struct frame_info *prev) |
464 | { | |
465 | prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) : | |
466 | prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ()); | |
467 | } | |
468 | ||
c906108c | 469 | static CORE_ADDR |
fba45db2 | 470 | read_next_frame_reg (struct frame_info *fi, int regno) |
c906108c SS |
471 | { |
472 | for (; fi; fi = fi->next) | |
473 | { | |
474 | /* We have to get the saved sp from the sigcontext | |
c5aa993b | 475 | if it is a signal handler frame. */ |
c906108c SS |
476 | if (regno == SP_REGNUM && !fi->signal_handler_caller) |
477 | return fi->frame; | |
478 | else | |
479 | { | |
480 | if (fi->saved_regs == NULL) | |
481 | alpha_find_saved_regs (fi); | |
482 | if (fi->saved_regs[regno]) | |
c5aa993b | 483 | return read_memory_integer (fi->saved_regs[regno], 8); |
c906108c SS |
484 | } |
485 | } | |
c5aa993b | 486 | return read_register (regno); |
c906108c SS |
487 | } |
488 | ||
dc129d82 | 489 | static CORE_ADDR |
fba45db2 | 490 | alpha_frame_saved_pc (struct frame_info *frame) |
c906108c | 491 | { |
140f9984 | 492 | alpha_extra_func_info_t proc_desc = frame->extra_info->proc_desc; |
c906108c SS |
493 | /* We have to get the saved pc from the sigcontext |
494 | if it is a signal handler frame. */ | |
140f9984 JT |
495 | int pcreg = frame->signal_handler_caller ? PC_REGNUM |
496 | : frame->extra_info->pc_reg; | |
c906108c | 497 | |
c5aa993b JM |
498 | if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc)) |
499 | return read_memory_integer (frame->frame - 8, 8); | |
c906108c | 500 | |
c5aa993b | 501 | return read_next_frame_reg (frame, pcreg); |
c906108c SS |
502 | } |
503 | ||
dc129d82 JT |
504 | static void |
505 | alpha_get_saved_register (char *raw_buffer, | |
506 | int *optimized, | |
507 | CORE_ADDR *addrp, | |
508 | struct frame_info *frame, | |
509 | int regnum, | |
510 | enum lval_type *lval) | |
511 | { | |
512 | CORE_ADDR addr; | |
513 | ||
514 | if (!target_has_registers) | |
515 | error ("No registers."); | |
516 | ||
517 | /* Normal systems don't optimize out things with register numbers. */ | |
518 | if (optimized != NULL) | |
519 | *optimized = 0; | |
520 | addr = find_saved_register (frame, regnum); | |
521 | if (addr != 0) | |
522 | { | |
523 | if (lval != NULL) | |
524 | *lval = lval_memory; | |
525 | if (regnum == SP_REGNUM) | |
526 | { | |
527 | if (raw_buffer != NULL) | |
528 | { | |
529 | /* Put it back in target format. */ | |
530 | store_address (raw_buffer, REGISTER_RAW_SIZE (regnum), | |
531 | (LONGEST) addr); | |
532 | } | |
533 | if (addrp != NULL) | |
534 | *addrp = 0; | |
535 | return; | |
536 | } | |
537 | if (raw_buffer != NULL) | |
538 | target_read_memory (addr, raw_buffer, REGISTER_RAW_SIZE (regnum)); | |
539 | } | |
540 | else | |
541 | { | |
542 | if (lval != NULL) | |
543 | *lval = lval_register; | |
544 | addr = REGISTER_BYTE (regnum); | |
545 | if (raw_buffer != NULL) | |
546 | read_register_gen (regnum, raw_buffer); | |
547 | } | |
548 | if (addrp != NULL) | |
549 | *addrp = addr; | |
550 | } | |
551 | ||
552 | static CORE_ADDR | |
fba45db2 | 553 | alpha_saved_pc_after_call (struct frame_info *frame) |
c906108c SS |
554 | { |
555 | CORE_ADDR pc = frame->pc; | |
556 | CORE_ADDR tmp; | |
557 | alpha_extra_func_info_t proc_desc; | |
558 | int pcreg; | |
559 | ||
560 | /* Skip over shared library trampoline if necessary. */ | |
561 | tmp = SKIP_TRAMPOLINE_CODE (pc); | |
562 | if (tmp != 0) | |
563 | pc = tmp; | |
564 | ||
565 | proc_desc = find_proc_desc (pc, frame->next); | |
dc129d82 | 566 | pcreg = proc_desc ? PROC_PC_REG (proc_desc) : ALPHA_RA_REGNUM; |
c906108c SS |
567 | |
568 | if (frame->signal_handler_caller) | |
569 | return alpha_frame_saved_pc (frame); | |
570 | else | |
571 | return read_register (pcreg); | |
572 | } | |
573 | ||
574 | ||
575 | static struct alpha_extra_func_info temp_proc_desc; | |
dc129d82 | 576 | static CORE_ADDR temp_saved_regs[ALPHA_NUM_REGS]; |
c906108c SS |
577 | |
578 | /* Nonzero if instruction at PC is a return instruction. "ret | |
579 | $zero,($ra),1" on alpha. */ | |
580 | ||
581 | static int | |
fba45db2 | 582 | alpha_about_to_return (CORE_ADDR pc) |
c906108c SS |
583 | { |
584 | return read_memory_integer (pc, 4) == 0x6bfa8001; | |
585 | } | |
586 | ||
587 | ||
588 | ||
589 | /* This fencepost looks highly suspicious to me. Removing it also | |
590 | seems suspicious as it could affect remote debugging across serial | |
591 | lines. */ | |
592 | ||
593 | static CORE_ADDR | |
fba45db2 | 594 | heuristic_proc_start (CORE_ADDR pc) |
c906108c | 595 | { |
d9b023cc | 596 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); |
c5aa993b JM |
597 | CORE_ADDR start_pc = pc; |
598 | CORE_ADDR fence = start_pc - heuristic_fence_post; | |
c906108c | 599 | |
c5aa993b JM |
600 | if (start_pc == 0) |
601 | return 0; | |
c906108c | 602 | |
c5aa993b | 603 | if (heuristic_fence_post == UINT_MAX |
d9b023cc JT |
604 | || fence < tdep->vm_min_address) |
605 | fence = tdep->vm_min_address; | |
c906108c | 606 | |
c5aa993b JM |
607 | /* search back for previous return */ |
608 | for (start_pc -= 4;; start_pc -= 4) | |
609 | if (start_pc < fence) | |
610 | { | |
611 | /* It's not clear to me why we reach this point when | |
612 | stop_soon_quietly, but with this test, at least we | |
613 | don't print out warnings for every child forked (eg, on | |
614 | decstation). 22apr93 [email protected]. */ | |
615 | if (!stop_soon_quietly) | |
c906108c | 616 | { |
c5aa993b JM |
617 | static int blurb_printed = 0; |
618 | ||
d9b023cc | 619 | if (fence == tdep->vm_min_address) |
c5aa993b JM |
620 | warning ("Hit beginning of text section without finding"); |
621 | else | |
622 | warning ("Hit heuristic-fence-post without finding"); | |
623 | ||
d4f3574e | 624 | warning ("enclosing function for address 0x%s", paddr_nz (pc)); |
c5aa993b | 625 | if (!blurb_printed) |
c906108c | 626 | { |
c5aa993b | 627 | printf_filtered ("\ |
c906108c SS |
628 | This warning occurs if you are debugging a function without any symbols\n\ |
629 | (for example, in a stripped executable). In that case, you may wish to\n\ | |
630 | increase the size of the search with the `set heuristic-fence-post' command.\n\ | |
631 | \n\ | |
632 | Otherwise, you told GDB there was a function where there isn't one, or\n\ | |
633 | (more likely) you have encountered a bug in GDB.\n"); | |
c5aa993b | 634 | blurb_printed = 1; |
c906108c | 635 | } |
c906108c | 636 | } |
c906108c | 637 | |
c5aa993b JM |
638 | return 0; |
639 | } | |
640 | else if (alpha_about_to_return (start_pc)) | |
641 | break; | |
642 | ||
643 | start_pc += 4; /* skip return */ | |
644 | return start_pc; | |
c906108c SS |
645 | } |
646 | ||
647 | static alpha_extra_func_info_t | |
fba45db2 KB |
648 | heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc, |
649 | struct frame_info *next_frame) | |
c906108c | 650 | { |
c5aa993b | 651 | CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM); |
dc1b0db2 | 652 | CORE_ADDR vfp = sp; |
c5aa993b JM |
653 | CORE_ADDR cur_pc; |
654 | int frame_size; | |
655 | int has_frame_reg = 0; | |
656 | unsigned long reg_mask = 0; | |
657 | int pcreg = -1; | |
dc1b0db2 | 658 | int regno; |
c5aa993b JM |
659 | |
660 | if (start_pc == 0) | |
661 | return NULL; | |
662 | memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc)); | |
140f9984 | 663 | memset (&temp_saved_regs, '\0', SIZEOF_FRAME_SAVED_REGS); |
c5aa993b JM |
664 | PROC_LOW_ADDR (&temp_proc_desc) = start_pc; |
665 | ||
666 | if (start_pc + 200 < limit_pc) | |
667 | limit_pc = start_pc + 200; | |
668 | frame_size = 0; | |
669 | for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4) | |
670 | { | |
671 | char buf[4]; | |
672 | unsigned long word; | |
673 | int status; | |
c906108c | 674 | |
c5aa993b JM |
675 | status = read_memory_nobpt (cur_pc, buf, 4); |
676 | if (status) | |
677 | memory_error (status, cur_pc); | |
678 | word = extract_unsigned_integer (buf, 4); | |
c906108c | 679 | |
c5aa993b JM |
680 | if ((word & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */ |
681 | { | |
682 | if (word & 0x8000) | |
dc1b0db2 JB |
683 | { |
684 | /* Consider only the first stack allocation instruction | |
685 | to contain the static size of the frame. */ | |
686 | if (frame_size == 0) | |
687 | frame_size += (-word) & 0xffff; | |
688 | } | |
c5aa993b JM |
689 | else |
690 | /* Exit loop if a positive stack adjustment is found, which | |
691 | usually means that the stack cleanup code in the function | |
692 | epilogue is reached. */ | |
693 | break; | |
694 | } | |
695 | else if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */ | |
696 | && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */ | |
697 | { | |
698 | int reg = (word & 0x03e00000) >> 21; | |
699 | reg_mask |= 1 << reg; | |
dc1b0db2 JB |
700 | |
701 | /* Do not compute the address where the register was saved yet, | |
702 | because we don't know yet if the offset will need to be | |
703 | relative to $sp or $fp (we can not compute the address relative | |
704 | to $sp if $sp is updated during the execution of the current | |
705 | subroutine, for instance when doing some alloca). So just store | |
706 | the offset for the moment, and compute the address later | |
707 | when we know whether this frame has a frame pointer or not. | |
708 | */ | |
709 | temp_saved_regs[reg] = (short) word; | |
c5aa993b JM |
710 | |
711 | /* Starting with OSF/1-3.2C, the system libraries are shipped | |
712 | without local symbols, but they still contain procedure | |
713 | descriptors without a symbol reference. GDB is currently | |
714 | unable to find these procedure descriptors and uses | |
715 | heuristic_proc_desc instead. | |
716 | As some low level compiler support routines (__div*, __add*) | |
717 | use a non-standard return address register, we have to | |
718 | add some heuristics to determine the return address register, | |
719 | or stepping over these routines will fail. | |
720 | Usually the return address register is the first register | |
721 | saved on the stack, but assembler optimization might | |
722 | rearrange the register saves. | |
723 | So we recognize only a few registers (t7, t9, ra) within | |
724 | the procedure prologue as valid return address registers. | |
725 | If we encounter a return instruction, we extract the | |
726 | the return address register from it. | |
727 | ||
728 | FIXME: Rewriting GDB to access the procedure descriptors, | |
729 | e.g. via the minimal symbol table, might obviate this hack. */ | |
730 | if (pcreg == -1 | |
731 | && cur_pc < (start_pc + 80) | |
dc129d82 JT |
732 | && (reg == ALPHA_T7_REGNUM || reg == ALPHA_T9_REGNUM |
733 | || reg == ALPHA_RA_REGNUM)) | |
c5aa993b JM |
734 | pcreg = reg; |
735 | } | |
736 | else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */ | |
737 | pcreg = (word >> 16) & 0x1f; | |
dc1b0db2 JB |
738 | else if (word == 0x47de040f || word == 0x47fe040f) /* bis sp,sp fp */ |
739 | { | |
740 | /* ??? I am not sure what instruction is 0x47fe040f, and I | |
741 | am suspecting that there was a typo and should have been | |
742 | 0x47fe040f. I'm keeping it in the test above until further | |
743 | investigation */ | |
744 | has_frame_reg = 1; | |
745 | vfp = read_next_frame_reg (next_frame, ALPHA_GCC_FP_REGNUM); | |
746 | } | |
c5aa993b JM |
747 | } |
748 | if (pcreg == -1) | |
749 | { | |
750 | /* If we haven't found a valid return address register yet, | |
751 | keep searching in the procedure prologue. */ | |
752 | while (cur_pc < (limit_pc + 80) && cur_pc < (start_pc + 80)) | |
753 | { | |
754 | char buf[4]; | |
755 | unsigned long word; | |
c906108c | 756 | |
c5aa993b JM |
757 | if (read_memory_nobpt (cur_pc, buf, 4)) |
758 | break; | |
759 | cur_pc += 4; | |
760 | word = extract_unsigned_integer (buf, 4); | |
c906108c | 761 | |
c5aa993b JM |
762 | if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */ |
763 | && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */ | |
764 | { | |
765 | int reg = (word & 0x03e00000) >> 21; | |
dc129d82 JT |
766 | if (reg == ALPHA_T7_REGNUM || reg == ALPHA_T9_REGNUM |
767 | || reg == ALPHA_RA_REGNUM) | |
c5aa993b JM |
768 | { |
769 | pcreg = reg; | |
770 | break; | |
771 | } | |
772 | } | |
773 | else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */ | |
774 | { | |
775 | pcreg = (word >> 16) & 0x1f; | |
776 | break; | |
777 | } | |
778 | } | |
779 | } | |
c906108c | 780 | |
c5aa993b | 781 | if (has_frame_reg) |
dc129d82 | 782 | PROC_FRAME_REG (&temp_proc_desc) = ALPHA_GCC_FP_REGNUM; |
c5aa993b JM |
783 | else |
784 | PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM; | |
dc1b0db2 JB |
785 | |
786 | /* At this point, we know which of the Stack Pointer or the Frame Pointer | |
787 | to use as the reference address to compute the saved registers address. | |
788 | But in both cases, the processing above has set vfp to this reference | |
789 | address, so just need to increment the offset of each saved register | |
790 | by this address. */ | |
791 | for (regno = 0; regno < NUM_REGS; regno++) | |
792 | { | |
793 | if (reg_mask & 1 << regno) | |
794 | temp_saved_regs[regno] += vfp; | |
795 | } | |
796 | ||
c5aa993b JM |
797 | PROC_FRAME_OFFSET (&temp_proc_desc) = frame_size; |
798 | PROC_REG_MASK (&temp_proc_desc) = reg_mask; | |
dc129d82 | 799 | PROC_PC_REG (&temp_proc_desc) = (pcreg == -1) ? ALPHA_RA_REGNUM : pcreg; |
c5aa993b JM |
800 | PROC_LOCALOFF (&temp_proc_desc) = 0; /* XXX - bogus */ |
801 | return &temp_proc_desc; | |
c906108c SS |
802 | } |
803 | ||
804 | /* This returns the PC of the first inst after the prologue. If we can't | |
805 | find the prologue, then return 0. */ | |
806 | ||
807 | static CORE_ADDR | |
fba45db2 | 808 | after_prologue (CORE_ADDR pc, alpha_extra_func_info_t proc_desc) |
c906108c SS |
809 | { |
810 | struct symtab_and_line sal; | |
811 | CORE_ADDR func_addr, func_end; | |
812 | ||
813 | if (!proc_desc) | |
814 | proc_desc = find_proc_desc (pc, NULL); | |
815 | ||
816 | if (proc_desc) | |
817 | { | |
36a6271d | 818 | if (alpha_proc_desc_is_dyn_sigtramp (proc_desc)) |
c906108c SS |
819 | return PROC_LOW_ADDR (proc_desc); /* "prologue" is in kernel */ |
820 | ||
821 | /* If function is frameless, then we need to do it the hard way. I | |
c5aa993b | 822 | strongly suspect that frameless always means prologueless... */ |
c906108c SS |
823 | if (PROC_FRAME_REG (proc_desc) == SP_REGNUM |
824 | && PROC_FRAME_OFFSET (proc_desc) == 0) | |
825 | return 0; | |
826 | } | |
827 | ||
828 | if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
829 | return 0; /* Unknown */ | |
830 | ||
831 | sal = find_pc_line (func_addr, 0); | |
832 | ||
833 | if (sal.end < func_end) | |
834 | return sal.end; | |
835 | ||
836 | /* The line after the prologue is after the end of the function. In this | |
837 | case, tell the caller to find the prologue the hard way. */ | |
838 | ||
839 | return 0; | |
840 | } | |
841 | ||
842 | /* Return non-zero if we *might* be in a function prologue. Return zero if we | |
843 | are definitively *not* in a function prologue. */ | |
844 | ||
845 | static int | |
fba45db2 | 846 | alpha_in_prologue (CORE_ADDR pc, alpha_extra_func_info_t proc_desc) |
c906108c SS |
847 | { |
848 | CORE_ADDR after_prologue_pc; | |
849 | ||
850 | after_prologue_pc = after_prologue (pc, proc_desc); | |
851 | ||
852 | if (after_prologue_pc == 0 | |
853 | || pc < after_prologue_pc) | |
854 | return 1; | |
855 | else | |
856 | return 0; | |
857 | } | |
858 | ||
859 | static alpha_extra_func_info_t | |
fba45db2 | 860 | find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame) |
c906108c SS |
861 | { |
862 | alpha_extra_func_info_t proc_desc; | |
863 | struct block *b; | |
864 | struct symbol *sym; | |
865 | CORE_ADDR startaddr; | |
866 | ||
867 | /* Try to get the proc_desc from the linked call dummy proc_descs | |
868 | if the pc is in the call dummy. | |
869 | This is hairy. In the case of nested dummy calls we have to find the | |
870 | right proc_desc, but we might not yet know the frame for the dummy | |
871 | as it will be contained in the proc_desc we are searching for. | |
872 | So we have to find the proc_desc whose frame is closest to the current | |
873 | stack pointer. */ | |
874 | ||
875 | if (PC_IN_CALL_DUMMY (pc, 0, 0)) | |
876 | { | |
877 | struct linked_proc_info *link; | |
878 | CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM); | |
879 | alpha_extra_func_info_t found_proc_desc = NULL; | |
880 | long min_distance = LONG_MAX; | |
881 | ||
882 | for (link = linked_proc_desc_table; link; link = link->next) | |
883 | { | |
884 | long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp; | |
885 | if (distance > 0 && distance < min_distance) | |
886 | { | |
887 | min_distance = distance; | |
888 | found_proc_desc = &link->info; | |
889 | } | |
890 | } | |
891 | if (found_proc_desc != NULL) | |
892 | return found_proc_desc; | |
893 | } | |
894 | ||
c5aa993b | 895 | b = block_for_pc (pc); |
c906108c SS |
896 | |
897 | find_pc_partial_function (pc, NULL, &startaddr, NULL); | |
898 | if (b == NULL) | |
899 | sym = NULL; | |
900 | else | |
901 | { | |
902 | if (startaddr > BLOCK_START (b)) | |
903 | /* This is the "pathological" case referred to in a comment in | |
904 | print_frame_info. It might be better to move this check into | |
905 | symbol reading. */ | |
906 | sym = NULL; | |
907 | else | |
908 | sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, | |
909 | 0, NULL); | |
910 | } | |
911 | ||
912 | /* If we never found a PDR for this function in symbol reading, then | |
913 | examine prologues to find the information. */ | |
914 | if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1) | |
915 | sym = NULL; | |
916 | ||
917 | if (sym) | |
918 | { | |
c5aa993b JM |
919 | /* IF this is the topmost frame AND |
920 | * (this proc does not have debugging information OR | |
921 | * the PC is in the procedure prologue) | |
922 | * THEN create a "heuristic" proc_desc (by analyzing | |
923 | * the actual code) to replace the "official" proc_desc. | |
924 | */ | |
925 | proc_desc = (alpha_extra_func_info_t) SYMBOL_VALUE (sym); | |
926 | if (next_frame == NULL) | |
927 | { | |
928 | if (PROC_DESC_IS_DUMMY (proc_desc) || alpha_in_prologue (pc, proc_desc)) | |
929 | { | |
930 | alpha_extra_func_info_t found_heuristic = | |
931 | heuristic_proc_desc (PROC_LOW_ADDR (proc_desc), | |
932 | pc, next_frame); | |
933 | if (found_heuristic) | |
934 | { | |
935 | PROC_LOCALOFF (found_heuristic) = | |
936 | PROC_LOCALOFF (proc_desc); | |
937 | PROC_PC_REG (found_heuristic) = PROC_PC_REG (proc_desc); | |
938 | proc_desc = found_heuristic; | |
939 | } | |
940 | } | |
941 | } | |
c906108c SS |
942 | } |
943 | else | |
944 | { | |
945 | long offset; | |
946 | ||
947 | /* Is linked_proc_desc_table really necessary? It only seems to be used | |
c5aa993b JM |
948 | by procedure call dummys. However, the procedures being called ought |
949 | to have their own proc_descs, and even if they don't, | |
950 | heuristic_proc_desc knows how to create them! */ | |
c906108c SS |
951 | |
952 | register struct linked_proc_info *link; | |
953 | for (link = linked_proc_desc_table; link; link = link->next) | |
c5aa993b JM |
954 | if (PROC_LOW_ADDR (&link->info) <= pc |
955 | && PROC_HIGH_ADDR (&link->info) > pc) | |
956 | return &link->info; | |
c906108c SS |
957 | |
958 | /* If PC is inside a dynamically generated sigtramp handler, | |
c5aa993b | 959 | create and push a procedure descriptor for that code: */ |
36a6271d | 960 | offset = alpha_dynamic_sigtramp_offset (pc); |
c906108c SS |
961 | if (offset >= 0) |
962 | return push_sigtramp_desc (pc - offset); | |
963 | ||
964 | /* If heuristic_fence_post is non-zero, determine the procedure | |
c5aa993b JM |
965 | start address by examining the instructions. |
966 | This allows us to find the start address of static functions which | |
967 | have no symbolic information, as startaddr would have been set to | |
968 | the preceding global function start address by the | |
969 | find_pc_partial_function call above. */ | |
c906108c SS |
970 | if (startaddr == 0 || heuristic_fence_post != 0) |
971 | startaddr = heuristic_proc_start (pc); | |
972 | ||
973 | proc_desc = | |
974 | heuristic_proc_desc (startaddr, pc, next_frame); | |
975 | } | |
976 | return proc_desc; | |
977 | } | |
978 | ||
979 | alpha_extra_func_info_t cached_proc_desc; | |
980 | ||
dc129d82 | 981 | static CORE_ADDR |
fba45db2 | 982 | alpha_frame_chain (struct frame_info *frame) |
c906108c | 983 | { |
c5aa993b JM |
984 | alpha_extra_func_info_t proc_desc; |
985 | CORE_ADDR saved_pc = FRAME_SAVED_PC (frame); | |
986 | ||
987 | if (saved_pc == 0 || inside_entry_file (saved_pc)) | |
988 | return 0; | |
989 | ||
990 | proc_desc = find_proc_desc (saved_pc, frame); | |
991 | if (!proc_desc) | |
992 | return 0; | |
993 | ||
994 | cached_proc_desc = proc_desc; | |
995 | ||
996 | /* Fetch the frame pointer for a dummy frame from the procedure | |
997 | descriptor. */ | |
998 | if (PROC_DESC_IS_DUMMY (proc_desc)) | |
999 | return (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc); | |
1000 | ||
1001 | /* If no frame pointer and frame size is zero, we must be at end | |
1002 | of stack (or otherwise hosed). If we don't check frame size, | |
1003 | we loop forever if we see a zero size frame. */ | |
1004 | if (PROC_FRAME_REG (proc_desc) == SP_REGNUM | |
1005 | && PROC_FRAME_OFFSET (proc_desc) == 0 | |
1006 | /* The previous frame from a sigtramp frame might be frameless | |
1007 | and have frame size zero. */ | |
1008 | && !frame->signal_handler_caller) | |
36a6271d | 1009 | return alpha_frame_past_sigtramp_frame (frame, saved_pc); |
c5aa993b JM |
1010 | else |
1011 | return read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc)) | |
1012 | + PROC_FRAME_OFFSET (proc_desc); | |
c906108c SS |
1013 | } |
1014 | ||
1015 | void | |
140f9984 JT |
1016 | alpha_print_extra_frame_info (struct frame_info *fi) |
1017 | { | |
1018 | if (fi | |
1019 | && fi->extra_info | |
1020 | && fi->extra_info->proc_desc | |
1021 | && fi->extra_info->proc_desc->pdr.framereg < NUM_REGS) | |
1022 | printf_filtered (" frame pointer is at %s+%s\n", | |
1023 | REGISTER_NAME (fi->extra_info->proc_desc->pdr.framereg), | |
1024 | paddr_d (fi->extra_info->proc_desc->pdr.frameoffset)); | |
1025 | } | |
1026 | ||
dc129d82 | 1027 | static void |
140f9984 | 1028 | alpha_init_extra_frame_info (int fromleaf, struct frame_info *frame) |
c906108c SS |
1029 | { |
1030 | /* Use proc_desc calculated in frame_chain */ | |
1031 | alpha_extra_func_info_t proc_desc = | |
c5aa993b | 1032 | frame->next ? cached_proc_desc : find_proc_desc (frame->pc, frame->next); |
c906108c | 1033 | |
140f9984 JT |
1034 | frame->extra_info = (struct frame_extra_info *) |
1035 | frame_obstack_alloc (sizeof (struct frame_extra_info)); | |
1036 | ||
c906108c | 1037 | frame->saved_regs = NULL; |
140f9984 | 1038 | frame->extra_info->localoff = 0; |
dc129d82 | 1039 | frame->extra_info->pc_reg = ALPHA_RA_REGNUM; |
140f9984 | 1040 | frame->extra_info->proc_desc = proc_desc == &temp_proc_desc ? 0 : proc_desc; |
c906108c SS |
1041 | if (proc_desc) |
1042 | { | |
1043 | /* Get the locals offset and the saved pc register from the | |
c5aa993b JM |
1044 | procedure descriptor, they are valid even if we are in the |
1045 | middle of the prologue. */ | |
140f9984 JT |
1046 | frame->extra_info->localoff = PROC_LOCALOFF (proc_desc); |
1047 | frame->extra_info->pc_reg = PROC_PC_REG (proc_desc); | |
c906108c SS |
1048 | |
1049 | /* Fixup frame-pointer - only needed for top frame */ | |
1050 | ||
1051 | /* Fetch the frame pointer for a dummy frame from the procedure | |
c5aa993b JM |
1052 | descriptor. */ |
1053 | if (PROC_DESC_IS_DUMMY (proc_desc)) | |
1054 | frame->frame = (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc); | |
c906108c SS |
1055 | |
1056 | /* This may not be quite right, if proc has a real frame register. | |
c5aa993b JM |
1057 | Get the value of the frame relative sp, procedure might have been |
1058 | interrupted by a signal at it's very start. */ | |
c906108c | 1059 | else if (frame->pc == PROC_LOW_ADDR (proc_desc) |
36a6271d | 1060 | && !alpha_proc_desc_is_dyn_sigtramp (proc_desc)) |
c906108c SS |
1061 | frame->frame = read_next_frame_reg (frame->next, SP_REGNUM); |
1062 | else | |
1063 | frame->frame = read_next_frame_reg (frame->next, PROC_FRAME_REG (proc_desc)) | |
1064 | + PROC_FRAME_OFFSET (proc_desc); | |
1065 | ||
1066 | if (proc_desc == &temp_proc_desc) | |
1067 | { | |
1068 | char *name; | |
1069 | ||
1070 | /* Do not set the saved registers for a sigtramp frame, | |
1071 | alpha_find_saved_registers will do that for us. | |
1072 | We can't use frame->signal_handler_caller, it is not yet set. */ | |
1073 | find_pc_partial_function (frame->pc, &name, | |
c5aa993b | 1074 | (CORE_ADDR *) NULL, (CORE_ADDR *) NULL); |
d7bd68ca | 1075 | if (!PC_IN_SIGTRAMP (frame->pc, name)) |
c906108c | 1076 | { |
c5aa993b | 1077 | frame->saved_regs = (CORE_ADDR *) |
c906108c | 1078 | frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS); |
140f9984 JT |
1079 | memcpy (frame->saved_regs, temp_saved_regs, |
1080 | SIZEOF_FRAME_SAVED_REGS); | |
c906108c | 1081 | frame->saved_regs[PC_REGNUM] |
dc129d82 | 1082 | = frame->saved_regs[ALPHA_RA_REGNUM]; |
c906108c SS |
1083 | } |
1084 | } | |
1085 | } | |
1086 | } | |
1087 | ||
dc129d82 | 1088 | static CORE_ADDR |
140f9984 JT |
1089 | alpha_frame_locals_address (struct frame_info *fi) |
1090 | { | |
1091 | return (fi->frame - fi->extra_info->localoff); | |
1092 | } | |
1093 | ||
dc129d82 | 1094 | static CORE_ADDR |
140f9984 JT |
1095 | alpha_frame_args_address (struct frame_info *fi) |
1096 | { | |
1097 | return (fi->frame - (ALPHA_NUM_ARG_REGS * 8)); | |
1098 | } | |
1099 | ||
c906108c SS |
1100 | /* ALPHA stack frames are almost impenetrable. When execution stops, |
1101 | we basically have to look at symbol information for the function | |
1102 | that we stopped in, which tells us *which* register (if any) is | |
1103 | the base of the frame pointer, and what offset from that register | |
1104 | the frame itself is at. | |
1105 | ||
1106 | This presents a problem when trying to examine a stack in memory | |
1107 | (that isn't executing at the moment), using the "frame" command. We | |
1108 | don't have a PC, nor do we have any registers except SP. | |
1109 | ||
1110 | This routine takes two arguments, SP and PC, and tries to make the | |
1111 | cached frames look as if these two arguments defined a frame on the | |
1112 | cache. This allows the rest of info frame to extract the important | |
1113 | arguments without difficulty. */ | |
1114 | ||
1115 | struct frame_info * | |
a57f9e49 | 1116 | alpha_setup_arbitrary_frame (int argc, CORE_ADDR *argv) |
c906108c SS |
1117 | { |
1118 | if (argc != 2) | |
1119 | error ("ALPHA frame specifications require two arguments: sp and pc"); | |
1120 | ||
1121 | return create_new_frame (argv[0], argv[1]); | |
1122 | } | |
1123 | ||
1124 | /* The alpha passes the first six arguments in the registers, the rest on | |
1125 | the stack. The register arguments are eventually transferred to the | |
1126 | argument transfer area immediately below the stack by the called function | |
1127 | anyway. So we `push' at least six arguments on the stack, `reload' the | |
1128 | argument registers and then adjust the stack pointer to point past the | |
1129 | sixth argument. This algorithm simplifies the passing of a large struct | |
1130 | which extends from the registers to the stack. | |
1131 | If the called function is returning a structure, the address of the | |
1132 | structure to be returned is passed as a hidden first argument. */ | |
1133 | ||
dc129d82 | 1134 | static CORE_ADDR |
ea7c478f | 1135 | alpha_push_arguments (int nargs, struct value **args, CORE_ADDR sp, |
fba45db2 | 1136 | int struct_return, CORE_ADDR struct_addr) |
c906108c | 1137 | { |
7a292a7a | 1138 | int i; |
c906108c SS |
1139 | int accumulate_size = struct_return ? 8 : 0; |
1140 | int arg_regs_size = ALPHA_NUM_ARG_REGS * 8; | |
c5aa993b JM |
1141 | struct alpha_arg |
1142 | { | |
1143 | char *contents; | |
1144 | int len; | |
1145 | int offset; | |
1146 | }; | |
c906108c | 1147 | struct alpha_arg *alpha_args = |
c5aa993b | 1148 | (struct alpha_arg *) alloca (nargs * sizeof (struct alpha_arg)); |
c906108c SS |
1149 | register struct alpha_arg *m_arg; |
1150 | char raw_buffer[sizeof (CORE_ADDR)]; | |
1151 | int required_arg_regs; | |
1152 | ||
1153 | for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++) | |
1154 | { | |
ea7c478f | 1155 | struct value *arg = args[i]; |
c906108c SS |
1156 | struct type *arg_type = check_typedef (VALUE_TYPE (arg)); |
1157 | /* Cast argument to long if necessary as the compiler does it too. */ | |
1158 | switch (TYPE_CODE (arg_type)) | |
1159 | { | |
1160 | case TYPE_CODE_INT: | |
1161 | case TYPE_CODE_BOOL: | |
1162 | case TYPE_CODE_CHAR: | |
1163 | case TYPE_CODE_RANGE: | |
1164 | case TYPE_CODE_ENUM: | |
1165 | if (TYPE_LENGTH (arg_type) < TYPE_LENGTH (builtin_type_long)) | |
1166 | { | |
1167 | arg_type = builtin_type_long; | |
1168 | arg = value_cast (arg_type, arg); | |
1169 | } | |
1170 | break; | |
1171 | default: | |
1172 | break; | |
1173 | } | |
1174 | m_arg->len = TYPE_LENGTH (arg_type); | |
1175 | m_arg->offset = accumulate_size; | |
1176 | accumulate_size = (accumulate_size + m_arg->len + 7) & ~7; | |
c5aa993b | 1177 | m_arg->contents = VALUE_CONTENTS (arg); |
c906108c SS |
1178 | } |
1179 | ||
1180 | /* Determine required argument register loads, loading an argument register | |
1181 | is expensive as it uses three ptrace calls. */ | |
1182 | required_arg_regs = accumulate_size / 8; | |
1183 | if (required_arg_regs > ALPHA_NUM_ARG_REGS) | |
1184 | required_arg_regs = ALPHA_NUM_ARG_REGS; | |
1185 | ||
1186 | /* Make room for the arguments on the stack. */ | |
1187 | if (accumulate_size < arg_regs_size) | |
c5aa993b | 1188 | accumulate_size = arg_regs_size; |
c906108c SS |
1189 | sp -= accumulate_size; |
1190 | ||
1191 | /* Keep sp aligned to a multiple of 16 as the compiler does it too. */ | |
1192 | sp &= ~15; | |
1193 | ||
1194 | /* `Push' arguments on the stack. */ | |
c5aa993b JM |
1195 | for (i = nargs; m_arg--, --i >= 0;) |
1196 | write_memory (sp + m_arg->offset, m_arg->contents, m_arg->len); | |
c906108c SS |
1197 | if (struct_return) |
1198 | { | |
1199 | store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr); | |
1200 | write_memory (sp, raw_buffer, sizeof (CORE_ADDR)); | |
1201 | } | |
1202 | ||
1203 | /* Load the argument registers. */ | |
1204 | for (i = 0; i < required_arg_regs; i++) | |
1205 | { | |
1206 | LONGEST val; | |
1207 | ||
1208 | val = read_memory_integer (sp + i * 8, 8); | |
dc129d82 JT |
1209 | write_register (ALPHA_A0_REGNUM + i, val); |
1210 | write_register (ALPHA_FPA0_REGNUM + i, val); | |
c906108c SS |
1211 | } |
1212 | ||
1213 | return sp + arg_regs_size; | |
1214 | } | |
1215 | ||
dc129d82 | 1216 | static void |
fba45db2 | 1217 | alpha_push_dummy_frame (void) |
c906108c SS |
1218 | { |
1219 | int ireg; | |
1220 | struct linked_proc_info *link; | |
1221 | alpha_extra_func_info_t proc_desc; | |
1222 | CORE_ADDR sp = read_register (SP_REGNUM); | |
1223 | CORE_ADDR save_address; | |
dc129d82 | 1224 | char raw_buffer[ALPHA_MAX_REGISTER_RAW_SIZE]; |
c906108c SS |
1225 | unsigned long mask; |
1226 | ||
c5aa993b | 1227 | link = (struct linked_proc_info *) xmalloc (sizeof (struct linked_proc_info)); |
c906108c SS |
1228 | link->next = linked_proc_desc_table; |
1229 | linked_proc_desc_table = link; | |
c5aa993b | 1230 | |
c906108c SS |
1231 | proc_desc = &link->info; |
1232 | ||
1233 | /* | |
1234 | * The registers we must save are all those not preserved across | |
1235 | * procedure calls. | |
1236 | * In addition, we must save the PC and RA. | |
1237 | * | |
1238 | * Dummy frame layout: | |
1239 | * (high memory) | |
c5aa993b | 1240 | * Saved PC |
c906108c SS |
1241 | * Saved F30 |
1242 | * ... | |
1243 | * Saved F0 | |
c5aa993b JM |
1244 | * Saved R29 |
1245 | * ... | |
1246 | * Saved R0 | |
1247 | * Saved R26 (RA) | |
1248 | * Parameter build area | |
c906108c SS |
1249 | * (low memory) |
1250 | */ | |
1251 | ||
1252 | /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */ | |
1253 | #define MASK(i,j) ((((LONGEST)1 << ((j)+1)) - 1) ^ (((LONGEST)1 << (i)) - 1)) | |
1254 | #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29)) | |
1255 | #define GEN_REG_SAVE_COUNT 24 | |
1256 | #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30)) | |
1257 | #define FLOAT_REG_SAVE_COUNT 23 | |
1258 | /* The special register is the PC as we have no bit for it in the save masks. | |
1259 | alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */ | |
1260 | #define SPECIAL_REG_SAVE_COUNT 1 | |
1261 | ||
c5aa993b JM |
1262 | PROC_REG_MASK (proc_desc) = GEN_REG_SAVE_MASK; |
1263 | PROC_FREG_MASK (proc_desc) = FLOAT_REG_SAVE_MASK; | |
c906108c SS |
1264 | /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA, |
1265 | but keep SP aligned to a multiple of 16. */ | |
c5aa993b JM |
1266 | PROC_REG_OFFSET (proc_desc) = |
1267 | -((8 * (SPECIAL_REG_SAVE_COUNT | |
c906108c SS |
1268 | + GEN_REG_SAVE_COUNT |
1269 | + FLOAT_REG_SAVE_COUNT) | |
c5aa993b JM |
1270 | + 15) & ~15); |
1271 | PROC_FREG_OFFSET (proc_desc) = | |
1272 | PROC_REG_OFFSET (proc_desc) + 8 * GEN_REG_SAVE_COUNT; | |
c906108c SS |
1273 | |
1274 | /* Save general registers. | |
1275 | The return address register is the first saved register, all other | |
1276 | registers follow in ascending order. | |
1277 | The PC is saved immediately below the SP. */ | |
c5aa993b | 1278 | save_address = sp + PROC_REG_OFFSET (proc_desc); |
dc129d82 | 1279 | store_address (raw_buffer, 8, read_register (ALPHA_RA_REGNUM)); |
c906108c SS |
1280 | write_memory (save_address, raw_buffer, 8); |
1281 | save_address += 8; | |
c5aa993b | 1282 | mask = PROC_REG_MASK (proc_desc) & 0xffffffffL; |
c906108c SS |
1283 | for (ireg = 0; mask; ireg++, mask >>= 1) |
1284 | if (mask & 1) | |
1285 | { | |
dc129d82 | 1286 | if (ireg == ALPHA_RA_REGNUM) |
c906108c SS |
1287 | continue; |
1288 | store_address (raw_buffer, 8, read_register (ireg)); | |
1289 | write_memory (save_address, raw_buffer, 8); | |
1290 | save_address += 8; | |
1291 | } | |
1292 | ||
1293 | store_address (raw_buffer, 8, read_register (PC_REGNUM)); | |
1294 | write_memory (sp - 8, raw_buffer, 8); | |
1295 | ||
1296 | /* Save floating point registers. */ | |
c5aa993b JM |
1297 | save_address = sp + PROC_FREG_OFFSET (proc_desc); |
1298 | mask = PROC_FREG_MASK (proc_desc) & 0xffffffffL; | |
c906108c SS |
1299 | for (ireg = 0; mask; ireg++, mask >>= 1) |
1300 | if (mask & 1) | |
1301 | { | |
1302 | store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM)); | |
1303 | write_memory (save_address, raw_buffer, 8); | |
1304 | save_address += 8; | |
1305 | } | |
1306 | ||
1307 | /* Set and save the frame address for the dummy. | |
1308 | This is tricky. The only registers that are suitable for a frame save | |
1309 | are those that are preserved across procedure calls (s0-s6). But if | |
1310 | a read system call is interrupted and then a dummy call is made | |
1311 | (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read | |
1312 | is satisfied. Then it returns with the s0-s6 registers set to the values | |
1313 | on entry to the read system call and our dummy frame pointer would be | |
1314 | destroyed. So we save the dummy frame in the proc_desc and handle the | |
1315 | retrieval of the frame pointer of a dummy specifically. The frame register | |
1316 | is set to the virtual frame (pseudo) register, it's value will always | |
1317 | be read as zero and will help us to catch any errors in the dummy frame | |
1318 | retrieval code. */ | |
c5aa993b JM |
1319 | PROC_DUMMY_FRAME (proc_desc) = sp; |
1320 | PROC_FRAME_REG (proc_desc) = FP_REGNUM; | |
1321 | PROC_FRAME_OFFSET (proc_desc) = 0; | |
1322 | sp += PROC_REG_OFFSET (proc_desc); | |
c906108c SS |
1323 | write_register (SP_REGNUM, sp); |
1324 | ||
c5aa993b JM |
1325 | PROC_LOW_ADDR (proc_desc) = CALL_DUMMY_ADDRESS (); |
1326 | PROC_HIGH_ADDR (proc_desc) = PROC_LOW_ADDR (proc_desc) + 4; | |
c906108c | 1327 | |
c5aa993b | 1328 | SET_PROC_DESC_IS_DUMMY (proc_desc); |
dc129d82 | 1329 | PROC_PC_REG (proc_desc) = ALPHA_RA_REGNUM; |
c906108c SS |
1330 | } |
1331 | ||
dc129d82 | 1332 | static void |
fba45db2 | 1333 | alpha_pop_frame (void) |
c906108c SS |
1334 | { |
1335 | register int regnum; | |
1336 | struct frame_info *frame = get_current_frame (); | |
1337 | CORE_ADDR new_sp = frame->frame; | |
1338 | ||
140f9984 | 1339 | alpha_extra_func_info_t proc_desc = frame->extra_info->proc_desc; |
c906108c | 1340 | |
9e0b60a8 JM |
1341 | /* we need proc_desc to know how to restore the registers; |
1342 | if it is NULL, construct (a temporary) one */ | |
1343 | if (proc_desc == NULL) | |
c5aa993b | 1344 | proc_desc = find_proc_desc (frame->pc, frame->next); |
9e0b60a8 JM |
1345 | |
1346 | /* Question: should we copy this proc_desc and save it in | |
1347 | frame->proc_desc? If we do, who will free it? | |
1348 | For now, we don't save a copy... */ | |
1349 | ||
c5aa993b | 1350 | write_register (PC_REGNUM, FRAME_SAVED_PC (frame)); |
c906108c SS |
1351 | if (frame->saved_regs == NULL) |
1352 | alpha_find_saved_regs (frame); | |
1353 | if (proc_desc) | |
1354 | { | |
c5aa993b JM |
1355 | for (regnum = 32; --regnum >= 0;) |
1356 | if (PROC_REG_MASK (proc_desc) & (1 << regnum)) | |
c906108c SS |
1357 | write_register (regnum, |
1358 | read_memory_integer (frame->saved_regs[regnum], | |
1359 | 8)); | |
c5aa993b JM |
1360 | for (regnum = 32; --regnum >= 0;) |
1361 | if (PROC_FREG_MASK (proc_desc) & (1 << regnum)) | |
c906108c | 1362 | write_register (regnum + FP0_REGNUM, |
c5aa993b | 1363 | read_memory_integer (frame->saved_regs[regnum + FP0_REGNUM], 8)); |
c906108c SS |
1364 | } |
1365 | write_register (SP_REGNUM, new_sp); | |
1366 | flush_cached_frames (); | |
1367 | ||
c5aa993b | 1368 | if (proc_desc && (PROC_DESC_IS_DUMMY (proc_desc) |
36a6271d | 1369 | || alpha_proc_desc_is_dyn_sigtramp (proc_desc))) |
c906108c SS |
1370 | { |
1371 | struct linked_proc_info *pi_ptr, *prev_ptr; | |
1372 | ||
1373 | for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL; | |
1374 | pi_ptr != NULL; | |
1375 | prev_ptr = pi_ptr, pi_ptr = pi_ptr->next) | |
1376 | { | |
1377 | if (&pi_ptr->info == proc_desc) | |
1378 | break; | |
1379 | } | |
1380 | ||
1381 | if (pi_ptr == NULL) | |
1382 | error ("Can't locate dummy extra frame info\n"); | |
1383 | ||
1384 | if (prev_ptr != NULL) | |
1385 | prev_ptr->next = pi_ptr->next; | |
1386 | else | |
1387 | linked_proc_desc_table = pi_ptr->next; | |
1388 | ||
b8c9b27d | 1389 | xfree (pi_ptr); |
c906108c SS |
1390 | } |
1391 | } | |
1392 | \f | |
1393 | /* To skip prologues, I use this predicate. Returns either PC itself | |
1394 | if the code at PC does not look like a function prologue; otherwise | |
1395 | returns an address that (if we're lucky) follows the prologue. If | |
1396 | LENIENT, then we must skip everything which is involved in setting | |
1397 | up the frame (it's OK to skip more, just so long as we don't skip | |
1398 | anything which might clobber the registers which are being saved. | |
0fb34c3a MS |
1399 | Currently we must not skip more on the alpha, but we might need the |
1400 | lenient stuff some day. */ | |
c906108c | 1401 | |
f8453e34 JT |
1402 | static CORE_ADDR |
1403 | alpha_skip_prologue_internal (CORE_ADDR pc, int lenient) | |
c906108c | 1404 | { |
c5aa993b JM |
1405 | unsigned long inst; |
1406 | int offset; | |
1407 | CORE_ADDR post_prologue_pc; | |
1408 | char buf[4]; | |
c906108c | 1409 | |
c5aa993b JM |
1410 | /* Silently return the unaltered pc upon memory errors. |
1411 | This could happen on OSF/1 if decode_line_1 tries to skip the | |
1412 | prologue for quickstarted shared library functions when the | |
1413 | shared library is not yet mapped in. | |
1414 | Reading target memory is slow over serial lines, so we perform | |
15d72a92 JT |
1415 | this check only if the target has shared libraries (which all |
1416 | Alpha targets do). */ | |
c5aa993b JM |
1417 | if (target_read_memory (pc, buf, 4)) |
1418 | return pc; | |
c906108c | 1419 | |
c5aa993b JM |
1420 | /* See if we can determine the end of the prologue via the symbol table. |
1421 | If so, then return either PC, or the PC after the prologue, whichever | |
1422 | is greater. */ | |
c906108c | 1423 | |
c5aa993b | 1424 | post_prologue_pc = after_prologue (pc, NULL); |
c906108c | 1425 | |
c5aa993b JM |
1426 | if (post_prologue_pc != 0) |
1427 | return max (pc, post_prologue_pc); | |
c906108c | 1428 | |
c5aa993b JM |
1429 | /* Can't determine prologue from the symbol table, need to examine |
1430 | instructions. */ | |
c906108c | 1431 | |
c5aa993b JM |
1432 | /* Skip the typical prologue instructions. These are the stack adjustment |
1433 | instruction and the instructions that save registers on the stack | |
1434 | or in the gcc frame. */ | |
1435 | for (offset = 0; offset < 100; offset += 4) | |
1436 | { | |
1437 | int status; | |
1438 | ||
1439 | status = read_memory_nobpt (pc + offset, buf, 4); | |
1440 | if (status) | |
1441 | memory_error (status, pc + offset); | |
1442 | inst = extract_unsigned_integer (buf, 4); | |
1443 | ||
1444 | /* The alpha has no delay slots. But let's keep the lenient stuff, | |
1445 | we might need it for something else in the future. */ | |
1446 | if (lenient && 0) | |
1447 | continue; | |
1448 | ||
1449 | if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */ | |
1450 | continue; | |
1451 | if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */ | |
1452 | continue; | |
1453 | if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */ | |
1454 | continue; | |
1455 | if ((inst & 0xffe01fff) == 0x43c0153e) /* subq $sp,n,$sp */ | |
1456 | continue; | |
1457 | ||
1458 | if ((inst & 0xfc1f0000) == 0xb41e0000 | |
1459 | && (inst & 0xffff0000) != 0xb7fe0000) | |
1460 | continue; /* stq reg,n($sp) */ | |
1461 | /* reg != $zero */ | |
1462 | if ((inst & 0xfc1f0000) == 0x9c1e0000 | |
1463 | && (inst & 0xffff0000) != 0x9ffe0000) | |
1464 | continue; /* stt reg,n($sp) */ | |
1465 | /* reg != $zero */ | |
1466 | if (inst == 0x47de040f) /* bis sp,sp,fp */ | |
1467 | continue; | |
1468 | ||
1469 | break; | |
c906108c | 1470 | } |
c5aa993b | 1471 | return pc + offset; |
c906108c SS |
1472 | } |
1473 | ||
dc129d82 | 1474 | static CORE_ADDR |
f8453e34 JT |
1475 | alpha_skip_prologue (CORE_ADDR addr) |
1476 | { | |
1477 | return (alpha_skip_prologue_internal (addr, 0)); | |
1478 | } | |
1479 | ||
c906108c SS |
1480 | #if 0 |
1481 | /* Is address PC in the prologue (loosely defined) for function at | |
1482 | STARTADDR? */ | |
1483 | ||
1484 | static int | |
fba45db2 | 1485 | alpha_in_lenient_prologue (CORE_ADDR startaddr, CORE_ADDR pc) |
c906108c | 1486 | { |
f8453e34 | 1487 | CORE_ADDR end_prologue = alpha_skip_prologue_internal (startaddr, 1); |
c906108c SS |
1488 | return pc >= startaddr && pc < end_prologue; |
1489 | } | |
1490 | #endif | |
1491 | ||
1492 | /* The alpha needs a conversion between register and memory format if | |
1493 | the register is a floating point register and | |
c5aa993b | 1494 | memory format is float, as the register format must be double |
c906108c | 1495 | or |
c5aa993b JM |
1496 | memory format is an integer with 4 bytes or less, as the representation |
1497 | of integers in floating point registers is different. */ | |
dc129d82 | 1498 | static void |
fba45db2 KB |
1499 | alpha_register_convert_to_virtual (int regnum, struct type *valtype, |
1500 | char *raw_buffer, char *virtual_buffer) | |
c906108c SS |
1501 | { |
1502 | if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum)) | |
1503 | { | |
1504 | memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum)); | |
1505 | return; | |
1506 | } | |
1507 | ||
1508 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
1509 | { | |
1510 | double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum)); | |
1511 | store_floating (virtual_buffer, TYPE_LENGTH (valtype), d); | |
1512 | } | |
1513 | else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4) | |
1514 | { | |
1515 | ULONGEST l; | |
1516 | l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum)); | |
1517 | l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff); | |
1518 | store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l); | |
1519 | } | |
1520 | else | |
1521 | error ("Cannot retrieve value from floating point register"); | |
1522 | } | |
1523 | ||
dc129d82 | 1524 | static void |
fba45db2 KB |
1525 | alpha_register_convert_to_raw (struct type *valtype, int regnum, |
1526 | char *virtual_buffer, char *raw_buffer) | |
c906108c SS |
1527 | { |
1528 | if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum)) | |
1529 | { | |
1530 | memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum)); | |
1531 | return; | |
1532 | } | |
1533 | ||
1534 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
1535 | { | |
1536 | double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype)); | |
1537 | store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d); | |
1538 | } | |
1539 | else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4) | |
1540 | { | |
1541 | ULONGEST l; | |
1542 | if (TYPE_UNSIGNED (valtype)) | |
1543 | l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype)); | |
1544 | else | |
1545 | l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype)); | |
1546 | l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29); | |
1547 | store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l); | |
1548 | } | |
1549 | else | |
1550 | error ("Cannot store value in floating point register"); | |
1551 | } | |
1552 | ||
95b80706 JT |
1553 | static const unsigned char * |
1554 | alpha_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr) | |
1555 | { | |
1556 | static const unsigned char alpha_breakpoint[] = | |
1557 | { 0x80, 0, 0, 0 }; /* call_pal bpt */ | |
1558 | ||
1559 | *lenptr = sizeof(alpha_breakpoint); | |
1560 | return (alpha_breakpoint); | |
1561 | } | |
1562 | ||
c906108c SS |
1563 | /* Given a return value in `regbuf' with a type `valtype', |
1564 | extract and copy its value into `valbuf'. */ | |
1565 | ||
dc129d82 | 1566 | static void |
732a6b2d | 1567 | alpha_extract_return_value (struct type *valtype, |
997b20b8 | 1568 | char regbuf[ALPHA_REGISTER_BYTES], char *valbuf) |
c906108c SS |
1569 | { |
1570 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) | |
1571 | alpha_register_convert_to_virtual (FP0_REGNUM, valtype, | |
1572 | regbuf + REGISTER_BYTE (FP0_REGNUM), | |
1573 | valbuf); | |
1574 | else | |
dc129d82 JT |
1575 | memcpy (valbuf, regbuf + REGISTER_BYTE (ALPHA_V0_REGNUM), |
1576 | TYPE_LENGTH (valtype)); | |
c906108c SS |
1577 | } |
1578 | ||
1579 | /* Given a return value in `regbuf' with a type `valtype', | |
1580 | write its value into the appropriate register. */ | |
1581 | ||
dc129d82 | 1582 | static void |
fba45db2 | 1583 | alpha_store_return_value (struct type *valtype, char *valbuf) |
c906108c | 1584 | { |
dc129d82 JT |
1585 | char raw_buffer[ALPHA_MAX_REGISTER_RAW_SIZE]; |
1586 | int regnum = ALPHA_V0_REGNUM; | |
c906108c | 1587 | int length = TYPE_LENGTH (valtype); |
c5aa993b | 1588 | |
c906108c SS |
1589 | if (TYPE_CODE (valtype) == TYPE_CODE_FLT) |
1590 | { | |
1591 | regnum = FP0_REGNUM; | |
1592 | length = REGISTER_RAW_SIZE (regnum); | |
1593 | alpha_register_convert_to_raw (valtype, regnum, valbuf, raw_buffer); | |
1594 | } | |
1595 | else | |
1596 | memcpy (raw_buffer, valbuf, length); | |
1597 | ||
1598 | write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, length); | |
1599 | } | |
1600 | ||
1601 | /* Just like reinit_frame_cache, but with the right arguments to be | |
1602 | callable as an sfunc. */ | |
1603 | ||
1604 | static void | |
fba45db2 | 1605 | reinit_frame_cache_sfunc (char *args, int from_tty, struct cmd_list_element *c) |
c906108c SS |
1606 | { |
1607 | reinit_frame_cache (); | |
1608 | } | |
1609 | ||
1610 | /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used | |
1611 | to find a convenient place in the text segment to stick a breakpoint to | |
1612 | detect the completion of a target function call (ala call_function_by_hand). | |
1613 | */ | |
1614 | ||
1615 | CORE_ADDR | |
fba45db2 | 1616 | alpha_call_dummy_address (void) |
c906108c SS |
1617 | { |
1618 | CORE_ADDR entry; | |
1619 | struct minimal_symbol *sym; | |
1620 | ||
1621 | entry = entry_point_address (); | |
1622 | ||
1623 | if (entry != 0) | |
1624 | return entry; | |
1625 | ||
1626 | sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile); | |
1627 | ||
1628 | if (!sym || MSYMBOL_TYPE (sym) != mst_text) | |
1629 | return 0; | |
1630 | else | |
1631 | return SYMBOL_VALUE_ADDRESS (sym) + 4; | |
ec32e4be JT |
1632 | } |
1633 | ||
dc129d82 | 1634 | static void |
0d056799 JT |
1635 | alpha_fix_call_dummy (char *dummy, CORE_ADDR pc, CORE_ADDR fun, int nargs, |
1636 | struct value **args, struct type *type, int gcc_p) | |
1637 | { | |
1638 | CORE_ADDR bp_address = CALL_DUMMY_ADDRESS (); | |
1639 | ||
1640 | if (bp_address == 0) | |
1641 | error ("no place to put call"); | |
dc129d82 JT |
1642 | write_register (ALPHA_RA_REGNUM, bp_address); |
1643 | write_register (ALPHA_T12_REGNUM, fun); | |
0d056799 JT |
1644 | } |
1645 | ||
ee1f65f0 JT |
1646 | /* On the Alpha, the call dummy code is nevery copied to user space |
1647 | (see alpha_fix_call_dummy() above). The contents of this do not | |
1648 | matter. */ | |
1649 | LONGEST alpha_call_dummy_words[] = { 0 }; | |
1650 | ||
dc129d82 | 1651 | static int |
d734c450 JT |
1652 | alpha_use_struct_convention (int gcc_p, struct type *type) |
1653 | { | |
1654 | /* Structures are returned by ref in extra arg0. */ | |
1655 | return 1; | |
1656 | } | |
1657 | ||
dc129d82 | 1658 | static void |
0d056799 JT |
1659 | alpha_store_struct_return (CORE_ADDR addr, CORE_ADDR sp) |
1660 | { | |
1661 | /* Store the address of the place in which to copy the structure the | |
1662 | subroutine will return. Handled by alpha_push_arguments. */ | |
1663 | } | |
1664 | ||
dc129d82 | 1665 | static CORE_ADDR |
0d056799 JT |
1666 | alpha_extract_struct_value_address (char *regbuf) |
1667 | { | |
dc129d82 JT |
1668 | return (extract_address (regbuf + REGISTER_BYTE (ALPHA_V0_REGNUM), |
1669 | REGISTER_RAW_SIZE (ALPHA_V0_REGNUM))); | |
0d056799 JT |
1670 | } |
1671 | ||
accc6d1f JT |
1672 | /* Figure out where the longjmp will land. |
1673 | We expect the first arg to be a pointer to the jmp_buf structure from | |
1674 | which we extract the PC (JB_PC) that we will land at. The PC is copied | |
1675 | into the "pc". This routine returns true on success. */ | |
1676 | ||
1677 | static int | |
1678 | alpha_get_longjmp_target (CORE_ADDR *pc) | |
1679 | { | |
1680 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
1681 | CORE_ADDR jb_addr; | |
1682 | char raw_buffer[ALPHA_MAX_REGISTER_RAW_SIZE]; | |
1683 | ||
1684 | jb_addr = read_register (ALPHA_A0_REGNUM); | |
1685 | ||
1686 | if (target_read_memory (jb_addr + (tdep->jb_pc * tdep->jb_elt_size), | |
1687 | raw_buffer, tdep->jb_elt_size)) | |
1688 | return 0; | |
1689 | ||
1690 | *pc = extract_address (raw_buffer, tdep->jb_elt_size); | |
1691 | return 1; | |
1692 | } | |
1693 | ||
ec32e4be JT |
1694 | /* alpha_software_single_step() is called just before we want to resume |
1695 | the inferior, if we want to single-step it but there is no hardware | |
1696 | or kernel single-step support (NetBSD on Alpha, for example). We find | |
1697 | the target of the coming instruction and breakpoint it. | |
1698 | ||
1699 | single_step is also called just after the inferior stops. If we had | |
1700 | set up a simulated single-step, we undo our damage. */ | |
1701 | ||
1702 | static CORE_ADDR | |
1703 | alpha_next_pc (CORE_ADDR pc) | |
1704 | { | |
1705 | unsigned int insn; | |
1706 | unsigned int op; | |
1707 | int offset; | |
1708 | LONGEST rav; | |
1709 | ||
1710 | insn = read_memory_unsigned_integer (pc, sizeof (insn)); | |
1711 | ||
1712 | /* Opcode is top 6 bits. */ | |
1713 | op = (insn >> 26) & 0x3f; | |
1714 | ||
1715 | if (op == 0x1a) | |
1716 | { | |
1717 | /* Jump format: target PC is: | |
1718 | RB & ~3 */ | |
1719 | return (read_register ((insn >> 16) & 0x1f) & ~3); | |
1720 | } | |
1721 | ||
1722 | if ((op & 0x30) == 0x30) | |
1723 | { | |
1724 | /* Branch format: target PC is: | |
1725 | (new PC) + (4 * sext(displacement)) */ | |
1726 | if (op == 0x30 || /* BR */ | |
1727 | op == 0x34) /* BSR */ | |
1728 | { | |
1729 | branch_taken: | |
1730 | offset = (insn & 0x001fffff); | |
1731 | if (offset & 0x00100000) | |
1732 | offset |= 0xffe00000; | |
1733 | offset *= 4; | |
1734 | return (pc + 4 + offset); | |
1735 | } | |
1736 | ||
1737 | /* Need to determine if branch is taken; read RA. */ | |
1738 | rav = (LONGEST) read_register ((insn >> 21) & 0x1f); | |
1739 | switch (op) | |
1740 | { | |
1741 | case 0x38: /* BLBC */ | |
1742 | if ((rav & 1) == 0) | |
1743 | goto branch_taken; | |
1744 | break; | |
1745 | case 0x3c: /* BLBS */ | |
1746 | if (rav & 1) | |
1747 | goto branch_taken; | |
1748 | break; | |
1749 | case 0x39: /* BEQ */ | |
1750 | if (rav == 0) | |
1751 | goto branch_taken; | |
1752 | break; | |
1753 | case 0x3d: /* BNE */ | |
1754 | if (rav != 0) | |
1755 | goto branch_taken; | |
1756 | break; | |
1757 | case 0x3a: /* BLT */ | |
1758 | if (rav < 0) | |
1759 | goto branch_taken; | |
1760 | break; | |
1761 | case 0x3b: /* BLE */ | |
1762 | if (rav <= 0) | |
1763 | goto branch_taken; | |
1764 | break; | |
1765 | case 0x3f: /* BGT */ | |
1766 | if (rav > 0) | |
1767 | goto branch_taken; | |
1768 | break; | |
1769 | case 0x3e: /* BGE */ | |
1770 | if (rav >= 0) | |
1771 | goto branch_taken; | |
1772 | break; | |
1773 | } | |
1774 | } | |
1775 | ||
1776 | /* Not a branch or branch not taken; target PC is: | |
1777 | pc + 4 */ | |
1778 | return (pc + 4); | |
1779 | } | |
1780 | ||
1781 | void | |
1782 | alpha_software_single_step (enum target_signal sig, int insert_breakpoints_p) | |
1783 | { | |
1784 | static CORE_ADDR next_pc; | |
1785 | typedef char binsn_quantum[BREAKPOINT_MAX]; | |
1786 | static binsn_quantum break_mem; | |
1787 | CORE_ADDR pc; | |
1788 | ||
1789 | if (insert_breakpoints_p) | |
1790 | { | |
1791 | pc = read_pc (); | |
1792 | next_pc = alpha_next_pc (pc); | |
1793 | ||
1794 | target_insert_breakpoint (next_pc, break_mem); | |
1795 | } | |
1796 | else | |
1797 | { | |
1798 | target_remove_breakpoint (next_pc, break_mem); | |
1799 | write_pc (next_pc); | |
1800 | } | |
c906108c SS |
1801 | } |
1802 | ||
dc129d82 | 1803 | \f |
44dffaac | 1804 | |
dc129d82 JT |
1805 | /* Initialize the current architecture based on INFO. If possible, re-use an |
1806 | architecture from ARCHES, which is a list of architectures already created | |
1807 | during this debugging session. | |
1808 | ||
1809 | Called e.g. at program startup, when reading a core file, and when reading | |
1810 | a binary file. */ | |
1811 | ||
1812 | static struct gdbarch * | |
1813 | alpha_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
1814 | { | |
1815 | struct gdbarch_tdep *tdep; | |
1816 | struct gdbarch *gdbarch; | |
70f80edf | 1817 | enum gdb_osabi osabi = GDB_OSABI_UNKNOWN; |
dc129d82 JT |
1818 | |
1819 | /* Try to determine the ABI of the object we are loading. */ | |
1820 | ||
1821 | if (info.abfd != NULL) | |
1822 | { | |
70f80edf JT |
1823 | osabi = gdbarch_lookup_osabi (info.abfd); |
1824 | if (osabi == GDB_OSABI_UNKNOWN) | |
dc129d82 | 1825 | { |
70f80edf JT |
1826 | /* If it's an ECOFF file, assume it's OSF/1. */ |
1827 | if (bfd_get_flavour (info.abfd) == bfd_target_ecoff_flavour) | |
1828 | osabi = GDB_OSABI_OSF1; | |
dc129d82 JT |
1829 | } |
1830 | } | |
1831 | ||
1832 | /* Find a candidate among extant architectures. */ | |
1833 | for (arches = gdbarch_list_lookup_by_info (arches, &info); | |
1834 | arches != NULL; | |
1835 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) | |
1836 | { | |
1837 | /* Make sure the ABI selection matches. */ | |
1838 | tdep = gdbarch_tdep (arches->gdbarch); | |
70f80edf | 1839 | if (tdep && tdep->osabi == osabi) |
dc129d82 JT |
1840 | return arches->gdbarch; |
1841 | } | |
1842 | ||
1843 | tdep = xmalloc (sizeof (struct gdbarch_tdep)); | |
1844 | gdbarch = gdbarch_alloc (&info, tdep); | |
1845 | ||
70f80edf | 1846 | tdep->osabi = osabi; |
dc129d82 | 1847 | |
d9b023cc JT |
1848 | /* Lowest text address. This is used by heuristic_proc_start() to |
1849 | decide when to stop looking. */ | |
1850 | tdep->vm_min_address = (CORE_ADDR) 0x120000000; | |
1851 | ||
36a6271d JT |
1852 | tdep->dynamic_sigtramp_offset = NULL; |
1853 | tdep->skip_sigtramp_frame = NULL; | |
5868c862 | 1854 | tdep->sigcontext_addr = NULL; |
36a6271d | 1855 | |
accc6d1f JT |
1856 | tdep->jb_pc = -1; /* longjmp support not enabled by default */ |
1857 | ||
dc129d82 JT |
1858 | /* Type sizes */ |
1859 | set_gdbarch_short_bit (gdbarch, 16); | |
1860 | set_gdbarch_int_bit (gdbarch, 32); | |
1861 | set_gdbarch_long_bit (gdbarch, 64); | |
1862 | set_gdbarch_long_long_bit (gdbarch, 64); | |
1863 | set_gdbarch_float_bit (gdbarch, 32); | |
1864 | set_gdbarch_double_bit (gdbarch, 64); | |
1865 | set_gdbarch_long_double_bit (gdbarch, 64); | |
1866 | set_gdbarch_ptr_bit (gdbarch, 64); | |
1867 | ||
1868 | /* Register info */ | |
1869 | set_gdbarch_num_regs (gdbarch, ALPHA_NUM_REGS); | |
1870 | set_gdbarch_sp_regnum (gdbarch, ALPHA_SP_REGNUM); | |
1871 | set_gdbarch_fp_regnum (gdbarch, ALPHA_FP_REGNUM); | |
1872 | set_gdbarch_pc_regnum (gdbarch, ALPHA_PC_REGNUM); | |
1873 | set_gdbarch_fp0_regnum (gdbarch, ALPHA_FP0_REGNUM); | |
1874 | ||
1875 | set_gdbarch_register_name (gdbarch, alpha_register_name); | |
1876 | set_gdbarch_register_size (gdbarch, ALPHA_REGISTER_SIZE); | |
1877 | set_gdbarch_register_bytes (gdbarch, ALPHA_REGISTER_BYTES); | |
1878 | set_gdbarch_register_byte (gdbarch, alpha_register_byte); | |
1879 | set_gdbarch_register_raw_size (gdbarch, alpha_register_raw_size); | |
1880 | set_gdbarch_max_register_raw_size (gdbarch, ALPHA_MAX_REGISTER_RAW_SIZE); | |
1881 | set_gdbarch_register_virtual_size (gdbarch, alpha_register_virtual_size); | |
1882 | set_gdbarch_max_register_virtual_size (gdbarch, | |
1883 | ALPHA_MAX_REGISTER_VIRTUAL_SIZE); | |
1884 | set_gdbarch_register_virtual_type (gdbarch, alpha_register_virtual_type); | |
1885 | ||
1886 | set_gdbarch_cannot_fetch_register (gdbarch, alpha_cannot_fetch_register); | |
1887 | set_gdbarch_cannot_store_register (gdbarch, alpha_cannot_store_register); | |
1888 | ||
1889 | set_gdbarch_register_convertible (gdbarch, alpha_register_convertible); | |
1890 | set_gdbarch_register_convert_to_virtual (gdbarch, | |
1891 | alpha_register_convert_to_virtual); | |
1892 | set_gdbarch_register_convert_to_raw (gdbarch, alpha_register_convert_to_raw); | |
1893 | ||
1894 | set_gdbarch_skip_prologue (gdbarch, alpha_skip_prologue); | |
1895 | ||
1896 | set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown); | |
1897 | set_gdbarch_frameless_function_invocation (gdbarch, | |
1898 | generic_frameless_function_invocation_not); | |
1899 | ||
1900 | set_gdbarch_saved_pc_after_call (gdbarch, alpha_saved_pc_after_call); | |
1901 | ||
1902 | set_gdbarch_frame_chain (gdbarch, alpha_frame_chain); | |
1903 | set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid); | |
1904 | set_gdbarch_frame_saved_pc (gdbarch, alpha_frame_saved_pc); | |
1905 | ||
1906 | set_gdbarch_frame_init_saved_regs (gdbarch, alpha_frame_init_saved_regs); | |
1907 | set_gdbarch_get_saved_register (gdbarch, alpha_get_saved_register); | |
1908 | ||
1909 | set_gdbarch_use_struct_convention (gdbarch, alpha_use_struct_convention); | |
26e9b323 | 1910 | set_gdbarch_deprecated_extract_return_value (gdbarch, alpha_extract_return_value); |
dc129d82 JT |
1911 | |
1912 | set_gdbarch_store_struct_return (gdbarch, alpha_store_struct_return); | |
1913 | set_gdbarch_store_return_value (gdbarch, alpha_store_return_value); | |
26e9b323 | 1914 | set_gdbarch_deprecated_extract_struct_value_address (gdbarch, |
dc129d82 JT |
1915 | alpha_extract_struct_value_address); |
1916 | ||
1917 | /* Settings for calling functions in the inferior. */ | |
1918 | set_gdbarch_use_generic_dummy_frames (gdbarch, 0); | |
1919 | set_gdbarch_call_dummy_length (gdbarch, 0); | |
1920 | set_gdbarch_push_arguments (gdbarch, alpha_push_arguments); | |
1921 | set_gdbarch_pop_frame (gdbarch, alpha_pop_frame); | |
1922 | ||
1923 | /* On the Alpha, the call dummy code is never copied to user space, | |
1924 | stopping the user call is achieved via a bp_call_dummy breakpoint. | |
1925 | But we need a fake CALL_DUMMY definition to enable the proper | |
1926 | call_function_by_hand and to avoid zero length array warnings. */ | |
1927 | set_gdbarch_call_dummy_p (gdbarch, 1); | |
1928 | set_gdbarch_call_dummy_words (gdbarch, alpha_call_dummy_words); | |
1929 | set_gdbarch_sizeof_call_dummy_words (gdbarch, 0); | |
1930 | set_gdbarch_frame_args_address (gdbarch, alpha_frame_args_address); | |
1931 | set_gdbarch_frame_locals_address (gdbarch, alpha_frame_locals_address); | |
1932 | set_gdbarch_init_extra_frame_info (gdbarch, alpha_init_extra_frame_info); | |
1933 | ||
1934 | /* Alpha OSF/1 inhibits execution of code on the stack. But there is | |
1935 | no need for a dummy on the Alpha. PUSH_ARGUMENTS takes care of all | |
1936 | argument handling and bp_call_dummy takes care of stopping the dummy. */ | |
1937 | set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT); | |
1938 | set_gdbarch_call_dummy_address (gdbarch, alpha_call_dummy_address); | |
1939 | set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1); | |
1940 | set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0); | |
1941 | set_gdbarch_call_dummy_start_offset (gdbarch, 0); | |
1942 | set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_at_entry_point); | |
1943 | set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0); | |
1944 | set_gdbarch_push_dummy_frame (gdbarch, alpha_push_dummy_frame); | |
1945 | set_gdbarch_fix_call_dummy (gdbarch, alpha_fix_call_dummy); | |
1946 | set_gdbarch_init_frame_pc (gdbarch, init_frame_pc_noop); | |
1947 | set_gdbarch_init_frame_pc_first (gdbarch, alpha_init_frame_pc_first); | |
1948 | ||
1949 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
36a6271d | 1950 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); |
dc129d82 | 1951 | |
65585be4 JT |
1952 | /* Floats are always passed as doubles. */ |
1953 | set_gdbarch_coerce_float_to_double (gdbarch, | |
1954 | standard_coerce_float_to_double); | |
1955 | ||
95b80706 | 1956 | set_gdbarch_breakpoint_from_pc (gdbarch, alpha_breakpoint_from_pc); |
dc129d82 | 1957 | set_gdbarch_decr_pc_after_break (gdbarch, 4); |
95b80706 JT |
1958 | |
1959 | set_gdbarch_function_start_offset (gdbarch, 0); | |
dc129d82 JT |
1960 | set_gdbarch_frame_args_skip (gdbarch, 0); |
1961 | ||
44dffaac | 1962 | /* Hook in ABI-specific overrides, if they have been registered. */ |
70f80edf | 1963 | gdbarch_init_osabi (info, gdbarch, osabi); |
44dffaac | 1964 | |
accc6d1f JT |
1965 | /* Now that we have tuned the configuration, set a few final things |
1966 | based on what the OS ABI has told us. */ | |
1967 | ||
1968 | if (tdep->jb_pc >= 0) | |
1969 | set_gdbarch_get_longjmp_target (gdbarch, alpha_get_longjmp_target); | |
1970 | ||
dc129d82 JT |
1971 | return gdbarch; |
1972 | } | |
1973 | ||
1974 | static void | |
1975 | alpha_dump_tdep (struct gdbarch *current_gdbarch, struct ui_file *file) | |
1976 | { | |
1977 | struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); | |
1978 | ||
1979 | if (tdep == NULL) | |
1980 | return; | |
1981 | ||
70f80edf JT |
1982 | fprintf_unfiltered (file, "alpha_dump_tdep: OS ABI = %s\n", |
1983 | gdbarch_osabi_name (tdep->osabi)); | |
d9b023cc JT |
1984 | |
1985 | fprintf_unfiltered (file, | |
1986 | "alpha_dump_tdep: vm_min_address = 0x%lx\n", | |
1987 | (long) tdep->vm_min_address); | |
accc6d1f JT |
1988 | |
1989 | fprintf_unfiltered (file, | |
1990 | "alpha_dump_tdep: jb_pc = %d\n", | |
1991 | tdep->jb_pc); | |
1992 | fprintf_unfiltered (file, | |
1993 | "alpha_dump_tdep: jb_elt_size = %ld\n", | |
1994 | (long) tdep->jb_elt_size); | |
dc129d82 JT |
1995 | } |
1996 | ||
c906108c | 1997 | void |
fba45db2 | 1998 | _initialize_alpha_tdep (void) |
c906108c SS |
1999 | { |
2000 | struct cmd_list_element *c; | |
2001 | ||
dc129d82 JT |
2002 | gdbarch_register (bfd_arch_alpha, alpha_gdbarch_init, alpha_dump_tdep); |
2003 | ||
c906108c SS |
2004 | tm_print_insn = print_insn_alpha; |
2005 | ||
2006 | /* Let the user set the fence post for heuristic_proc_start. */ | |
2007 | ||
2008 | /* We really would like to have both "0" and "unlimited" work, but | |
2009 | command.c doesn't deal with that. So make it a var_zinteger | |
2010 | because the user can always use "999999" or some such for unlimited. */ | |
2011 | c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger, | |
2012 | (char *) &heuristic_fence_post, | |
2013 | "\ | |
2014 | Set the distance searched for the start of a function.\n\ | |
2015 | If you are debugging a stripped executable, GDB needs to search through the\n\ | |
2016 | program for the start of a function. This command sets the distance of the\n\ | |
2017 | search. The only need to set it is when debugging a stripped executable.", | |
2018 | &setlist); | |
2019 | /* We need to throw away the frame cache when we set this, since it | |
2020 | might change our ability to get backtraces. */ | |
9f60d481 | 2021 | set_cmd_sfunc (c, reinit_frame_cache_sfunc); |
c906108c SS |
2022 | add_show_from_set (c, &showlist); |
2023 | } |