1 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
2 Copyright 1993, 1994, 1995, 1996 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. */
30 #include "gdb_string.h"
32 /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
34 /* FIXME: Put this declaration in frame.h. */
35 extern struct obstack frame_cache_obstack;
38 /* Forward declarations. */
40 static alpha_extra_func_info_t push_sigtramp_desc PARAMS ((CORE_ADDR low_addr));
42 static CORE_ADDR read_next_frame_reg PARAMS ((struct frame_info *, int));
44 static CORE_ADDR heuristic_proc_start PARAMS ((CORE_ADDR));
46 static alpha_extra_func_info_t heuristic_proc_desc PARAMS ((CORE_ADDR,
48 struct frame_info *));
50 static alpha_extra_func_info_t find_proc_desc PARAMS ((CORE_ADDR,
51 struct frame_info *));
54 static int alpha_in_lenient_prologue PARAMS ((CORE_ADDR, CORE_ADDR));
57 static void reinit_frame_cache_sfunc PARAMS ((char *, int,
58 struct cmd_list_element *));
60 static CORE_ADDR after_prologue PARAMS ((CORE_ADDR pc,
61 alpha_extra_func_info_t proc_desc));
63 static int alpha_in_prologue PARAMS ((CORE_ADDR pc,
64 alpha_extra_func_info_t proc_desc));
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
114 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
115 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
116 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.iopt) /* frame for CALL_DUMMY */
117 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
118 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
119 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
120 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
121 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
122 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
123 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
124 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
125 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
126 #define _PROC_MAGIC_ 0x0F0F0F0F
127 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
128 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
130 struct linked_proc_info
132 struct alpha_extra_func_info info;
133 struct linked_proc_info *next;
134 } *linked_proc_desc_table = NULL;
137 /* Under Linux, signal handler invocations can be identified by the
138 designated code sequence that is used to return from a signal
139 handler. In particular, the return address of a signal handler
140 points to the following sequence (the first instruction is quadword
147 Each instruction has a unique encoding, so we simply attempt to
148 match the instruction the pc is pointing to with any of the above
149 instructions. If there is a hit, we know the offset to the start
150 of the designated sequence and can then check whether we really are
151 executing in a designated sequence. If not, -1 is returned,
152 otherwise the offset from the start of the desingated sequence is
155 There is a slight chance of false hits: code could jump into the
156 middle of the designated sequence, in which case there is no
157 guarantee that we are in the middle of a sigreturn syscall. Don't
158 think this will be a problem in praxis, though.
162 alpha_linux_sigtramp_offset (CORE_ADDR pc)
164 unsigned int i[3], w;
167 if (read_memory_nobpt(pc, (char *) &w, 4) != 0)
173 case 0x47de0410: off = 0; break; /* bis $30,$30,$16 */
174 case 0x43ecf400: off = 4; break; /* addq $31,0x67,$0 */
175 case 0x00000083: off = 8; break; /* call_pal callsys */
181 /* designated sequence is not quadword aligned */
185 if (read_memory_nobpt(pc, (char *) i, sizeof(i)) != 0)
188 if (i[0] == 0x47de0410 && i[1] == 0x43ecf400 && i[2] == 0x00000083)
195 /* Under OSF/1, the __sigtramp routine is frameless and has a frame
196 size of zero, but we are able to backtrace through it. */
198 alpha_osf_skip_sigtramp_frame (frame, pc)
199 struct frame_info *frame;
203 find_pc_partial_function (pc, &name, (CORE_ADDR *)NULL, (CORE_ADDR *)NULL);
204 if (IN_SIGTRAMP (pc, name))
211 /* Dynamically create a signal-handler caller procedure descriptor for
212 the signal-handler return code starting at address LOW_ADDR. The
213 descriptor is added to the linked_proc_desc_table. */
215 static alpha_extra_func_info_t
216 push_sigtramp_desc (low_addr)
219 struct linked_proc_info *link;
220 alpha_extra_func_info_t proc_desc;
222 link = (struct linked_proc_info *)
223 xmalloc (sizeof (struct linked_proc_info));
224 link->next = linked_proc_desc_table;
225 linked_proc_desc_table = link;
227 proc_desc = &link->info;
229 proc_desc->numargs = 0;
230 PROC_LOW_ADDR (proc_desc) = low_addr;
231 PROC_HIGH_ADDR (proc_desc) = low_addr + 3 * 4;
232 PROC_DUMMY_FRAME (proc_desc) = 0;
233 PROC_FRAME_OFFSET (proc_desc) = 0x298; /* sizeof(struct sigcontext_struct) */
234 PROC_FRAME_REG (proc_desc) = SP_REGNUM;
235 PROC_REG_MASK (proc_desc) = 0xffff;
236 PROC_FREG_MASK (proc_desc) = 0xffff;
237 PROC_PC_REG (proc_desc) = 26;
238 PROC_LOCALOFF (proc_desc) = 0;
239 SET_PROC_DESC_IS_DYN_SIGTRAMP (proc_desc);
244 /* Guaranteed to set frame->saved_regs to some values (it never leaves it
248 alpha_find_saved_regs (frame)
249 struct frame_info *frame;
252 CORE_ADDR reg_position;
254 alpha_extra_func_info_t proc_desc;
257 frame->saved_regs = (struct frame_saved_regs *)
258 obstack_alloc (&frame_cache_obstack, sizeof(struct frame_saved_regs));
259 memset (frame->saved_regs, 0, sizeof (struct frame_saved_regs));
261 /* If it is the frame for __sigtramp, the saved registers are located
262 in a sigcontext structure somewhere on the stack. __sigtramp
263 passes a pointer to the sigcontext structure on the stack.
264 If the stack layout for __sigtramp changes, or if sigcontext offsets
265 change, we might have to update this code. */
266 #ifndef SIGFRAME_PC_OFF
267 #define SIGFRAME_PC_OFF (2 * 8)
268 #define SIGFRAME_REGSAVE_OFF (4 * 8)
269 #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
271 if (frame->signal_handler_caller)
273 CORE_ADDR sigcontext_addr;
275 sigcontext_addr = SIGCONTEXT_ADDR (frame);
276 for (ireg = 0; ireg < 32; ireg++)
278 reg_position = sigcontext_addr + SIGFRAME_REGSAVE_OFF + ireg * 8;
279 frame->saved_regs->regs[ireg] = reg_position;
281 for (ireg = 0; ireg < 32; ireg++)
283 reg_position = sigcontext_addr + SIGFRAME_FPREGSAVE_OFF + ireg * 8;
284 frame->saved_regs->regs[FP0_REGNUM + ireg] = reg_position;
286 frame->saved_regs->regs[PC_REGNUM] = sigcontext_addr + SIGFRAME_PC_OFF;
290 proc_desc = frame->proc_desc;
291 if (proc_desc == NULL)
292 /* I'm not sure how/whether this can happen. Normally when we can't
293 find a proc_desc, we "synthesize" one using heuristic_proc_desc
294 and set the saved_regs right away. */
297 /* Fill in the offsets for the registers which gen_mask says
300 reg_position = frame->frame + PROC_REG_OFFSET (proc_desc);
301 mask = PROC_REG_MASK (proc_desc);
303 returnreg = PROC_PC_REG (proc_desc);
305 /* Note that RA is always saved first, regardless of its actual
307 if (mask & (1 << returnreg))
309 frame->saved_regs->regs[returnreg] = reg_position;
311 mask &= ~(1 << returnreg); /* Clear bit for RA so we
312 don't save again later. */
315 for (ireg = 0; ireg <= 31 ; ++ireg)
316 if (mask & (1 << ireg))
318 frame->saved_regs->regs[ireg] = reg_position;
322 /* Fill in the offsets for the registers which float_mask says
325 reg_position = frame->frame + PROC_FREG_OFFSET (proc_desc);
326 mask = PROC_FREG_MASK (proc_desc);
328 for (ireg = 0; ireg <= 31 ; ++ireg)
329 if (mask & (1 << ireg))
331 frame->saved_regs->regs[FP0_REGNUM+ireg] = reg_position;
335 frame->saved_regs->regs[PC_REGNUM] = frame->saved_regs->regs[returnreg];
339 read_next_frame_reg(fi, regno)
340 struct frame_info *fi;
343 for (; fi; fi = fi->next)
345 /* We have to get the saved sp from the sigcontext
346 if it is a signal handler frame. */
347 if (regno == SP_REGNUM && !fi->signal_handler_caller)
351 if (fi->saved_regs == NULL)
352 alpha_find_saved_regs (fi);
353 if (fi->saved_regs->regs[regno])
354 return read_memory_integer(fi->saved_regs->regs[regno], 8);
357 return read_register(regno);
361 alpha_frame_saved_pc(frame)
362 struct frame_info *frame;
364 alpha_extra_func_info_t proc_desc = frame->proc_desc;
365 /* We have to get the saved pc from the sigcontext
366 if it is a signal handler frame. */
367 int pcreg = frame->signal_handler_caller ? PC_REGNUM : frame->pc_reg;
369 if (proc_desc && PROC_DESC_IS_DUMMY(proc_desc))
370 return read_memory_integer(frame->frame - 8, 8);
372 return read_next_frame_reg(frame, pcreg);
376 alpha_saved_pc_after_call (frame)
377 struct frame_info *frame;
379 CORE_ADDR pc = frame->pc;
381 alpha_extra_func_info_t proc_desc;
384 /* Skip over shared library trampoline if necessary. */
385 tmp = SKIP_TRAMPOLINE_CODE (pc);
389 proc_desc = find_proc_desc (pc, frame->next);
390 pcreg = proc_desc ? PROC_PC_REG (proc_desc) : RA_REGNUM;
392 if (frame->signal_handler_caller)
393 return alpha_frame_saved_pc (frame);
395 return read_register (pcreg);
399 static struct alpha_extra_func_info temp_proc_desc;
400 static struct frame_saved_regs temp_saved_regs;
402 /* This fencepost looks highly suspicious to me. Removing it also
403 seems suspicious as it could affect remote debugging across serial
407 heuristic_proc_start(pc)
410 CORE_ADDR start_pc = pc;
411 CORE_ADDR fence = start_pc - heuristic_fence_post;
413 if (start_pc == 0) return 0;
415 if (heuristic_fence_post == UINT_MAX
416 || fence < VM_MIN_ADDRESS)
417 fence = VM_MIN_ADDRESS;
419 /* search back for previous return */
420 for (start_pc -= 4; ; start_pc -= 4)
421 if (start_pc < fence)
423 /* It's not clear to me why we reach this point when
424 stop_soon_quietly, but with this test, at least we
425 don't print out warnings for every child forked (eg, on
427 if (!stop_soon_quietly)
429 static int blurb_printed = 0;
431 if (fence == VM_MIN_ADDRESS)
432 warning("Hit beginning of text section without finding");
434 warning("Hit heuristic-fence-post without finding");
436 warning("enclosing function for address 0x%lx", pc);
440 This warning occurs if you are debugging a function without any symbols\n\
441 (for example, in a stripped executable). In that case, you may wish to\n\
442 increase the size of the search with the `set heuristic-fence-post' command.\n\
444 Otherwise, you told GDB there was a function where there isn't one, or\n\
445 (more likely) you have encountered a bug in GDB.\n");
452 else if (ABOUT_TO_RETURN(start_pc))
455 start_pc += 4; /* skip return */
459 static alpha_extra_func_info_t
460 heuristic_proc_desc(start_pc, limit_pc, next_frame)
461 CORE_ADDR start_pc, limit_pc;
462 struct frame_info *next_frame;
464 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
467 int has_frame_reg = 0;
468 unsigned long reg_mask = 0;
473 memset (&temp_proc_desc, '\0', sizeof(temp_proc_desc));
474 memset (&temp_saved_regs, '\0', sizeof(struct frame_saved_regs));
475 PROC_LOW_ADDR (&temp_proc_desc) = start_pc;
477 if (start_pc + 200 < limit_pc)
478 limit_pc = start_pc + 200;
480 for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += 4)
486 status = read_memory_nobpt (cur_pc, buf, 4);
488 memory_error (status, cur_pc);
489 word = extract_unsigned_integer (buf, 4);
491 if ((word & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
494 frame_size += (-word) & 0xffff;
496 /* Exit loop if a positive stack adjustment is found, which
497 usually means that the stack cleanup code in the function
498 epilogue is reached. */
501 else if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
502 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
504 int reg = (word & 0x03e00000) >> 21;
505 reg_mask |= 1 << reg;
506 temp_saved_regs.regs[reg] = sp + (short)word;
508 /* Starting with OSF/1-3.2C, the system libraries are shipped
509 without local symbols, but they still contain procedure
510 descriptors without a symbol reference. GDB is currently
511 unable to find these procedure descriptors and uses
512 heuristic_proc_desc instead.
513 As some low level compiler support routines (__div*, __add*)
514 use a non-standard return address register, we have to
515 add some heuristics to determine the return address register,
516 or stepping over these routines will fail.
517 Usually the return address register is the first register
518 saved on the stack, but assembler optimization might
519 rearrange the register saves.
520 So we recognize only a few registers (t7, t9, ra) within
521 the procedure prologue as valid return address registers.
523 FIXME: Rewriting GDB to access the procedure descriptors,
524 e.g. via the minimal symbol table, might obviate this hack. */
526 && cur_pc < (start_pc + 20)
527 && (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM))
530 else if (word == 0x47de040f) /* bis sp,sp fp */
535 /* If we haven't found a valid return address register yet,
536 keep searching in the procedure prologue. */
537 while (cur_pc < (limit_pc + 20) && cur_pc < (start_pc + 20))
543 status = read_memory_nobpt (cur_pc, buf, 4);
545 memory_error (status, cur_pc);
547 word = extract_unsigned_integer (buf, 4);
549 if ((word & 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
550 && (word & 0xffff0000) != 0xb7fe0000) /* reg != $zero */
552 int reg = (word & 0x03e00000) >> 21;
553 if (reg == T7_REGNUM || reg == T9_REGNUM || reg == RA_REGNUM)
563 PROC_FRAME_REG(&temp_proc_desc) = GCC_FP_REGNUM;
565 PROC_FRAME_REG(&temp_proc_desc) = SP_REGNUM;
566 PROC_FRAME_OFFSET(&temp_proc_desc) = frame_size;
567 PROC_REG_MASK(&temp_proc_desc) = reg_mask;
568 PROC_PC_REG(&temp_proc_desc) = (pcreg == -1) ? RA_REGNUM : pcreg;
569 PROC_LOCALOFF(&temp_proc_desc) = 0; /* XXX - bogus */
570 return &temp_proc_desc;
573 /* This returns the PC of the first inst after the prologue. If we can't
574 find the prologue, then return 0. */
577 after_prologue (pc, proc_desc)
579 alpha_extra_func_info_t proc_desc;
581 struct symtab_and_line sal;
582 CORE_ADDR func_addr, func_end;
585 proc_desc = find_proc_desc (pc, NULL);
589 if (PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
590 return PROC_LOW_ADDR (proc_desc); /* "prologue" is in kernel */
592 /* If function is frameless, then we need to do it the hard way. I
593 strongly suspect that frameless always means prologueless... */
594 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
595 && PROC_FRAME_OFFSET (proc_desc) == 0)
599 if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
600 return 0; /* Unknown */
602 sal = find_pc_line (func_addr, 0);
604 if (sal.end < func_end)
607 /* The line after the prologue is after the end of the function. In this
608 case, tell the caller to find the prologue the hard way. */
613 /* Return non-zero if we *might* be in a function prologue. Return zero if we
614 are definitively *not* in a function prologue. */
617 alpha_in_prologue (pc, proc_desc)
619 alpha_extra_func_info_t proc_desc;
621 CORE_ADDR after_prologue_pc;
623 after_prologue_pc = after_prologue (pc, proc_desc);
625 if (after_prologue_pc == 0
626 || pc < after_prologue_pc)
632 static alpha_extra_func_info_t
633 find_proc_desc (pc, next_frame)
635 struct frame_info *next_frame;
637 alpha_extra_func_info_t proc_desc;
642 /* Try to get the proc_desc from the linked call dummy proc_descs
643 if the pc is in the call dummy.
644 This is hairy. In the case of nested dummy calls we have to find the
645 right proc_desc, but we might not yet know the frame for the dummy
646 as it will be contained in the proc_desc we are searching for.
647 So we have to find the proc_desc whose frame is closest to the current
650 if (PC_IN_CALL_DUMMY (pc, 0, 0))
652 struct linked_proc_info *link;
653 CORE_ADDR sp = read_next_frame_reg (next_frame, SP_REGNUM);
654 alpha_extra_func_info_t found_proc_desc = NULL;
655 long min_distance = LONG_MAX;
657 for (link = linked_proc_desc_table; link; link = link->next)
659 long distance = (CORE_ADDR) PROC_DUMMY_FRAME (&link->info) - sp;
660 if (distance > 0 && distance < min_distance)
662 min_distance = distance;
663 found_proc_desc = &link->info;
666 if (found_proc_desc != NULL)
667 return found_proc_desc;
670 b = block_for_pc(pc);
672 find_pc_partial_function (pc, NULL, &startaddr, NULL);
677 if (startaddr > BLOCK_START (b))
678 /* This is the "pathological" case referred to in a comment in
679 print_frame_info. It might be better to move this check into
683 sym = lookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE,
687 /* If we never found a PDR for this function in symbol reading, then
688 examine prologues to find the information. */
689 if (sym && ((mips_extra_func_info_t) SYMBOL_VALUE (sym))->pdr.framereg == -1)
694 /* IF this is the topmost frame AND
695 * (this proc does not have debugging information OR
696 * the PC is in the procedure prologue)
697 * THEN create a "heuristic" proc_desc (by analyzing
698 * the actual code) to replace the "official" proc_desc.
700 proc_desc = (alpha_extra_func_info_t)SYMBOL_VALUE(sym);
701 if (next_frame == NULL)
703 if (PROC_DESC_IS_DUMMY (proc_desc) || alpha_in_prologue (pc, proc_desc))
705 alpha_extra_func_info_t found_heuristic =
706 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc),
710 PROC_LOCALOFF (found_heuristic) =
711 PROC_LOCALOFF (proc_desc);
712 PROC_PC_REG (found_heuristic) = PROC_PC_REG (proc_desc);
713 proc_desc = found_heuristic;
722 /* Is linked_proc_desc_table really necessary? It only seems to be used
723 by procedure call dummys. However, the procedures being called ought
724 to have their own proc_descs, and even if they don't,
725 heuristic_proc_desc knows how to create them! */
727 register struct linked_proc_info *link;
728 for (link = linked_proc_desc_table; link; link = link->next)
729 if (PROC_LOW_ADDR(&link->info) <= pc
730 && PROC_HIGH_ADDR(&link->info) > pc)
733 /* If PC is inside a dynamically generated sigtramp handler,
734 create and push a procedure descriptor for that code: */
735 offset = DYNAMIC_SIGTRAMP_OFFSET (pc);
737 return push_sigtramp_desc (pc - offset);
739 /* If heuristic_fence_post is non-zero, determine the procedure
740 start address by examining the instructions.
741 This allows us to find the start address of static functions which
742 have no symbolic information, as startaddr would have been set to
743 the preceding global function start address by the
744 find_pc_partial_function call above. */
745 if (startaddr == 0 || heuristic_fence_post != 0)
746 startaddr = heuristic_proc_start (pc);
749 heuristic_proc_desc (startaddr, pc, next_frame);
754 alpha_extra_func_info_t cached_proc_desc;
757 alpha_frame_chain(frame)
758 struct frame_info *frame;
760 alpha_extra_func_info_t proc_desc;
761 CORE_ADDR saved_pc = FRAME_SAVED_PC(frame);
763 if (saved_pc == 0 || inside_entry_file (saved_pc))
766 proc_desc = find_proc_desc(saved_pc, frame);
770 cached_proc_desc = proc_desc;
772 /* Fetch the frame pointer for a dummy frame from the procedure
774 if (PROC_DESC_IS_DUMMY(proc_desc))
775 return (CORE_ADDR) PROC_DUMMY_FRAME(proc_desc);
777 /* If no frame pointer and frame size is zero, we must be at end
778 of stack (or otherwise hosed). If we don't check frame size,
779 we loop forever if we see a zero size frame. */
780 if (PROC_FRAME_REG (proc_desc) == SP_REGNUM
781 && PROC_FRAME_OFFSET (proc_desc) == 0
782 /* The previous frame from a sigtramp frame might be frameless
783 and have frame size zero. */
784 && !frame->signal_handler_caller)
785 return FRAME_PAST_SIGTRAMP_FRAME (frame, saved_pc);
787 return read_next_frame_reg(frame, PROC_FRAME_REG(proc_desc))
788 + PROC_FRAME_OFFSET(proc_desc);
792 init_extra_frame_info (frame)
793 struct frame_info *frame;
795 /* Use proc_desc calculated in frame_chain */
796 alpha_extra_func_info_t proc_desc =
797 frame->next ? cached_proc_desc : find_proc_desc(frame->pc, frame->next);
799 frame->saved_regs = NULL;
801 frame->pc_reg = RA_REGNUM;
802 frame->proc_desc = proc_desc == &temp_proc_desc ? 0 : proc_desc;
805 /* Get the locals offset and the saved pc register from the
806 procedure descriptor, they are valid even if we are in the
807 middle of the prologue. */
808 frame->localoff = PROC_LOCALOFF(proc_desc);
809 frame->pc_reg = PROC_PC_REG(proc_desc);
811 /* Fixup frame-pointer - only needed for top frame */
813 /* Fetch the frame pointer for a dummy frame from the procedure
815 if (PROC_DESC_IS_DUMMY(proc_desc))
816 frame->frame = (CORE_ADDR) PROC_DUMMY_FRAME(proc_desc);
818 /* This may not be quite right, if proc has a real frame register.
819 Get the value of the frame relative sp, procedure might have been
820 interrupted by a signal at it's very start. */
821 else if (frame->pc == PROC_LOW_ADDR (proc_desc)
822 && !PROC_DESC_IS_DYN_SIGTRAMP (proc_desc))
823 frame->frame = read_next_frame_reg (frame->next, SP_REGNUM);
825 frame->frame = read_next_frame_reg (frame->next, PROC_FRAME_REG (proc_desc))
826 + PROC_FRAME_OFFSET (proc_desc);
828 if (proc_desc == &temp_proc_desc)
832 /* Do not set the saved registers for a sigtramp frame,
833 alpha_find_saved_registers will do that for us.
834 We can't use frame->signal_handler_caller, it is not yet set. */
835 find_pc_partial_function (frame->pc, &name,
836 (CORE_ADDR *)NULL,(CORE_ADDR *)NULL);
837 if (!IN_SIGTRAMP (frame->pc, name))
839 frame->saved_regs = (struct frame_saved_regs*)
840 obstack_alloc (&frame_cache_obstack,
841 sizeof (struct frame_saved_regs));
842 *frame->saved_regs = temp_saved_regs;
843 frame->saved_regs->regs[PC_REGNUM]
844 = frame->saved_regs->regs[RA_REGNUM];
850 /* ALPHA stack frames are almost impenetrable. When execution stops,
851 we basically have to look at symbol information for the function
852 that we stopped in, which tells us *which* register (if any) is
853 the base of the frame pointer, and what offset from that register
854 the frame itself is at.
856 This presents a problem when trying to examine a stack in memory
857 (that isn't executing at the moment), using the "frame" command. We
858 don't have a PC, nor do we have any registers except SP.
860 This routine takes two arguments, SP and PC, and tries to make the
861 cached frames look as if these two arguments defined a frame on the
862 cache. This allows the rest of info frame to extract the important
863 arguments without difficulty. */
866 setup_arbitrary_frame (argc, argv)
871 error ("ALPHA frame specifications require two arguments: sp and pc");
873 return create_new_frame (argv[0], argv[1]);
876 /* The alpha passes the first six arguments in the registers, the rest on
877 the stack. The register arguments are eventually transferred to the
878 argument transfer area immediately below the stack by the called function
879 anyway. So we `push' at least six arguments on the stack, `reload' the
880 argument registers and then adjust the stack pointer to point past the
881 sixth argument. This algorithm simplifies the passing of a large struct
882 which extends from the registers to the stack.
883 If the called function is returning a structure, the address of the
884 structure to be returned is passed as a hidden first argument. */
887 alpha_push_arguments (nargs, args, sp, struct_return, struct_addr)
892 CORE_ADDR struct_addr;
895 int accumulate_size = struct_return ? 8 : 0;
896 int arg_regs_size = ALPHA_NUM_ARG_REGS * 8;
897 struct alpha_arg { char *contents; int len; int offset; };
898 struct alpha_arg *alpha_args =
899 (struct alpha_arg*)alloca (nargs * sizeof (struct alpha_arg));
900 register struct alpha_arg *m_arg;
901 char raw_buffer[sizeof (CORE_ADDR)];
902 int required_arg_regs;
904 for (i = 0, m_arg = alpha_args; i < nargs; i++, m_arg++)
906 value_ptr arg = args[i];
907 struct type *arg_type = check_typedef (VALUE_TYPE (arg));
908 /* Cast argument to long if necessary as the compiler does it too. */
909 switch (TYPE_CODE (arg_type))
914 case TYPE_CODE_RANGE:
916 if (TYPE_LENGTH (arg_type) < TYPE_LENGTH (builtin_type_long))
918 arg_type = builtin_type_long;
919 arg = value_cast (arg_type, arg);
925 m_arg->len = TYPE_LENGTH (arg_type);
926 m_arg->offset = accumulate_size;
927 accumulate_size = (accumulate_size + m_arg->len + 7) & ~7;
928 m_arg->contents = VALUE_CONTENTS(arg);
931 /* Determine required argument register loads, loading an argument register
932 is expensive as it uses three ptrace calls. */
933 required_arg_regs = accumulate_size / 8;
934 if (required_arg_regs > ALPHA_NUM_ARG_REGS)
935 required_arg_regs = ALPHA_NUM_ARG_REGS;
937 /* Make room for the arguments on the stack. */
938 if (accumulate_size < arg_regs_size)
939 accumulate_size = arg_regs_size;
940 sp -= accumulate_size;
942 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
945 /* `Push' arguments on the stack. */
946 for (i = nargs; m_arg--, --i >= 0; )
947 write_memory(sp + m_arg->offset, m_arg->contents, m_arg->len);
950 store_address (raw_buffer, sizeof (CORE_ADDR), struct_addr);
951 write_memory (sp, raw_buffer, sizeof (CORE_ADDR));
954 /* Load the argument registers. */
955 for (i = 0; i < required_arg_regs; i++)
959 val = read_memory_integer (sp + i * 8, 8);
960 write_register (A0_REGNUM + i, val);
961 write_register (FPA0_REGNUM + i, val);
964 return sp + arg_regs_size;
968 alpha_push_dummy_frame()
971 struct linked_proc_info *link;
972 alpha_extra_func_info_t proc_desc;
973 CORE_ADDR sp = read_register (SP_REGNUM);
974 CORE_ADDR save_address;
975 char raw_buffer[MAX_REGISTER_RAW_SIZE];
978 link = (struct linked_proc_info *) xmalloc(sizeof (struct linked_proc_info));
979 link->next = linked_proc_desc_table;
980 linked_proc_desc_table = link;
982 proc_desc = &link->info;
985 * The registers we must save are all those not preserved across
987 * In addition, we must save the PC and RA.
989 * Dummy frame layout:
999 * Parameter build area
1003 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
1004 #define MASK(i,j) (((1L << ((j)+1)) - 1) ^ ((1L << (i)) - 1))
1005 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
1006 #define GEN_REG_SAVE_COUNT 24
1007 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
1008 #define FLOAT_REG_SAVE_COUNT 23
1009 /* The special register is the PC as we have no bit for it in the save masks.
1010 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
1011 #define SPECIAL_REG_SAVE_COUNT 1
1013 PROC_REG_MASK(proc_desc) = GEN_REG_SAVE_MASK;
1014 PROC_FREG_MASK(proc_desc) = FLOAT_REG_SAVE_MASK;
1015 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
1016 but keep SP aligned to a multiple of 16. */
1017 PROC_REG_OFFSET(proc_desc) =
1018 - ((8 * (SPECIAL_REG_SAVE_COUNT
1019 + GEN_REG_SAVE_COUNT
1020 + FLOAT_REG_SAVE_COUNT)
1022 PROC_FREG_OFFSET(proc_desc) =
1023 PROC_REG_OFFSET(proc_desc) + 8 * GEN_REG_SAVE_COUNT;
1025 /* Save general registers.
1026 The return address register is the first saved register, all other
1027 registers follow in ascending order.
1028 The PC is saved immediately below the SP. */
1029 save_address = sp + PROC_REG_OFFSET(proc_desc);
1030 store_address (raw_buffer, 8, read_register (RA_REGNUM));
1031 write_memory (save_address, raw_buffer, 8);
1033 mask = PROC_REG_MASK(proc_desc) & 0xffffffffL;
1034 for (ireg = 0; mask; ireg++, mask >>= 1)
1037 if (ireg == RA_REGNUM)
1039 store_address (raw_buffer, 8, read_register (ireg));
1040 write_memory (save_address, raw_buffer, 8);
1044 store_address (raw_buffer, 8, read_register (PC_REGNUM));
1045 write_memory (sp - 8, raw_buffer, 8);
1047 /* Save floating point registers. */
1048 save_address = sp + PROC_FREG_OFFSET(proc_desc);
1049 mask = PROC_FREG_MASK(proc_desc) & 0xffffffffL;
1050 for (ireg = 0; mask; ireg++, mask >>= 1)
1053 store_address (raw_buffer, 8, read_register (ireg + FP0_REGNUM));
1054 write_memory (save_address, raw_buffer, 8);
1058 /* Set and save the frame address for the dummy.
1059 This is tricky. The only registers that are suitable for a frame save
1060 are those that are preserved across procedure calls (s0-s6). But if
1061 a read system call is interrupted and then a dummy call is made
1062 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
1063 is satisfied. Then it returns with the s0-s6 registers set to the values
1064 on entry to the read system call and our dummy frame pointer would be
1065 destroyed. So we save the dummy frame in the proc_desc and handle the
1066 retrieval of the frame pointer of a dummy specifically. The frame register
1067 is set to the virtual frame (pseudo) register, it's value will always
1068 be read as zero and will help us to catch any errors in the dummy frame
1070 PROC_DUMMY_FRAME(proc_desc) = sp;
1071 PROC_FRAME_REG(proc_desc) = FP_REGNUM;
1072 PROC_FRAME_OFFSET(proc_desc) = 0;
1073 sp += PROC_REG_OFFSET(proc_desc);
1074 write_register (SP_REGNUM, sp);
1076 PROC_LOW_ADDR(proc_desc) = CALL_DUMMY_ADDRESS ();
1077 PROC_HIGH_ADDR(proc_desc) = PROC_LOW_ADDR(proc_desc) + 4;
1079 SET_PROC_DESC_IS_DUMMY(proc_desc);
1080 PROC_PC_REG(proc_desc) = RA_REGNUM;
1086 register int regnum;
1087 struct frame_info *frame = get_current_frame ();
1088 CORE_ADDR new_sp = frame->frame;
1090 alpha_extra_func_info_t proc_desc = frame->proc_desc;
1092 write_register (PC_REGNUM, FRAME_SAVED_PC(frame));
1093 if (frame->saved_regs == NULL)
1094 alpha_find_saved_regs (frame);
1097 for (regnum = 32; --regnum >= 0; )
1098 if (PROC_REG_MASK(proc_desc) & (1 << regnum))
1099 write_register (regnum,
1100 read_memory_integer (frame->saved_regs->regs[regnum],
1102 for (regnum = 32; --regnum >= 0; )
1103 if (PROC_FREG_MASK(proc_desc) & (1 << regnum))
1104 write_register (regnum + FP0_REGNUM,
1105 read_memory_integer (frame->saved_regs->regs[regnum + FP0_REGNUM], 8));
1107 write_register (SP_REGNUM, new_sp);
1108 flush_cached_frames ();
1110 if (proc_desc && (PROC_DESC_IS_DUMMY(proc_desc)
1111 || PROC_DESC_IS_DYN_SIGTRAMP (proc_desc)))
1113 struct linked_proc_info *pi_ptr, *prev_ptr;
1115 for (pi_ptr = linked_proc_desc_table, prev_ptr = NULL;
1117 prev_ptr = pi_ptr, pi_ptr = pi_ptr->next)
1119 if (&pi_ptr->info == proc_desc)
1124 error ("Can't locate dummy extra frame info\n");
1126 if (prev_ptr != NULL)
1127 prev_ptr->next = pi_ptr->next;
1129 linked_proc_desc_table = pi_ptr->next;
1135 /* To skip prologues, I use this predicate. Returns either PC itself
1136 if the code at PC does not look like a function prologue; otherwise
1137 returns an address that (if we're lucky) follows the prologue. If
1138 LENIENT, then we must skip everything which is involved in setting
1139 up the frame (it's OK to skip more, just so long as we don't skip
1140 anything which might clobber the registers which are being saved.
1141 Currently we must not skip more on the alpha, but we might the lenient
1145 alpha_skip_prologue (pc, lenient)
1151 CORE_ADDR post_prologue_pc;
1154 #ifdef GDB_TARGET_HAS_SHARED_LIBS
1155 /* Silently return the unaltered pc upon memory errors.
1156 This could happen on OSF/1 if decode_line_1 tries to skip the
1157 prologue for quickstarted shared library functions when the
1158 shared library is not yet mapped in.
1159 Reading target memory is slow over serial lines, so we perform
1160 this check only if the target has shared libraries. */
1161 if (target_read_memory (pc, buf, 4))
1165 /* See if we can determine the end of the prologue via the symbol table.
1166 If so, then return either PC, or the PC after the prologue, whichever
1169 post_prologue_pc = after_prologue (pc, NULL);
1171 if (post_prologue_pc != 0)
1172 return max (pc, post_prologue_pc);
1174 /* Can't determine prologue from the symbol table, need to examine
1177 /* Skip the typical prologue instructions. These are the stack adjustment
1178 instruction and the instructions that save registers on the stack
1179 or in the gcc frame. */
1180 for (offset = 0; offset < 100; offset += 4)
1184 status = read_memory_nobpt (pc + offset, buf, 4);
1186 memory_error (status, pc + offset);
1187 inst = extract_unsigned_integer (buf, 4);
1189 /* The alpha has no delay slots. But let's keep the lenient stuff,
1190 we might need it for something else in the future. */
1194 if ((inst & 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1196 if ((inst & 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1198 if ((inst & 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1200 else if ((inst & 0xfc1f0000) == 0xb41e0000
1201 && (inst & 0xffff0000) != 0xb7fe0000)
1202 continue; /* stq reg,n($sp) */
1204 else if ((inst & 0xfc1f0000) == 0x9c1e0000
1205 && (inst & 0xffff0000) != 0x9ffe0000)
1206 continue; /* stt reg,n($sp) */
1208 else if (inst == 0x47de040f) /* bis sp,sp,fp */
1217 /* Is address PC in the prologue (loosely defined) for function at
1221 alpha_in_lenient_prologue (startaddr, pc)
1222 CORE_ADDR startaddr;
1225 CORE_ADDR end_prologue = alpha_skip_prologue (startaddr, 1);
1226 return pc >= startaddr && pc < end_prologue;
1230 /* The alpha needs a conversion between register and memory format if
1231 the register is a floating point register and
1232 memory format is float, as the register format must be double
1234 memory format is an integer with 4 bytes or less, as the representation
1235 of integers in floating point registers is different. */
1237 alpha_register_convert_to_virtual (regnum, valtype, raw_buffer, virtual_buffer)
1239 struct type *valtype;
1241 char *virtual_buffer;
1243 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1245 memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
1249 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1251 double d = extract_floating (raw_buffer, REGISTER_RAW_SIZE (regnum));
1252 store_floating (virtual_buffer, TYPE_LENGTH (valtype), d);
1254 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1257 l = extract_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum));
1258 l = ((l >> 32) & 0xc0000000) | ((l >> 29) & 0x3fffffff);
1259 store_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype), l);
1262 error ("Cannot retrieve value from floating point register");
1266 alpha_register_convert_to_raw (valtype, regnum, virtual_buffer, raw_buffer)
1267 struct type *valtype;
1269 char *virtual_buffer;
1272 if (TYPE_LENGTH (valtype) >= REGISTER_RAW_SIZE (regnum))
1274 memcpy (raw_buffer, virtual_buffer, REGISTER_RAW_SIZE (regnum));
1278 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1280 double d = extract_floating (virtual_buffer, TYPE_LENGTH (valtype));
1281 store_floating (raw_buffer, REGISTER_RAW_SIZE (regnum), d);
1283 else if (TYPE_CODE (valtype) == TYPE_CODE_INT && TYPE_LENGTH (valtype) <= 4)
1286 if (TYPE_UNSIGNED (valtype))
1287 l = extract_unsigned_integer (virtual_buffer, TYPE_LENGTH (valtype));
1289 l = extract_signed_integer (virtual_buffer, TYPE_LENGTH (valtype));
1290 l = ((l & 0xc0000000) << 32) | ((l & 0x3fffffff) << 29);
1291 store_unsigned_integer (raw_buffer, REGISTER_RAW_SIZE (regnum), l);
1294 error ("Cannot store value in floating point register");
1297 /* Given a return value in `regbuf' with a type `valtype',
1298 extract and copy its value into `valbuf'. */
1301 alpha_extract_return_value (valtype, regbuf, valbuf)
1302 struct type *valtype;
1303 char regbuf[REGISTER_BYTES];
1306 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1307 alpha_register_convert_to_virtual (FP0_REGNUM, valtype,
1308 regbuf + REGISTER_BYTE (FP0_REGNUM),
1311 memcpy (valbuf, regbuf + REGISTER_BYTE (V0_REGNUM), TYPE_LENGTH (valtype));
1314 /* Given a return value in `regbuf' with a type `valtype',
1315 write its value into the appropriate register. */
1318 alpha_store_return_value (valtype, valbuf)
1319 struct type *valtype;
1322 char raw_buffer[MAX_REGISTER_RAW_SIZE];
1323 int regnum = V0_REGNUM;
1324 int length = TYPE_LENGTH (valtype);
1326 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1328 regnum = FP0_REGNUM;
1329 length = REGISTER_RAW_SIZE (regnum);
1330 alpha_register_convert_to_raw (valtype, regnum, valbuf, raw_buffer);
1333 memcpy (raw_buffer, valbuf, length);
1335 write_register_bytes (REGISTER_BYTE (regnum), raw_buffer, length);
1338 /* Just like reinit_frame_cache, but with the right arguments to be
1339 callable as an sfunc. */
1342 reinit_frame_cache_sfunc (args, from_tty, c)
1345 struct cmd_list_element *c;
1347 reinit_frame_cache ();
1350 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1351 to find a convenient place in the text segment to stick a breakpoint to
1352 detect the completion of a target function call (ala call_function_by_hand).
1356 alpha_call_dummy_address ()
1359 struct minimal_symbol *sym;
1361 entry = entry_point_address ();
1366 sym = lookup_minimal_symbol ("_Prelude", NULL, symfile_objfile);
1368 if (!sym || MSYMBOL_TYPE (sym) != mst_text)
1371 return SYMBOL_VALUE_ADDRESS (sym) + 4;
1375 _initialize_alpha_tdep ()
1377 struct cmd_list_element *c;
1379 tm_print_insn = print_insn_alpha;
1381 /* Let the user set the fence post for heuristic_proc_start. */
1383 /* We really would like to have both "0" and "unlimited" work, but
1384 command.c doesn't deal with that. So make it a var_zinteger
1385 because the user can always use "999999" or some such for unlimited. */
1386 c = add_set_cmd ("heuristic-fence-post", class_support, var_zinteger,
1387 (char *) &heuristic_fence_post,
1389 Set the distance searched for the start of a function.\n\
1390 If you are debugging a stripped executable, GDB needs to search through the\n\
1391 program for the start of a function. This command sets the distance of the\n\
1392 search. The only need to set it is when debugging a stripped executable.",
1394 /* We need to throw away the frame cache when we set this, since it
1395 might change our ability to get backtraces. */
1396 c->function.sfunc = reinit_frame_cache_sfunc;
1397 add_show_from_set (c, &showlist);