1 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
2 Copyright 1993, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
31 #include "gdb_string.h"
33 /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
35 /* Prototypes for local functions. */
37 static alpha_extra_func_info_t push_sigtramp_desc (CORE_ADDR low_addr);
39 static CORE_ADDR read_next_frame_reg (struct frame_info *, int);
41 static CORE_ADDR heuristic_proc_start (CORE_ADDR);
43 static alpha_extra_func_info_t heuristic_proc_desc (CORE_ADDR,
47 static alpha_extra_func_info_t find_proc_desc (CORE_ADDR,
51 static int alpha_in_lenient_prologue (CORE_ADDR, CORE_ADDR);
54 static void reinit_frame_cache_sfunc (char *, int, struct cmd_list_element *);
56 static CORE_ADDR after_prologue (CORE_ADDR pc,
57 alpha_extra_func_info_t proc_desc);
59 static int alpha_in_prologue (CORE_ADDR pc,
60 alpha_extra_func_info_t proc_desc);
62 static int alpha_about_to_return (CORE_ADDR pc);
64 void _initialize_alpha_tdep (void);
66 /* Heuristic_proc_start may hunt through the text section for a long
67 time across a 2400 baud serial line. Allows the user to limit this
69 static unsigned int heuristic_fence_post = 0;
71 /* Layout of a stack frame on the alpha:
74 pdr members: | 7th ... nth arg, |
75 | `pushed' by caller. |
77 ----------------|-------------------------------|<-- old_sp == vfp
80 | |localoff | Copies of 1st .. 6th |
81 | | | | | argument if necessary. |
83 | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
85 | | | | Locals and temporaries. |
87 | | | |-------------------------------|
89 |-fregoffset | Saved float registers. |
95 | | -------|-------------------------------|
97 | | | Saved registers. |
104 | ----------|-------------------------------|
106 frameoffset | Argument build area, gets |
107 | | 7th ... nth arg for any |
108 | | called procedure. |
110 -------------|-------------------------------|<-- sp
117 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
118 /* These next two fields are kind of being hijacked. I wonder if
119 iline is too small for the values it needs to hold, if GDB is
120 running on a 32-bit host. */
121 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
122 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.cbLineOffset) /*CALL_DUMMY frame */
123 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
124 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
125 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
126 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
127 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
128 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
129 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
130 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
131 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
132 #define _PROC_MAGIC_ 0x0F0F0F0F
133 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
134 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
136 struct linked_proc_info
138 struct alpha_extra_func_info info;
139 struct linked_proc_info *next;
141 *linked_proc_desc_table = NULL;
144 /* Under GNU/Linux, signal handler invocations can be identified by the
145 designated code sequence that is used to return from a signal
146 handler. In particular, the return address of a signal handler
147 points to the following sequence (the first instruction is quadword
154 Each instruction has a unique encoding, so we simply attempt to
155 match the instruction the pc is pointing to with any of the above
156 instructions. If there is a hit, we know the offset to the start
157 of the designated sequence and can then check whether we really are
158 executing in a designated sequence. If not, -1 is returned,
159 otherwise the offset from the start of the desingated sequence is
162 There is a slight chance of false hits: code could jump into the
163 middle of the designated sequence, in which case there is no
164 guarantee that we are in the middle of a sigreturn syscall. Don't
165 think this will be a problem in praxis, though.
168 #ifndef TM_LINUXALPHA_H
169 /* HACK: Provide a prototype when compiling this file for non
170 linuxalpha targets. */
171 long alpha_linux_sigtramp_offset (CORE_ADDR pc);
174 alpha_linux_sigtramp_offset (pc)
177 unsigned int i[3], w;
180 if (read_memory_nobpt (pc, (char *) &w, 4) != 0)
188 break; /* bis $30,$30,$16 */
191 break; /* addq $31,0x67,$0 */
194 break; /* call_pal callsys */
201 /* designated sequence is not quadword aligned */
205 if (read_memory_nobpt (pc, (char *) i, sizeof (i)) != 0)
208 if (i[0] == 0x47de0410 && i[1] == 0x43ecf400 && i[2] == 0x00000083)
215 /* Under OSF/1, the __sigtramp routine is frameless and has a frame
216 size of zero, but we are able to backtrace through it. */
218 alpha_osf_skip_sigtramp_frame (frame, pc)
219 struct frame_info *frame;
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 (low_addr)
239 struct linked_proc_info *link;
240 alpha_extra_func_info_t proc_desc;
242 link = (struct linked_proc_info *)
243 xmalloc (sizeof (struct linked_proc_info));
244 link->next = linked_proc_desc_table;
245 linked_proc_desc_table = link;
247 proc_desc = &link->info;
249 proc_desc->numargs = 0;
250 PROC_LOW_ADDR (proc_desc) = low_addr;
251 PROC_HIGH_ADDR (proc_desc) = low_addr + 3 * 4;
252 PROC_DUMMY_FRAME (proc_desc) = 0;
253 PROC_FRAME_OFFSET (proc_desc) = 0x298; /* sizeof(struct sigcontext_struct) */
254 PROC_FRAME_REG (proc_desc) = SP_REGNUM;
255 PROC_REG_MASK (proc_desc) = 0xffff;
256 PROC_FREG_MASK (proc_desc) = 0xffff;
257 PROC_PC_REG (proc_desc) = 26;
258 PROC_LOCALOFF (proc_desc) = 0;
259 SET_PROC_DESC_IS_DYN_SIGTRAMP (proc_desc);
264 /* Guaranteed to set frame->saved_regs to some values (it never leaves it
268 alpha_find_saved_regs (frame)
269 struct frame_info *frame;
272 CORE_ADDR reg_position;
274 alpha_extra_func_info_t proc_desc;
277 frame_saved_regs_zalloc (frame);
279 /* If it is the frame for __sigtramp, the saved registers are located
280 in a sigcontext structure somewhere on the stack. __sigtramp
281 passes a pointer to the sigcontext structure on the stack.
282 If the stack layout for __sigtramp changes, or if sigcontext offsets
283 change, we might have to update this code. */
284 #ifndef SIGFRAME_PC_OFF
285 #define SIGFRAME_PC_OFF (2 * 8)
286 #define SIGFRAME_REGSAVE_OFF (4 * 8)
287 #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
289 if (frame->signal_handler_caller)
291 CORE_ADDR sigcontext_addr;
293 sigcontext_addr = SIGCONTEXT_ADDR (frame);
294 for (ireg = 0; ireg < 32; ireg++)
296 reg_position = sigcontext_addr + SIGFRAME_REGSAVE_OFF + ireg * 8;
297 frame->saved_regs[ireg] = reg_position;
299 for (ireg = 0; ireg < 32; ireg++)
301 reg_position = sigcontext_addr + SIGFRAME_FPREGSAVE_OFF + ireg * 8;
302 frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
304 frame->saved_regs[PC_REGNUM] = sigcontext_addr + SIGFRAME_PC_OFF;
308 proc_desc = frame->proc_desc;
309 if (proc_desc == NULL)
310 /* I'm not sure how/whether this can happen. Normally when we can't
311 find a proc_desc, we "synthesize" one using heuristic_proc_desc
312 and set the saved_regs right away. */
315 /* Fill in the offsets for the registers which gen_mask says
318 reg_position = frame->frame + PROC_REG_OFFSET (proc_desc);
319 mask = PROC_REG_MASK (proc_desc);
321 returnreg = PROC_PC_REG (proc_desc);
323 /* Note that RA is always saved first, regardless of its actual
325 if (mask & (1 << returnreg))
327 frame->saved_regs[returnreg] = reg_position;
329 mask &= ~(1 << returnreg); /* Clear bit for RA so we
330 don't save again later. */
333 for (ireg = 0; ireg <= 31; ++ireg)
334 if (mask & (1 << ireg))
336 frame->saved_regs[ireg] = reg_position;
340 /* Fill in the offsets for the registers which float_mask says
343 reg_position = frame->frame + PROC_FREG_OFFSET (proc_desc);
344 mask = PROC_FREG_MASK (proc_desc);
346 for (ireg = 0; ireg <= 31; ++ireg)
347 if (mask & (1 << ireg))
349 frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
353 frame->saved_regs[PC_REGNUM] = frame->saved_regs[returnreg];
357 read_next_frame_reg (fi, regno)
358 struct frame_info *fi;
361 for (; fi; fi = fi->next)
363 /* We have to get the saved sp from the sigcontext
364 if it is a signal handler frame. */
365 if (regno == SP_REGNUM && !fi->signal_handler_caller)
369 if (fi->saved_regs == NULL)
370 alpha_find_saved_regs (fi);
371 if (fi->saved_regs[regno])
372 return read_memory_integer (fi->saved_regs[regno], 8);
375 return read_register (regno);
379 alpha_frame_saved_pc (frame)
380 struct frame_info *frame;
382 alpha_extra_func_info_t proc_desc = frame->proc_desc;
383 /* We have to get the saved pc from the sigcontext
384 if it is a signal handler frame. */
385 int pcreg = frame->signal_handler_caller ? PC_REGNUM : frame->pc_reg;
387 if (proc_desc && PROC_DESC_IS_DUMMY (proc_desc))
388 return read_memory_integer (frame->frame - 8, 8);
390 return read_next_frame_reg (frame, pcreg);
394 alpha_saved_pc_after_call (frame)
395 struct frame_info *frame;
397 CORE_ADDR pc = frame->pc;
399 alpha_extra_func_info_t proc_desc;
402 /* Skip over shared library trampoline if necessary. */
403 tmp = SKIP_TRAMPOLINE_CODE (pc);
407 proc_desc = find_proc_desc (pc, frame->next);
408 pcreg = proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM;
410 if (frame->signal_handler_caller)
411 return alpha_frame_saved_pc (frame);
413 return read_register (pcreg);
417 static struct alpha_extra_func_info temp_proc_desc;
418 static struct frame_saved_regs temp_saved_regs;
420 /* Nonzero if instruction at PC is a return instruction. "ret
421 $zero,($ra),1" on alpha. */
424 alpha_about_to_return (pc)
427 return read_memory_integer (pc, 4) == 0x6bfa8001;
432 /* This fencepost looks highly suspicious to me. Removing it also
433 seems suspicious as it could affect remote debugging across serial
437 heuristic_proc_start (pc)
440 CORE_ADDR start_pc = pc;
441 CORE_ADDR fence = start_pc - heuristic_fence_post;
446 if (heuristic_fence_post == UINT_MAX
447 || fence < VM_MIN_ADDRESS)
448 fence = VM_MIN_ADDRESS;
450 /* search back for previous return */
451 for (start_pc -= 4;; start_pc -= 4)
452 if (start_pc < fence)
454 /* It's not clear to me why we reach this point when
455 stop_soon_quietly, but with this test, at least we
456 don't print out warnings for every child forked (eg, on
458 if (!stop_soon_quietly)
460 static int blurb_printed = 0;
462 if (fence == VM_MIN_ADDRESS)
463 warning ("Hit beginning of text section without finding");
465 warning ("Hit heuristic-fence-post without finding");
467 warning ("enclosing function for address 0x%s", paddr_nz (pc));
471 This warning occurs if you are debugging a function without any symbols\n\
472 (for example, in a stripped executable). In that case, you may wish to\n\
473 increase the size of the search with the `set heuristic-fence-post' command.\n\
475 Otherwise, you told GDB there was a function where there isn't one, or\n\
476 (more likely) you have encountered a bug in GDB.\n");
483 else if (alpha_about_to_return (start_pc))
486 start_pc += 4; /* skip return */
490 static alpha_extra_func_info_t
491 heuristic_proc_desc (start_pc, limit_pc, next_frame)
492 CORE_ADDR start_pc, limit_pc;
493 struct frame_info *next_frame;
495 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
498 int has_frame_reg = 0;
499 unsigned long reg_mask = 0;
504 memset (&temp_proc_desc, '\0', sizeof (temp_proc_desc));
505 memset (&temp_saved_regs, '\0', sizeof (struct frame_saved_regs));
506 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
508 if (start_pc + 200 < limit_pc)
509 limit_pc = start_pc + 200;
511 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4)
517 status = read_memory_nobpt (cur_pc, buf, 4);
519 memory_error (status, cur_pc);
520 word = extract_unsigned_integer (buf, 4);
522 if ((word & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
525 frame_size += (-word) & 0xffff;
527 /* Exit loop if a positive stack adjustment is found, which
528 usually means that the stack cleanup code in the function
529 epilogue is reached. */
532 else if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
533 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
535 int reg = (word & 0x03e00000) >> 21;
536 reg_mask |= 1 << reg;
537 temp_saved_regs.regs[reg] = sp + (short) word;
539 /* Starting with OSF/1-3.2C, the system libraries are shipped
540 without local symbols, but they still contain procedure
541 descriptors without a symbol reference. GDB is currently
542 unable to find these procedure descriptors and uses
543 heuristic_proc_desc instead.
544 As some low level compiler support routines (__div*, __add*)
545 use a non-standard return address register, we have to
546 add some heuristics to determine the return address register,
547 or stepping over these routines will fail.
548 Usually the return address register is the first register
549 saved on the stack, but assembler optimization might
550 rearrange the register saves.
551 So we recognize only a few registers (t7, t9, ra) within
552 the procedure prologue as valid return address registers.
553 If we encounter a return instruction, we extract the
554 the return address register from it.
556 FIXME: Rewriting GDB to access the procedure descriptors,
557 e.g. via the minimal symbol table, might obviate this hack. */
559 && cur_pc < (start_pc + 80)
560 && (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM))
563 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
564 pcreg = (word >> 16) & 0x1f;
565 else if (word == 0x47de040f) /* bis sp,sp fp */
570 /* If we haven't found a valid return address register yet,
571 keep searching in the procedure prologue. */
572 while (cur_pc < (limit_pc + 80) && cur_pc < (start_pc + 80))
577 if (read_memory_nobpt (cur_pc, buf, 4))
580 word = extract_unsigned_integer (buf, 4);
582 if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
583 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
585 int reg = (word & 0x03e00000) >> 21;
586 if (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM)
592 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
594 pcreg = (word >> 16) & 0x1f;
601 PROC_FRAME_REG (&temp_proc_desc) = GCC_FP_REGNUM;
603 PROC_FRAME_REG (&temp_proc_desc) = SP_REGNUM;
604 PROC_FRAME_OFFSET (&temp_proc_desc) = frame_size;
605 PROC_REG_MASK (&temp_proc_desc) = reg_mask;
606 PROC_PC_REG (&temp_proc_desc) = (pcreg == -1) ? RA_REGNUM : pcreg;
607 PROC_LOCALOFF (&temp_proc_desc) = 0; /* XXX - bogus */
608 return &temp_proc_desc;
611 /* This returns the PC of the first inst after the prologue. If we can't
612 find the prologue, then return 0. */
615 after_prologue (pc, proc_desc)
617 alpha_extra_func_info_t proc_desc;
619 struct symtab_and_line sal;
620 CORE_ADDR func_addr, func_end;
623 proc_desc = find_proc_desc (pc, NULL);
627 if (PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
628 return PROC_LOW_ADDR (proc_desc); /* "prologue" is in kernel */
630 /* If function is frameless, then we need to do it the hard way. I
631 strongly suspect that frameless always means prologueless... */
632 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
633 && PROC_FRAME_OFFSET (proc_desc) == 0)
637 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
638 return 0; /* Unknown */
640 sal = find_pc_line (func_addr, 0);
642 if (sal.end < func_end)
645 /* The line after the prologue is after the end of the function. In this
646 case, tell the caller to find the prologue the hard way. */
651 /* Return non-zero if we *might* be in a function prologue. Return zero if we
652 are definitively *not* in a function prologue. */
655 alpha_in_prologue (pc, proc_desc)
657 alpha_extra_func_info_t proc_desc;
659 CORE_ADDR after_prologue_pc;
661 after_prologue_pc = after_prologue (pc, proc_desc);
663 if (after_prologue_pc == 0
664 || pc < after_prologue_pc)
670 static alpha_extra_func_info_t
671 find_proc_desc (pc, next_frame)
673 struct frame_info *next_frame;
675 alpha_extra_func_info_t proc_desc;
680 /* Try to get the proc_desc from the linked call dummy proc_descs
681 if the pc is in the call dummy.
682 This is hairy. In the case of nested dummy calls we have to find the
683 right proc_desc, but we might not yet know the frame for the dummy
684 as it will be contained in the proc_desc we are searching for.
685 So we have to find the proc_desc whose frame is closest to the current
688 if (PC_IN_CALL_DUMMY (pc, 0, 0))
690 struct linked_proc_info *link;
691 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
692 alpha_extra_func_info_t found_proc_desc = NULL;
693 long min_distance = LONG_MAX;
695 for (link = linked_proc_desc_table; link; link = link->next)
697 long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp;
698 if (distance > 0 && distance < min_distance)
700 min_distance = distance;
701 found_proc_desc = &link->info;
704 if (found_proc_desc != NULL)
705 return found_proc_desc;
708 b = block_for_pc (pc);
710 find_pc_partial_function (pc, NULL, &startaddr, NULL);
715 if (startaddr > BLOCK_START (b))
716 /* This is the "pathological" case referred to in a comment in
717 print_frame_info. It might be better to move this check into
721 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
725 /* If we never found a PDR for this function in symbol reading, then
726 examine prologues to find the information. */
727 if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
732 /* IF this is the topmost frame AND
733 * (this proc does not have debugging information OR
734 * the PC is in the procedure prologue)
735 * THEN create a "heuristic" proc_desc (by analyzing
736 * the actual code) to replace the "official" proc_desc.
738 proc_desc = (alpha_extra_func_info_t) SYMBOL_VALUE (sym);
739 if (next_frame == NULL)
741 if (PROC_DESC_IS_DUMMY (proc_desc) || alpha_in_prologue (pc, proc_desc))
743 alpha_extra_func_info_t found_heuristic =
744 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
748 PROC_LOCALOFF (found_heuristic) =
749 PROC_LOCALOFF (proc_desc);
750 PROC_PC_REG (found_heuristic) = PROC_PC_REG (proc_desc);
751 proc_desc = found_heuristic;
760 /* Is linked_proc_desc_table really necessary? It only seems to be used
761 by procedure call dummys. However, the procedures being called ought
762 to have their own proc_descs, and even if they don't,
763 heuristic_proc_desc knows how to create them! */
765 register struct linked_proc_info *link;
766 for (link = linked_proc_desc_table; link; link = link->next)
767 if (PROC_LOW_ADDR (&link->info) <= pc
768 && PROC_HIGH_ADDR (&link->info) > pc)
771 /* If PC is inside a dynamically generated sigtramp handler,
772 create and push a procedure descriptor for that code: */
773 offset = DYNAMIC_SIGTRAMP_OFFSET (pc);
775 return push_sigtramp_desc (pc - offset);
777 /* If heuristic_fence_post is non-zero, determine the procedure
778 start address by examining the instructions.
779 This allows us to find the start address of static functions which
780 have no symbolic information, as startaddr would have been set to
781 the preceding global function start address by the
782 find_pc_partial_function call above. */
783 if (startaddr == 0 || heuristic_fence_post != 0)
784 startaddr = heuristic_proc_start (pc);
787 heuristic_proc_desc (startaddr, pc, next_frame);
792 alpha_extra_func_info_t cached_proc_desc;
795 alpha_frame_chain (frame)
796 struct frame_info *frame;
798 alpha_extra_func_info_t proc_desc;
799 CORE_ADDR saved_pc = FRAME_SAVED_PC (frame);
801 if (saved_pc == 0 || inside_entry_file (saved_pc))
804 proc_desc = find_proc_desc (saved_pc, frame);
808 cached_proc_desc = proc_desc;
810 /* Fetch the frame pointer for a dummy frame from the procedure
812 if (PROC_DESC_IS_DUMMY (proc_desc))
813 return (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
815 /* If no frame pointer and frame size is zero, we must be at end
816 of stack (or otherwise hosed). If we don't check frame size,
817 we loop forever if we see a zero size frame. */
818 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
819 && PROC_FRAME_OFFSET (proc_desc) == 0
820 /* The previous frame from a sigtramp frame might be frameless
821 and have frame size zero. */
822 && !frame->signal_handler_caller)
823 return FRAME_PAST_SIGTRAMP_FRAME (frame, saved_pc);
825 return read_next_frame_reg (frame, PROC_FRAME_REG (proc_desc))
826 + PROC_FRAME_OFFSET (proc_desc);
830 init_extra_frame_info (frame)
831 struct frame_info *frame;
833 /* Use proc_desc calculated in frame_chain */
834 alpha_extra_func_info_t proc_desc =
835 frame->next ? cached_proc_desc : find_proc_desc (frame->pc, frame->next);
837 frame->saved_regs = NULL;
839 frame->pc_reg = RA_REGNUM;
840 frame->proc_desc = proc_desc == &temp_proc_desc ? 0 : proc_desc;
843 /* Get the locals offset and the saved pc register from the
844 procedure descriptor, they are valid even if we are in the
845 middle of the prologue. */
846 frame->localoff = PROC_LOCALOFF (proc_desc);
847 frame->pc_reg = PROC_PC_REG (proc_desc);
849 /* Fixup frame-pointer - only needed for top frame */
851 /* Fetch the frame pointer for a dummy frame from the procedure
853 if (PROC_DESC_IS_DUMMY (proc_desc))
854 frame->frame = (CORE_ADDR) PROC_DUMMY_FRAME (proc_desc);
856 /* This may not be quite right, if proc has a real frame register.
857 Get the value of the frame relative sp, procedure might have been
858 interrupted by a signal at it's very start. */
859 else if (frame->pc == PROC_LOW_ADDR (proc_desc)
860 && !PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
861 frame->frame = read_next_frame_reg (frame->next, SP_REGNUM);
863 frame->frame = read_next_frame_reg (frame->next, PROC_FRAME_REG (proc_desc))
864 + PROC_FRAME_OFFSET (proc_desc);
866 if (proc_desc == &temp_proc_desc)
870 /* Do not set the saved registers for a sigtramp frame,
871 alpha_find_saved_registers will do that for us.
872 We can't use frame->signal_handler_caller, it is not yet set. */
873 find_pc_partial_function (frame->pc, &name,
874 (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
875 if (!IN_SIGTRAMP (frame->pc, name))
877 frame->saved_regs = (CORE_ADDR *)
878 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
879 memcpy (frame->saved_regs, temp_saved_regs.regs, SIZEOF_FRAME_SAVED_REGS);
880 frame->saved_regs[PC_REGNUM]
881 = frame->saved_regs[RA_REGNUM];
887 /* ALPHA stack frames are almost impenetrable. When execution stops,
888 we basically have to look at symbol information for the function
889 that we stopped in, which tells us *which* register (if any) is
890 the base of the frame pointer, and what offset from that register
891 the frame itself is at.
893 This presents a problem when trying to examine a stack in memory
894 (that isn't executing at the moment), using the "frame" command. We
895 don't have a PC, nor do we have any registers except SP.
897 This routine takes two arguments, SP and PC, and tries to make the
898 cached frames look as if these two arguments defined a frame on the
899 cache. This allows the rest of info frame to extract the important
900 arguments without difficulty. */
903 setup_arbitrary_frame (argc, argv)
908 error ("ALPHA frame specifications require two arguments: sp and pc");
910 return create_new_frame (argv[0], argv[1]);
913 /* The alpha passes the first six arguments in the registers, the rest on
914 the stack. The register arguments are eventually transferred to the
915 argument transfer area immediately below the stack by the called function
916 anyway. So we `push' at least six arguments on the stack, `reload' the
917 argument registers and then adjust the stack pointer to point past the
918 sixth argument. This algorithm simplifies the passing of a large struct
919 which extends from the registers to the stack.
920 If the called function is returning a structure, the address of the
921 structure to be returned is passed as a hidden first argument. */
924 alpha_push_arguments (nargs, args, sp, struct_return, struct_addr)
929 CORE_ADDR struct_addr;
932 int accumulate_size = struct_return ? 8 : 0;
933 int arg_regs_size = ALPHA_NUM_ARG_REGS * 8;
940 struct alpha_arg *alpha_args =
941 (struct alpha_arg *) alloca (nargs * sizeof (struct alpha_arg));
942 register struct alpha_arg *m_arg;
943 char raw_buffer[sizeof (CORE_ADDR)];
944 int required_arg_regs;
946 for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
948 value_ptr arg = args[i];
949 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
950 /* Cast argument to long if necessary as the compiler does it too. */
951 switch (TYPE_CODE (arg_type))
956 case TYPE_CODE_RANGE:
958 if (TYPE_LENGTH (arg_type) < TYPE_LENGTH (builtin_type_long))
960 arg_type = builtin_type_long;
961 arg = value_cast (arg_type, arg);
967 m_arg->len = TYPE_LENGTH (arg_type);
968 m_arg->offset = accumulate_size;
969 accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
970 m_arg->contents = VALUE_CONTENTS (arg);
973 /* Determine required argument register loads, loading an argument register
974 is expensive as it uses three ptrace calls. */
975 required_arg_regs = accumulate_size / 8;
976 if (required_arg_regs > ALPHA_NUM_ARG_REGS)
977 required_arg_regs = ALPHA_NUM_ARG_REGS;
979 /* Make room for the arguments on the stack. */
980 if (accumulate_size < arg_regs_size)
981 accumulate_size = arg_regs_size;
982 sp -= accumulate_size;
984 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
987 /* `Push' arguments on the stack. */
988 for (i = nargs; m_arg--, --i >= 0;)
989 write_memory (sp + m_arg->offset, m_arg->contents, m_arg->len);
992 store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr);
993 write_memory (sp, raw_buffer, sizeof (CORE_ADDR));
996 /* Load the argument registers. */
997 for (i = 0; i < required_arg_regs; i++)
1001 val = read_memory_integer (sp + i * 8, 8);
1002 write_register (A0_REGNUM + i, val);
1003 write_register (FPA0_REGNUM + i, val);
1006 return sp + arg_regs_size;
1010 alpha_push_dummy_frame ()
1013 struct linked_proc_info *link;
1014 alpha_extra_func_info_t proc_desc;
1015 CORE_ADDR sp = read_register (SP_REGNUM);
1016 CORE_ADDR save_address;
1017 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1020 link = (struct linked_proc_info *) xmalloc (sizeof (struct linked_proc_info));
1021 link->next = linked_proc_desc_table;
1022 linked_proc_desc_table = link;
1024 proc_desc = &link->info;
1027 * The registers we must save are all those not preserved across
1029 * In addition, we must save the PC and RA.
1031 * Dummy frame layout:
1041 * Parameter build area
1045 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
1046 #define MASK(i,j) ((((LONGEST)1 << ((j)+1)) - 1) ^ (((LONGEST)1 << (i)) - 1))
1047 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
1048 #define GEN_REG_SAVE_COUNT 24
1049 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
1050 #define FLOAT_REG_SAVE_COUNT 23
1051 /* The special register is the PC as we have no bit for it in the save masks.
1052 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
1053 #define SPECIAL_REG_SAVE_COUNT 1
1055 PROC_REG_MASK (proc_desc) = GEN_REG_SAVE_MASK;
1056 PROC_FREG_MASK (proc_desc) = FLOAT_REG_SAVE_MASK;
1057 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
1058 but keep SP aligned to a multiple of 16. */
1059 PROC_REG_OFFSET (proc_desc) =
1060 -((8 * (SPECIAL_REG_SAVE_COUNT
1061 + GEN_REG_SAVE_COUNT
1062 + FLOAT_REG_SAVE_COUNT)
1064 PROC_FREG_OFFSET (proc_desc) =
1065 PROC_REG_OFFSET (proc_desc) + 8 * GEN_REG_SAVE_COUNT;
1067 /* Save general registers.
1068 The return address register is the first saved register, all other
1069 registers follow in ascending order.
1070 The PC is saved immediately below the SP. */
1071 save_address = sp + PROC_REG_OFFSET (proc_desc);
1072 store_address (raw_buffer, 8, read_register (RA_REGNUM));
1073 write_memory (save_address, raw_buffer, 8);
1075 mask = PROC_REG_MASK (proc_desc) & 0xffffffffL;
1076 for (ireg = 0; mask; ireg++, mask >>= 1)
1079 if (ireg == RA_REGNUM)
1081 store_address (raw_buffer, 8, read_register (ireg));
1082 write_memory (save_address, raw_buffer, 8);
1086 store_address (raw_buffer, 8, read_register (PC_REGNUM));
1087 write_memory (sp - 8, raw_buffer, 8);
1089 /* Save floating point registers. */
1090 save_address = sp + PROC_FREG_OFFSET (proc_desc);
1091 mask = PROC_FREG_MASK (proc_desc) & 0xffffffffL;
1092 for (ireg = 0; mask; ireg++, mask >>= 1)
1095 store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM));
1096 write_memory (save_address, raw_buffer, 8);
1100 /* Set and save the frame address for the dummy.
1101 This is tricky. The only registers that are suitable for a frame save
1102 are those that are preserved across procedure calls (s0-s6). But if
1103 a read system call is interrupted and then a dummy call is made
1104 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
1105 is satisfied. Then it returns with the s0-s6 registers set to the values
1106 on entry to the read system call and our dummy frame pointer would be
1107 destroyed. So we save the dummy frame in the proc_desc and handle the
1108 retrieval of the frame pointer of a dummy specifically. The frame register
1109 is set to the virtual frame (pseudo) register, it's value will always
1110 be read as zero and will help us to catch any errors in the dummy frame
1112 PROC_DUMMY_FRAME (proc_desc) = sp;
1113 PROC_FRAME_REG (proc_desc) = FP_REGNUM;
1114 PROC_FRAME_OFFSET (proc_desc) = 0;
1115 sp += PROC_REG_OFFSET (proc_desc);
1116 write_register (SP_REGNUM, sp);
1118 PROC_LOW_ADDR (proc_desc) = CALL_DUMMY_ADDRESS ();
1119 PROC_HIGH_ADDR (proc_desc) = PROC_LOW_ADDR (proc_desc) + 4;
1121 SET_PROC_DESC_IS_DUMMY (proc_desc);
1122 PROC_PC_REG (proc_desc) = RA_REGNUM;
1128 register int regnum;
1129 struct frame_info *frame = get_current_frame ();
1130 CORE_ADDR new_sp = frame->frame;
1132 alpha_extra_func_info_t proc_desc = frame->proc_desc;
1134 /* we need proc_desc to know how to restore the registers;
1135 if it is NULL, construct (a temporary) one */
1136 if (proc_desc == NULL)
1137 proc_desc = find_proc_desc (frame->pc, frame->next);
1139 /* Question: should we copy this proc_desc and save it in
1140 frame->proc_desc? If we do, who will free it?
1141 For now, we don't save a copy... */
1143 write_register (PC_REGNUM, FRAME_SAVED_PC (frame));
1144 if (frame->saved_regs == NULL)
1145 alpha_find_saved_regs (frame);
1148 for (regnum = 32; --regnum >= 0;)
1149 if (PROC_REG_MASK (proc_desc) & (1 << regnum))
1150 write_register (regnum,
1151 read_memory_integer (frame->saved_regs[regnum],
1153 for (regnum = 32; --regnum >= 0;)
1154 if (PROC_FREG_MASK (proc_desc) & (1 << regnum))
1155 write_register (regnum + FP0_REGNUM,
1156 read_memory_integer (frame->saved_regs[regnum + FP0_REGNUM], 8));
1158 write_register (SP_REGNUM, new_sp);
1159 flush_cached_frames ();
1161 if (proc_desc && (PROC_DESC_IS_DUMMY (proc_desc)
1162 || PROC_DESC_IS_DYN_SIGTRAMP (proc_desc)))
1164 struct linked_proc_info *pi_ptr, *prev_ptr;
1166 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
1168 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
1170 if (&pi_ptr->info == proc_desc)
1175 error ("Can't locate dummy extra frame info\n");
1177 if (prev_ptr != NULL)
1178 prev_ptr->next = pi_ptr->next;
1180 linked_proc_desc_table = pi_ptr->next;
1186 /* To skip prologues, I use this predicate. Returns either PC itself
1187 if the code at PC does not look like a function prologue; otherwise
1188 returns an address that (if we're lucky) follows the prologue. If
1189 LENIENT, then we must skip everything which is involved in setting
1190 up the frame (it's OK to skip more, just so long as we don't skip
1191 anything which might clobber the registers which are being saved.
1192 Currently we must not skip more on the alpha, but we might the lenient
1196 alpha_skip_prologue (pc, lenient)
1202 CORE_ADDR post_prologue_pc;
1205 #ifdef GDB_TARGET_HAS_SHARED_LIBS
1206 /* Silently return the unaltered pc upon memory errors.
1207 This could happen on OSF/1 if decode_line_1 tries to skip the
1208 prologue for quickstarted shared library functions when the
1209 shared library is not yet mapped in.
1210 Reading target memory is slow over serial lines, so we perform
1211 this check only if the target has shared libraries. */
1212 if (target_read_memory (pc, buf, 4))
1216 /* See if we can determine the end of the prologue via the symbol table.
1217 If so, then return either PC, or the PC after the prologue, whichever
1220 post_prologue_pc = after_prologue (pc, NULL);
1222 if (post_prologue_pc != 0)
1223 return max (pc, post_prologue_pc);
1225 /* Can't determine prologue from the symbol table, need to examine
1228 /* Skip the typical prologue instructions. These are the stack adjustment
1229 instruction and the instructions that save registers on the stack
1230 or in the gcc frame. */
1231 for (offset = 0; offset < 100; offset += 4)
1235 status = read_memory_nobpt (pc + offset, buf, 4);
1237 memory_error (status, pc + offset);
1238 inst = extract_unsigned_integer (buf, 4);
1240 /* The alpha has no delay slots. But let's keep the lenient stuff,
1241 we might need it for something else in the future. */
1245 if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1247 if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1249 if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1251 if ((inst & 0xffe01fff) == 0x43c0153e) /* subq $sp,n,$sp */
1254 if ((inst & 0xfc1f0000) == 0xb41e0000
1255 && (inst & 0xffff0000) != 0xb7fe0000)
1256 continue; /* stq reg,n($sp) */
1258 if ((inst & 0xfc1f0000) == 0x9c1e0000
1259 && (inst & 0xffff0000) != 0x9ffe0000)
1260 continue; /* stt reg,n($sp) */
1262 if (inst == 0x47de040f) /* bis sp,sp,fp */
1271 /* Is address PC in the prologue (loosely defined) for function at
1275 alpha_in_lenient_prologue (startaddr, pc)
1276 CORE_ADDR startaddr;
1279 CORE_ADDR end_prologue = alpha_skip_prologue (startaddr, 1);
1280 return pc >= startaddr && pc < end_prologue;
1284 /* The alpha needs a conversion between register and memory format if
1285 the register is a floating point register and
1286 memory format is float, as the register format must be double
1288 memory format is an integer with 4 bytes or less, as the representation
1289 of integers in floating point registers is different. */
1291 alpha_register_convert_to_virtual (regnum, valtype, raw_buffer, virtual_buffer)
1293 struct type *valtype;
1295 char *virtual_buffer;
1297 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1299 memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
1303 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1305 double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum));
1306 store_floating (virtual_buffer, TYPE_LENGTH (valtype), d);
1308 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1311 l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum));
1312 l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff);
1313 store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l);
1316 error ("Cannot retrieve value from floating point register");
1320 alpha_register_convert_to_raw (valtype, regnum, virtual_buffer, raw_buffer)
1321 struct type *valtype;
1323 char *virtual_buffer;
1326 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1328 memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum));
1332 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1334 double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype));
1335 store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d);
1337 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1340 if (TYPE_UNSIGNED (valtype))
1341 l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype));
1343 l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype));
1344 l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29);
1345 store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l);
1348 error ("Cannot store value in floating point register");
1351 /* Given a return value in `regbuf' with a type `valtype',
1352 extract and copy its value into `valbuf'. */
1355 alpha_extract_return_value (valtype, regbuf, valbuf)
1356 struct type *valtype;
1357 char regbuf[REGISTER_BYTES];
1360 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1361 alpha_register_convert_to_virtual (FP0_REGNUM, valtype,
1362 regbuf + REGISTER_BYTE (FP0_REGNUM),
1365 memcpy (valbuf, regbuf + REGISTER_BYTE (V0_REGNUM), TYPE_LENGTH (valtype));
1368 /* Given a return value in `regbuf' with a type `valtype',
1369 write its value into the appropriate register. */
1372 alpha_store_return_value (valtype, valbuf)
1373 struct type *valtype;
1376 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1377 int regnum = V0_REGNUM;
1378 int length = TYPE_LENGTH (valtype);
1380 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1382 regnum = FP0_REGNUM;
1383 length = REGISTER_RAW_SIZE (regnum);
1384 alpha_register_convert_to_raw (valtype, regnum, valbuf, raw_buffer);
1387 memcpy (raw_buffer, valbuf, length);
1389 write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, length);
1392 /* Just like reinit_frame_cache, but with the right arguments to be
1393 callable as an sfunc. */
1396 reinit_frame_cache_sfunc (args, from_tty, c)
1399 struct cmd_list_element *c;
1401 reinit_frame_cache ();
1404 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1405 to find a convenient place in the text segment to stick a breakpoint to
1406 detect the completion of a target function call (ala call_function_by_hand).
1410 alpha_call_dummy_address ()
1413 struct minimal_symbol *sym;
1415 entry = entry_point_address ();
1420 sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile);
1422 if (!sym || MSYMBOL_TYPE (sym) != mst_text)
1425 return SYMBOL_VALUE_ADDRESS (sym) + 4;
1429 _initialize_alpha_tdep ()
1431 struct cmd_list_element *c;
1433 tm_print_insn = print_insn_alpha;
1435 /* Let the user set the fence post for heuristic_proc_start. */
1437 /* We really would like to have both "0" and "unlimited" work, but
1438 command.c doesn't deal with that. So make it a var_zinteger
1439 because the user can always use "999999" or some such for unlimited. */
1440 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
1441 (char *) &heuristic_fence_post,
1443 Set the distance searched for the start of a function.\n\
1444 If you are debugging a stripped executable, GDB needs to search through the\n\
1445 program for the start of a function. This command sets the distance of the\n\
1446 search. The only need to set it is when debugging a stripped executable.",
1448 /* We need to throw away the frame cache when we set this, since it
1449 might change our ability to get backtraces. */
1450 c->function.sfunc = reinit_frame_cache_sfunc;
1451 add_show_from_set (c, &showlist);