1 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
2 Copyright 1993, 1994, 1995 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 CORE_ADDR read_next_frame_reg
PARAMS ((struct frame_info
*, int));
42 static CORE_ADDR heuristic_proc_start
PARAMS ((CORE_ADDR
));
44 static alpha_extra_func_info_t heuristic_proc_desc
PARAMS ((CORE_ADDR
,
46 struct frame_info
*));
48 static alpha_extra_func_info_t find_proc_desc
PARAMS ((CORE_ADDR
,
49 struct frame_info
*));
52 static int alpha_in_lenient_prologue
PARAMS ((CORE_ADDR
, CORE_ADDR
));
55 static void reinit_frame_cache_sfunc
PARAMS ((char *, int,
56 struct cmd_list_element
*));
58 static CORE_ADDR after_prologue
PARAMS ((CORE_ADDR pc
,
59 alpha_extra_func_info_t proc_desc
));
61 static int alpha_in_prologue
PARAMS ((CORE_ADDR pc
,
62 alpha_extra_func_info_t proc_desc
));
64 /* Heuristic_proc_start may hunt through the text section for a long
65 time across a 2400 baud serial line. Allows the user to limit this
67 static unsigned int heuristic_fence_post
= 0;
69 /* Layout of a stack frame on the alpha:
72 pdr members: | 7th ... nth arg, |
73 | `pushed' by caller. |
75 ----------------|-------------------------------|<-- old_sp == vfp
78 | |localoff | Copies of 1st .. 6th |
79 | | | | | argument if necessary. |
81 | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
83 | | | | Locals and temporaries. |
85 | | | |-------------------------------|
87 |-fregoffset | Saved float registers. |
93 | | -------|-------------------------------|
95 | | | Saved registers. |
102 | ----------|-------------------------------|
104 frameoffset | Argument build area, gets |
105 | | 7th ... nth arg for any |
106 | | called procedure. |
108 -------------|-------------------------------|<-- sp
112 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
113 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
114 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.iopt) /* frame for CALL_DUMMY */
115 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
116 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
117 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
118 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
119 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
120 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
121 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
122 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
123 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
124 #define _PROC_MAGIC_ 0x0F0F0F0F
125 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
126 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
128 struct linked_proc_info
130 struct alpha_extra_func_info info
;
131 struct linked_proc_info
*next
;
132 } *linked_proc_desc_table
= NULL
;
135 /* Under Linux, signal handler invocations can be identified by the
136 designated code sequence that is used to return from a signal
137 handler. In particular, the return address of a signal handler
138 points to the following sequence (the first instruction is quadword
145 Each instruction has a unique encoding, so we simply attempt to
146 match the instruction the pc is pointing to with any of the above
147 instructions. If there is a hit, we know the offset to the start
148 of the designated sequence and can then check whether we really are
149 executing in a designated sequence. If not, -1 is returned,
150 otherwise the offset from the start of the desingated sequence is
153 There is a slight chance of false hits: code could jump into the
154 middle of the designated sequence, in which case there is no
155 guarantee that we are in the middle of a sigreturn syscall. Don't
156 think this will be a problem in praxis, though.
159 alpha_linux_sigtramp_offset (CORE_ADDR pc
)
161 unsigned int i
[3], w
;
164 if (read_memory_nobpt(pc
, (char *) &w
, 4) != 0)
170 case 0x47de0410: off
= 0; break; /* bis $30,$30,$16 */
171 case 0x43ecf400: off
= 4; break; /* addq $31,0x67,$0 */
172 case 0x00000083: off
= 8; break; /* call_pal callsys */
178 /* designated sequence is not quadword aligned */
182 if (read_memory_nobpt(pc
, (char *) i
, sizeof(i
)) != 0)
185 if (i
[0] == 0x47de0410 && i
[1] == 0x43ecf400 && i
[2] == 0x00000083)
192 /* Under OSF/1, the __sigtramp routine is frameless and has a frame
193 size of zero, but we are able to backtrace through it. */
195 alpha_osf_skip_sigtramp_frame (frame
, pc
)
196 struct frame_info
*frame
;
200 find_pc_partial_function (pc
, &name
, (CORE_ADDR
*)NULL
, (CORE_ADDR
*)NULL
);
201 if (IN_SIGTRAMP (pc
, name
))
208 /* Dynamically create a signal-handler caller procedure descriptor for
209 the signal-handler return code starting at address LOW_ADDR. The
210 descriptor is added to the linked_proc_desc_table. */
212 alpha_extra_func_info_t
213 push_sigtramp_desc (CORE_ADDR low_addr
)
215 struct linked_proc_info
*link
;
216 alpha_extra_func_info_t proc_desc
;
218 link
= (struct linked_proc_info
*)
219 xmalloc (sizeof (struct linked_proc_info
));
220 link
->next
= linked_proc_desc_table
;
221 linked_proc_desc_table
= link
;
223 proc_desc
= &link
->info
;
225 proc_desc
->numargs
= 0;
226 PROC_LOW_ADDR (proc_desc
) = low_addr
;
227 PROC_HIGH_ADDR (proc_desc
) = low_addr
+ 3 * 4;
228 PROC_DUMMY_FRAME (proc_desc
) = 0;
229 PROC_FRAME_OFFSET (proc_desc
) = 0x298; /* sizeof(struct sigcontext_struct) */
230 PROC_FRAME_REG (proc_desc
) = SP_REGNUM
;
231 PROC_REG_MASK (proc_desc
) = 0xffff;
232 PROC_FREG_MASK (proc_desc
) = 0xffff;
233 PROC_PC_REG (proc_desc
) = 26;
234 PROC_LOCALOFF (proc_desc
) = 0;
235 SET_PROC_DESC_IS_DYN_SIGTRAMP (proc_desc
);
239 /* Guaranteed to set frame->saved_regs to some values (it never leaves it
243 alpha_find_saved_regs (frame
)
244 struct frame_info
*frame
;
247 CORE_ADDR reg_position
;
249 alpha_extra_func_info_t proc_desc
;
252 frame
->saved_regs
= (struct frame_saved_regs
*)
253 obstack_alloc (&frame_cache_obstack
, sizeof(struct frame_saved_regs
));
254 memset (frame
->saved_regs
, 0, sizeof (struct frame_saved_regs
));
256 /* If it is the frame for __sigtramp, the saved registers are located
257 in a sigcontext structure somewhere on the stack. __sigtramp
258 passes a pointer to the sigcontext structure on the stack.
259 If the stack layout for __sigtramp changes, or if sigcontext offsets
260 change, we might have to update this code. */
261 #ifndef SIGFRAME_PC_OFF
262 #define SIGFRAME_PC_OFF (2 * 8)
263 #define SIGFRAME_REGSAVE_OFF (4 * 8)
264 #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
266 if (frame
->signal_handler_caller
)
268 CORE_ADDR sigcontext_addr
;
270 sigcontext_addr
= SIGCONTEXT_ADDR (frame
);
271 for (ireg
= 0; ireg
< 32; ireg
++)
273 reg_position
= sigcontext_addr
+ SIGFRAME_REGSAVE_OFF
+ ireg
* 8;
274 frame
->saved_regs
->regs
[ireg
] = reg_position
;
276 for (ireg
= 0; ireg
< 32; ireg
++)
278 reg_position
= sigcontext_addr
+ SIGFRAME_FPREGSAVE_OFF
+ ireg
* 8;
279 frame
->saved_regs
->regs
[FP0_REGNUM
+ ireg
] = reg_position
;
281 frame
->saved_regs
->regs
[PC_REGNUM
] = sigcontext_addr
+ SIGFRAME_PC_OFF
;
285 proc_desc
= frame
->proc_desc
;
286 if (proc_desc
== NULL
)
287 /* I'm not sure how/whether this can happen. Normally when we can't
288 find a proc_desc, we "synthesize" one using heuristic_proc_desc
289 and set the saved_regs right away. */
292 /* Fill in the offsets for the registers which gen_mask says
295 reg_position
= frame
->frame
+ PROC_REG_OFFSET (proc_desc
);
296 mask
= PROC_REG_MASK (proc_desc
);
298 returnreg
= PROC_PC_REG (proc_desc
);
300 /* Note that RA is always saved first, regardless of its actual
302 if (mask
& (1 << returnreg
))
304 frame
->saved_regs
->regs
[returnreg
] = reg_position
;
306 mask
&= ~(1 << returnreg
); /* Clear bit for RA so we
307 don't save again later. */
310 for (ireg
= 0; ireg
<= 31 ; ++ireg
)
311 if (mask
& (1 << ireg
))
313 frame
->saved_regs
->regs
[ireg
] = reg_position
;
317 /* Fill in the offsets for the registers which float_mask says
320 reg_position
= frame
->frame
+ PROC_FREG_OFFSET (proc_desc
);
321 mask
= PROC_FREG_MASK (proc_desc
);
323 for (ireg
= 0; ireg
<= 31 ; ++ireg
)
324 if (mask
& (1 << ireg
))
326 frame
->saved_regs
->regs
[FP0_REGNUM
+ireg
] = reg_position
;
330 frame
->saved_regs
->regs
[PC_REGNUM
] = frame
->saved_regs
->regs
[returnreg
];
334 read_next_frame_reg(fi
, regno
)
335 struct frame_info
*fi
;
338 for (; fi
; fi
= fi
->next
)
340 /* We have to get the saved sp from the sigcontext
341 if it is a signal handler frame. */
342 if (regno
== SP_REGNUM
&& !fi
->signal_handler_caller
)
346 if (fi
->saved_regs
== NULL
)
347 alpha_find_saved_regs (fi
);
348 if (fi
->saved_regs
->regs
[regno
])
349 return read_memory_integer(fi
->saved_regs
->regs
[regno
], 8);
352 return read_register(regno
);
356 alpha_frame_saved_pc(frame
)
357 struct frame_info
*frame
;
359 alpha_extra_func_info_t proc_desc
= frame
->proc_desc
;
360 /* We have to get the saved pc from the sigcontext
361 if it is a signal handler frame. */
362 int pcreg
= frame
->signal_handler_caller
? PC_REGNUM
: frame
->pc_reg
;
364 if (proc_desc
&& PROC_DESC_IS_DUMMY(proc_desc
))
365 return read_memory_integer(frame
->frame
- 8, 8);
367 return read_next_frame_reg(frame
, pcreg
);
371 alpha_saved_pc_after_call (frame
)
372 struct frame_info
*frame
;
374 CORE_ADDR pc
= frame
->pc
;
376 alpha_extra_func_info_t proc_desc
;
379 /* Skip over shared library trampoline if necessary. */
380 tmp
= SKIP_TRAMPOLINE_CODE (pc
);
384 proc_desc
= find_proc_desc (pc
, frame
->next
);
385 pcreg
= proc_desc
? PROC_PC_REG (proc_desc
) : RA_REGNUM
;
387 if (frame
->signal_handler_caller
)
388 return alpha_frame_saved_pc (frame
);
390 return read_register (pcreg
);
394 static struct alpha_extra_func_info temp_proc_desc
;
395 static struct frame_saved_regs temp_saved_regs
;
397 /* This fencepost looks highly suspicious to me. Removing it also
398 seems suspicious as it could affect remote debugging across serial
402 heuristic_proc_start(pc
)
405 CORE_ADDR start_pc
= pc
;
406 CORE_ADDR fence
= start_pc
- heuristic_fence_post
;
408 if (start_pc
== 0) return 0;
410 if (heuristic_fence_post
== UINT_MAX
411 || fence
< VM_MIN_ADDRESS
)
412 fence
= VM_MIN_ADDRESS
;
414 /* search back for previous return */
415 for (start_pc
-= 4; ; start_pc
-= 4)
416 if (start_pc
< fence
)
418 /* It's not clear to me why we reach this point when
419 stop_soon_quietly, but with this test, at least we
420 don't print out warnings for every child forked (eg, on
421 decstation). 22apr93 rich@cygnus.com. */
422 if (!stop_soon_quietly
)
424 static int blurb_printed
= 0;
426 if (fence
== VM_MIN_ADDRESS
)
427 warning("Hit beginning of text section without finding");
429 warning("Hit heuristic-fence-post without finding");
431 warning("enclosing function for address 0x%lx", pc
);
435 This warning occurs if you are debugging a function without any symbols\n\
436 (for example, in a stripped executable). In that case, you may wish to\n\
437 increase the size of the search with the `set heuristic-fence-post' command.\n\
439 Otherwise, you told GDB there was a function where there isn't one, or\n\
440 (more likely) you have encountered a bug in GDB.\n");
447 else if (ABOUT_TO_RETURN(start_pc
))
450 start_pc
+= 4; /* skip return */
454 static alpha_extra_func_info_t
455 heuristic_proc_desc(start_pc
, limit_pc
, next_frame
)
456 CORE_ADDR start_pc
, limit_pc
;
457 struct frame_info
*next_frame
;
459 CORE_ADDR sp
= read_next_frame_reg (next_frame
, SP_REGNUM
);
462 int has_frame_reg
= 0;
463 unsigned long reg_mask
= 0;
468 memset (&temp_proc_desc
, '\0', sizeof(temp_proc_desc
));
469 memset (&temp_saved_regs
, '\0', sizeof(struct frame_saved_regs
));
470 PROC_LOW_ADDR (&temp_proc_desc
) = start_pc
;
472 if (start_pc
+ 200 < limit_pc
)
473 limit_pc
= start_pc
+ 200;
475 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= 4)
481 status
= read_memory_nobpt (cur_pc
, buf
, 4);
483 memory_error (status
, cur_pc
);
484 word
= extract_unsigned_integer (buf
, 4);
486 if ((word
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
487 frame_size
+= (-word
) & 0xffff;
488 else if ((word
& 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
489 && (word
& 0xffff0000) != 0xb7fe0000) /* reg != $zero */
491 int reg
= (word
& 0x03e00000) >> 21;
492 reg_mask
|= 1 << reg
;
493 temp_saved_regs
.regs
[reg
] = sp
+ (short)word
;
495 /* Starting with OSF/1-3.2C, the system libraries are shipped
496 without local symbols, but they still contain procedure
497 descriptors without a symbol reference. GDB is currently
498 unable to find these procedure descriptors and uses
499 heuristic_proc_desc instead.
500 As some low level compiler support routines (__div*, __add*)
501 use a non-standard return address register, we have to
502 add some heuristics to determine the return address register,
503 or stepping over these routines will fail.
504 Usually the return address register is the first register
505 saved on the stack, but assembler optimization might
506 rearrange the register saves.
507 So we recognize only a few registers (t7, t9, ra) within
508 the procedure prologue as valid return address registers.
510 FIXME: Rewriting GDB to access the procedure descriptors,
511 e.g. via the minimal symbol table, might obviate this hack. */
513 && cur_pc
< (start_pc
+ 20)
514 && (reg
== T7_REGNUM
|| reg
== T9_REGNUM
|| reg
== RA_REGNUM
))
517 else if (word
== 0x47de040f) /* bis sp,sp fp */
522 /* If we haven't found a valid return address register yet,
523 keep searching in the procedure prologue. */
524 while (cur_pc
< (limit_pc
+ 20) && cur_pc
< (start_pc
+ 20))
530 status
= read_memory_nobpt (cur_pc
, buf
, 4);
532 memory_error (status
, cur_pc
);
534 word
= extract_unsigned_integer (buf
, 4);
536 if ((word
& 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
537 && (word
& 0xffff0000) != 0xb7fe0000) /* reg != $zero */
539 int reg
= (word
& 0x03e00000) >> 21;
540 if (reg
== T7_REGNUM
|| reg
== T9_REGNUM
|| reg
== RA_REGNUM
)
550 PROC_FRAME_REG(&temp_proc_desc
) = GCC_FP_REGNUM
;
552 PROC_FRAME_REG(&temp_proc_desc
) = SP_REGNUM
;
553 PROC_FRAME_OFFSET(&temp_proc_desc
) = frame_size
;
554 PROC_REG_MASK(&temp_proc_desc
) = reg_mask
;
555 PROC_PC_REG(&temp_proc_desc
) = (pcreg
== -1) ? RA_REGNUM
: pcreg
;
556 PROC_LOCALOFF(&temp_proc_desc
) = 0; /* XXX - bogus */
557 return &temp_proc_desc
;
560 /* This returns the PC of the first inst after the prologue. If we can't
561 find the prologue, then return 0. */
564 after_prologue (pc
, proc_desc
)
566 alpha_extra_func_info_t proc_desc
;
568 struct symtab_and_line sal
;
569 CORE_ADDR func_addr
, func_end
;
572 proc_desc
= find_proc_desc (pc
, NULL
);
576 if (PROC_DESC_IS_DYN_SIGTRAMP (proc_desc
))
577 return PROC_LOW_ADDR (proc_desc
); /* "prologue" is in kernel */
579 /* If function is frameless, then we need to do it the hard way. I
580 strongly suspect that frameless always means prologueless... */
581 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
582 && PROC_FRAME_OFFSET (proc_desc
) == 0)
586 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
587 return 0; /* Unknown */
589 sal
= find_pc_line (func_addr
, 0);
591 if (sal
.end
< func_end
)
594 /* The line after the prologue is after the end of the function. In this
595 case, tell the caller to find the prologue the hard way. */
600 /* Return non-zero if we *might* be in a function prologue. Return zero if we
601 are definitively *not* in a function prologue. */
604 alpha_in_prologue (pc
, proc_desc
)
606 alpha_extra_func_info_t proc_desc
;
608 CORE_ADDR after_prologue_pc
;
610 after_prologue_pc
= after_prologue (pc
, proc_desc
);
612 if (after_prologue_pc
== 0
613 || pc
< after_prologue_pc
)
619 static alpha_extra_func_info_t
620 find_proc_desc (pc
, next_frame
)
622 struct frame_info
*next_frame
;
624 alpha_extra_func_info_t proc_desc
;
629 /* Try to get the proc_desc from the linked call dummy proc_descs
630 if the pc is in the call dummy.
631 This is hairy. In the case of nested dummy calls we have to find the
632 right proc_desc, but we might not yet know the frame for the dummy
633 as it will be contained in the proc_desc we are searching for.
634 So we have to find the proc_desc whose frame is closest to the current
637 if (PC_IN_CALL_DUMMY (pc
, 0, 0))
639 struct linked_proc_info
*link
;
640 CORE_ADDR sp
= read_next_frame_reg (next_frame
, SP_REGNUM
);
641 alpha_extra_func_info_t found_proc_desc
= NULL
;
642 long min_distance
= LONG_MAX
;
644 for (link
= linked_proc_desc_table
; link
; link
= link
->next
)
646 long distance
= (CORE_ADDR
) PROC_DUMMY_FRAME (&link
->info
) - sp
;
647 if (distance
> 0 && distance
< min_distance
)
649 min_distance
= distance
;
650 found_proc_desc
= &link
->info
;
653 if (found_proc_desc
!= NULL
)
654 return found_proc_desc
;
657 b
= block_for_pc(pc
);
659 find_pc_partial_function (pc
, NULL
, &startaddr
, NULL
);
664 if (startaddr
> BLOCK_START (b
))
665 /* This is the "pathological" case referred to in a comment in
666 print_frame_info. It might be better to move this check into
670 sym
= lookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
,
674 /* If we never found a PDR for this function in symbol reading, then
675 examine prologues to find the information. */
676 if (sym
&& ((mips_extra_func_info_t
) SYMBOL_VALUE (sym
))->pdr
.framereg
== -1)
681 /* IF this is the topmost frame AND
682 * (this proc does not have debugging information OR
683 * the PC is in the procedure prologue)
684 * THEN create a "heuristic" proc_desc (by analyzing
685 * the actual code) to replace the "official" proc_desc.
687 proc_desc
= (alpha_extra_func_info_t
)SYMBOL_VALUE(sym
);
688 if (next_frame
== NULL
)
690 if (PROC_DESC_IS_DUMMY (proc_desc
) || alpha_in_prologue (pc
, proc_desc
))
692 alpha_extra_func_info_t found_heuristic
=
693 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc
),
697 PROC_LOCALOFF (found_heuristic
) =
698 PROC_LOCALOFF (proc_desc
);
699 PROC_PC_REG (found_heuristic
) = PROC_PC_REG (proc_desc
);
700 proc_desc
= found_heuristic
;
709 /* Is linked_proc_desc_table really necessary? It only seems to be used
710 by procedure call dummys. However, the procedures being called ought
711 to have their own proc_descs, and even if they don't,
712 heuristic_proc_desc knows how to create them! */
714 register struct linked_proc_info
*link
;
715 for (link
= linked_proc_desc_table
; link
; link
= link
->next
)
716 if (PROC_LOW_ADDR(&link
->info
) <= pc
717 && PROC_HIGH_ADDR(&link
->info
) > pc
)
720 /* If PC is inside a dynamically generated sigtramp handler,
721 create and push a procedure descriptor for that code: */
722 offset
= DYNAMIC_SIGTRAMP_OFFSET (pc
);
724 return push_sigtramp_desc (pc
- offset
);
727 startaddr
= heuristic_proc_start (pc
);
730 heuristic_proc_desc (startaddr
, pc
, next_frame
);
735 alpha_extra_func_info_t cached_proc_desc
;
738 alpha_frame_chain(frame
)
739 struct frame_info
*frame
;
741 alpha_extra_func_info_t proc_desc
;
742 CORE_ADDR saved_pc
= FRAME_SAVED_PC(frame
);
744 if (saved_pc
== 0 || inside_entry_file (saved_pc
))
747 proc_desc
= find_proc_desc(saved_pc
, frame
);
751 cached_proc_desc
= proc_desc
;
753 /* Fetch the frame pointer for a dummy frame from the procedure
755 if (PROC_DESC_IS_DUMMY(proc_desc
))
756 return (CORE_ADDR
) PROC_DUMMY_FRAME(proc_desc
);
758 /* If no frame pointer and frame size is zero, we must be at end
759 of stack (or otherwise hosed). If we don't check frame size,
760 we loop forever if we see a zero size frame. */
761 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
762 && PROC_FRAME_OFFSET (proc_desc
) == 0
763 /* The previous frame from a sigtramp frame might be frameless
764 and have frame size zero. */
765 && !frame
->signal_handler_caller
)
766 return FRAME_PAST_SIGTRAMP_FRAME (frame
, saved_pc
);
768 return read_next_frame_reg(frame
, PROC_FRAME_REG(proc_desc
))
769 + PROC_FRAME_OFFSET(proc_desc
);
773 init_extra_frame_info (frame
)
774 struct frame_info
*frame
;
776 /* Use proc_desc calculated in frame_chain */
777 alpha_extra_func_info_t proc_desc
=
778 frame
->next
? cached_proc_desc
: find_proc_desc(frame
->pc
, frame
->next
);
780 frame
->saved_regs
= NULL
;
782 frame
->pc_reg
= RA_REGNUM
;
783 frame
->proc_desc
= proc_desc
== &temp_proc_desc
? 0 : proc_desc
;
786 /* Get the locals offset and the saved pc register from the
787 procedure descriptor, they are valid even if we are in the
788 middle of the prologue. */
789 frame
->localoff
= PROC_LOCALOFF(proc_desc
);
790 frame
->pc_reg
= PROC_PC_REG(proc_desc
);
792 /* Fixup frame-pointer - only needed for top frame */
794 /* Fetch the frame pointer for a dummy frame from the procedure
796 if (PROC_DESC_IS_DUMMY(proc_desc
))
797 frame
->frame
= (CORE_ADDR
) PROC_DUMMY_FRAME(proc_desc
);
799 /* This may not be quite right, if proc has a real frame register.
800 Get the value of the frame relative sp, procedure might have been
801 interrupted by a signal at it's very start. */
802 else if (frame
->pc
== PROC_LOW_ADDR (proc_desc
)
803 && !PROC_DESC_IS_DYN_SIGTRAMP (proc_desc
))
804 frame
->frame
= read_next_frame_reg (frame
->next
, SP_REGNUM
);
806 frame
->frame
= read_next_frame_reg (frame
->next
, PROC_FRAME_REG (proc_desc
))
807 + PROC_FRAME_OFFSET (proc_desc
);
809 if (proc_desc
== &temp_proc_desc
)
813 /* Do not set the saved registers for a sigtramp frame,
814 alpha_find_saved_registers will do that for us.
815 We can't use frame->signal_handler_caller, it is not yet set. */
816 find_pc_partial_function (frame
->pc
, &name
,
817 (CORE_ADDR
*)NULL
,(CORE_ADDR
*)NULL
);
818 if (!IN_SIGTRAMP (frame
->pc
, name
))
820 frame
->saved_regs
= (struct frame_saved_regs
*)
821 obstack_alloc (&frame_cache_obstack
,
822 sizeof (struct frame_saved_regs
));
823 *frame
->saved_regs
= temp_saved_regs
;
824 frame
->saved_regs
->regs
[PC_REGNUM
]
825 = frame
->saved_regs
->regs
[RA_REGNUM
];
831 /* ALPHA stack frames are almost impenetrable. When execution stops,
832 we basically have to look at symbol information for the function
833 that we stopped in, which tells us *which* register (if any) is
834 the base of the frame pointer, and what offset from that register
835 the frame itself is at.
837 This presents a problem when trying to examine a stack in memory
838 (that isn't executing at the moment), using the "frame" command. We
839 don't have a PC, nor do we have any registers except SP.
841 This routine takes two arguments, SP and PC, and tries to make the
842 cached frames look as if these two arguments defined a frame on the
843 cache. This allows the rest of info frame to extract the important
844 arguments without difficulty. */
847 setup_arbitrary_frame (argc
, argv
)
852 error ("ALPHA frame specifications require two arguments: sp and pc");
854 return create_new_frame (argv
[0], argv
[1]);
857 /* The alpha passes the first six arguments in the registers, the rest on
858 the stack. The register arguments are eventually transferred to the
859 argument transfer area immediately below the stack by the called function
860 anyway. So we `push' at least six arguments on the stack, `reload' the
861 argument registers and then adjust the stack pointer to point past the
862 sixth argument. This algorithm simplifies the passing of a large struct
863 which extends from the registers to the stack.
864 If the called function is returning a structure, the address of the
865 structure to be returned is passed as a hidden first argument. */
868 alpha_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
873 CORE_ADDR struct_addr
;
876 int accumulate_size
= struct_return
? 8 : 0;
877 int arg_regs_size
= ALPHA_NUM_ARG_REGS
* 8;
878 struct alpha_arg
{ char *contents
; int len
; int offset
; };
879 struct alpha_arg
*alpha_args
=
880 (struct alpha_arg
*)alloca (nargs
* sizeof (struct alpha_arg
));
881 register struct alpha_arg
*m_arg
;
882 char raw_buffer
[sizeof (CORE_ADDR
)];
883 int required_arg_regs
;
885 for (i
= 0, m_arg
= alpha_args
; i
< nargs
; i
++, m_arg
++)
887 value_ptr arg
= args
[i
];
888 struct type
*arg_type
= check_typedef (VALUE_TYPE (arg
));
889 /* Cast argument to long if necessary as the compiler does it too. */
890 switch (TYPE_CODE (arg_type
))
895 case TYPE_CODE_RANGE
:
897 if (TYPE_LENGTH (arg_type
) < TYPE_LENGTH (builtin_type_long
))
899 arg_type
= builtin_type_long
;
900 arg
= value_cast (arg_type
, arg
);
906 m_arg
->len
= TYPE_LENGTH (arg_type
);
907 m_arg
->offset
= accumulate_size
;
908 accumulate_size
= (accumulate_size
+ m_arg
->len
+ 7) & ~7;
909 m_arg
->contents
= VALUE_CONTENTS(arg
);
912 /* Determine required argument register loads, loading an argument register
913 is expensive as it uses three ptrace calls. */
914 required_arg_regs
= accumulate_size
/ 8;
915 if (required_arg_regs
> ALPHA_NUM_ARG_REGS
)
916 required_arg_regs
= ALPHA_NUM_ARG_REGS
;
918 /* Make room for the arguments on the stack. */
919 if (accumulate_size
< arg_regs_size
)
920 accumulate_size
= arg_regs_size
;
921 sp
-= accumulate_size
;
923 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
926 /* `Push' arguments on the stack. */
927 for (i
= nargs
; m_arg
--, --i
>= 0; )
928 write_memory(sp
+ m_arg
->offset
, m_arg
->contents
, m_arg
->len
);
931 store_address (raw_buffer
, sizeof (CORE_ADDR
), struct_addr
);
932 write_memory (sp
, raw_buffer
, sizeof (CORE_ADDR
));
935 /* Load the argument registers. */
936 for (i
= 0; i
< required_arg_regs
; i
++)
940 val
= read_memory_integer (sp
+ i
* 8, 8);
941 write_register (A0_REGNUM
+ i
, val
);
942 write_register (FPA0_REGNUM
+ i
, val
);
945 return sp
+ arg_regs_size
;
949 alpha_push_dummy_frame()
952 struct linked_proc_info
*link
;
953 alpha_extra_func_info_t proc_desc
;
954 CORE_ADDR sp
= read_register (SP_REGNUM
);
955 CORE_ADDR save_address
;
956 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
959 link
= (struct linked_proc_info
*) xmalloc(sizeof (struct linked_proc_info
));
960 link
->next
= linked_proc_desc_table
;
961 linked_proc_desc_table
= link
;
963 proc_desc
= &link
->info
;
966 * The registers we must save are all those not preserved across
968 * In addition, we must save the PC and RA.
970 * Dummy frame layout:
980 * Parameter build area
984 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
985 #define MASK(i,j) (((1L << ((j)+1)) - 1) ^ ((1L << (i)) - 1))
986 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
987 #define GEN_REG_SAVE_COUNT 24
988 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
989 #define FLOAT_REG_SAVE_COUNT 23
990 /* The special register is the PC as we have no bit for it in the save masks.
991 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
992 #define SPECIAL_REG_SAVE_COUNT 1
994 PROC_REG_MASK(proc_desc
) = GEN_REG_SAVE_MASK
;
995 PROC_FREG_MASK(proc_desc
) = FLOAT_REG_SAVE_MASK
;
996 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
997 but keep SP aligned to a multiple of 16. */
998 PROC_REG_OFFSET(proc_desc
) =
999 - ((8 * (SPECIAL_REG_SAVE_COUNT
1000 + GEN_REG_SAVE_COUNT
1001 + FLOAT_REG_SAVE_COUNT
)
1003 PROC_FREG_OFFSET(proc_desc
) =
1004 PROC_REG_OFFSET(proc_desc
) + 8 * GEN_REG_SAVE_COUNT
;
1006 /* Save general registers.
1007 The return address register is the first saved register, all other
1008 registers follow in ascending order.
1009 The PC is saved immediately below the SP. */
1010 save_address
= sp
+ PROC_REG_OFFSET(proc_desc
);
1011 store_address (raw_buffer
, 8, read_register (RA_REGNUM
));
1012 write_memory (save_address
, raw_buffer
, 8);
1014 mask
= PROC_REG_MASK(proc_desc
) & 0xffffffffL
;
1015 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
1018 if (ireg
== RA_REGNUM
)
1020 store_address (raw_buffer
, 8, read_register (ireg
));
1021 write_memory (save_address
, raw_buffer
, 8);
1025 store_address (raw_buffer
, 8, read_register (PC_REGNUM
));
1026 write_memory (sp
- 8, raw_buffer
, 8);
1028 /* Save floating point registers. */
1029 save_address
= sp
+ PROC_FREG_OFFSET(proc_desc
);
1030 mask
= PROC_FREG_MASK(proc_desc
) & 0xffffffffL
;
1031 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
1034 store_address (raw_buffer
, 8, read_register (ireg
+ FP0_REGNUM
));
1035 write_memory (save_address
, raw_buffer
, 8);
1039 /* Set and save the frame address for the dummy.
1040 This is tricky. The only registers that are suitable for a frame save
1041 are those that are preserved across procedure calls (s0-s6). But if
1042 a read system call is interrupted and then a dummy call is made
1043 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
1044 is satisfied. Then it returns with the s0-s6 registers set to the values
1045 on entry to the read system call and our dummy frame pointer would be
1046 destroyed. So we save the dummy frame in the proc_desc and handle the
1047 retrieval of the frame pointer of a dummy specifically. The frame register
1048 is set to the virtual frame (pseudo) register, it's value will always
1049 be read as zero and will help us to catch any errors in the dummy frame
1051 PROC_DUMMY_FRAME(proc_desc
) = sp
;
1052 PROC_FRAME_REG(proc_desc
) = FP_REGNUM
;
1053 PROC_FRAME_OFFSET(proc_desc
) = 0;
1054 sp
+= PROC_REG_OFFSET(proc_desc
);
1055 write_register (SP_REGNUM
, sp
);
1057 PROC_LOW_ADDR(proc_desc
) = CALL_DUMMY_ADDRESS ();
1058 PROC_HIGH_ADDR(proc_desc
) = PROC_LOW_ADDR(proc_desc
) + 4;
1060 SET_PROC_DESC_IS_DUMMY(proc_desc
);
1061 PROC_PC_REG(proc_desc
) = RA_REGNUM
;
1067 register int regnum
;
1068 struct frame_info
*frame
= get_current_frame ();
1069 CORE_ADDR new_sp
= frame
->frame
;
1071 alpha_extra_func_info_t proc_desc
= frame
->proc_desc
;
1073 write_register (PC_REGNUM
, FRAME_SAVED_PC(frame
));
1074 if (frame
->saved_regs
== NULL
)
1075 alpha_find_saved_regs (frame
);
1078 for (regnum
= 32; --regnum
>= 0; )
1079 if (PROC_REG_MASK(proc_desc
) & (1 << regnum
))
1080 write_register (regnum
,
1081 read_memory_integer (frame
->saved_regs
->regs
[regnum
],
1083 for (regnum
= 32; --regnum
>= 0; )
1084 if (PROC_FREG_MASK(proc_desc
) & (1 << regnum
))
1085 write_register (regnum
+ FP0_REGNUM
,
1086 read_memory_integer (frame
->saved_regs
->regs
[regnum
+ FP0_REGNUM
], 8));
1088 write_register (SP_REGNUM
, new_sp
);
1089 flush_cached_frames ();
1091 if (proc_desc
&& (PROC_DESC_IS_DUMMY(proc_desc
)
1092 || PROC_DESC_IS_DYN_SIGTRAMP (proc_desc
)))
1094 struct linked_proc_info
*pi_ptr
, *prev_ptr
;
1096 for (pi_ptr
= linked_proc_desc_table
, prev_ptr
= NULL
;
1098 prev_ptr
= pi_ptr
, pi_ptr
= pi_ptr
->next
)
1100 if (&pi_ptr
->info
== proc_desc
)
1105 error ("Can't locate dummy extra frame info\n");
1107 if (prev_ptr
!= NULL
)
1108 prev_ptr
->next
= pi_ptr
->next
;
1110 linked_proc_desc_table
= pi_ptr
->next
;
1116 /* To skip prologues, I use this predicate. Returns either PC itself
1117 if the code at PC does not look like a function prologue; otherwise
1118 returns an address that (if we're lucky) follows the prologue. If
1119 LENIENT, then we must skip everything which is involved in setting
1120 up the frame (it's OK to skip more, just so long as we don't skip
1121 anything which might clobber the registers which are being saved.
1122 Currently we must not skip more on the alpha, but we might the lenient
1126 alpha_skip_prologue (pc
, lenient
)
1132 CORE_ADDR post_prologue_pc
;
1135 #ifdef GDB_TARGET_HAS_SHARED_LIBS
1136 /* Silently return the unaltered pc upon memory errors.
1137 This could happen on OSF/1 if decode_line_1 tries to skip the
1138 prologue for quickstarted shared library functions when the
1139 shared library is not yet mapped in.
1140 Reading target memory is slow over serial lines, so we perform
1141 this check only if the target has shared libraries. */
1142 if (target_read_memory (pc
, buf
, 4))
1146 /* See if we can determine the end of the prologue via the symbol table.
1147 If so, then return either PC, or the PC after the prologue, whichever
1150 post_prologue_pc
= after_prologue (pc
, NULL
);
1152 if (post_prologue_pc
!= 0)
1153 return max (pc
, post_prologue_pc
);
1155 /* Can't determine prologue from the symbol table, need to examine
1158 /* Skip the typical prologue instructions. These are the stack adjustment
1159 instruction and the instructions that save registers on the stack
1160 or in the gcc frame. */
1161 for (offset
= 0; offset
< 100; offset
+= 4)
1165 status
= read_memory_nobpt (pc
+ offset
, buf
, 4);
1167 memory_error (status
, pc
+ offset
);
1168 inst
= extract_unsigned_integer (buf
, 4);
1170 /* The alpha has no delay slots. But let's keep the lenient stuff,
1171 we might need it for something else in the future. */
1175 if ((inst
& 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1177 if ((inst
& 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1179 if ((inst
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1181 else if ((inst
& 0xfc1f0000) == 0xb41e0000
1182 && (inst
& 0xffff0000) != 0xb7fe0000)
1183 continue; /* stq reg,n($sp) */
1185 else if ((inst
& 0xfc1f0000) == 0x9c1e0000
1186 && (inst
& 0xffff0000) != 0x9ffe0000)
1187 continue; /* stt reg,n($sp) */
1189 else if (inst
== 0x47de040f) /* bis sp,sp,fp */
1198 /* Is address PC in the prologue (loosely defined) for function at
1202 alpha_in_lenient_prologue (startaddr
, pc
)
1203 CORE_ADDR startaddr
;
1206 CORE_ADDR end_prologue
= alpha_skip_prologue (startaddr
, 1);
1207 return pc
>= startaddr
&& pc
< end_prologue
;
1211 /* The alpha needs a conversion between register and memory format if
1212 the register is a floating point register and
1213 memory format is float, as the register format must be double
1215 memory format is an integer with 4 bytes or less, as the representation
1216 of integers in floating point registers is different. */
1218 alpha_register_convert_to_virtual (regnum
, valtype
, raw_buffer
, virtual_buffer
)
1220 struct type
*valtype
;
1222 char *virtual_buffer
;
1224 if (TYPE_LENGTH (valtype
) >= REGISTER_RAW_SIZE (regnum
))
1226 memcpy (virtual_buffer
, raw_buffer
, REGISTER_VIRTUAL_SIZE (regnum
));
1230 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1232 double d
= extract_floating (raw_buffer
, REGISTER_RAW_SIZE (regnum
));
1233 store_floating (virtual_buffer
, TYPE_LENGTH (valtype
), d
);
1235 else if (TYPE_CODE (valtype
) == TYPE_CODE_INT
&& TYPE_LENGTH (valtype
) <= 4)
1238 l
= extract_unsigned_integer (raw_buffer
, REGISTER_RAW_SIZE (regnum
));
1239 l
= ((l
>> 32) & 0xc0000000) | ((l
>> 29) & 0x3fffffff);
1240 store_unsigned_integer (virtual_buffer
, TYPE_LENGTH (valtype
), l
);
1243 error ("Cannot retrieve value from floating point register");
1247 alpha_register_convert_to_raw (valtype
, regnum
, virtual_buffer
, raw_buffer
)
1248 struct type
*valtype
;
1250 char *virtual_buffer
;
1253 if (TYPE_LENGTH (valtype
) >= REGISTER_RAW_SIZE (regnum
))
1255 memcpy (raw_buffer
, virtual_buffer
, REGISTER_RAW_SIZE (regnum
));
1259 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1261 double d
= extract_floating (virtual_buffer
, TYPE_LENGTH (valtype
));
1262 store_floating (raw_buffer
, REGISTER_RAW_SIZE (regnum
), d
);
1264 else if (TYPE_CODE (valtype
) == TYPE_CODE_INT
&& TYPE_LENGTH (valtype
) <= 4)
1267 if (TYPE_UNSIGNED (valtype
))
1268 l
= extract_unsigned_integer (virtual_buffer
, TYPE_LENGTH (valtype
));
1270 l
= extract_signed_integer (virtual_buffer
, TYPE_LENGTH (valtype
));
1271 l
= ((l
& 0xc0000000) << 32) | ((l
& 0x3fffffff) << 29);
1272 store_unsigned_integer (raw_buffer
, REGISTER_RAW_SIZE (regnum
), l
);
1275 error ("Cannot store value in floating point register");
1278 /* Given a return value in `regbuf' with a type `valtype',
1279 extract and copy its value into `valbuf'. */
1282 alpha_extract_return_value (valtype
, regbuf
, valbuf
)
1283 struct type
*valtype
;
1284 char regbuf
[REGISTER_BYTES
];
1287 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1288 alpha_register_convert_to_virtual (FP0_REGNUM
, valtype
,
1289 regbuf
+ REGISTER_BYTE (FP0_REGNUM
),
1292 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (V0_REGNUM
), TYPE_LENGTH (valtype
));
1295 /* Given a return value in `regbuf' with a type `valtype',
1296 write its value into the appropriate register. */
1299 alpha_store_return_value (valtype
, valbuf
)
1300 struct type
*valtype
;
1303 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
1304 int regnum
= V0_REGNUM
;
1305 int length
= TYPE_LENGTH (valtype
);
1307 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1309 regnum
= FP0_REGNUM
;
1310 length
= REGISTER_RAW_SIZE (regnum
);
1311 alpha_register_convert_to_raw (valtype
, regnum
, valbuf
, raw_buffer
);
1314 memcpy (raw_buffer
, valbuf
, length
);
1316 write_register_bytes (REGISTER_BYTE (regnum
), raw_buffer
, length
);
1319 /* Just like reinit_frame_cache, but with the right arguments to be
1320 callable as an sfunc. */
1323 reinit_frame_cache_sfunc (args
, from_tty
, c
)
1326 struct cmd_list_element
*c
;
1328 reinit_frame_cache ();
1331 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1332 to find a convenient place in the text segment to stick a breakpoint to
1333 detect the completion of a target function call (ala call_function_by_hand).
1337 alpha_call_dummy_address ()
1340 struct minimal_symbol
*sym
;
1342 entry
= entry_point_address ();
1347 sym
= lookup_minimal_symbol ("_Prelude", NULL
, symfile_objfile
);
1349 if (!sym
|| MSYMBOL_TYPE (sym
) != mst_text
)
1352 return SYMBOL_VALUE_ADDRESS (sym
) + 4;
1356 _initialize_alpha_tdep ()
1358 struct cmd_list_element
*c
;
1360 tm_print_insn
= print_insn_alpha
;
1362 /* Let the user set the fence post for heuristic_proc_start. */
1364 /* We really would like to have both "0" and "unlimited" work, but
1365 command.c doesn't deal with that. So make it a var_zinteger
1366 because the user can always use "999999" or some such for unlimited. */
1367 c
= add_set_cmd ("heuristic-fence-post", class_support
, var_zinteger
,
1368 (char *) &heuristic_fence_post
,
1370 Set the distance searched for the start of a function.\n\
1371 If you are debugging a stripped executable, GDB needs to search through the\n\
1372 program for the start of a function. This command sets the distance of the\n\
1373 search. The only need to set it is when debugging a stripped executable.",
1375 /* We need to throw away the frame cache when we set this, since it
1376 might change our ability to get backtraces. */
1377 c
->function
.sfunc
= reinit_frame_cache_sfunc
;
1378 add_show_from_set (c
, &showlist
);