1 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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. */
32 #include "gdb_string.h"
36 /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
38 /* Prototypes for local functions. */
40 static alpha_extra_func_info_t push_sigtramp_desc (CORE_ADDR low_addr);
42 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
44 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
46 static alpha_extra_func_info_t heuristic_proc_desc (CORE_ADDR,
50 static alpha_extra_func_info_t find_proc_desc (CORE_ADDR,
54 static int alpha_in_lenient_prologue (CORE_ADDR, CORE_ADDR);
57 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
59 static CORE_ADDR after_prologue (CORE_ADDR pc,
60 alpha_extra_func_info_t proc_desc);
62 static int alpha_in_prologue (CORE_ADDR pc,
63 alpha_extra_func_info_t proc_desc);
65 static int alpha_about_to_return (CORE_ADDR pc);
67 void _initialize_alpha_tdep (void);
69 /* Heuristic_proc_start may hunt through the text section for a long
70 time across a 2400 baud serial line. Allows the user to limit this
72 static unsigned int heuristic_fence_post = 0;
74 /* Layout of a stack frame on the alpha:
77 pdr members: | 7th ... nth arg, |
78 | `pushed' by caller. |
80 ----------------|-------------------------------|<-- old_sp == vfp
83 | |localoff | Copies of 1st .. 6th |
84 | | | | | argument if necessary. |
86 | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
88 | | | | Locals and temporaries. |
90 | | | |-------------------------------|
92 |-fregoffset | Saved float registers. |
98 | | -------|-------------------------------|
100 | | | Saved registers. |
107 | ----------|-------------------------------|
109 frameoffset | Argument build area, gets |
110 | | 7th ... nth arg for any |
111 | | called procedure. |
113 -------------|-------------------------------|<-- sp
120 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
121 /* These next two fields are kind of being hijacked. I wonder if
122 iline is too small for the values it needs to hold, if GDB is
123 running on a 32-bit host. */
124 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
125 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.cbLineOffset) /*CALL_DUMMY frame */
126 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
127 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
128 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
129 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
130 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
131 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
132 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
133 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
134 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
135 #define _PROC_MAGIC_ 0x0F0F0F0F
136 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
137 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
139 struct linked_proc_info
141 struct alpha_extra_func_info info;
142 struct linked_proc_info *next;
144 *linked_proc_desc_table = NULL;
147 /* Under GNU/Linux, signal handler invocations can be identified by the
148 designated code sequence that is used to return from a signal
149 handler. In particular, the return address of a signal handler
150 points to the following sequence (the first instruction is quadword
157 Each instruction has a unique encoding, so we simply attempt to
158 match the instruction the pc is pointing to with any of the above
159 instructions. If there is a hit, we know the offset to the start
160 of the designated sequence and can then check whether we really are
161 executing in a designated sequence. If not, -1 is returned,
162 otherwise the offset from the start of the desingated sequence is
165 There is a slight chance of false hits: code could jump into the
166 middle of the designated sequence, in which case there is no
167 guarantee that we are in the middle of a sigreturn syscall. Don't
168 think this will be a problem in praxis, though.
171 #ifndef TM_LINUXALPHA_H
172 /* HACK: Provide a prototype when compiling this file for non
173 linuxalpha targets. */
174 long alpha_linux_sigtramp_offset (CORE_ADDR pc);
177 alpha_linux_sigtramp_offset (CORE_ADDR pc)
179 unsigned int i[3], w;
182 if (read_memory_nobpt (pc, (char *) &w, 4) != 0)
190 break; /* bis $30,$30,$16 */
193 break; /* addq $31,0x67,$0 */
196 break; /* call_pal callsys */
203 /* designated sequence is not quadword aligned */
207 if (read_memory_nobpt (pc, (char *) i, sizeof (i)) != 0)
210 if (i[0] == 0x47de0410 && i[1] == 0x43ecf400 && i[2] == 0x00000083)
217 /* Under OSF/1, the __sigtramp routine is frameless and has a frame
218 size of zero, but we are able to backtrace through it. */
220 alpha_osf_skip_sigtramp_frame (struct frame_info *frame, CORE_ADDR pc)
223 find_pc_partial_function (pc, &name, (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
224 if (IN_SIGTRAMP (pc, name))
231 /* Dynamically create a signal-handler caller procedure descriptor for
232 the signal-handler return code starting at address LOW_ADDR. The
233 descriptor is added to the linked_proc_desc_table. */
235 static alpha_extra_func_info_t
236 push_sigtramp_desc (CORE_ADDR low_addr)
238 struct linked_proc_info *link;
239 alpha_extra_func_info_t proc_desc;
241 link = (struct linked_proc_info *)
242 xmalloc (sizeof (struct linked_proc_info));
243 link->next = linked_proc_desc_table;
244 linked_proc_desc_table = link;
246 proc_desc = &link->info;
248 proc_desc->numargs = 0;
249 PROC_LOW_ADDR (proc_desc) = low_addr;
250 PROC_HIGH_ADDR (proc_desc) = low_addr + 3 * 4;
251 PROC_DUMMY_FRAME (proc_desc) = 0;
252 PROC_FRAME_OFFSET (proc_desc) = 0x298; /* sizeof(struct sigcontext_struct) */
253 PROC_FRAME_REG (proc_desc) = SP_REGNUM;
254 PROC_REG_MASK (proc_desc) = 0xffff;
255 PROC_FREG_MASK (proc_desc) = 0xffff;
256 PROC_PC_REG (proc_desc) = 26;
257 PROC_LOCALOFF (proc_desc) = 0;
258 SET_PROC_DESC_IS_DYN_SIGTRAMP (proc_desc);
263 /* Guaranteed to set frame->saved_regs to some values (it never leaves it
267 alpha_find_saved_regs (struct frame_info *frame)
270 CORE_ADDR reg_position;
272 alpha_extra_func_info_t proc_desc;
275 frame_saved_regs_zalloc (frame);
277 /* If it is the frame for __sigtramp, the saved registers are located
278 in a sigcontext structure somewhere on the stack. __sigtramp
279 passes a pointer to the sigcontext structure on the stack.
280 If the stack layout for __sigtramp changes, or if sigcontext offsets
281 change, we might have to update this code. */
282 #ifndef SIGFRAME_PC_OFF
283 #define SIGFRAME_PC_OFF (2 * 8)
284 #define SIGFRAME_REGSAVE_OFF (4 * 8)
285 #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
287 if (frame->signal_handler_caller)
289 CORE_ADDR sigcontext_addr;
291 sigcontext_addr = SIGCONTEXT_ADDR (frame);
292 for (ireg = 0; ireg < 32; ireg++)
294 reg_position = sigcontext_addr + SIGFRAME_REGSAVE_OFF + ireg * 8;
295 frame->saved_regs[ireg] = reg_position;
297 for (ireg = 0; ireg < 32; ireg++)
299 reg_position = sigcontext_addr + SIGFRAME_FPREGSAVE_OFF + ireg * 8;
300 frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
302 frame->saved_regs[PC_REGNUM] = sigcontext_addr + SIGFRAME_PC_OFF;
306 proc_desc = frame->proc_desc;
307 if (proc_desc == NULL)
308 /* I'm not sure how/whether this can happen. Normally when we can't
309 find a proc_desc, we "synthesize" one using heuristic_proc_desc
310 and set the saved_regs right away. */
313 /* Fill in the offsets for the registers which gen_mask says
316 reg_position = frame->frame + PROC_REG_OFFSET (proc_desc);
317 mask = PROC_REG_MASK (proc_desc);
319 returnreg = PROC_PC_REG (proc_desc);
321 /* Note that RA is always saved first, regardless of its actual
323 if (mask & (1 << returnreg))
325 frame->saved_regs[returnreg] = reg_position;
327 mask &= ~(1 << returnreg); /* Clear bit for RA so we
328 don't save again later. */
331 for (ireg = 0; ireg <= 31; ++ireg)
332 if (mask & (1 << ireg))
334 frame->saved_regs[ireg] = reg_position;
338 /* Fill in the offsets for the registers which float_mask says
341 reg_position = frame->frame + PROC_FREG_OFFSET (proc_desc);
342 mask = PROC_FREG_MASK (proc_desc);
344 for (ireg = 0; ireg <= 31; ++ireg)
345 if (mask & (1 << ireg))
347 frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
351 frame->saved_regs[PC_REGNUM] = frame->saved_regs[returnreg];
355 read_next_frame_reg (struct frame_info *fi, int regno)
357 for (; fi; fi = fi->next)
359 /* We have to get the saved sp from the sigcontext
360 if it is a signal handler frame. */
361 if (regno == SP_REGNUM && !fi->signal_handler_caller)
365 if (fi->saved_regs == NULL)
366 alpha_find_saved_regs (fi);
367 if (fi->saved_regs[regno])
368 return read_memory_integer (fi->saved_regs[regno], 8);
371 return read_register (regno);
375 alpha_frame_saved_pc (struct frame_info *frame)
377 alpha_extra_func_info_t proc_desc = frame->proc_desc;
378 /* We have to get the saved pc from the sigcontext
379 if it is a signal handler frame. */
380 int pcreg = frame->signal_handler_caller ? PC_REGNUM : frame->pc_reg;
382 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
383 return read_memory_integer (frame->frame - 8, 8);
385 return read_next_frame_reg (frame, pcreg);
389 alpha_saved_pc_after_call (struct frame_info *frame)
391 CORE_ADDR pc = frame->pc;
393 alpha_extra_func_info_t proc_desc;
396 /* Skip over shared library trampoline if necessary. */
397 tmp = SKIP_TRAMPOLINE_CODE (pc);
401 proc_desc = find_proc_desc (pc, frame->next);
402 pcreg = proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM;
404 if (frame->signal_handler_caller)
405 return alpha_frame_saved_pc (frame);
407 return read_register (pcreg);
411 static struct alpha_extra_func_info temp_proc_desc;
412 static struct frame_saved_regs temp_saved_regs;
414 /* Nonzero if instruction at PC is a return instruction. "ret
415 $zero,($ra),1" on alpha. */
418 alpha_about_to_return (CORE_ADDR pc)
420 return read_memory_integer (pc, 4) == 0x6bfa8001;
425 /* This fencepost looks highly suspicious to me. Removing it also
426 seems suspicious as it could affect remote debugging across serial
430 heuristic_proc_start (CORE_ADDR pc)
432 CORE_ADDR start_pc = pc;
433 CORE_ADDR fence = start_pc - heuristic_fence_post;
438 if (heuristic_fence_post == UINT_MAX
439 || fence < VM_MIN_ADDRESS)
440 fence = VM_MIN_ADDRESS;
442 /* search back for previous return */
443 for (start_pc -= 4;; start_pc -= 4)
444 if (start_pc < fence)
446 /* It's not clear to me why we reach this point when
447 stop_soon_quietly, but with this test, at least we
448 don't print out warnings for every child forked (eg, on
450 if (!stop_soon_quietly)
452 static int blurb_printed = 0;
454 if (fence == VM_MIN_ADDRESS)
455 warning ("Hit beginning of text section without finding");
457 warning ("Hit heuristic-fence-post without finding");
459 warning ("enclosing function for address 0x%s", paddr_nz (pc));
463 This warning occurs if you are debugging a function without any symbols\n\
464 (for example, in a stripped executable). In that case, you may wish to\n\
465 increase the size of the search with the `set heuristic-fence-post' command.\n\
467 Otherwise, you told GDB there was a function where there isn't one, or\n\
468 (more likely) you have encountered a bug in GDB.\n");
475 else if (alpha_about_to_return (start_pc))
478 start_pc += 4; /* skip return */
482 static alpha_extra_func_info_t
483 heuristic_proc_desc (CORE_ADDR start_pc, CORE_ADDR limit_pc,
484 struct frame_info *next_frame)
486 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
489 int has_frame_reg = 0;
490 unsigned long reg_mask = 0;
495 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
496 memset (&temp_saved_regs, '\0', sizeof (struct frame_saved_regs));
497 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
499 if (start_pc + 200 < limit_pc)
500 limit_pc = start_pc + 200;
502 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4)
508 status = read_memory_nobpt (cur_pc, buf, 4);
510 memory_error (status, cur_pc);
511 word = extract_unsigned_integer (buf, 4);
513 if ((word & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
516 frame_size += (-word) & 0xffff;
518 /* Exit loop if a positive stack adjustment is found, which
519 usually means that the stack cleanup code in the function
520 epilogue is reached. */
523 else if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
524 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
526 int reg = (word & 0x03e00000) >> 21;
527 reg_mask |= 1 << reg;
528 temp_saved_regs.regs[reg] = sp + (short) word;
530 /* Starting with OSF/1-3.2C, the system libraries are shipped
531 without local symbols, but they still contain procedure
532 descriptors without a symbol reference. GDB is currently
533 unable to find these procedure descriptors and uses
534 heuristic_proc_desc instead.
535 As some low level compiler support routines (__div*, __add*)
536 use a non-standard return address register, we have to
537 add some heuristics to determine the return address register,
538 or stepping over these routines will fail.
539 Usually the return address register is the first register
540 saved on the stack, but assembler optimization might
541 rearrange the register saves.
542 So we recognize only a few registers (t7, t9, ra) within
543 the procedure prologue as valid return address registers.
544 If we encounter a return instruction, we extract the
545 the return address register from it.
547 FIXME: Rewriting GDB to access the procedure descriptors,
548 e.g. via the minimal symbol table, might obviate this hack. */
550 && cur_pc < (start_pc + 80)
551 && (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM))
554 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
555 pcreg = (word >> 16) & 0x1f;
556 else if (word == 0x47de040f) /* bis sp,sp fp */
561 /* If we haven't found a valid return address register yet,
562 keep searching in the procedure prologue. */
563 while (cur_pc < (limit_pc + 80) && cur_pc < (start_pc + 80))
568 if (read_memory_nobpt (cur_pc, buf, 4))
571 word = extract_unsigned_integer (buf, 4);
573 if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
574 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
576 int reg = (word & 0x03e00000) >> 21;
577 if (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM)
583 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
585 pcreg = (word >> 16) & 0x1f;
592 PROC_FRAME_REG (&temp_proc_desc) = GCC_FP_REGNUM;
594 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
595 PROC_FRAME_OFFSET (&temp_proc_desc) = frame_size;
596 PROC_REG_MASK (&temp_proc_desc) = reg_mask;
597 PROC_PC_REG (&temp_proc_desc) = (pcreg == -1) ? RA_REGNUM : pcreg;
598 PROC_LOCALOFF (&temp_proc_desc) = 0; /* XXX - bogus */
599 return &temp_proc_desc;
602 /* This returns the PC of the first inst after the prologue. If we can't
603 find the prologue, then return 0. */
606 after_prologue (CORE_ADDR pc, alpha_extra_func_info_t proc_desc)
608 struct symtab_and_line sal;
609 CORE_ADDR func_addr, func_end;
612 proc_desc = find_proc_desc (pc, NULL);
616 if (PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
617 return PROC_LOW_ADDR (proc_desc); /* "prologue" is in kernel */
619 /* If function is frameless, then we need to do it the hard way. I
620 strongly suspect that frameless always means prologueless... */
621 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
622 && PROC_FRAME_OFFSET (proc_desc) == 0)
626 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
627 return 0; /* Unknown */
629 sal = find_pc_line (func_addr, 0);
631 if (sal.end < func_end)
634 /* The line after the prologue is after the end of the function. In this
635 case, tell the caller to find the prologue the hard way. */
640 /* Return non-zero if we *might* be in a function prologue. Return zero if we
641 are definitively *not* in a function prologue. */
644 alpha_in_prologue (CORE_ADDR pc, alpha_extra_func_info_t proc_desc)
646 CORE_ADDR after_prologue_pc;
648 after_prologue_pc = after_prologue (pc, proc_desc);
650 if (after_prologue_pc == 0
651 || pc < after_prologue_pc)
657 static alpha_extra_func_info_t
658 find_proc_desc (CORE_ADDR pc, struct frame_info *next_frame)
660 alpha_extra_func_info_t proc_desc;
665 /* Try to get the proc_desc from the linked call dummy proc_descs
666 if the pc is in the call dummy.
667 This is hairy. In the case of nested dummy calls we have to find the
668 right proc_desc, but we might not yet know the frame for the dummy
669 as it will be contained in the proc_desc we are searching for.
670 So we have to find the proc_desc whose frame is closest to the current
673 if (PC_IN_CALL_DUMMY (pc, 0, 0))
675 struct linked_proc_info *link;
676 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
677 alpha_extra_func_info_t found_proc_desc = NULL;
678 long min_distance = LONG_MAX;
680 for (link = linked_proc_desc_table; link; link = link->next)
682 long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp;
683 if (distance > 0 && distance < min_distance)
685 min_distance = distance;
686 found_proc_desc = &link->info;
689 if (found_proc_desc != NULL)
690 return found_proc_desc;
693 b = block_for_pc (pc);
695 find_pc_partial_function (pc, NULL, &startaddr, NULL);
700 if (startaddr > BLOCK_START (b))
701 /* This is the "pathological" case referred to in a comment in
702 print_frame_info. It might be better to move this check into
706 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
710 /* If we never found a PDR for this function in symbol reading, then
711 examine prologues to find the information. */
712 if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
717 /* IF this is the topmost frame AND
718 * (this proc does not have debugging information OR
719 * the PC is in the procedure prologue)
720 * THEN create a "heuristic" proc_desc (by analyzing
721 * the actual code) to replace the "official" proc_desc.
723 proc_desc = (alpha_extra_func_info_t) SYMBOL_VALUE (sym);
724 if (next_frame == NULL)
726 if (PROC_DESC_IS_DUMMY (proc_desc) || alpha_in_prologue (pc, proc_desc))
728 alpha_extra_func_info_t found_heuristic =
729 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
733 PROC_LOCALOFF (found_heuristic) =
734 PROC_LOCALOFF (proc_desc);
735 PROC_PC_REG (found_heuristic) = PROC_PC_REG (proc_desc);
736 proc_desc = found_heuristic;
745 /* Is linked_proc_desc_table really necessary? It only seems to be used
746 by procedure call dummys. However, the procedures being called ought
747 to have their own proc_descs, and even if they don't,
748 heuristic_proc_desc knows how to create them! */
750 register struct linked_proc_info *link;
751 for (link = linked_proc_desc_table; link; link = link->next)
752 if (PROC_LOW_ADDR (&link->info) <= pc
753 && PROC_HIGH_ADDR (&link->info) > pc)
756 /* If PC is inside a dynamically generated sigtramp handler,
757 create and push a procedure descriptor for that code: */
758 offset = DYNAMIC_SIGTRAMP_OFFSET (pc);
760 return push_sigtramp_desc (pc - offset);
762 /* If heuristic_fence_post is non-zero, determine the procedure
763 start address by examining the instructions.
764 This allows us to find the start address of static functions which
765 have no symbolic information, as startaddr would have been set to
766 the preceding global function start address by the
767 find_pc_partial_function call above. */
768 if (startaddr == 0 || heuristic_fence_post != 0)
769 startaddr = heuristic_proc_start (pc);
772 heuristic_proc_desc (startaddr, pc, next_frame);
777 alpha_extra_func_info_t cached_proc_desc;
780 alpha_frame_chain (struct frame_info *frame)
782 alpha_extra_func_info_t proc_desc;
783 CORE_ADDR saved_pc = FRAME_SAVED_PC (frame);
785 if (saved_pc == 0 || inside_entry_file (saved_pc))
788 proc_desc = find_proc_desc (saved_pc, frame);
792 cached_proc_desc = proc_desc;
794 /* Fetch the frame pointer for a dummy frame from the procedure
796 if (PROC_DESC_IS_DUMMY (proc_desc))
797 return (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
799 /* If no frame pointer and frame size is zero, we must be at end
800 of stack (or otherwise hosed). If we don't check frame size,
801 we loop forever if we see a zero size frame. */
802 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
803 && PROC_FRAME_OFFSET (proc_desc) == 0
804 /* The previous frame from a sigtramp frame might be frameless
805 and have frame size zero. */
806 && !frame->signal_handler_caller)
807 return FRAME_PAST_SIGTRAMP_FRAME (frame, saved_pc);
809 return read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc))
810 + PROC_FRAME_OFFSET (proc_desc);
814 init_extra_frame_info (struct frame_info *frame)
816 /* Use proc_desc calculated in frame_chain */
817 alpha_extra_func_info_t proc_desc =
818 frame->next ? cached_proc_desc : find_proc_desc (frame->pc, frame->next);
820 frame->saved_regs = NULL;
822 frame->pc_reg = RA_REGNUM;
823 frame->proc_desc = proc_desc == &temp_proc_desc ? 0 : proc_desc;
826 /* Get the locals offset and the saved pc register from the
827 procedure descriptor, they are valid even if we are in the
828 middle of the prologue. */
829 frame->localoff = PROC_LOCALOFF (proc_desc);
830 frame->pc_reg = PROC_PC_REG (proc_desc);
832 /* Fixup frame-pointer - only needed for top frame */
834 /* Fetch the frame pointer for a dummy frame from the procedure
836 if (PROC_DESC_IS_DUMMY (proc_desc))
837 frame->frame = (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
839 /* This may not be quite right, if proc has a real frame register.
840 Get the value of the frame relative sp, procedure might have been
841 interrupted by a signal at it's very start. */
842 else if (frame->pc == PROC_LOW_ADDR (proc_desc)
843 && !PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
844 frame->frame = read_next_frame_reg (frame->next, SP_REGNUM);
846 frame->frame = read_next_frame_reg (frame->next, PROC_FRAME_REG (proc_desc))
847 + PROC_FRAME_OFFSET (proc_desc);
849 if (proc_desc == &temp_proc_desc)
853 /* Do not set the saved registers for a sigtramp frame,
854 alpha_find_saved_registers will do that for us.
855 We can't use frame->signal_handler_caller, it is not yet set. */
856 find_pc_partial_function (frame->pc, &name,
857 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
858 if (!IN_SIGTRAMP (frame->pc, name))
860 frame->saved_regs = (CORE_ADDR *)
861 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
862 memcpy (frame->saved_regs, temp_saved_regs.regs, SIZEOF_FRAME_SAVED_REGS);
863 frame->saved_regs[PC_REGNUM]
864 = frame->saved_regs[RA_REGNUM];
870 /* ALPHA stack frames are almost impenetrable. When execution stops,
871 we basically have to look at symbol information for the function
872 that we stopped in, which tells us *which* register (if any) is
873 the base of the frame pointer, and what offset from that register
874 the frame itself is at.
876 This presents a problem when trying to examine a stack in memory
877 (that isn't executing at the moment), using the "frame" command. We
878 don't have a PC, nor do we have any registers except SP.
880 This routine takes two arguments, SP and PC, and tries to make the
881 cached frames look as if these two arguments defined a frame on the
882 cache. This allows the rest of info frame to extract the important
883 arguments without difficulty. */
886 setup_arbitrary_frame (int argc, CORE_ADDR *argv)
889 error ("ALPHA frame specifications require two arguments: sp and pc");
891 return create_new_frame (argv[0], argv[1]);
894 /* The alpha passes the first six arguments in the registers, the rest on
895 the stack. The register arguments are eventually transferred to the
896 argument transfer area immediately below the stack by the called function
897 anyway. So we `push' at least six arguments on the stack, `reload' the
898 argument registers and then adjust the stack pointer to point past the
899 sixth argument. This algorithm simplifies the passing of a large struct
900 which extends from the registers to the stack.
901 If the called function is returning a structure, the address of the
902 structure to be returned is passed as a hidden first argument. */
905 alpha_push_arguments (int nargs, value_ptr *args, CORE_ADDR sp,
906 int struct_return, CORE_ADDR struct_addr)
909 int accumulate_size = struct_return ? 8 : 0;
910 int arg_regs_size = ALPHA_NUM_ARG_REGS * 8;
917 struct alpha_arg *alpha_args =
918 (struct alpha_arg *) alloca (nargs * sizeof (struct alpha_arg));
919 register struct alpha_arg *m_arg;
920 char raw_buffer[sizeof (CORE_ADDR)];
921 int required_arg_regs;
923 for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
925 value_ptr arg = args[i];
926 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
927 /* Cast argument to long if necessary as the compiler does it too. */
928 switch (TYPE_CODE (arg_type))
933 case TYPE_CODE_RANGE:
935 if (TYPE_LENGTH (arg_type) < TYPE_LENGTH (builtin_type_long))
937 arg_type = builtin_type_long;
938 arg = value_cast (arg_type, arg);
944 m_arg->len = TYPE_LENGTH (arg_type);
945 m_arg->offset = accumulate_size;
946 accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
947 m_arg->contents = VALUE_CONTENTS (arg);
950 /* Determine required argument register loads, loading an argument register
951 is expensive as it uses three ptrace calls. */
952 required_arg_regs = accumulate_size / 8;
953 if (required_arg_regs > ALPHA_NUM_ARG_REGS)
954 required_arg_regs = ALPHA_NUM_ARG_REGS;
956 /* Make room for the arguments on the stack. */
957 if (accumulate_size < arg_regs_size)
958 accumulate_size = arg_regs_size;
959 sp -= accumulate_size;
961 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
964 /* `Push' arguments on the stack. */
965 for (i = nargs; m_arg--, --i >= 0;)
966 write_memory (sp + m_arg->offset, m_arg->contents, m_arg->len);
969 store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr);
970 write_memory (sp, raw_buffer, sizeof (CORE_ADDR));
973 /* Load the argument registers. */
974 for (i = 0; i < required_arg_regs; i++)
978 val = read_memory_integer (sp + i * 8, 8);
979 write_register (A0_REGNUM + i, val);
980 write_register (FPA0_REGNUM + i, val);
983 return sp + arg_regs_size;
987 alpha_push_dummy_frame (void)
990 struct linked_proc_info *link;
991 alpha_extra_func_info_t proc_desc;
992 CORE_ADDR sp = read_register (SP_REGNUM);
993 CORE_ADDR save_address;
994 char raw_buffer[MAX_REGISTER_RAW_SIZE];
997 link = (struct linked_proc_info *) xmalloc (sizeof (struct linked_proc_info));
998 link->next = linked_proc_desc_table;
999 linked_proc_desc_table = link;
1001 proc_desc = &link->info;
1004 * The registers we must save are all those not preserved across
1006 * In addition, we must save the PC and RA.
1008 * Dummy frame layout:
1018 * Parameter build area
1022 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
1023 #define MASK(i,j) ((((LONGEST)1 << ((j)+1)) - 1) ^ (((LONGEST)1 << (i)) - 1))
1024 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
1025 #define GEN_REG_SAVE_COUNT 24
1026 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
1027 #define FLOAT_REG_SAVE_COUNT 23
1028 /* The special register is the PC as we have no bit for it in the save masks.
1029 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
1030 #define SPECIAL_REG_SAVE_COUNT 1
1032 PROC_REG_MASK (proc_desc) = GEN_REG_SAVE_MASK;
1033 PROC_FREG_MASK (proc_desc) = FLOAT_REG_SAVE_MASK;
1034 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
1035 but keep SP aligned to a multiple of 16. */
1036 PROC_REG_OFFSET (proc_desc) =
1037 -((8 * (SPECIAL_REG_SAVE_COUNT
1038 + GEN_REG_SAVE_COUNT
1039 + FLOAT_REG_SAVE_COUNT)
1041 PROC_FREG_OFFSET (proc_desc) =
1042 PROC_REG_OFFSET (proc_desc) + 8 * GEN_REG_SAVE_COUNT;
1044 /* Save general registers.
1045 The return address register is the first saved register, all other
1046 registers follow in ascending order.
1047 The PC is saved immediately below the SP. */
1048 save_address = sp + PROC_REG_OFFSET (proc_desc);
1049 store_address (raw_buffer, 8, read_register (RA_REGNUM));
1050 write_memory (save_address, raw_buffer, 8);
1052 mask = PROC_REG_MASK (proc_desc) & 0xffffffffL;
1053 for (ireg = 0; mask; ireg++, mask >>= 1)
1056 if (ireg == RA_REGNUM)
1058 store_address (raw_buffer, 8, read_register (ireg));
1059 write_memory (save_address, raw_buffer, 8);
1063 store_address (raw_buffer, 8, read_register (PC_REGNUM));
1064 write_memory (sp - 8, raw_buffer, 8);
1066 /* Save floating point registers. */
1067 save_address = sp + PROC_FREG_OFFSET (proc_desc);
1068 mask = PROC_FREG_MASK (proc_desc) & 0xffffffffL;
1069 for (ireg = 0; mask; ireg++, mask >>= 1)
1072 store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM));
1073 write_memory (save_address, raw_buffer, 8);
1077 /* Set and save the frame address for the dummy.
1078 This is tricky. The only registers that are suitable for a frame save
1079 are those that are preserved across procedure calls (s0-s6). But if
1080 a read system call is interrupted and then a dummy call is made
1081 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
1082 is satisfied. Then it returns with the s0-s6 registers set to the values
1083 on entry to the read system call and our dummy frame pointer would be
1084 destroyed. So we save the dummy frame in the proc_desc and handle the
1085 retrieval of the frame pointer of a dummy specifically. The frame register
1086 is set to the virtual frame (pseudo) register, it's value will always
1087 be read as zero and will help us to catch any errors in the dummy frame
1089 PROC_DUMMY_FRAME (proc_desc) = sp;
1090 PROC_FRAME_REG (proc_desc) = FP_REGNUM;
1091 PROC_FRAME_OFFSET (proc_desc) = 0;
1092 sp += PROC_REG_OFFSET (proc_desc);
1093 write_register (SP_REGNUM, sp);
1095 PROC_LOW_ADDR (proc_desc) = CALL_DUMMY_ADDRESS ();
1096 PROC_HIGH_ADDR (proc_desc) = PROC_LOW_ADDR (proc_desc) + 4;
1098 SET_PROC_DESC_IS_DUMMY (proc_desc);
1099 PROC_PC_REG (proc_desc) = RA_REGNUM;
1103 alpha_pop_frame (void)
1105 register int regnum;
1106 struct frame_info *frame = get_current_frame ();
1107 CORE_ADDR new_sp = frame->frame;
1109 alpha_extra_func_info_t proc_desc = frame->proc_desc;
1111 /* we need proc_desc to know how to restore the registers;
1112 if it is NULL, construct (a temporary) one */
1113 if (proc_desc == NULL)
1114 proc_desc = find_proc_desc (frame->pc, frame->next);
1116 /* Question: should we copy this proc_desc and save it in
1117 frame->proc_desc? If we do, who will free it?
1118 For now, we don't save a copy... */
1120 write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
1121 if (frame->saved_regs == NULL)
1122 alpha_find_saved_regs (frame);
1125 for (regnum = 32; --regnum >= 0;)
1126 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
1127 write_register (regnum,
1128 read_memory_integer (frame->saved_regs[regnum],
1130 for (regnum = 32; --regnum >= 0;)
1131 if (PROC_FREG_MASK (proc_desc) & (1 << regnum))
1132 write_register (regnum + FP0_REGNUM,
1133 read_memory_integer (frame->saved_regs[regnum + FP0_REGNUM], 8));
1135 write_register (SP_REGNUM, new_sp);
1136 flush_cached_frames ();
1138 if (proc_desc && (PROC_DESC_IS_DUMMY (proc_desc)
1139 || PROC_DESC_IS_DYN_SIGTRAMP (proc_desc)))
1141 struct linked_proc_info *pi_ptr, *prev_ptr;
1143 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
1145 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
1147 if (&pi_ptr->info == proc_desc)
1152 error ("Can't locate dummy extra frame info\n");
1154 if (prev_ptr != NULL)
1155 prev_ptr->next = pi_ptr->next;
1157 linked_proc_desc_table = pi_ptr->next;
1163 /* To skip prologues, I use this predicate. Returns either PC itself
1164 if the code at PC does not look like a function prologue; otherwise
1165 returns an address that (if we're lucky) follows the prologue. If
1166 LENIENT, then we must skip everything which is involved in setting
1167 up the frame (it's OK to skip more, just so long as we don't skip
1168 anything which might clobber the registers which are being saved.
1169 Currently we must not skip more on the alpha, but we might need the
1170 lenient stuff some day. */
1173 alpha_skip_prologue (CORE_ADDR pc, int lenient)
1177 CORE_ADDR post_prologue_pc;
1180 #ifdef GDB_TARGET_HAS_SHARED_LIBS
1181 /* Silently return the unaltered pc upon memory errors.
1182 This could happen on OSF/1 if decode_line_1 tries to skip the
1183 prologue for quickstarted shared library functions when the
1184 shared library is not yet mapped in.
1185 Reading target memory is slow over serial lines, so we perform
1186 this check only if the target has shared libraries. */
1187 if (target_read_memory (pc, buf, 4))
1191 /* See if we can determine the end of the prologue via the symbol table.
1192 If so, then return either PC, or the PC after the prologue, whichever
1195 post_prologue_pc = after_prologue (pc, NULL);
1197 if (post_prologue_pc != 0)
1198 return max (pc, post_prologue_pc);
1200 /* Can't determine prologue from the symbol table, need to examine
1203 /* Skip the typical prologue instructions. These are the stack adjustment
1204 instruction and the instructions that save registers on the stack
1205 or in the gcc frame. */
1206 for (offset = 0; offset < 100; offset += 4)
1210 status = read_memory_nobpt (pc + offset, buf, 4);
1212 memory_error (status, pc + offset);
1213 inst = extract_unsigned_integer (buf, 4);
1215 /* The alpha has no delay slots. But let's keep the lenient stuff,
1216 we might need it for something else in the future. */
1220 if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1222 if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1224 if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1226 if ((inst & 0xffe01fff) == 0x43c0153e) /* subq $sp,n,$sp */
1229 if ((inst & 0xfc1f0000) == 0xb41e0000
1230 && (inst & 0xffff0000) != 0xb7fe0000)
1231 continue; /* stq reg,n($sp) */
1233 if ((inst & 0xfc1f0000) == 0x9c1e0000
1234 && (inst & 0xffff0000) != 0x9ffe0000)
1235 continue; /* stt reg,n($sp) */
1237 if (inst == 0x47de040f) /* bis sp,sp,fp */
1246 /* Is address PC in the prologue (loosely defined) for function at
1250 alpha_in_lenient_prologue (CORE_ADDR startaddr, CORE_ADDR pc)
1252 CORE_ADDR end_prologue = alpha_skip_prologue (startaddr, 1);
1253 return pc >= startaddr && pc < end_prologue;
1257 /* The alpha needs a conversion between register and memory format if
1258 the register is a floating point register and
1259 memory format is float, as the register format must be double
1261 memory format is an integer with 4 bytes or less, as the representation
1262 of integers in floating point registers is different. */
1264 alpha_register_convert_to_virtual (int regnum, struct type *valtype,
1265 char *raw_buffer, char *virtual_buffer)
1267 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1269 memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
1273 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1275 double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum));
1276 store_floating (virtual_buffer, TYPE_LENGTH (valtype), d);
1278 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1281 l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum));
1282 l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff);
1283 store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l);
1286 error ("Cannot retrieve value from floating point register");
1290 alpha_register_convert_to_raw (struct type *valtype, int regnum,
1291 char *virtual_buffer, char *raw_buffer)
1293 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1295 memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum));
1299 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1301 double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype));
1302 store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d);
1304 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1307 if (TYPE_UNSIGNED (valtype))
1308 l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype));
1310 l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype));
1311 l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29);
1312 store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l);
1315 error ("Cannot store value in floating point register");
1318 /* Given a return value in `regbuf' with a type `valtype',
1319 extract and copy its value into `valbuf'. */
1322 alpha_extract_return_value (struct type *valtype,
1323 char regbuf[REGISTER_BYTES], char *valbuf)
1325 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1326 alpha_register_convert_to_virtual (FP0_REGNUM, valtype,
1327 regbuf + REGISTER_BYTE (FP0_REGNUM),
1330 memcpy (valbuf, regbuf + REGISTER_BYTE (V0_REGNUM), TYPE_LENGTH (valtype));
1333 /* Given a return value in `regbuf' with a type `valtype',
1334 write its value into the appropriate register. */
1337 alpha_store_return_value (struct type *valtype, char *valbuf)
1339 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1340 int regnum = V0_REGNUM;
1341 int length = TYPE_LENGTH (valtype);
1343 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1345 regnum = FP0_REGNUM;
1346 length = REGISTER_RAW_SIZE (regnum);
1347 alpha_register_convert_to_raw (valtype, regnum, valbuf, raw_buffer);
1350 memcpy (raw_buffer, valbuf, length);
1352 write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, length);
1355 /* Just like reinit_frame_cache, but with the right arguments to be
1356 callable as an sfunc. */
1359 reinit_frame_cache_sfunc (char *args, int from_tty, struct cmd_list_element *c)
1361 reinit_frame_cache ();
1364 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1365 to find a convenient place in the text segment to stick a breakpoint to
1366 detect the completion of a target function call (ala call_function_by_hand).
1370 alpha_call_dummy_address (void)
1373 struct minimal_symbol *sym;
1375 entry = entry_point_address ();
1380 sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile);
1382 if (!sym || MSYMBOL_TYPE (sym) != mst_text)
1385 return SYMBOL_VALUE_ADDRESS (sym) + 4;
1389 _initialize_alpha_tdep (void)
1391 struct cmd_list_element *c;
1393 tm_print_insn = print_insn_alpha;
1395 /* Let the user set the fence post for heuristic_proc_start. */
1397 /* We really would like to have both "0" and "unlimited" work, but
1398 command.c doesn't deal with that. So make it a var_zinteger
1399 because the user can always use "999999" or some such for unlimited. */
1400 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
1401 (char *) &heuristic_fence_post,
1403 Set the distance searched for the start of a function.\n\
1404 If you are debugging a stripped executable, GDB needs to search through the\n\
1405 program for the start of a function. This command sets the distance of the\n\
1406 search. The only need to set it is when debugging a stripped executable.",
1408 /* We need to throw away the frame cache when we set this, since it
1409 might change our ability to get backtraces. */
1410 c->function.sfunc = reinit_frame_cache_sfunc;
1411 add_show_from_set (c, &showlist);