1 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
2 Copyright 1993, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
31 #include "gdb_string.h"
33 /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
35 /* Prototypes for local functions. */
37 static alpha_extra_func_info_t push_sigtramp_desc
PARAMS ((CORE_ADDR low_addr
));
39 static CORE_ADDR read_next_frame_reg
PARAMS ((struct frame_info
*, int));
41 static CORE_ADDR heuristic_proc_start
PARAMS ((CORE_ADDR
));
43 static alpha_extra_func_info_t heuristic_proc_desc
PARAMS ((CORE_ADDR
,
45 struct frame_info
*));
47 static alpha_extra_func_info_t find_proc_desc
PARAMS ((CORE_ADDR
,
48 struct frame_info
*));
51 static int alpha_in_lenient_prologue
PARAMS ((CORE_ADDR
, CORE_ADDR
));
54 static void reinit_frame_cache_sfunc
PARAMS ((char *, int,
55 struct cmd_list_element
*));
57 static CORE_ADDR after_prologue
PARAMS ((CORE_ADDR pc
,
58 alpha_extra_func_info_t proc_desc
));
60 static int alpha_in_prologue
PARAMS ((CORE_ADDR pc
,
61 alpha_extra_func_info_t proc_desc
));
63 static int alpha_about_to_return
PARAMS ((CORE_ADDR pc
));
65 void _initialize_alpha_tdep
PARAMS ((void));
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
118 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
119 /* These next two fields are kind of being hijacked. I wonder if
120 iline is too small for the values it needs to hold, if GDB is
121 running on a 32-bit host. */
122 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
123 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.cbLineOffset) /*CALL_DUMMY frame */
124 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
125 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
126 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
127 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
128 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
129 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
130 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
131 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
132 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
133 #define _PROC_MAGIC_ 0x0F0F0F0F
134 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
135 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
137 struct linked_proc_info
139 struct alpha_extra_func_info info
;
140 struct linked_proc_info
*next
;
142 *linked_proc_desc_table
= NULL
;
145 /* Under GNU/Linux, signal handler invocations can be identified by the
146 designated code sequence that is used to return from a signal
147 handler. In particular, the return address of a signal handler
148 points to the following sequence (the first instruction is quadword
155 Each instruction has a unique encoding, so we simply attempt to
156 match the instruction the pc is pointing to with any of the above
157 instructions. If there is a hit, we know the offset to the start
158 of the designated sequence and can then check whether we really are
159 executing in a designated sequence. If not, -1 is returned,
160 otherwise the offset from the start of the desingated sequence is
163 There is a slight chance of false hits: code could jump into the
164 middle of the designated sequence, in which case there is no
165 guarantee that we are in the middle of a sigreturn syscall. Don't
166 think this will be a problem in praxis, though.
169 #ifndef TM_LINUXALPHA_H
170 /* HACK: Provide a prototype when compiling this file for non
171 linuxalpha targets. */
172 long alpha_linux_sigtramp_offset
PARAMS ((CORE_ADDR pc
));
175 alpha_linux_sigtramp_offset (pc
)
178 unsigned int i
[3], w
;
181 if (read_memory_nobpt (pc
, (char *) &w
, 4) != 0)
189 break; /* bis $30,$30,$16 */
192 break; /* addq $31,0x67,$0 */
195 break; /* call_pal callsys */
202 /* designated sequence is not quadword aligned */
206 if (read_memory_nobpt (pc
, (char *) i
, sizeof (i
)) != 0)
209 if (i
[0] == 0x47de0410 && i
[1] == 0x43ecf400 && i
[2] == 0x00000083)
216 /* Under OSF/1, the __sigtramp routine is frameless and has a frame
217 size of zero, but we are able to backtrace through it. */
219 alpha_osf_skip_sigtramp_frame (frame
, pc
)
220 struct frame_info
*frame
;
224 find_pc_partial_function (pc
, &name
, (CORE_ADDR
*) NULL
, (CORE_ADDR
*) NULL
);
225 if (IN_SIGTRAMP (pc
, name
))
232 /* Dynamically create a signal-handler caller procedure descriptor for
233 the signal-handler return code starting at address LOW_ADDR. The
234 descriptor is added to the linked_proc_desc_table. */
236 static alpha_extra_func_info_t
237 push_sigtramp_desc (low_addr
)
240 struct linked_proc_info
*link
;
241 alpha_extra_func_info_t proc_desc
;
243 link
= (struct linked_proc_info
*)
244 xmalloc (sizeof (struct linked_proc_info
));
245 link
->next
= linked_proc_desc_table
;
246 linked_proc_desc_table
= link
;
248 proc_desc
= &link
->info
;
250 proc_desc
->numargs
= 0;
251 PROC_LOW_ADDR (proc_desc
) = low_addr
;
252 PROC_HIGH_ADDR (proc_desc
) = low_addr
+ 3 * 4;
253 PROC_DUMMY_FRAME (proc_desc
) = 0;
254 PROC_FRAME_OFFSET (proc_desc
) = 0x298; /* sizeof(struct sigcontext_struct) */
255 PROC_FRAME_REG (proc_desc
) = SP_REGNUM
;
256 PROC_REG_MASK (proc_desc
) = 0xffff;
257 PROC_FREG_MASK (proc_desc
) = 0xffff;
258 PROC_PC_REG (proc_desc
) = 26;
259 PROC_LOCALOFF (proc_desc
) = 0;
260 SET_PROC_DESC_IS_DYN_SIGTRAMP (proc_desc
);
265 /* Guaranteed to set frame->saved_regs to some values (it never leaves it
269 alpha_find_saved_regs (frame
)
270 struct frame_info
*frame
;
273 CORE_ADDR reg_position
;
275 alpha_extra_func_info_t proc_desc
;
278 frame_saved_regs_zalloc (frame
);
280 /* If it is the frame for __sigtramp, the saved registers are located
281 in a sigcontext structure somewhere on the stack. __sigtramp
282 passes a pointer to the sigcontext structure on the stack.
283 If the stack layout for __sigtramp changes, or if sigcontext offsets
284 change, we might have to update this code. */
285 #ifndef SIGFRAME_PC_OFF
286 #define SIGFRAME_PC_OFF (2 * 8)
287 #define SIGFRAME_REGSAVE_OFF (4 * 8)
288 #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
290 if (frame
->signal_handler_caller
)
292 CORE_ADDR sigcontext_addr
;
294 sigcontext_addr
= SIGCONTEXT_ADDR (frame
);
295 for (ireg
= 0; ireg
< 32; ireg
++)
297 reg_position
= sigcontext_addr
+ SIGFRAME_REGSAVE_OFF
+ ireg
* 8;
298 frame
->saved_regs
[ireg
] = reg_position
;
300 for (ireg
= 0; ireg
< 32; ireg
++)
302 reg_position
= sigcontext_addr
+ SIGFRAME_FPREGSAVE_OFF
+ ireg
* 8;
303 frame
->saved_regs
[FP0_REGNUM
+ ireg
] = reg_position
;
305 frame
->saved_regs
[PC_REGNUM
] = sigcontext_addr
+ SIGFRAME_PC_OFF
;
309 proc_desc
= frame
->proc_desc
;
310 if (proc_desc
== NULL
)
311 /* I'm not sure how/whether this can happen. Normally when we can't
312 find a proc_desc, we "synthesize" one using heuristic_proc_desc
313 and set the saved_regs right away. */
316 /* Fill in the offsets for the registers which gen_mask says
319 reg_position
= frame
->frame
+ PROC_REG_OFFSET (proc_desc
);
320 mask
= PROC_REG_MASK (proc_desc
);
322 returnreg
= PROC_PC_REG (proc_desc
);
324 /* Note that RA is always saved first, regardless of its actual
326 if (mask
& (1 << returnreg
))
328 frame
->saved_regs
[returnreg
] = reg_position
;
330 mask
&= ~(1 << returnreg
); /* Clear bit for RA so we
331 don't save again later. */
334 for (ireg
= 0; ireg
<= 31; ++ireg
)
335 if (mask
& (1 << ireg
))
337 frame
->saved_regs
[ireg
] = reg_position
;
341 /* Fill in the offsets for the registers which float_mask says
344 reg_position
= frame
->frame
+ PROC_FREG_OFFSET (proc_desc
);
345 mask
= PROC_FREG_MASK (proc_desc
);
347 for (ireg
= 0; ireg
<= 31; ++ireg
)
348 if (mask
& (1 << ireg
))
350 frame
->saved_regs
[FP0_REGNUM
+ ireg
] = reg_position
;
354 frame
->saved_regs
[PC_REGNUM
] = frame
->saved_regs
[returnreg
];
358 read_next_frame_reg (fi
, regno
)
359 struct frame_info
*fi
;
362 for (; fi
; fi
= fi
->next
)
364 /* We have to get the saved sp from the sigcontext
365 if it is a signal handler frame. */
366 if (regno
== SP_REGNUM
&& !fi
->signal_handler_caller
)
370 if (fi
->saved_regs
== NULL
)
371 alpha_find_saved_regs (fi
);
372 if (fi
->saved_regs
[regno
])
373 return read_memory_integer (fi
->saved_regs
[regno
], 8);
376 return read_register (regno
);
380 alpha_frame_saved_pc (frame
)
381 struct frame_info
*frame
;
383 alpha_extra_func_info_t proc_desc
= frame
->proc_desc
;
384 /* We have to get the saved pc from the sigcontext
385 if it is a signal handler frame. */
386 int pcreg
= frame
->signal_handler_caller
? PC_REGNUM
: frame
->pc_reg
;
388 if (proc_desc
&& PROC_DESC_IS_DUMMY (proc_desc
))
389 return read_memory_integer (frame
->frame
- 8, 8);
391 return read_next_frame_reg (frame
, pcreg
);
395 alpha_saved_pc_after_call (frame
)
396 struct frame_info
*frame
;
398 CORE_ADDR pc
= frame
->pc
;
400 alpha_extra_func_info_t proc_desc
;
403 /* Skip over shared library trampoline if necessary. */
404 tmp
= SKIP_TRAMPOLINE_CODE (pc
);
408 proc_desc
= find_proc_desc (pc
, frame
->next
);
409 pcreg
= proc_desc
? PROC_PC_REG (proc_desc
) : RA_REGNUM
;
411 if (frame
->signal_handler_caller
)
412 return alpha_frame_saved_pc (frame
);
414 return read_register (pcreg
);
418 static struct alpha_extra_func_info temp_proc_desc
;
419 static struct frame_saved_regs temp_saved_regs
;
421 /* Nonzero if instruction at PC is a return instruction. "ret
422 $zero,($ra),1" on alpha. */
425 alpha_about_to_return (pc
)
428 return read_memory_integer (pc
, 4) == 0x6bfa8001;
433 /* This fencepost looks highly suspicious to me. Removing it also
434 seems suspicious as it could affect remote debugging across serial
438 heuristic_proc_start (pc
)
441 CORE_ADDR start_pc
= pc
;
442 CORE_ADDR fence
= start_pc
- heuristic_fence_post
;
447 if (heuristic_fence_post
== UINT_MAX
448 || fence
< VM_MIN_ADDRESS
)
449 fence
= VM_MIN_ADDRESS
;
451 /* search back for previous return */
452 for (start_pc
-= 4;; start_pc
-= 4)
453 if (start_pc
< fence
)
455 /* It's not clear to me why we reach this point when
456 stop_soon_quietly, but with this test, at least we
457 don't print out warnings for every child forked (eg, on
458 decstation). 22apr93 rich@cygnus.com. */
459 if (!stop_soon_quietly
)
461 static int blurb_printed
= 0;
463 if (fence
== VM_MIN_ADDRESS
)
464 warning ("Hit beginning of text section without finding");
466 warning ("Hit heuristic-fence-post without finding");
468 warning ("enclosing function for address 0x%lx", pc
);
472 This warning occurs if you are debugging a function without any symbols\n\
473 (for example, in a stripped executable). In that case, you may wish to\n\
474 increase the size of the search with the `set heuristic-fence-post' command.\n\
476 Otherwise, you told GDB there was a function where there isn't one, or\n\
477 (more likely) you have encountered a bug in GDB.\n");
484 else if (alpha_about_to_return (start_pc
))
487 start_pc
+= 4; /* skip return */
491 static alpha_extra_func_info_t
492 heuristic_proc_desc (start_pc
, limit_pc
, next_frame
)
493 CORE_ADDR start_pc
, limit_pc
;
494 struct frame_info
*next_frame
;
496 CORE_ADDR sp
= read_next_frame_reg (next_frame
, SP_REGNUM
);
499 int has_frame_reg
= 0;
500 unsigned long reg_mask
= 0;
505 memset (&temp_proc_desc
, '\0', sizeof (temp_proc_desc
));
506 memset (&temp_saved_regs
, '\0', sizeof (struct frame_saved_regs
));
507 PROC_LOW_ADDR (&temp_proc_desc
) = start_pc
;
509 if (start_pc
+ 200 < limit_pc
)
510 limit_pc
= start_pc
+ 200;
512 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= 4)
518 status
= read_memory_nobpt (cur_pc
, buf
, 4);
520 memory_error (status
, cur_pc
);
521 word
= extract_unsigned_integer (buf
, 4);
523 if ((word
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
526 frame_size
+= (-word
) & 0xffff;
528 /* Exit loop if a positive stack adjustment is found, which
529 usually means that the stack cleanup code in the function
530 epilogue is reached. */
533 else if ((word
& 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
534 && (word
& 0xffff0000) != 0xb7fe0000) /* reg != $zero */
536 int reg
= (word
& 0x03e00000) >> 21;
537 reg_mask
|= 1 << reg
;
538 temp_saved_regs
.regs
[reg
] = sp
+ (short) word
;
540 /* Starting with OSF/1-3.2C, the system libraries are shipped
541 without local symbols, but they still contain procedure
542 descriptors without a symbol reference. GDB is currently
543 unable to find these procedure descriptors and uses
544 heuristic_proc_desc instead.
545 As some low level compiler support routines (__div*, __add*)
546 use a non-standard return address register, we have to
547 add some heuristics to determine the return address register,
548 or stepping over these routines will fail.
549 Usually the return address register is the first register
550 saved on the stack, but assembler optimization might
551 rearrange the register saves.
552 So we recognize only a few registers (t7, t9, ra) within
553 the procedure prologue as valid return address registers.
554 If we encounter a return instruction, we extract the
555 the return address register from it.
557 FIXME: Rewriting GDB to access the procedure descriptors,
558 e.g. via the minimal symbol table, might obviate this hack. */
560 && cur_pc
< (start_pc
+ 80)
561 && (reg
== T7_REGNUM
|| reg
== T9_REGNUM
|| reg
== RA_REGNUM
))
564 else if ((word
& 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
565 pcreg
= (word
>> 16) & 0x1f;
566 else if (word
== 0x47de040f) /* bis sp,sp fp */
571 /* If we haven't found a valid return address register yet,
572 keep searching in the procedure prologue. */
573 while (cur_pc
< (limit_pc
+ 80) && cur_pc
< (start_pc
+ 80))
578 if (read_memory_nobpt (cur_pc
, buf
, 4))
581 word
= extract_unsigned_integer (buf
, 4);
583 if ((word
& 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
584 && (word
& 0xffff0000) != 0xb7fe0000) /* reg != $zero */
586 int reg
= (word
& 0x03e00000) >> 21;
587 if (reg
== T7_REGNUM
|| reg
== T9_REGNUM
|| reg
== RA_REGNUM
)
593 else if ((word
& 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
595 pcreg
= (word
>> 16) & 0x1f;
602 PROC_FRAME_REG (&temp_proc_desc
) = GCC_FP_REGNUM
;
604 PROC_FRAME_REG (&temp_proc_desc
) = SP_REGNUM
;
605 PROC_FRAME_OFFSET (&temp_proc_desc
) = frame_size
;
606 PROC_REG_MASK (&temp_proc_desc
) = reg_mask
;
607 PROC_PC_REG (&temp_proc_desc
) = (pcreg
== -1) ? RA_REGNUM
: pcreg
;
608 PROC_LOCALOFF (&temp_proc_desc
) = 0; /* XXX - bogus */
609 return &temp_proc_desc
;
612 /* This returns the PC of the first inst after the prologue. If we can't
613 find the prologue, then return 0. */
616 after_prologue (pc
, proc_desc
)
618 alpha_extra_func_info_t proc_desc
;
620 struct symtab_and_line sal
;
621 CORE_ADDR func_addr
, func_end
;
624 proc_desc
= find_proc_desc (pc
, NULL
);
628 if (PROC_DESC_IS_DYN_SIGTRAMP (proc_desc
))
629 return PROC_LOW_ADDR (proc_desc
); /* "prologue" is in kernel */
631 /* If function is frameless, then we need to do it the hard way. I
632 strongly suspect that frameless always means prologueless... */
633 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
634 && PROC_FRAME_OFFSET (proc_desc
) == 0)
638 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
639 return 0; /* Unknown */
641 sal
= find_pc_line (func_addr
, 0);
643 if (sal
.end
< func_end
)
646 /* The line after the prologue is after the end of the function. In this
647 case, tell the caller to find the prologue the hard way. */
652 /* Return non-zero if we *might* be in a function prologue. Return zero if we
653 are definitively *not* in a function prologue. */
656 alpha_in_prologue (pc
, proc_desc
)
658 alpha_extra_func_info_t proc_desc
;
660 CORE_ADDR after_prologue_pc
;
662 after_prologue_pc
= after_prologue (pc
, proc_desc
);
664 if (after_prologue_pc
== 0
665 || pc
< after_prologue_pc
)
671 static alpha_extra_func_info_t
672 find_proc_desc (pc
, next_frame
)
674 struct frame_info
*next_frame
;
676 alpha_extra_func_info_t proc_desc
;
681 /* Try to get the proc_desc from the linked call dummy proc_descs
682 if the pc is in the call dummy.
683 This is hairy. In the case of nested dummy calls we have to find the
684 right proc_desc, but we might not yet know the frame for the dummy
685 as it will be contained in the proc_desc we are searching for.
686 So we have to find the proc_desc whose frame is closest to the current
689 if (PC_IN_CALL_DUMMY (pc
, 0, 0))
691 struct linked_proc_info
*link
;
692 CORE_ADDR sp
= read_next_frame_reg (next_frame
, SP_REGNUM
);
693 alpha_extra_func_info_t found_proc_desc
= NULL
;
694 long min_distance
= LONG_MAX
;
696 for (link
= linked_proc_desc_table
; link
; link
= link
->next
)
698 long distance
= (CORE_ADDR
) PROC_DUMMY_FRAME (&link
->info
) - sp
;
699 if (distance
> 0 && distance
< min_distance
)
701 min_distance
= distance
;
702 found_proc_desc
= &link
->info
;
705 if (found_proc_desc
!= NULL
)
706 return found_proc_desc
;
709 b
= block_for_pc (pc
);
711 find_pc_partial_function (pc
, NULL
, &startaddr
, NULL
);
716 if (startaddr
> BLOCK_START (b
))
717 /* This is the "pathological" case referred to in a comment in
718 print_frame_info. It might be better to move this check into
722 sym
= lookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
,
726 /* If we never found a PDR for this function in symbol reading, then
727 examine prologues to find the information. */
728 if (sym
&& ((mips_extra_func_info_t
) SYMBOL_VALUE (sym
))->pdr
.framereg
== -1)
733 /* IF this is the topmost frame AND
734 * (this proc does not have debugging information OR
735 * the PC is in the procedure prologue)
736 * THEN create a "heuristic" proc_desc (by analyzing
737 * the actual code) to replace the "official" proc_desc.
739 proc_desc
= (alpha_extra_func_info_t
) SYMBOL_VALUE (sym
);
740 if (next_frame
== NULL
)
742 if (PROC_DESC_IS_DUMMY (proc_desc
) || alpha_in_prologue (pc
, proc_desc
))
744 alpha_extra_func_info_t found_heuristic
=
745 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc
),
749 PROC_LOCALOFF (found_heuristic
) =
750 PROC_LOCALOFF (proc_desc
);
751 PROC_PC_REG (found_heuristic
) = PROC_PC_REG (proc_desc
);
752 proc_desc
= found_heuristic
;
761 /* Is linked_proc_desc_table really necessary? It only seems to be used
762 by procedure call dummys. However, the procedures being called ought
763 to have their own proc_descs, and even if they don't,
764 heuristic_proc_desc knows how to create them! */
766 register struct linked_proc_info
*link
;
767 for (link
= linked_proc_desc_table
; link
; link
= link
->next
)
768 if (PROC_LOW_ADDR (&link
->info
) <= pc
769 && PROC_HIGH_ADDR (&link
->info
) > pc
)
772 /* If PC is inside a dynamically generated sigtramp handler,
773 create and push a procedure descriptor for that code: */
774 offset
= DYNAMIC_SIGTRAMP_OFFSET (pc
);
776 return push_sigtramp_desc (pc
- offset
);
778 /* If heuristic_fence_post is non-zero, determine the procedure
779 start address by examining the instructions.
780 This allows us to find the start address of static functions which
781 have no symbolic information, as startaddr would have been set to
782 the preceding global function start address by the
783 find_pc_partial_function call above. */
784 if (startaddr
== 0 || heuristic_fence_post
!= 0)
785 startaddr
= heuristic_proc_start (pc
);
788 heuristic_proc_desc (startaddr
, pc
, next_frame
);
793 alpha_extra_func_info_t cached_proc_desc
;
796 alpha_frame_chain (frame
)
797 struct frame_info
*frame
;
799 alpha_extra_func_info_t proc_desc
;
800 CORE_ADDR saved_pc
= FRAME_SAVED_PC (frame
);
802 if (saved_pc
== 0 || inside_entry_file (saved_pc
))
805 proc_desc
= find_proc_desc (saved_pc
, frame
);
809 cached_proc_desc
= proc_desc
;
811 /* Fetch the frame pointer for a dummy frame from the procedure
813 if (PROC_DESC_IS_DUMMY (proc_desc
))
814 return (CORE_ADDR
) PROC_DUMMY_FRAME (proc_desc
);
816 /* If no frame pointer and frame size is zero, we must be at end
817 of stack (or otherwise hosed). If we don't check frame size,
818 we loop forever if we see a zero size frame. */
819 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
820 && PROC_FRAME_OFFSET (proc_desc
) == 0
821 /* The previous frame from a sigtramp frame might be frameless
822 and have frame size zero. */
823 && !frame
->signal_handler_caller
)
824 return FRAME_PAST_SIGTRAMP_FRAME (frame
, saved_pc
);
826 return read_next_frame_reg (frame
, PROC_FRAME_REG (proc_desc
))
827 + PROC_FRAME_OFFSET (proc_desc
);
831 init_extra_frame_info (frame
)
832 struct frame_info
*frame
;
834 /* Use proc_desc calculated in frame_chain */
835 alpha_extra_func_info_t proc_desc
=
836 frame
->next
? cached_proc_desc
: find_proc_desc (frame
->pc
, frame
->next
);
838 frame
->saved_regs
= NULL
;
840 frame
->pc_reg
= RA_REGNUM
;
841 frame
->proc_desc
= proc_desc
== &temp_proc_desc
? 0 : proc_desc
;
844 /* Get the locals offset and the saved pc register from the
845 procedure descriptor, they are valid even if we are in the
846 middle of the prologue. */
847 frame
->localoff
= PROC_LOCALOFF (proc_desc
);
848 frame
->pc_reg
= PROC_PC_REG (proc_desc
);
850 /* Fixup frame-pointer - only needed for top frame */
852 /* Fetch the frame pointer for a dummy frame from the procedure
854 if (PROC_DESC_IS_DUMMY (proc_desc
))
855 frame
->frame
= (CORE_ADDR
) PROC_DUMMY_FRAME (proc_desc
);
857 /* This may not be quite right, if proc has a real frame register.
858 Get the value of the frame relative sp, procedure might have been
859 interrupted by a signal at it's very start. */
860 else if (frame
->pc
== PROC_LOW_ADDR (proc_desc
)
861 && !PROC_DESC_IS_DYN_SIGTRAMP (proc_desc
))
862 frame
->frame
= read_next_frame_reg (frame
->next
, SP_REGNUM
);
864 frame
->frame
= read_next_frame_reg (frame
->next
, PROC_FRAME_REG (proc_desc
))
865 + PROC_FRAME_OFFSET (proc_desc
);
867 if (proc_desc
== &temp_proc_desc
)
871 /* Do not set the saved registers for a sigtramp frame,
872 alpha_find_saved_registers will do that for us.
873 We can't use frame->signal_handler_caller, it is not yet set. */
874 find_pc_partial_function (frame
->pc
, &name
,
875 (CORE_ADDR
*) NULL
, (CORE_ADDR
*) NULL
);
876 if (!IN_SIGTRAMP (frame
->pc
, name
))
878 frame
->saved_regs
= (CORE_ADDR
*)
879 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS
);
880 memcpy (frame
->saved_regs
, temp_saved_regs
.regs
, SIZEOF_FRAME_SAVED_REGS
);
881 frame
->saved_regs
[PC_REGNUM
]
882 = frame
->saved_regs
[RA_REGNUM
];
888 /* ALPHA stack frames are almost impenetrable. When execution stops,
889 we basically have to look at symbol information for the function
890 that we stopped in, which tells us *which* register (if any) is
891 the base of the frame pointer, and what offset from that register
892 the frame itself is at.
894 This presents a problem when trying to examine a stack in memory
895 (that isn't executing at the moment), using the "frame" command. We
896 don't have a PC, nor do we have any registers except SP.
898 This routine takes two arguments, SP and PC, and tries to make the
899 cached frames look as if these two arguments defined a frame on the
900 cache. This allows the rest of info frame to extract the important
901 arguments without difficulty. */
904 setup_arbitrary_frame (argc
, argv
)
909 error ("ALPHA frame specifications require two arguments: sp and pc");
911 return create_new_frame (argv
[0], argv
[1]);
914 /* The alpha passes the first six arguments in the registers, the rest on
915 the stack. The register arguments are eventually transferred to the
916 argument transfer area immediately below the stack by the called function
917 anyway. So we `push' at least six arguments on the stack, `reload' the
918 argument registers and then adjust the stack pointer to point past the
919 sixth argument. This algorithm simplifies the passing of a large struct
920 which extends from the registers to the stack.
921 If the called function is returning a structure, the address of the
922 structure to be returned is passed as a hidden first argument. */
925 alpha_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
930 CORE_ADDR struct_addr
;
933 int accumulate_size
= struct_return
? 8 : 0;
934 int arg_regs_size
= ALPHA_NUM_ARG_REGS
* 8;
941 struct alpha_arg
*alpha_args
=
942 (struct alpha_arg
*) alloca (nargs
* sizeof (struct alpha_arg
));
943 register struct alpha_arg
*m_arg
;
944 char raw_buffer
[sizeof (CORE_ADDR
)];
945 int required_arg_regs
;
947 for (i
= 0, m_arg
= alpha_args
; i
< nargs
; i
++, m_arg
++)
949 value_ptr arg
= args
[i
];
950 struct type
*arg_type
= check_typedef (VALUE_TYPE (arg
));
951 /* Cast argument to long if necessary as the compiler does it too. */
952 switch (TYPE_CODE (arg_type
))
957 case TYPE_CODE_RANGE
:
959 if (TYPE_LENGTH (arg_type
) < TYPE_LENGTH (builtin_type_long
))
961 arg_type
= builtin_type_long
;
962 arg
= value_cast (arg_type
, arg
);
968 m_arg
->len
= TYPE_LENGTH (arg_type
);
969 m_arg
->offset
= accumulate_size
;
970 accumulate_size
= (accumulate_size
+ m_arg
->len
+ 7) & ~7;
971 m_arg
->contents
= VALUE_CONTENTS (arg
);
974 /* Determine required argument register loads, loading an argument register
975 is expensive as it uses three ptrace calls. */
976 required_arg_regs
= accumulate_size
/ 8;
977 if (required_arg_regs
> ALPHA_NUM_ARG_REGS
)
978 required_arg_regs
= ALPHA_NUM_ARG_REGS
;
980 /* Make room for the arguments on the stack. */
981 if (accumulate_size
< arg_regs_size
)
982 accumulate_size
= arg_regs_size
;
983 sp
-= accumulate_size
;
985 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
988 /* `Push' arguments on the stack. */
989 for (i
= nargs
; m_arg
--, --i
>= 0;)
990 write_memory (sp
+ m_arg
->offset
, m_arg
->contents
, m_arg
->len
);
993 store_address (raw_buffer
, sizeof (CORE_ADDR
), struct_addr
);
994 write_memory (sp
, raw_buffer
, sizeof (CORE_ADDR
));
997 /* Load the argument registers. */
998 for (i
= 0; i
< required_arg_regs
; i
++)
1002 val
= read_memory_integer (sp
+ i
* 8, 8);
1003 write_register (A0_REGNUM
+ i
, val
);
1004 write_register (FPA0_REGNUM
+ i
, val
);
1007 return sp
+ arg_regs_size
;
1011 alpha_push_dummy_frame ()
1014 struct linked_proc_info
*link
;
1015 alpha_extra_func_info_t proc_desc
;
1016 CORE_ADDR sp
= read_register (SP_REGNUM
);
1017 CORE_ADDR save_address
;
1018 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
1021 link
= (struct linked_proc_info
*) xmalloc (sizeof (struct linked_proc_info
));
1022 link
->next
= linked_proc_desc_table
;
1023 linked_proc_desc_table
= link
;
1025 proc_desc
= &link
->info
;
1028 * The registers we must save are all those not preserved across
1030 * In addition, we must save the PC and RA.
1032 * Dummy frame layout:
1042 * Parameter build area
1046 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
1047 #define MASK(i,j) ((((LONGEST)1 << ((j)+1)) - 1) ^ (((LONGEST)1 << (i)) - 1))
1048 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
1049 #define GEN_REG_SAVE_COUNT 24
1050 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
1051 #define FLOAT_REG_SAVE_COUNT 23
1052 /* The special register is the PC as we have no bit for it in the save masks.
1053 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
1054 #define SPECIAL_REG_SAVE_COUNT 1
1056 PROC_REG_MASK (proc_desc
) = GEN_REG_SAVE_MASK
;
1057 PROC_FREG_MASK (proc_desc
) = FLOAT_REG_SAVE_MASK
;
1058 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
1059 but keep SP aligned to a multiple of 16. */
1060 PROC_REG_OFFSET (proc_desc
) =
1061 -((8 * (SPECIAL_REG_SAVE_COUNT
1062 + GEN_REG_SAVE_COUNT
1063 + FLOAT_REG_SAVE_COUNT
)
1065 PROC_FREG_OFFSET (proc_desc
) =
1066 PROC_REG_OFFSET (proc_desc
) + 8 * GEN_REG_SAVE_COUNT
;
1068 /* Save general registers.
1069 The return address register is the first saved register, all other
1070 registers follow in ascending order.
1071 The PC is saved immediately below the SP. */
1072 save_address
= sp
+ PROC_REG_OFFSET (proc_desc
);
1073 store_address (raw_buffer
, 8, read_register (RA_REGNUM
));
1074 write_memory (save_address
, raw_buffer
, 8);
1076 mask
= PROC_REG_MASK (proc_desc
) & 0xffffffffL
;
1077 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
1080 if (ireg
== RA_REGNUM
)
1082 store_address (raw_buffer
, 8, read_register (ireg
));
1083 write_memory (save_address
, raw_buffer
, 8);
1087 store_address (raw_buffer
, 8, read_register (PC_REGNUM
));
1088 write_memory (sp
- 8, raw_buffer
, 8);
1090 /* Save floating point registers. */
1091 save_address
= sp
+ PROC_FREG_OFFSET (proc_desc
);
1092 mask
= PROC_FREG_MASK (proc_desc
) & 0xffffffffL
;
1093 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
1096 store_address (raw_buffer
, 8, read_register (ireg
+ FP0_REGNUM
));
1097 write_memory (save_address
, raw_buffer
, 8);
1101 /* Set and save the frame address for the dummy.
1102 This is tricky. The only registers that are suitable for a frame save
1103 are those that are preserved across procedure calls (s0-s6). But if
1104 a read system call is interrupted and then a dummy call is made
1105 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
1106 is satisfied. Then it returns with the s0-s6 registers set to the values
1107 on entry to the read system call and our dummy frame pointer would be
1108 destroyed. So we save the dummy frame in the proc_desc and handle the
1109 retrieval of the frame pointer of a dummy specifically. The frame register
1110 is set to the virtual frame (pseudo) register, it's value will always
1111 be read as zero and will help us to catch any errors in the dummy frame
1113 PROC_DUMMY_FRAME (proc_desc
) = sp
;
1114 PROC_FRAME_REG (proc_desc
) = FP_REGNUM
;
1115 PROC_FRAME_OFFSET (proc_desc
) = 0;
1116 sp
+= PROC_REG_OFFSET (proc_desc
);
1117 write_register (SP_REGNUM
, sp
);
1119 PROC_LOW_ADDR (proc_desc
) = CALL_DUMMY_ADDRESS ();
1120 PROC_HIGH_ADDR (proc_desc
) = PROC_LOW_ADDR (proc_desc
) + 4;
1122 SET_PROC_DESC_IS_DUMMY (proc_desc
);
1123 PROC_PC_REG (proc_desc
) = RA_REGNUM
;
1129 register int regnum
;
1130 struct frame_info
*frame
= get_current_frame ();
1131 CORE_ADDR new_sp
= frame
->frame
;
1133 alpha_extra_func_info_t proc_desc
= frame
->proc_desc
;
1135 /* we need proc_desc to know how to restore the registers;
1136 if it is NULL, construct (a temporary) one */
1137 if (proc_desc
== NULL
)
1138 proc_desc
= find_proc_desc (frame
->pc
, frame
->next
);
1140 /* Question: should we copy this proc_desc and save it in
1141 frame->proc_desc? If we do, who will free it?
1142 For now, we don't save a copy... */
1144 write_register (PC_REGNUM
, FRAME_SAVED_PC (frame
));
1145 if (frame
->saved_regs
== NULL
)
1146 alpha_find_saved_regs (frame
);
1149 for (regnum
= 32; --regnum
>= 0;)
1150 if (PROC_REG_MASK (proc_desc
) & (1 << regnum
))
1151 write_register (regnum
,
1152 read_memory_integer (frame
->saved_regs
[regnum
],
1154 for (regnum
= 32; --regnum
>= 0;)
1155 if (PROC_FREG_MASK (proc_desc
) & (1 << regnum
))
1156 write_register (regnum
+ FP0_REGNUM
,
1157 read_memory_integer (frame
->saved_regs
[regnum
+ FP0_REGNUM
], 8));
1159 write_register (SP_REGNUM
, new_sp
);
1160 flush_cached_frames ();
1162 if (proc_desc
&& (PROC_DESC_IS_DUMMY (proc_desc
)
1163 || PROC_DESC_IS_DYN_SIGTRAMP (proc_desc
)))
1165 struct linked_proc_info
*pi_ptr
, *prev_ptr
;
1167 for (pi_ptr
= linked_proc_desc_table
, prev_ptr
= NULL
;
1169 prev_ptr
= pi_ptr
, pi_ptr
= pi_ptr
->next
)
1171 if (&pi_ptr
->info
== proc_desc
)
1176 error ("Can't locate dummy extra frame info\n");
1178 if (prev_ptr
!= NULL
)
1179 prev_ptr
->next
= pi_ptr
->next
;
1181 linked_proc_desc_table
= pi_ptr
->next
;
1187 /* To skip prologues, I use this predicate. Returns either PC itself
1188 if the code at PC does not look like a function prologue; otherwise
1189 returns an address that (if we're lucky) follows the prologue. If
1190 LENIENT, then we must skip everything which is involved in setting
1191 up the frame (it's OK to skip more, just so long as we don't skip
1192 anything which might clobber the registers which are being saved.
1193 Currently we must not skip more on the alpha, but we might the lenient
1197 alpha_skip_prologue (pc
, lenient
)
1203 CORE_ADDR post_prologue_pc
;
1206 #ifdef GDB_TARGET_HAS_SHARED_LIBS
1207 /* Silently return the unaltered pc upon memory errors.
1208 This could happen on OSF/1 if decode_line_1 tries to skip the
1209 prologue for quickstarted shared library functions when the
1210 shared library is not yet mapped in.
1211 Reading target memory is slow over serial lines, so we perform
1212 this check only if the target has shared libraries. */
1213 if (target_read_memory (pc
, buf
, 4))
1217 /* See if we can determine the end of the prologue via the symbol table.
1218 If so, then return either PC, or the PC after the prologue, whichever
1221 post_prologue_pc
= after_prologue (pc
, NULL
);
1223 if (post_prologue_pc
!= 0)
1224 return max (pc
, post_prologue_pc
);
1226 /* Can't determine prologue from the symbol table, need to examine
1229 /* Skip the typical prologue instructions. These are the stack adjustment
1230 instruction and the instructions that save registers on the stack
1231 or in the gcc frame. */
1232 for (offset
= 0; offset
< 100; offset
+= 4)
1236 status
= read_memory_nobpt (pc
+ offset
, buf
, 4);
1238 memory_error (status
, pc
+ offset
);
1239 inst
= extract_unsigned_integer (buf
, 4);
1241 /* The alpha has no delay slots. But let's keep the lenient stuff,
1242 we might need it for something else in the future. */
1246 if ((inst
& 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1248 if ((inst
& 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1250 if ((inst
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1252 if ((inst
& 0xffe01fff) == 0x43c0153e) /* subq $sp,n,$sp */
1255 if ((inst
& 0xfc1f0000) == 0xb41e0000
1256 && (inst
& 0xffff0000) != 0xb7fe0000)
1257 continue; /* stq reg,n($sp) */
1259 if ((inst
& 0xfc1f0000) == 0x9c1e0000
1260 && (inst
& 0xffff0000) != 0x9ffe0000)
1261 continue; /* stt reg,n($sp) */
1263 if (inst
== 0x47de040f) /* bis sp,sp,fp */
1272 /* Is address PC in the prologue (loosely defined) for function at
1276 alpha_in_lenient_prologue (startaddr
, pc
)
1277 CORE_ADDR startaddr
;
1280 CORE_ADDR end_prologue
= alpha_skip_prologue (startaddr
, 1);
1281 return pc
>= startaddr
&& pc
< end_prologue
;
1285 /* The alpha needs a conversion between register and memory format if
1286 the register is a floating point register and
1287 memory format is float, as the register format must be double
1289 memory format is an integer with 4 bytes or less, as the representation
1290 of integers in floating point registers is different. */
1292 alpha_register_convert_to_virtual (regnum
, valtype
, raw_buffer
, virtual_buffer
)
1294 struct type
*valtype
;
1296 char *virtual_buffer
;
1298 if (TYPE_LENGTH (valtype
) >= REGISTER_RAW_SIZE (regnum
))
1300 memcpy (virtual_buffer
, raw_buffer
, REGISTER_VIRTUAL_SIZE (regnum
));
1304 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1306 double d
= extract_floating (raw_buffer
, REGISTER_RAW_SIZE (regnum
));
1307 store_floating (virtual_buffer
, TYPE_LENGTH (valtype
), d
);
1309 else if (TYPE_CODE (valtype
) == TYPE_CODE_INT
&& TYPE_LENGTH (valtype
) <= 4)
1312 l
= extract_unsigned_integer (raw_buffer
, REGISTER_RAW_SIZE (regnum
));
1313 l
= ((l
>> 32) & 0xc0000000) | ((l
>> 29) & 0x3fffffff);
1314 store_unsigned_integer (virtual_buffer
, TYPE_LENGTH (valtype
), l
);
1317 error ("Cannot retrieve value from floating point register");
1321 alpha_register_convert_to_raw (valtype
, regnum
, virtual_buffer
, raw_buffer
)
1322 struct type
*valtype
;
1324 char *virtual_buffer
;
1327 if (TYPE_LENGTH (valtype
) >= REGISTER_RAW_SIZE (regnum
))
1329 memcpy (raw_buffer
, virtual_buffer
, REGISTER_RAW_SIZE (regnum
));
1333 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1335 double d
= extract_floating (virtual_buffer
, TYPE_LENGTH (valtype
));
1336 store_floating (raw_buffer
, REGISTER_RAW_SIZE (regnum
), d
);
1338 else if (TYPE_CODE (valtype
) == TYPE_CODE_INT
&& TYPE_LENGTH (valtype
) <= 4)
1341 if (TYPE_UNSIGNED (valtype
))
1342 l
= extract_unsigned_integer (virtual_buffer
, TYPE_LENGTH (valtype
));
1344 l
= extract_signed_integer (virtual_buffer
, TYPE_LENGTH (valtype
));
1345 l
= ((l
& 0xc0000000) << 32) | ((l
& 0x3fffffff) << 29);
1346 store_unsigned_integer (raw_buffer
, REGISTER_RAW_SIZE (regnum
), l
);
1349 error ("Cannot store value in floating point register");
1352 /* Given a return value in `regbuf' with a type `valtype',
1353 extract and copy its value into `valbuf'. */
1356 alpha_extract_return_value (valtype
, regbuf
, valbuf
)
1357 struct type
*valtype
;
1358 char regbuf
[REGISTER_BYTES
];
1361 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1362 alpha_register_convert_to_virtual (FP0_REGNUM
, valtype
,
1363 regbuf
+ REGISTER_BYTE (FP0_REGNUM
),
1366 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (V0_REGNUM
), TYPE_LENGTH (valtype
));
1369 /* Given a return value in `regbuf' with a type `valtype',
1370 write its value into the appropriate register. */
1373 alpha_store_return_value (valtype
, valbuf
)
1374 struct type
*valtype
;
1377 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
1378 int regnum
= V0_REGNUM
;
1379 int length
= TYPE_LENGTH (valtype
);
1381 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1383 regnum
= FP0_REGNUM
;
1384 length
= REGISTER_RAW_SIZE (regnum
);
1385 alpha_register_convert_to_raw (valtype
, regnum
, valbuf
, raw_buffer
);
1388 memcpy (raw_buffer
, valbuf
, length
);
1390 write_register_bytes (REGISTER_BYTE (regnum
), raw_buffer
, length
);
1393 /* Just like reinit_frame_cache, but with the right arguments to be
1394 callable as an sfunc. */
1397 reinit_frame_cache_sfunc (args
, from_tty
, c
)
1400 struct cmd_list_element
*c
;
1402 reinit_frame_cache ();
1405 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1406 to find a convenient place in the text segment to stick a breakpoint to
1407 detect the completion of a target function call (ala call_function_by_hand).
1411 alpha_call_dummy_address ()
1414 struct minimal_symbol
*sym
;
1416 entry
= entry_point_address ();
1421 sym
= lookup_minimal_symbol ("_Prelude", NULL
, symfile_objfile
);
1423 if (!sym
|| MSYMBOL_TYPE (sym
) != mst_text
)
1426 return SYMBOL_VALUE_ADDRESS (sym
) + 4;
1430 _initialize_alpha_tdep ()
1432 struct cmd_list_element
*c
;
1434 tm_print_insn
= print_insn_alpha
;
1436 /* Let the user set the fence post for heuristic_proc_start. */
1438 /* We really would like to have both "0" and "unlimited" work, but
1439 command.c doesn't deal with that. So make it a var_zinteger
1440 because the user can always use "999999" or some such for unlimited. */
1441 c
= add_set_cmd ("heuristic-fence-post", class_support
, var_zinteger
,
1442 (char *) &heuristic_fence_post
,
1444 Set the distance searched for the start of a function.\n\
1445 If you are debugging a stripped executable, GDB needs to search through the\n\
1446 program for the start of a function. This command sets the distance of the\n\
1447 search. The only need to set it is when debugging a stripped executable.",
1449 /* We need to throw away the frame cache when we set this, since it
1450 might change our ability to get backtraces. */
1451 c
->function
.sfunc
= reinit_frame_cache_sfunc
;
1452 add_show_from_set (c
, &showlist
);