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