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, Boston, MA 02111-1307, USA. */
21 #include <sys/param.h>
22 #include <machine/alpha_cpu.h>
23 #include <machine/vmparam.h>
35 #include "gdb_string.h"
37 /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
39 /* Prototypes for local functions. */
41 static alpha_extra_func_info_t push_sigtramp_desc PARAMS ((CORE_ADDR low_addr));
43 static CORE_ADDR read_next_frame_reg PARAMS ((struct frame_info *, int));
45 static CORE_ADDR heuristic_proc_start PARAMS ((CORE_ADDR));
47 static alpha_extra_func_info_t heuristic_proc_desc PARAMS ((CORE_ADDR,
49 struct frame_info *));
51 static alpha_extra_func_info_t find_proc_desc PARAMS ((CORE_ADDR,
52 struct frame_info *));
55 static int alpha_in_lenient_prologue PARAMS ((CORE_ADDR, CORE_ADDR));
58 static void reinit_frame_cache_sfunc PARAMS ((char *, int,
59 struct cmd_list_element *));
61 static CORE_ADDR after_prologue PARAMS ((CORE_ADDR pc,
62 alpha_extra_func_info_t proc_desc));
64 static int alpha_in_prologue PARAMS ((CORE_ADDR pc,
65 alpha_extra_func_info_t proc_desc));
67 /* Heuristic_proc_start may hunt through the text section for a long
68 time across a 2400 baud serial line. Allows the user to limit this
70 static unsigned int heuristic_fence_post = 0;
72 /* Layout of a stack frame on the alpha:
75 pdr members: | 7th ... nth arg, |
76 | `pushed' by caller. |
78 ----------------|-------------------------------|<-- old_sp == vfp
81 | |localoff | Copies of 1st .. 6th |
82 | | | | | argument if necessary. |
84 | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
86 | | | | Locals and temporaries. |
88 | | | |-------------------------------|
90 |-fregoffset | Saved float registers. |
96 | | -------|-------------------------------|
98 | | | Saved registers. |
105 | ----------|-------------------------------|
107 frameoffset | Argument build area, gets |
108 | | 7th ... nth arg for any |
109 | | called procedure. |
111 -------------|-------------------------------|<-- sp
115 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
116 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
117 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.iopt) /* frame for CALL_DUMMY */
118 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
119 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
120 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
121 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
122 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
123 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
124 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
125 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
126 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
127 #define _PROC_MAGIC_ 0x0F0F0F0F
128 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
129 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
131 struct linked_proc_info
133 struct alpha_extra_func_info info;
134 struct linked_proc_info *next;
135 } *linked_proc_desc_table = NULL;
138 /* Under GNU/Linux, signal handler invocations can be identified by the
139 designated code sequence that is used to return from a signal
140 handler. In particular, the return address of a signal handler
141 points to the following sequence (the first instruction is quadword
148 Each instruction has a unique encoding, so we simply attempt to
149 match the instruction the pc is pointing to with any of the above
150 instructions. If there is a hit, we know the offset to the start
151 of the designated sequence and can then check whether we really are
152 executing in a designated sequence. If not, -1 is returned,
153 otherwise the offset from the start of the desingated sequence is
156 There is a slight chance of false hits: code could jump into the
157 middle of the designated sequence, in which case there is no
158 guarantee that we are in the middle of a sigreturn syscall. Don't
159 think this will be a problem in praxis, though.
163 alpha_linux_sigtramp_offset (CORE_ADDR pc)
165 unsigned int i[3], w;
168 if (read_memory_nobpt(pc, (char *) &w, 4) != 0)
174 case 0x47de0410: off = 0; break; /* bis $30,$30,$16 */
175 case 0x43ecf400: off = 4; break; /* addq $31,0x67,$0 */
176 case 0x00000083: off = 8; break; /* call_pal callsys */
182 /* designated sequence is not quadword aligned */
186 if (read_memory_nobpt(pc, (char *) i, sizeof(i)) != 0)
189 if (i[0] == 0x47de0410 && i[1] == 0x43ecf400 && i[2] == 0x00000083)
196 /* Under OSF/1, the __sigtramp routine is frameless and has a frame
197 size of zero, but we are able to backtrace through it. */
199 alpha_osf_skip_sigtramp_frame (frame, pc)
200 struct frame_info *frame;
204 find_pc_partial_function (pc, &name, (CORE_ADDR *)NULL, (CORE_ADDR *)NULL);
205 if (IN_SIGTRAMP (pc, name))
212 /* Dynamically create a signal-handler caller procedure descriptor for
213 the signal-handler return code starting at address LOW_ADDR. The
214 descriptor is added to the linked_proc_desc_table. */
216 static alpha_extra_func_info_t
217 push_sigtramp_desc (low_addr)
220 struct linked_proc_info *link;
221 alpha_extra_func_info_t proc_desc;
223 link = (struct linked_proc_info *)
224 xmalloc (sizeof (struct linked_proc_info));
225 link->next = linked_proc_desc_table;
226 linked_proc_desc_table = link;
228 proc_desc = &link->info;
230 proc_desc->numargs = 0;
231 PROC_LOW_ADDR (proc_desc) = low_addr;
232 PROC_HIGH_ADDR (proc_desc) = low_addr + 3 * 4;
233 PROC_DUMMY_FRAME (proc_desc) = 0;
234 PROC_FRAME_OFFSET (proc_desc) = 0x298; /* sizeof(struct sigcontext_struct) */
235 PROC_FRAME_REG (proc_desc) = SP_REGNUM;
236 PROC_REG_MASK (proc_desc) = 0xffff;
237 PROC_FREG_MASK (proc_desc) = 0xffff;
238 PROC_PC_REG (proc_desc) = 26;
239 PROC_LOCALOFF (proc_desc) = 0;
240 SET_PROC_DESC_IS_DYN_SIGTRAMP (proc_desc);
245 /* Guaranteed to set frame->saved_regs to some values (it never leaves it
249 alpha_find_saved_regs (frame)
250 struct frame_info *frame;
253 CORE_ADDR reg_position;
255 alpha_extra_func_info_t proc_desc;
258 frame_saved_regs_zalloc (frame);
260 /* If it is the frame for __sigtramp, the saved registers are located
261 in a sigcontext structure somewhere on the stack. __sigtramp
262 passes a pointer to the sigcontext structure on the stack.
263 If the stack layout for __sigtramp changes, or if sigcontext offsets
264 change, we might have to update this code. */
265 #ifndef SIGFRAME_PC_OFF
266 #define SIGFRAME_PC_OFF (2 * 8)
267 #define SIGFRAME_REGSAVE_OFF (4 * 8)
268 #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
270 if (frame->signal_handler_caller)
272 CORE_ADDR sigcontext_addr;
274 sigcontext_addr = SIGCONTEXT_ADDR (frame);
275 for (ireg = 0; ireg < 32; ireg++)
277 reg_position = sigcontext_addr + SIGFRAME_REGSAVE_OFF + ireg * 8;
278 frame->saved_regs[ireg] = reg_position;
280 for (ireg = 0; ireg < 32; ireg++)
282 reg_position = sigcontext_addr + SIGFRAME_FPREGSAVE_OFF + ireg * 8;
283 frame->saved_regs[FP0_REGNUM + ireg] = reg_position;
285 frame->saved_regs[PC_REGNUM] = sigcontext_addr + SIGFRAME_PC_OFF;
289 proc_desc = frame->proc_desc;
290 if (proc_desc == NULL)
291 /* I'm not sure how/whether this can happen. Normally when we can't
292 find a proc_desc, we "synthesize" one using heuristic_proc_desc
293 and set the saved_regs right away. */
296 /* Fill in the offsets for the registers which gen_mask says
299 reg_position = frame->frame + PROC_REG_OFFSET (proc_desc);
300 mask = PROC_REG_MASK (proc_desc);
302 returnreg = PROC_PC_REG (proc_desc);
304 /* Note that RA is always saved first, regardless of its actual
306 if (mask & (1 << returnreg))
308 frame->saved_regs[returnreg] = reg_position;
310 mask &= ~(1 << returnreg); /* Clear bit for RA so we
311 don't save again later. */
314 for (ireg = 0; ireg <= 31 ; ++ireg)
315 if (mask & (1 << ireg))
317 frame->saved_regs[ireg] = reg_position;
321 /* Fill in the offsets for the registers which float_mask says
324 reg_position = frame->frame + PROC_FREG_OFFSET (proc_desc);
325 mask = PROC_FREG_MASK (proc_desc);
327 for (ireg = 0; ireg <= 31 ; ++ireg)
328 if (mask & (1 << ireg))
330 frame->saved_regs[FP0_REGNUM+ireg] = reg_position;
334 frame->saved_regs[PC_REGNUM] = frame->saved_regs[returnreg];
338 read_next_frame_reg(fi, regno)
339 struct frame_info *fi;
342 for (; fi; fi = fi->next)
344 /* We have to get the saved sp from the sigcontext
345 if it is a signal handler frame. */
346 if (regno == SP_REGNUM && !fi->signal_handler_caller)
350 if (fi->saved_regs == NULL)
351 alpha_find_saved_regs (fi);
352 if (fi->saved_regs[regno])
353 return read_memory_integer(fi->saved_regs[regno], 8);
356 return read_register(regno);
360 alpha_frame_saved_pc(frame)
361 struct frame_info *frame;
363 alpha_extra_func_info_t proc_desc = frame->proc_desc;
364 /* We have to get the saved pc from the sigcontext
365 if it is a signal handler frame. */
366 int pcreg = frame->signal_handler_caller ? PC_REGNUM : frame->pc_reg;
368 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
369 return read_memory_integer(frame->frame - 8, 8);
371 return read_next_frame_reg(frame, pcreg);
375 alpha_saved_pc_after_call (frame)
376 struct frame_info *frame;
378 CORE_ADDR pc = frame->pc;
380 alpha_extra_func_info_t proc_desc;
383 /* Skip over shared library trampoline if necessary. */
384 tmp = SKIP_TRAMPOLINE_CODE (pc);
388 proc_desc = find_proc_desc (pc, frame->next);
389 pcreg = proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM;
391 if (frame->signal_handler_caller)
392 return alpha_frame_saved_pc (frame);
394 return read_register (pcreg);
398 static struct alpha_extra_func_info temp_proc_desc;
399 static struct frame_saved_regs temp_saved_regs;
401 /* Nonzero if instruction at PC is a return instruction. "ret
402 $zero,($ra),1" on alpha. */
405 alpha_about_to_return (pc)
408 return read_memory_integer (pc, 4) == 0x6bfa8001;
413 /* This fencepost looks highly suspicious to me. Removing it also
414 seems suspicious as it could affect remote debugging across serial
418 heuristic_proc_start(pc)
421 CORE_ADDR start_pc = pc;
422 CORE_ADDR fence = start_pc - heuristic_fence_post;
424 if (start_pc == 0) return 0;
426 if (heuristic_fence_post == UINT_MAX
427 || fence < VM_MIN_ADDRESS)
428 fence = VM_MIN_ADDRESS;
430 /* search back for previous return */
431 for (start_pc -= 4; ; start_pc -= 4)
432 if (start_pc < fence)
434 /* It's not clear to me why we reach this point when
435 stop_soon_quietly, but with this test, at least we
436 don't print out warnings for every child forked (eg, on
437 decstation). 22apr93 rich@cygnus.com. */
438 if (!stop_soon_quietly)
440 static int blurb_printed = 0;
442 if (fence == VM_MIN_ADDRESS)
443 warning("Hit beginning of text section without finding");
445 warning("Hit heuristic-fence-post without finding");
447 warning("enclosing function for address 0x%lx", pc);
451 This warning occurs if you are debugging a function without any symbols\n\
452 (for example, in a stripped executable). In that case, you may wish to\n\
453 increase the size of the search with the `set heuristic-fence-post' command.\n\
455 Otherwise, you told GDB there was a function where there isn't one, or\n\
456 (more likely) you have encountered a bug in GDB.\n");
463 else if (alpha_about_to_return (start_pc))
466 start_pc += 4; /* skip return */
470 static alpha_extra_func_info_t
471 heuristic_proc_desc(start_pc, limit_pc, next_frame)
472 CORE_ADDR start_pc, limit_pc;
473 struct frame_info *next_frame;
475 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
478 int has_frame_reg = 0;
479 unsigned long reg_mask = 0;
484 memset (&temp_proc_desc, '\0', sizeof(temp_proc_desc));
485 memset (&temp_saved_regs, '\0', sizeof(struct frame_saved_regs));
486 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
488 if (start_pc + 200 < limit_pc)
489 limit_pc = start_pc + 200;
491 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4)
497 status = read_memory_nobpt (cur_pc, buf, 4);
499 memory_error (status, cur_pc);
500 word = extract_unsigned_integer (buf, 4);
502 if ((word & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
505 frame_size += (-word) & 0xffff;
507 /* Exit loop if a positive stack adjustment is found, which
508 usually means that the stack cleanup code in the function
509 epilogue is reached. */
512 else if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
513 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
515 int reg = (word & 0x03e00000) >> 21;
516 reg_mask |= 1 << reg;
517 temp_saved_regs.regs[reg] = sp + (short)word;
519 /* Starting with OSF/1-3.2C, the system libraries are shipped
520 without local symbols, but they still contain procedure
521 descriptors without a symbol reference. GDB is currently
522 unable to find these procedure descriptors and uses
523 heuristic_proc_desc instead.
524 As some low level compiler support routines (__div*, __add*)
525 use a non-standard return address register, we have to
526 add some heuristics to determine the return address register,
527 or stepping over these routines will fail.
528 Usually the return address register is the first register
529 saved on the stack, but assembler optimization might
530 rearrange the register saves.
531 So we recognize only a few registers (t7, t9, ra) within
532 the procedure prologue as valid return address registers.
533 If we encounter a return instruction, we extract the
534 the return address register from it.
536 FIXME: Rewriting GDB to access the procedure descriptors,
537 e.g. via the minimal symbol table, might obviate this hack. */
539 && cur_pc < (start_pc + 80)
540 && (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM))
543 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
544 pcreg = (word >> 16) & 0x1f;
545 else if (word == 0x47de040f) /* bis sp,sp fp */
550 /* If we haven't found a valid return address register yet,
551 keep searching in the procedure prologue. */
552 while (cur_pc < (limit_pc + 80) && cur_pc < (start_pc + 80))
557 if (read_memory_nobpt (cur_pc, buf, 4))
560 word = extract_unsigned_integer (buf, 4);
562 if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
563 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
565 int reg = (word & 0x03e00000) >> 21;
566 if (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM)
572 else if ((word & 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
574 pcreg = (word >> 16) & 0x1f;
581 PROC_FRAME_REG(&temp_proc_desc) = GCC_FP_REGNUM;
583 PROC_FRAME_REG(&temp_proc_desc) = SP_REGNUM;
584 PROC_FRAME_OFFSET(&temp_proc_desc) = frame_size;
585 PROC_REG_MASK(&temp_proc_desc) = reg_mask;
586 PROC_PC_REG(&temp_proc_desc) = (pcreg == -1) ? RA_REGNUM : pcreg;
587 PROC_LOCALOFF(&temp_proc_desc) = 0; /* XXX - bogus */
588 return &temp_proc_desc;
591 /* This returns the PC of the first inst after the prologue. If we can't
592 find the prologue, then return 0. */
595 after_prologue (pc, proc_desc)
597 alpha_extra_func_info_t proc_desc;
599 struct symtab_and_line sal;
600 CORE_ADDR func_addr, func_end;
603 proc_desc = find_proc_desc (pc, NULL);
607 if (PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
608 return PROC_LOW_ADDR (proc_desc); /* "prologue" is in kernel */
610 /* If function is frameless, then we need to do it the hard way. I
611 strongly suspect that frameless always means prologueless... */
612 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
613 && PROC_FRAME_OFFSET (proc_desc) == 0)
617 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
618 return 0; /* Unknown */
620 sal = find_pc_line (func_addr, 0);
622 if (sal.end < func_end)
625 /* The line after the prologue is after the end of the function. In this
626 case, tell the caller to find the prologue the hard way. */
631 /* Return non-zero if we *might* be in a function prologue. Return zero if we
632 are definitively *not* in a function prologue. */
635 alpha_in_prologue (pc, proc_desc)
637 alpha_extra_func_info_t proc_desc;
639 CORE_ADDR after_prologue_pc;
641 after_prologue_pc = after_prologue (pc, proc_desc);
643 if (after_prologue_pc == 0
644 || pc < after_prologue_pc)
650 static alpha_extra_func_info_t
651 find_proc_desc (pc, next_frame)
653 struct frame_info *next_frame;
655 alpha_extra_func_info_t proc_desc;
660 /* Try to get the proc_desc from the linked call dummy proc_descs
661 if the pc is in the call dummy.
662 This is hairy. In the case of nested dummy calls we have to find the
663 right proc_desc, but we might not yet know the frame for the dummy
664 as it will be contained in the proc_desc we are searching for.
665 So we have to find the proc_desc whose frame is closest to the current
668 if (PC_IN_CALL_DUMMY (pc, 0, 0))
670 struct linked_proc_info *link;
671 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
672 alpha_extra_func_info_t found_proc_desc = NULL;
673 long min_distance = LONG_MAX;
675 for (link = linked_proc_desc_table; link; link = link->next)
677 long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp;
678 if (distance > 0 && distance < min_distance)
680 min_distance = distance;
681 found_proc_desc = &link->info;
684 if (found_proc_desc != NULL)
685 return found_proc_desc;
688 b = block_for_pc(pc);
690 find_pc_partial_function (pc, NULL, &startaddr, NULL);
695 if (startaddr > BLOCK_START (b))
696 /* This is the "pathological" case referred to in a comment in
697 print_frame_info. It might be better to move this check into
701 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
705 /* If we never found a PDR for this function in symbol reading, then
706 examine prologues to find the information. */
707 if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
712 /* IF this is the topmost frame AND
713 * (this proc does not have debugging information OR
714 * the PC is in the procedure prologue)
715 * THEN create a "heuristic" proc_desc (by analyzing
716 * the actual code) to replace the "official" proc_desc.
718 proc_desc = (alpha_extra_func_info_t)SYMBOL_VALUE(sym);
719 if (next_frame == NULL)
721 if (PROC_DESC_IS_DUMMY (proc_desc) || alpha_in_prologue (pc, proc_desc))
723 alpha_extra_func_info_t found_heuristic =
724 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
728 PROC_LOCALOFF (found_heuristic) =
729 PROC_LOCALOFF (proc_desc);
730 PROC_PC_REG (found_heuristic) = PROC_PC_REG (proc_desc);
731 proc_desc = found_heuristic;
740 /* Is linked_proc_desc_table really necessary? It only seems to be used
741 by procedure call dummys. However, the procedures being called ought
742 to have their own proc_descs, and even if they don't,
743 heuristic_proc_desc knows how to create them! */
745 register struct linked_proc_info *link;
746 for (link = linked_proc_desc_table; link; link = link->next)
747 if (PROC_LOW_ADDR(&link->info) <= pc
748 && PROC_HIGH_ADDR(&link->info) > pc)
751 /* If PC is inside a dynamically generated sigtramp handler,
752 create and push a procedure descriptor for that code: */
753 offset = DYNAMIC_SIGTRAMP_OFFSET (pc);
755 return push_sigtramp_desc (pc - offset);
757 /* If heuristic_fence_post is non-zero, determine the procedure
758 start address by examining the instructions.
759 This allows us to find the start address of static functions which
760 have no symbolic information, as startaddr would have been set to
761 the preceding global function start address by the
762 find_pc_partial_function call above. */
763 if (startaddr == 0 || heuristic_fence_post != 0)
764 startaddr = heuristic_proc_start (pc);
767 heuristic_proc_desc (startaddr, pc, next_frame);
772 alpha_extra_func_info_t cached_proc_desc;
775 alpha_frame_chain(frame)
776 struct frame_info *frame;
778 alpha_extra_func_info_t proc_desc;
779 CORE_ADDR saved_pc = FRAME_SAVED_PC(frame);
781 if (saved_pc == 0 || inside_entry_file (saved_pc))
784 proc_desc = find_proc_desc(saved_pc, frame);
788 cached_proc_desc = proc_desc;
790 /* Fetch the frame pointer for a dummy frame from the procedure
792 if (PROC_DESC_IS_DUMMY(proc_desc))
793 return (CORE_ADDR) PROC_DUMMY_FRAME(proc_desc);
795 /* If no frame pointer and frame size is zero, we must be at end
796 of stack (or otherwise hosed). If we don't check frame size,
797 we loop forever if we see a zero size frame. */
798 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
799 && PROC_FRAME_OFFSET (proc_desc) == 0
800 /* The previous frame from a sigtramp frame might be frameless
801 and have frame size zero. */
802 && !frame->signal_handler_caller)
803 return FRAME_PAST_SIGTRAMP_FRAME (frame, saved_pc);
805 return read_next_frame_reg(frame, PROC_FRAME_REG(proc_desc))
806 + PROC_FRAME_OFFSET(proc_desc);
810 init_extra_frame_info (frame)
811 struct frame_info *frame;
813 /* Use proc_desc calculated in frame_chain */
814 alpha_extra_func_info_t proc_desc =
815 frame->next ? cached_proc_desc : find_proc_desc(frame->pc, frame->next);
817 frame->saved_regs = NULL;
819 frame->pc_reg = RA_REGNUM;
820 frame->proc_desc = proc_desc == &temp_proc_desc ? 0 : proc_desc;
823 /* Get the locals offset and the saved pc register from the
824 procedure descriptor, they are valid even if we are in the
825 middle of the prologue. */
826 frame->localoff = PROC_LOCALOFF(proc_desc);
827 frame->pc_reg = PROC_PC_REG(proc_desc);
829 /* Fixup frame-pointer - only needed for top frame */
831 /* Fetch the frame pointer for a dummy frame from the procedure
833 if (PROC_DESC_IS_DUMMY(proc_desc))
834 frame->frame = (CORE_ADDR) PROC_DUMMY_FRAME(proc_desc);
836 /* This may not be quite right, if proc has a real frame register.
837 Get the value of the frame relative sp, procedure might have been
838 interrupted by a signal at it's very start. */
839 else if (frame->pc == PROC_LOW_ADDR (proc_desc)
840 && !PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
841 frame->frame = read_next_frame_reg (frame->next, SP_REGNUM);
843 frame->frame = read_next_frame_reg (frame->next, PROC_FRAME_REG (proc_desc))
844 + PROC_FRAME_OFFSET (proc_desc);
846 if (proc_desc == &temp_proc_desc)
850 /* Do not set the saved registers for a sigtramp frame,
851 alpha_find_saved_registers will do that for us.
852 We can't use frame->signal_handler_caller, it is not yet set. */
853 find_pc_partial_function (frame->pc, &name,
854 (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
855 if (!IN_SIGTRAMP (frame->pc, name))
857 frame->saved_regs = (CORE_ADDR*)
858 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS);
859 memcpy (frame->saved_regs, temp_saved_regs.regs, SIZEOF_FRAME_SAVED_REGS);
860 frame->saved_regs[PC_REGNUM]
861 = frame->saved_regs[RA_REGNUM];
867 /* ALPHA stack frames are almost impenetrable. When execution stops,
868 we basically have to look at symbol information for the function
869 that we stopped in, which tells us *which* register (if any) is
870 the base of the frame pointer, and what offset from that register
871 the frame itself is at.
873 This presents a problem when trying to examine a stack in memory
874 (that isn't executing at the moment), using the "frame" command. We
875 don't have a PC, nor do we have any registers except SP.
877 This routine takes two arguments, SP and PC, and tries to make the
878 cached frames look as if these two arguments defined a frame on the
879 cache. This allows the rest of info frame to extract the important
880 arguments without difficulty. */
883 setup_arbitrary_frame (argc, argv)
888 error ("ALPHA frame specifications require two arguments: sp and pc");
890 return create_new_frame (argv[0], argv[1]);
893 /* The alpha passes the first six arguments in the registers, the rest on
894 the stack. The register arguments are eventually transferred to the
895 argument transfer area immediately below the stack by the called function
896 anyway. So we `push' at least six arguments on the stack, `reload' the
897 argument registers and then adjust the stack pointer to point past the
898 sixth argument. This algorithm simplifies the passing of a large struct
899 which extends from the registers to the stack.
900 If the called function is returning a structure, the address of the
901 structure to be returned is passed as a hidden first argument. */
904 alpha_push_arguments (nargs, args, sp, struct_return, struct_addr)
909 CORE_ADDR struct_addr;
912 int accumulate_size = struct_return ? 8 : 0;
913 int arg_regs_size = ALPHA_NUM_ARG_REGS * 8;
914 struct alpha_arg { char *contents; int len; int offset; };
915 struct alpha_arg *alpha_args =
916 (struct alpha_arg*)alloca (nargs * sizeof (struct alpha_arg));
917 register struct alpha_arg *m_arg;
918 char raw_buffer[sizeof (CORE_ADDR)];
919 int required_arg_regs;
921 for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
923 value_ptr arg = args[i];
924 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
925 /* Cast argument to long if necessary as the compiler does it too. */
926 switch (TYPE_CODE (arg_type))
931 case TYPE_CODE_RANGE:
933 if (TYPE_LENGTH (arg_type) < TYPE_LENGTH (builtin_type_long))
935 arg_type = builtin_type_long;
936 arg = value_cast (arg_type, arg);
942 m_arg->len = TYPE_LENGTH (arg_type);
943 m_arg->offset = accumulate_size;
944 accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
945 m_arg->contents = VALUE_CONTENTS(arg);
948 /* Determine required argument register loads, loading an argument register
949 is expensive as it uses three ptrace calls. */
950 required_arg_regs = accumulate_size / 8;
951 if (required_arg_regs > ALPHA_NUM_ARG_REGS)
952 required_arg_regs = ALPHA_NUM_ARG_REGS;
954 /* Make room for the arguments on the stack. */
955 if (accumulate_size < arg_regs_size)
956 accumulate_size = arg_regs_size;
957 sp -= accumulate_size;
959 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
962 /* `Push' arguments on the stack. */
963 for (i = nargs; m_arg--, --i >= 0; )
964 write_memory(sp + m_arg->offset, m_arg->contents, m_arg->len);
967 store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr);
968 write_memory (sp, raw_buffer, sizeof (CORE_ADDR));
971 /* Load the argument registers. */
972 for (i = 0; i < required_arg_regs; i++)
976 val = read_memory_integer (sp + i * 8, 8);
977 write_register (A0_REGNUM + i, val);
978 write_register (FPA0_REGNUM + i, val);
981 return sp + arg_regs_size;
985 alpha_push_dummy_frame()
988 struct linked_proc_info *link;
989 alpha_extra_func_info_t proc_desc;
990 CORE_ADDR sp = read_register (SP_REGNUM);
991 CORE_ADDR save_address;
992 char raw_buffer[MAX_REGISTER_RAW_SIZE];
995 link = (struct linked_proc_info *) xmalloc(sizeof (struct linked_proc_info));
996 link->next = linked_proc_desc_table;
997 linked_proc_desc_table = link;
999 proc_desc = &link->info;
1002 * The registers we must save are all those not preserved across
1004 * In addition, we must save the PC and RA.
1006 * Dummy frame layout:
1016 * Parameter build area
1020 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
1021 #define MASK(i,j) ((((LONGEST)1 << ((j)+1)) - 1) ^ (((LONGEST)1 << (i)) - 1))
1022 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
1023 #define GEN_REG_SAVE_COUNT 24
1024 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
1025 #define FLOAT_REG_SAVE_COUNT 23
1026 /* The special register is the PC as we have no bit for it in the save masks.
1027 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
1028 #define SPECIAL_REG_SAVE_COUNT 1
1030 PROC_REG_MASK(proc_desc) = GEN_REG_SAVE_MASK;
1031 PROC_FREG_MASK(proc_desc) = FLOAT_REG_SAVE_MASK;
1032 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
1033 but keep SP aligned to a multiple of 16. */
1034 PROC_REG_OFFSET(proc_desc) =
1035 - ((8 * (SPECIAL_REG_SAVE_COUNT
1036 + GEN_REG_SAVE_COUNT
1037 + FLOAT_REG_SAVE_COUNT)
1039 PROC_FREG_OFFSET(proc_desc) =
1040 PROC_REG_OFFSET(proc_desc) + 8 * GEN_REG_SAVE_COUNT;
1042 /* Save general registers.
1043 The return address register is the first saved register, all other
1044 registers follow in ascending order.
1045 The PC is saved immediately below the SP. */
1046 save_address = sp + PROC_REG_OFFSET(proc_desc);
1047 store_address (raw_buffer, 8, read_register (RA_REGNUM));
1048 write_memory (save_address, raw_buffer, 8);
1050 mask = PROC_REG_MASK(proc_desc) & 0xffffffffL;
1051 for (ireg = 0; mask; ireg++, mask >>= 1)
1054 if (ireg == RA_REGNUM)
1056 store_address (raw_buffer, 8, read_register (ireg));
1057 write_memory (save_address, raw_buffer, 8);
1061 store_address (raw_buffer, 8, read_register (PC_REGNUM));
1062 write_memory (sp - 8, raw_buffer, 8);
1064 /* Save floating point registers. */
1065 save_address = sp + PROC_FREG_OFFSET(proc_desc);
1066 mask = PROC_FREG_MASK(proc_desc) & 0xffffffffL;
1067 for (ireg = 0; mask; ireg++, mask >>= 1)
1070 store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM));
1071 write_memory (save_address, raw_buffer, 8);
1075 /* Set and save the frame address for the dummy.
1076 This is tricky. The only registers that are suitable for a frame save
1077 are those that are preserved across procedure calls (s0-s6). But if
1078 a read system call is interrupted and then a dummy call is made
1079 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
1080 is satisfied. Then it returns with the s0-s6 registers set to the values
1081 on entry to the read system call and our dummy frame pointer would be
1082 destroyed. So we save the dummy frame in the proc_desc and handle the
1083 retrieval of the frame pointer of a dummy specifically. The frame register
1084 is set to the virtual frame (pseudo) register, it's value will always
1085 be read as zero and will help us to catch any errors in the dummy frame
1087 PROC_DUMMY_FRAME(proc_desc) = sp;
1088 PROC_FRAME_REG(proc_desc) = FP_REGNUM;
1089 PROC_FRAME_OFFSET(proc_desc) = 0;
1090 sp += PROC_REG_OFFSET(proc_desc);
1091 write_register (SP_REGNUM, sp);
1093 PROC_LOW_ADDR(proc_desc) = CALL_DUMMY_ADDRESS ();
1094 PROC_HIGH_ADDR(proc_desc) = PROC_LOW_ADDR(proc_desc) + 4;
1096 SET_PROC_DESC_IS_DUMMY(proc_desc);
1097 PROC_PC_REG(proc_desc) = RA_REGNUM;
1103 register int regnum;
1104 struct frame_info *frame = get_current_frame ();
1105 CORE_ADDR new_sp = frame->frame;
1107 alpha_extra_func_info_t proc_desc = frame->proc_desc;
1109 write_register (PC_REGNUM, FRAME_SAVED_PC(frame));
1110 if (frame->saved_regs == NULL)
1111 alpha_find_saved_regs (frame);
1114 for (regnum = 32; --regnum >= 0; )
1115 if (PROC_REG_MASK(proc_desc) & (1 << regnum))
1116 write_register (regnum,
1117 read_memory_integer (frame->saved_regs[regnum],
1119 for (regnum = 32; --regnum >= 0; )
1120 if (PROC_FREG_MASK(proc_desc) & (1 << regnum))
1121 write_register (regnum + FP0_REGNUM,
1122 read_memory_integer (frame->saved_regs[regnum + FP0_REGNUM], 8));
1124 write_register (SP_REGNUM, new_sp);
1125 flush_cached_frames ();
1127 if (proc_desc && (PROC_DESC_IS_DUMMY(proc_desc)
1128 || PROC_DESC_IS_DYN_SIGTRAMP (proc_desc)))
1130 struct linked_proc_info *pi_ptr, *prev_ptr;
1132 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
1134 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
1136 if (&pi_ptr->info == proc_desc)
1141 error ("Can't locate dummy extra frame info\n");
1143 if (prev_ptr != NULL)
1144 prev_ptr->next = pi_ptr->next;
1146 linked_proc_desc_table = pi_ptr->next;
1152 /* To skip prologues, I use this predicate. Returns either PC itself
1153 if the code at PC does not look like a function prologue; otherwise
1154 returns an address that (if we're lucky) follows the prologue. If
1155 LENIENT, then we must skip everything which is involved in setting
1156 up the frame (it's OK to skip more, just so long as we don't skip
1157 anything which might clobber the registers which are being saved.
1158 Currently we must not skip more on the alpha, but we might the lenient
1162 alpha_skip_prologue (pc, lenient)
1168 CORE_ADDR post_prologue_pc;
1171 #ifdef GDB_TARGET_HAS_SHARED_LIBS
1172 /* Silently return the unaltered pc upon memory errors.
1173 This could happen on OSF/1 if decode_line_1 tries to skip the
1174 prologue for quickstarted shared library functions when the
1175 shared library is not yet mapped in.
1176 Reading target memory is slow over serial lines, so we perform
1177 this check only if the target has shared libraries. */
1178 if (target_read_memory (pc, buf, 4))
1182 /* See if we can determine the end of the prologue via the symbol table.
1183 If so, then return either PC, or the PC after the prologue, whichever
1186 post_prologue_pc = after_prologue (pc, NULL);
1188 if (post_prologue_pc != 0)
1189 return max (pc, post_prologue_pc);
1191 /* Can't determine prologue from the symbol table, need to examine
1194 /* Skip the typical prologue instructions. These are the stack adjustment
1195 instruction and the instructions that save registers on the stack
1196 or in the gcc frame. */
1197 for (offset = 0; offset < 100; offset += 4)
1201 status = read_memory_nobpt (pc + offset, buf, 4);
1203 memory_error (status, pc + offset);
1204 inst = extract_unsigned_integer (buf, 4);
1206 /* The alpha has no delay slots. But let's keep the lenient stuff,
1207 we might need it for something else in the future. */
1211 if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1213 if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1215 if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1217 else if ((inst & 0xfc1f0000) == 0xb41e0000
1218 && (inst & 0xffff0000) != 0xb7fe0000)
1219 continue; /* stq reg,n($sp) */
1221 else if ((inst & 0xfc1f0000) == 0x9c1e0000
1222 && (inst & 0xffff0000) != 0x9ffe0000)
1223 continue; /* stt reg,n($sp) */
1225 else if (inst == 0x47de040f) /* bis sp,sp,fp */
1234 /* Is address PC in the prologue (loosely defined) for function at
1238 alpha_in_lenient_prologue (startaddr, pc)
1239 CORE_ADDR startaddr;
1242 CORE_ADDR end_prologue = alpha_skip_prologue (startaddr, 1);
1243 return pc >= startaddr && pc < end_prologue;
1247 /* The alpha needs a conversion between register and memory format if
1248 the register is a floating point register and
1249 memory format is float, as the register format must be double
1251 memory format is an integer with 4 bytes or less, as the representation
1252 of integers in floating point registers is different. */
1254 alpha_register_convert_to_virtual (regnum, valtype, raw_buffer, virtual_buffer)
1256 struct type *valtype;
1258 char *virtual_buffer;
1260 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1262 memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
1266 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1268 double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum));
1269 store_floating (virtual_buffer, TYPE_LENGTH (valtype), d);
1271 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1274 l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum));
1275 l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff);
1276 store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l);
1279 error ("Cannot retrieve value from floating point register");
1283 alpha_register_convert_to_raw (valtype, regnum, virtual_buffer, raw_buffer)
1284 struct type *valtype;
1286 char *virtual_buffer;
1289 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1291 memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum));
1295 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1297 double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype));
1298 store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d);
1300 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1303 if (TYPE_UNSIGNED (valtype))
1304 l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype));
1306 l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype));
1307 l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29);
1308 store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l);
1311 error ("Cannot store value in floating point register");
1314 /* Given a return value in `regbuf' with a type `valtype',
1315 extract and copy its value into `valbuf'. */
1318 alpha_extract_return_value (valtype, regbuf, valbuf)
1319 struct type *valtype;
1320 char regbuf[REGISTER_BYTES];
1323 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1324 alpha_register_convert_to_virtual (FP0_REGNUM, valtype,
1325 regbuf + REGISTER_BYTE (FP0_REGNUM),
1328 memcpy (valbuf, regbuf + REGISTER_BYTE (V0_REGNUM), TYPE_LENGTH (valtype));
1331 /* Given a return value in `regbuf' with a type `valtype',
1332 write its value into the appropriate register. */
1335 alpha_store_return_value (valtype, valbuf)
1336 struct type *valtype;
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 (args, from_tty, c)
1362 struct cmd_list_element *c;
1364 reinit_frame_cache ();
1367 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1368 to find a convenient place in the text segment to stick a breakpoint to
1369 detect the completion of a target function call (ala call_function_by_hand).
1373 alpha_call_dummy_address ()
1376 struct minimal_symbol *sym;
1378 entry = entry_point_address ();
1383 sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile);
1385 if (!sym || MSYMBOL_TYPE (sym) != mst_text)
1388 return SYMBOL_VALUE_ADDRESS (sym) + 4;
1392 _initialize_alpha_tdep ()
1394 struct cmd_list_element *c;
1396 tm_print_insn = print_insn_alpha;
1398 /* Let the user set the fence post for heuristic_proc_start. */
1400 /* We really would like to have both "0" and "unlimited" work, but
1401 command.c doesn't deal with that. So make it a var_zinteger
1402 because the user can always use "999999" or some such for unlimited. */
1403 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
1404 (char *) &heuristic_fence_post,
1406 Set the distance searched for the start of a function.\n\
1407 If you are debugging a stripped executable, GDB needs to search through the\n\
1408 program for the start of a function. This command sets the distance of the\n\
1409 search. The only need to set it is when debugging a stripped executable.",
1411 /* We need to throw away the frame cache when we set this, since it
1412 might change our ability to get backtraces. */
1413 c->function.sfunc = reinit_frame_cache_sfunc;
1414 add_show_from_set (c, &showlist);