1 /* Target-dependent code for the ALPHA architecture, for GDB, the GNU Debugger.
2 Copyright 1993, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
30 #include "gdb_string.h"
32 /* FIXME: Some of this code should perhaps be merged with mips-tdep.c. */
34 /* Prototypes for local functions. */
36 static alpha_extra_func_info_t push_sigtramp_desc
PARAMS ((CORE_ADDR low_addr
));
38 static CORE_ADDR read_next_frame_reg
PARAMS ((struct frame_info
*, int));
40 static CORE_ADDR heuristic_proc_start
PARAMS ((CORE_ADDR
));
42 static alpha_extra_func_info_t heuristic_proc_desc
PARAMS ((CORE_ADDR
,
44 struct frame_info
*));
46 static alpha_extra_func_info_t find_proc_desc
PARAMS ((CORE_ADDR
,
47 struct frame_info
*));
50 static int alpha_in_lenient_prologue
PARAMS ((CORE_ADDR
, CORE_ADDR
));
53 static void reinit_frame_cache_sfunc
PARAMS ((char *, int,
54 struct cmd_list_element
*));
56 static CORE_ADDR after_prologue
PARAMS ((CORE_ADDR pc
,
57 alpha_extra_func_info_t proc_desc
));
59 static int alpha_in_prologue
PARAMS ((CORE_ADDR pc
,
60 alpha_extra_func_info_t proc_desc
));
62 static int alpha_about_to_return
PARAMS ((CORE_ADDR pc
));
64 void _initialize_alpha_tdep
PARAMS ((void));
66 /* Heuristic_proc_start may hunt through the text section for a long
67 time across a 2400 baud serial line. Allows the user to limit this
69 static unsigned int heuristic_fence_post
= 0;
71 /* Layout of a stack frame on the alpha:
74 pdr members: | 7th ... nth arg, |
75 | `pushed' by caller. |
77 ----------------|-------------------------------|<-- old_sp == vfp
80 | |localoff | Copies of 1st .. 6th |
81 | | | | | argument if necessary. |
83 | | | --- |-------------------------------|<-- FRAME_LOCALS_ADDRESS
85 | | | | Locals and temporaries. |
87 | | | |-------------------------------|
89 |-fregoffset | Saved float registers. |
95 | | -------|-------------------------------|
97 | | | Saved registers. |
104 | ----------|-------------------------------|
106 frameoffset | Argument build area, gets |
107 | | 7th ... nth arg for any |
108 | | called procedure. |
110 -------------|-------------------------------|<-- sp
114 #define PROC_LOW_ADDR(proc) ((proc)->pdr.adr) /* least address */
115 /* These next two fields are kind of being hijacked. I wonder if
116 iline is too small for the values it needs to hold, if GDB is
117 running on a 32-bit host. */
118 #define PROC_HIGH_ADDR(proc) ((proc)->pdr.iline) /* upper address bound */
119 #define PROC_DUMMY_FRAME(proc) ((proc)->pdr.cbLineOffset) /*CALL_DUMMY frame */
120 #define PROC_FRAME_OFFSET(proc) ((proc)->pdr.frameoffset)
121 #define PROC_FRAME_REG(proc) ((proc)->pdr.framereg)
122 #define PROC_REG_MASK(proc) ((proc)->pdr.regmask)
123 #define PROC_FREG_MASK(proc) ((proc)->pdr.fregmask)
124 #define PROC_REG_OFFSET(proc) ((proc)->pdr.regoffset)
125 #define PROC_FREG_OFFSET(proc) ((proc)->pdr.fregoffset)
126 #define PROC_PC_REG(proc) ((proc)->pdr.pcreg)
127 #define PROC_LOCALOFF(proc) ((proc)->pdr.localoff)
128 #define PROC_SYMBOL(proc) (*(struct symbol**)&(proc)->pdr.isym)
129 #define _PROC_MAGIC_ 0x0F0F0F0F
130 #define PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym == _PROC_MAGIC_)
131 #define SET_PROC_DESC_IS_DUMMY(proc) ((proc)->pdr.isym = _PROC_MAGIC_)
133 struct linked_proc_info
135 struct alpha_extra_func_info info
;
136 struct linked_proc_info
*next
;
137 } *linked_proc_desc_table
= NULL
;
140 /* Under GNU/Linux, signal handler invocations can be identified by the
141 designated code sequence that is used to return from a signal
142 handler. In particular, the return address of a signal handler
143 points to the following sequence (the first instruction is quadword
150 Each instruction has a unique encoding, so we simply attempt to
151 match the instruction the pc is pointing to with any of the above
152 instructions. If there is a hit, we know the offset to the start
153 of the designated sequence and can then check whether we really are
154 executing in a designated sequence. If not, -1 is returned,
155 otherwise the offset from the start of the desingated sequence is
158 There is a slight chance of false hits: code could jump into the
159 middle of the designated sequence, in which case there is no
160 guarantee that we are in the middle of a sigreturn syscall. Don't
161 think this will be a problem in praxis, though.
164 #ifndef TM_LINUXALPHA_H
165 /* HACK: Provide a prototype when compiling this file for non
166 linuxalpha targets. */
167 long alpha_linux_sigtramp_offset
PARAMS ((CORE_ADDR pc
));
170 alpha_linux_sigtramp_offset (pc
)
173 unsigned int i
[3], w
;
176 if (read_memory_nobpt(pc
, (char *) &w
, 4) != 0)
182 case 0x47de0410: off
= 0; break; /* bis $30,$30,$16 */
183 case 0x43ecf400: off
= 4; break; /* addq $31,0x67,$0 */
184 case 0x00000083: off
= 8; break; /* call_pal callsys */
190 /* designated sequence is not quadword aligned */
194 if (read_memory_nobpt(pc
, (char *) i
, sizeof(i
)) != 0)
197 if (i
[0] == 0x47de0410 && i
[1] == 0x43ecf400 && i
[2] == 0x00000083)
204 /* Under OSF/1, the __sigtramp routine is frameless and has a frame
205 size of zero, but we are able to backtrace through it. */
207 alpha_osf_skip_sigtramp_frame (frame
, pc
)
208 struct frame_info
*frame
;
212 find_pc_partial_function (pc
, &name
, (CORE_ADDR
*)NULL
, (CORE_ADDR
*)NULL
);
213 if (IN_SIGTRAMP (pc
, name
))
220 /* Dynamically create a signal-handler caller procedure descriptor for
221 the signal-handler return code starting at address LOW_ADDR. The
222 descriptor is added to the linked_proc_desc_table. */
224 static alpha_extra_func_info_t
225 push_sigtramp_desc (low_addr
)
228 struct linked_proc_info
*link
;
229 alpha_extra_func_info_t proc_desc
;
231 link
= (struct linked_proc_info
*)
232 xmalloc (sizeof (struct linked_proc_info
));
233 link
->next
= linked_proc_desc_table
;
234 linked_proc_desc_table
= link
;
236 proc_desc
= &link
->info
;
238 proc_desc
->numargs
= 0;
239 PROC_LOW_ADDR (proc_desc
) = low_addr
;
240 PROC_HIGH_ADDR (proc_desc
) = low_addr
+ 3 * 4;
241 PROC_DUMMY_FRAME (proc_desc
) = 0;
242 PROC_FRAME_OFFSET (proc_desc
) = 0x298; /* sizeof(struct sigcontext_struct) */
243 PROC_FRAME_REG (proc_desc
) = SP_REGNUM
;
244 PROC_REG_MASK (proc_desc
) = 0xffff;
245 PROC_FREG_MASK (proc_desc
) = 0xffff;
246 PROC_PC_REG (proc_desc
) = 26;
247 PROC_LOCALOFF (proc_desc
) = 0;
248 SET_PROC_DESC_IS_DYN_SIGTRAMP (proc_desc
);
253 /* Guaranteed to set frame->saved_regs to some values (it never leaves it
257 alpha_find_saved_regs (frame
)
258 struct frame_info
*frame
;
261 CORE_ADDR reg_position
;
263 alpha_extra_func_info_t proc_desc
;
266 frame_saved_regs_zalloc (frame
);
268 /* If it is the frame for __sigtramp, the saved registers are located
269 in a sigcontext structure somewhere on the stack. __sigtramp
270 passes a pointer to the sigcontext structure on the stack.
271 If the stack layout for __sigtramp changes, or if sigcontext offsets
272 change, we might have to update this code. */
273 #ifndef SIGFRAME_PC_OFF
274 #define SIGFRAME_PC_OFF (2 * 8)
275 #define SIGFRAME_REGSAVE_OFF (4 * 8)
276 #define SIGFRAME_FPREGSAVE_OFF (SIGFRAME_REGSAVE_OFF + 32 * 8 + 8)
278 if (frame
->signal_handler_caller
)
280 CORE_ADDR sigcontext_addr
;
282 sigcontext_addr
= SIGCONTEXT_ADDR (frame
);
283 for (ireg
= 0; ireg
< 32; ireg
++)
285 reg_position
= sigcontext_addr
+ SIGFRAME_REGSAVE_OFF
+ ireg
* 8;
286 frame
->saved_regs
[ireg
] = reg_position
;
288 for (ireg
= 0; ireg
< 32; ireg
++)
290 reg_position
= sigcontext_addr
+ SIGFRAME_FPREGSAVE_OFF
+ ireg
* 8;
291 frame
->saved_regs
[FP0_REGNUM
+ ireg
] = reg_position
;
293 frame
->saved_regs
[PC_REGNUM
] = sigcontext_addr
+ SIGFRAME_PC_OFF
;
297 proc_desc
= frame
->proc_desc
;
298 if (proc_desc
== NULL
)
299 /* I'm not sure how/whether this can happen. Normally when we can't
300 find a proc_desc, we "synthesize" one using heuristic_proc_desc
301 and set the saved_regs right away. */
304 /* Fill in the offsets for the registers which gen_mask says
307 reg_position
= frame
->frame
+ PROC_REG_OFFSET (proc_desc
);
308 mask
= PROC_REG_MASK (proc_desc
);
310 returnreg
= PROC_PC_REG (proc_desc
);
312 /* Note that RA is always saved first, regardless of its actual
314 if (mask
& (1 << returnreg
))
316 frame
->saved_regs
[returnreg
] = reg_position
;
318 mask
&= ~(1 << returnreg
); /* Clear bit for RA so we
319 don't save again later. */
322 for (ireg
= 0; ireg
<= 31 ; ++ireg
)
323 if (mask
& (1 << ireg
))
325 frame
->saved_regs
[ireg
] = reg_position
;
329 /* Fill in the offsets for the registers which float_mask says
332 reg_position
= frame
->frame
+ PROC_FREG_OFFSET (proc_desc
);
333 mask
= PROC_FREG_MASK (proc_desc
);
335 for (ireg
= 0; ireg
<= 31 ; ++ireg
)
336 if (mask
& (1 << ireg
))
338 frame
->saved_regs
[FP0_REGNUM
+ireg
] = reg_position
;
342 frame
->saved_regs
[PC_REGNUM
] = frame
->saved_regs
[returnreg
];
346 read_next_frame_reg(fi
, regno
)
347 struct frame_info
*fi
;
350 for (; fi
; fi
= fi
->next
)
352 /* We have to get the saved sp from the sigcontext
353 if it is a signal handler frame. */
354 if (regno
== SP_REGNUM
&& !fi
->signal_handler_caller
)
358 if (fi
->saved_regs
== NULL
)
359 alpha_find_saved_regs (fi
);
360 if (fi
->saved_regs
[regno
])
361 return read_memory_integer(fi
->saved_regs
[regno
], 8);
364 return read_register(regno
);
368 alpha_frame_saved_pc(frame
)
369 struct frame_info
*frame
;
371 alpha_extra_func_info_t proc_desc
= frame
->proc_desc
;
372 /* We have to get the saved pc from the sigcontext
373 if it is a signal handler frame. */
374 int pcreg
= frame
->signal_handler_caller
? PC_REGNUM
: frame
->pc_reg
;
376 if (proc_desc
&& PROC_DESC_IS_DUMMY(proc_desc
))
377 return read_memory_integer(frame
->frame
- 8, 8);
379 return read_next_frame_reg(frame
, pcreg
);
383 alpha_saved_pc_after_call (frame
)
384 struct frame_info
*frame
;
386 CORE_ADDR pc
= frame
->pc
;
388 alpha_extra_func_info_t proc_desc
;
391 /* Skip over shared library trampoline if necessary. */
392 tmp
= SKIP_TRAMPOLINE_CODE (pc
);
396 proc_desc
= find_proc_desc (pc
, frame
->next
);
397 pcreg
= proc_desc
? PROC_PC_REG (proc_desc
) : RA_REGNUM
;
399 if (frame
->signal_handler_caller
)
400 return alpha_frame_saved_pc (frame
);
402 return read_register (pcreg
);
406 static struct alpha_extra_func_info temp_proc_desc
;
407 static struct frame_saved_regs temp_saved_regs
;
409 /* Nonzero if instruction at PC is a return instruction. "ret
410 $zero,($ra),1" on alpha. */
413 alpha_about_to_return (pc
)
416 return read_memory_integer (pc
, 4) == 0x6bfa8001;
421 /* This fencepost looks highly suspicious to me. Removing it also
422 seems suspicious as it could affect remote debugging across serial
426 heuristic_proc_start(pc
)
429 CORE_ADDR start_pc
= pc
;
430 CORE_ADDR fence
= start_pc
- heuristic_fence_post
;
432 if (start_pc
== 0) return 0;
434 if (heuristic_fence_post
== UINT_MAX
435 || fence
< VM_MIN_ADDRESS
)
436 fence
= VM_MIN_ADDRESS
;
438 /* search back for previous return */
439 for (start_pc
-= 4; ; start_pc
-= 4)
440 if (start_pc
< fence
)
442 /* It's not clear to me why we reach this point when
443 stop_soon_quietly, but with this test, at least we
444 don't print out warnings for every child forked (eg, on
445 decstation). 22apr93 rich@cygnus.com. */
446 if (!stop_soon_quietly
)
448 static int blurb_printed
= 0;
450 if (fence
== VM_MIN_ADDRESS
)
451 warning("Hit beginning of text section without finding");
453 warning("Hit heuristic-fence-post without finding");
455 warning("enclosing function for address 0x%lx", pc
);
459 This warning occurs if you are debugging a function without any symbols\n\
460 (for example, in a stripped executable). In that case, you may wish to\n\
461 increase the size of the search with the `set heuristic-fence-post' command.\n\
463 Otherwise, you told GDB there was a function where there isn't one, or\n\
464 (more likely) you have encountered a bug in GDB.\n");
471 else if (alpha_about_to_return (start_pc
))
474 start_pc
+= 4; /* skip return */
478 static alpha_extra_func_info_t
479 heuristic_proc_desc(start_pc
, limit_pc
, next_frame
)
480 CORE_ADDR start_pc
, limit_pc
;
481 struct frame_info
*next_frame
;
483 CORE_ADDR sp
= read_next_frame_reg (next_frame
, SP_REGNUM
);
486 int has_frame_reg
= 0;
487 unsigned long reg_mask
= 0;
492 memset (&temp_proc_desc
, '\0', sizeof(temp_proc_desc
));
493 memset (&temp_saved_regs
, '\0', sizeof(struct frame_saved_regs
));
494 PROC_LOW_ADDR (&temp_proc_desc
) = start_pc
;
496 if (start_pc
+ 200 < limit_pc
)
497 limit_pc
= start_pc
+ 200;
499 for (cur_pc
= start_pc
; cur_pc
< limit_pc
; cur_pc
+= 4)
505 status
= read_memory_nobpt (cur_pc
, buf
, 4);
507 memory_error (status
, cur_pc
);
508 word
= extract_unsigned_integer (buf
, 4);
510 if ((word
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
513 frame_size
+= (-word
) & 0xffff;
515 /* Exit loop if a positive stack adjustment is found, which
516 usually means that the stack cleanup code in the function
517 epilogue is reached. */
520 else if ((word
& 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
521 && (word
& 0xffff0000) != 0xb7fe0000) /* reg != $zero */
523 int reg
= (word
& 0x03e00000) >> 21;
524 reg_mask
|= 1 << reg
;
525 temp_saved_regs
.regs
[reg
] = sp
+ (short)word
;
527 /* Starting with OSF/1-3.2C, the system libraries are shipped
528 without local symbols, but they still contain procedure
529 descriptors without a symbol reference. GDB is currently
530 unable to find these procedure descriptors and uses
531 heuristic_proc_desc instead.
532 As some low level compiler support routines (__div*, __add*)
533 use a non-standard return address register, we have to
534 add some heuristics to determine the return address register,
535 or stepping over these routines will fail.
536 Usually the return address register is the first register
537 saved on the stack, but assembler optimization might
538 rearrange the register saves.
539 So we recognize only a few registers (t7, t9, ra) within
540 the procedure prologue as valid return address registers.
541 If we encounter a return instruction, we extract the
542 the return address register from it.
544 FIXME: Rewriting GDB to access the procedure descriptors,
545 e.g. via the minimal symbol table, might obviate this hack. */
547 && cur_pc
< (start_pc
+ 80)
548 && (reg
== T7_REGNUM
|| reg
== T9_REGNUM
|| reg
== RA_REGNUM
))
551 else if ((word
& 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
552 pcreg
= (word
>> 16) & 0x1f;
553 else if (word
== 0x47de040f) /* bis sp,sp fp */
558 /* If we haven't found a valid return address register yet,
559 keep searching in the procedure prologue. */
560 while (cur_pc
< (limit_pc
+ 80) && cur_pc
< (start_pc
+ 80))
565 if (read_memory_nobpt (cur_pc
, buf
, 4))
568 word
= extract_unsigned_integer (buf
, 4);
570 if ((word
& 0xfc1f0000) == 0xb41e0000 /* stq reg,n($sp) */
571 && (word
& 0xffff0000) != 0xb7fe0000) /* reg != $zero */
573 int reg
= (word
& 0x03e00000) >> 21;
574 if (reg
== T7_REGNUM
|| reg
== T9_REGNUM
|| reg
== RA_REGNUM
)
580 else if ((word
& 0xffe0ffff) == 0x6be08001) /* ret zero,reg,1 */
582 pcreg
= (word
>> 16) & 0x1f;
589 PROC_FRAME_REG(&temp_proc_desc
) = GCC_FP_REGNUM
;
591 PROC_FRAME_REG(&temp_proc_desc
) = SP_REGNUM
;
592 PROC_FRAME_OFFSET(&temp_proc_desc
) = frame_size
;
593 PROC_REG_MASK(&temp_proc_desc
) = reg_mask
;
594 PROC_PC_REG(&temp_proc_desc
) = (pcreg
== -1) ? RA_REGNUM
: pcreg
;
595 PROC_LOCALOFF(&temp_proc_desc
) = 0; /* XXX - bogus */
596 return &temp_proc_desc
;
599 /* This returns the PC of the first inst after the prologue. If we can't
600 find the prologue, then return 0. */
603 after_prologue (pc
, proc_desc
)
605 alpha_extra_func_info_t proc_desc
;
607 struct symtab_and_line sal
;
608 CORE_ADDR func_addr
, func_end
;
611 proc_desc
= find_proc_desc (pc
, NULL
);
615 if (PROC_DESC_IS_DYN_SIGTRAMP (proc_desc
))
616 return PROC_LOW_ADDR (proc_desc
); /* "prologue" is in kernel */
618 /* If function is frameless, then we need to do it the hard way. I
619 strongly suspect that frameless always means prologueless... */
620 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
621 && PROC_FRAME_OFFSET (proc_desc
) == 0)
625 if (!find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
626 return 0; /* Unknown */
628 sal
= find_pc_line (func_addr
, 0);
630 if (sal
.end
< func_end
)
633 /* The line after the prologue is after the end of the function. In this
634 case, tell the caller to find the prologue the hard way. */
639 /* Return non-zero if we *might* be in a function prologue. Return zero if we
640 are definitively *not* in a function prologue. */
643 alpha_in_prologue (pc
, proc_desc
)
645 alpha_extra_func_info_t proc_desc
;
647 CORE_ADDR after_prologue_pc
;
649 after_prologue_pc
= after_prologue (pc
, proc_desc
);
651 if (after_prologue_pc
== 0
652 || pc
< after_prologue_pc
)
658 static alpha_extra_func_info_t
659 find_proc_desc (pc
, next_frame
)
661 struct frame_info
*next_frame
;
663 alpha_extra_func_info_t proc_desc
;
668 /* Try to get the proc_desc from the linked call dummy proc_descs
669 if the pc is in the call dummy.
670 This is hairy. In the case of nested dummy calls we have to find the
671 right proc_desc, but we might not yet know the frame for the dummy
672 as it will be contained in the proc_desc we are searching for.
673 So we have to find the proc_desc whose frame is closest to the current
676 if (PC_IN_CALL_DUMMY (pc
, 0, 0))
678 struct linked_proc_info
*link
;
679 CORE_ADDR sp
= read_next_frame_reg (next_frame
, SP_REGNUM
);
680 alpha_extra_func_info_t found_proc_desc
= NULL
;
681 long min_distance
= LONG_MAX
;
683 for (link
= linked_proc_desc_table
; link
; link
= link
->next
)
685 long distance
= (CORE_ADDR
) PROC_DUMMY_FRAME (&link
->info
) - sp
;
686 if (distance
> 0 && distance
< min_distance
)
688 min_distance
= distance
;
689 found_proc_desc
= &link
->info
;
692 if (found_proc_desc
!= NULL
)
693 return found_proc_desc
;
696 b
= block_for_pc(pc
);
698 find_pc_partial_function (pc
, NULL
, &startaddr
, NULL
);
703 if (startaddr
> BLOCK_START (b
))
704 /* This is the "pathological" case referred to in a comment in
705 print_frame_info. It might be better to move this check into
709 sym
= lookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
,
713 /* If we never found a PDR for this function in symbol reading, then
714 examine prologues to find the information. */
715 if (sym
&& ((mips_extra_func_info_t
) SYMBOL_VALUE (sym
))->pdr
.framereg
== -1)
720 /* IF this is the topmost frame AND
721 * (this proc does not have debugging information OR
722 * the PC is in the procedure prologue)
723 * THEN create a "heuristic" proc_desc (by analyzing
724 * the actual code) to replace the "official" proc_desc.
726 proc_desc
= (alpha_extra_func_info_t
)SYMBOL_VALUE(sym
);
727 if (next_frame
== NULL
)
729 if (PROC_DESC_IS_DUMMY (proc_desc
) || alpha_in_prologue (pc
, proc_desc
))
731 alpha_extra_func_info_t found_heuristic
=
732 heuristic_proc_desc (PROC_LOW_ADDR (proc_desc
),
736 PROC_LOCALOFF (found_heuristic
) =
737 PROC_LOCALOFF (proc_desc
);
738 PROC_PC_REG (found_heuristic
) = PROC_PC_REG (proc_desc
);
739 proc_desc
= found_heuristic
;
748 /* Is linked_proc_desc_table really necessary? It only seems to be used
749 by procedure call dummys. However, the procedures being called ought
750 to have their own proc_descs, and even if they don't,
751 heuristic_proc_desc knows how to create them! */
753 register struct linked_proc_info
*link
;
754 for (link
= linked_proc_desc_table
; link
; link
= link
->next
)
755 if (PROC_LOW_ADDR(&link
->info
) <= pc
756 && PROC_HIGH_ADDR(&link
->info
) > pc
)
759 /* If PC is inside a dynamically generated sigtramp handler,
760 create and push a procedure descriptor for that code: */
761 offset
= DYNAMIC_SIGTRAMP_OFFSET (pc
);
763 return push_sigtramp_desc (pc
- offset
);
765 /* If heuristic_fence_post is non-zero, determine the procedure
766 start address by examining the instructions.
767 This allows us to find the start address of static functions which
768 have no symbolic information, as startaddr would have been set to
769 the preceding global function start address by the
770 find_pc_partial_function call above. */
771 if (startaddr
== 0 || heuristic_fence_post
!= 0)
772 startaddr
= heuristic_proc_start (pc
);
775 heuristic_proc_desc (startaddr
, pc
, next_frame
);
780 alpha_extra_func_info_t cached_proc_desc
;
783 alpha_frame_chain(frame
)
784 struct frame_info
*frame
;
786 alpha_extra_func_info_t proc_desc
;
787 CORE_ADDR saved_pc
= FRAME_SAVED_PC(frame
);
789 if (saved_pc
== 0 || inside_entry_file (saved_pc
))
792 proc_desc
= find_proc_desc(saved_pc
, frame
);
796 cached_proc_desc
= proc_desc
;
798 /* Fetch the frame pointer for a dummy frame from the procedure
800 if (PROC_DESC_IS_DUMMY(proc_desc
))
801 return (CORE_ADDR
) PROC_DUMMY_FRAME(proc_desc
);
803 /* If no frame pointer and frame size is zero, we must be at end
804 of stack (or otherwise hosed). If we don't check frame size,
805 we loop forever if we see a zero size frame. */
806 if (PROC_FRAME_REG (proc_desc
) == SP_REGNUM
807 && PROC_FRAME_OFFSET (proc_desc
) == 0
808 /* The previous frame from a sigtramp frame might be frameless
809 and have frame size zero. */
810 && !frame
->signal_handler_caller
)
811 return FRAME_PAST_SIGTRAMP_FRAME (frame
, saved_pc
);
813 return read_next_frame_reg(frame
, PROC_FRAME_REG(proc_desc
))
814 + PROC_FRAME_OFFSET(proc_desc
);
818 init_extra_frame_info (frame
)
819 struct frame_info
*frame
;
821 /* Use proc_desc calculated in frame_chain */
822 alpha_extra_func_info_t proc_desc
=
823 frame
->next
? cached_proc_desc
: find_proc_desc(frame
->pc
, frame
->next
);
825 frame
->saved_regs
= NULL
;
827 frame
->pc_reg
= RA_REGNUM
;
828 frame
->proc_desc
= proc_desc
== &temp_proc_desc
? 0 : proc_desc
;
831 /* Get the locals offset and the saved pc register from the
832 procedure descriptor, they are valid even if we are in the
833 middle of the prologue. */
834 frame
->localoff
= PROC_LOCALOFF(proc_desc
);
835 frame
->pc_reg
= PROC_PC_REG(proc_desc
);
837 /* Fixup frame-pointer - only needed for top frame */
839 /* Fetch the frame pointer for a dummy frame from the procedure
841 if (PROC_DESC_IS_DUMMY(proc_desc
))
842 frame
->frame
= (CORE_ADDR
) PROC_DUMMY_FRAME(proc_desc
);
844 /* This may not be quite right, if proc has a real frame register.
845 Get the value of the frame relative sp, procedure might have been
846 interrupted by a signal at it's very start. */
847 else if (frame
->pc
== PROC_LOW_ADDR (proc_desc
)
848 && !PROC_DESC_IS_DYN_SIGTRAMP (proc_desc
))
849 frame
->frame
= read_next_frame_reg (frame
->next
, SP_REGNUM
);
851 frame
->frame
= read_next_frame_reg (frame
->next
, PROC_FRAME_REG (proc_desc
))
852 + PROC_FRAME_OFFSET (proc_desc
);
854 if (proc_desc
== &temp_proc_desc
)
858 /* Do not set the saved registers for a sigtramp frame,
859 alpha_find_saved_registers will do that for us.
860 We can't use frame->signal_handler_caller, it is not yet set. */
861 find_pc_partial_function (frame
->pc
, &name
,
862 (CORE_ADDR
*)NULL
,(CORE_ADDR
*)NULL
);
863 if (!IN_SIGTRAMP (frame
->pc
, name
))
865 frame
->saved_regs
= (CORE_ADDR
*)
866 frame_obstack_alloc (SIZEOF_FRAME_SAVED_REGS
);
867 memcpy (frame
->saved_regs
, temp_saved_regs
.regs
, SIZEOF_FRAME_SAVED_REGS
);
868 frame
->saved_regs
[PC_REGNUM
]
869 = frame
->saved_regs
[RA_REGNUM
];
875 /* ALPHA stack frames are almost impenetrable. When execution stops,
876 we basically have to look at symbol information for the function
877 that we stopped in, which tells us *which* register (if any) is
878 the base of the frame pointer, and what offset from that register
879 the frame itself is at.
881 This presents a problem when trying to examine a stack in memory
882 (that isn't executing at the moment), using the "frame" command. We
883 don't have a PC, nor do we have any registers except SP.
885 This routine takes two arguments, SP and PC, and tries to make the
886 cached frames look as if these two arguments defined a frame on the
887 cache. This allows the rest of info frame to extract the important
888 arguments without difficulty. */
891 setup_arbitrary_frame (argc
, argv
)
896 error ("ALPHA frame specifications require two arguments: sp and pc");
898 return create_new_frame (argv
[0], argv
[1]);
901 /* The alpha passes the first six arguments in the registers, the rest on
902 the stack. The register arguments are eventually transferred to the
903 argument transfer area immediately below the stack by the called function
904 anyway. So we `push' at least six arguments on the stack, `reload' the
905 argument registers and then adjust the stack pointer to point past the
906 sixth argument. This algorithm simplifies the passing of a large struct
907 which extends from the registers to the stack.
908 If the called function is returning a structure, the address of the
909 structure to be returned is passed as a hidden first argument. */
912 alpha_push_arguments (nargs
, args
, sp
, struct_return
, struct_addr
)
917 CORE_ADDR struct_addr
;
920 int accumulate_size
= struct_return
? 8 : 0;
921 int arg_regs_size
= ALPHA_NUM_ARG_REGS
* 8;
922 struct alpha_arg
{ char *contents
; int len
; int offset
; };
923 struct alpha_arg
*alpha_args
=
924 (struct alpha_arg
*)alloca (nargs
* sizeof (struct alpha_arg
));
925 register struct alpha_arg
*m_arg
;
926 char raw_buffer
[sizeof (CORE_ADDR
)];
927 int required_arg_regs
;
929 for (i
= 0, m_arg
= alpha_args
; i
< nargs
; i
++, m_arg
++)
931 value_ptr arg
= args
[i
];
932 struct type
*arg_type
= check_typedef (VALUE_TYPE (arg
));
933 /* Cast argument to long if necessary as the compiler does it too. */
934 switch (TYPE_CODE (arg_type
))
939 case TYPE_CODE_RANGE
:
941 if (TYPE_LENGTH (arg_type
) < TYPE_LENGTH (builtin_type_long
))
943 arg_type
= builtin_type_long
;
944 arg
= value_cast (arg_type
, arg
);
950 m_arg
->len
= TYPE_LENGTH (arg_type
);
951 m_arg
->offset
= accumulate_size
;
952 accumulate_size
= (accumulate_size
+ m_arg
->len
+ 7) & ~7;
953 m_arg
->contents
= VALUE_CONTENTS(arg
);
956 /* Determine required argument register loads, loading an argument register
957 is expensive as it uses three ptrace calls. */
958 required_arg_regs
= accumulate_size
/ 8;
959 if (required_arg_regs
> ALPHA_NUM_ARG_REGS
)
960 required_arg_regs
= ALPHA_NUM_ARG_REGS
;
962 /* Make room for the arguments on the stack. */
963 if (accumulate_size
< arg_regs_size
)
964 accumulate_size
= arg_regs_size
;
965 sp
-= accumulate_size
;
967 /* Keep sp aligned to a multiple of 16 as the compiler does it too. */
970 /* `Push' arguments on the stack. */
971 for (i
= nargs
; m_arg
--, --i
>= 0; )
972 write_memory(sp
+ m_arg
->offset
, m_arg
->contents
, m_arg
->len
);
975 store_address (raw_buffer
, sizeof (CORE_ADDR
), struct_addr
);
976 write_memory (sp
, raw_buffer
, sizeof (CORE_ADDR
));
979 /* Load the argument registers. */
980 for (i
= 0; i
< required_arg_regs
; i
++)
984 val
= read_memory_integer (sp
+ i
* 8, 8);
985 write_register (A0_REGNUM
+ i
, val
);
986 write_register (FPA0_REGNUM
+ i
, val
);
989 return sp
+ arg_regs_size
;
993 alpha_push_dummy_frame()
996 struct linked_proc_info
*link
;
997 alpha_extra_func_info_t proc_desc
;
998 CORE_ADDR sp
= read_register (SP_REGNUM
);
999 CORE_ADDR save_address
;
1000 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
1003 link
= (struct linked_proc_info
*) xmalloc(sizeof (struct linked_proc_info
));
1004 link
->next
= linked_proc_desc_table
;
1005 linked_proc_desc_table
= link
;
1007 proc_desc
= &link
->info
;
1010 * The registers we must save are all those not preserved across
1012 * In addition, we must save the PC and RA.
1014 * Dummy frame layout:
1024 * Parameter build area
1028 /* MASK(i,j) == (1<<i) + (1<<(i+1)) + ... + (1<<j)). Assume i<=j<31. */
1029 #define MASK(i,j) ((((LONGEST)1 << ((j)+1)) - 1) ^ (((LONGEST)1 << (i)) - 1))
1030 #define GEN_REG_SAVE_MASK (MASK(0,8) | MASK(16,29))
1031 #define GEN_REG_SAVE_COUNT 24
1032 #define FLOAT_REG_SAVE_MASK (MASK(0,1) | MASK(10,30))
1033 #define FLOAT_REG_SAVE_COUNT 23
1034 /* The special register is the PC as we have no bit for it in the save masks.
1035 alpha_frame_saved_pc knows where the pc is saved in a dummy frame. */
1036 #define SPECIAL_REG_SAVE_COUNT 1
1038 PROC_REG_MASK(proc_desc
) = GEN_REG_SAVE_MASK
;
1039 PROC_FREG_MASK(proc_desc
) = FLOAT_REG_SAVE_MASK
;
1040 /* PROC_REG_OFFSET is the offset from the dummy frame to the saved RA,
1041 but keep SP aligned to a multiple of 16. */
1042 PROC_REG_OFFSET(proc_desc
) =
1043 - ((8 * (SPECIAL_REG_SAVE_COUNT
1044 + GEN_REG_SAVE_COUNT
1045 + FLOAT_REG_SAVE_COUNT
)
1047 PROC_FREG_OFFSET(proc_desc
) =
1048 PROC_REG_OFFSET(proc_desc
) + 8 * GEN_REG_SAVE_COUNT
;
1050 /* Save general registers.
1051 The return address register is the first saved register, all other
1052 registers follow in ascending order.
1053 The PC is saved immediately below the SP. */
1054 save_address
= sp
+ PROC_REG_OFFSET(proc_desc
);
1055 store_address (raw_buffer
, 8, read_register (RA_REGNUM
));
1056 write_memory (save_address
, raw_buffer
, 8);
1058 mask
= PROC_REG_MASK(proc_desc
) & 0xffffffffL
;
1059 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
1062 if (ireg
== RA_REGNUM
)
1064 store_address (raw_buffer
, 8, read_register (ireg
));
1065 write_memory (save_address
, raw_buffer
, 8);
1069 store_address (raw_buffer
, 8, read_register (PC_REGNUM
));
1070 write_memory (sp
- 8, raw_buffer
, 8);
1072 /* Save floating point registers. */
1073 save_address
= sp
+ PROC_FREG_OFFSET(proc_desc
);
1074 mask
= PROC_FREG_MASK(proc_desc
) & 0xffffffffL
;
1075 for (ireg
= 0; mask
; ireg
++, mask
>>= 1)
1078 store_address (raw_buffer
, 8, read_register (ireg
+ FP0_REGNUM
));
1079 write_memory (save_address
, raw_buffer
, 8);
1083 /* Set and save the frame address for the dummy.
1084 This is tricky. The only registers that are suitable for a frame save
1085 are those that are preserved across procedure calls (s0-s6). But if
1086 a read system call is interrupted and then a dummy call is made
1087 (see testsuite/gdb.t17/interrupt.exp) the dummy call hangs till the read
1088 is satisfied. Then it returns with the s0-s6 registers set to the values
1089 on entry to the read system call and our dummy frame pointer would be
1090 destroyed. So we save the dummy frame in the proc_desc and handle the
1091 retrieval of the frame pointer of a dummy specifically. The frame register
1092 is set to the virtual frame (pseudo) register, it's value will always
1093 be read as zero and will help us to catch any errors in the dummy frame
1095 PROC_DUMMY_FRAME(proc_desc
) = sp
;
1096 PROC_FRAME_REG(proc_desc
) = FP_REGNUM
;
1097 PROC_FRAME_OFFSET(proc_desc
) = 0;
1098 sp
+= PROC_REG_OFFSET(proc_desc
);
1099 write_register (SP_REGNUM
, sp
);
1101 PROC_LOW_ADDR(proc_desc
) = CALL_DUMMY_ADDRESS ();
1102 PROC_HIGH_ADDR(proc_desc
) = PROC_LOW_ADDR(proc_desc
) + 4;
1104 SET_PROC_DESC_IS_DUMMY(proc_desc
);
1105 PROC_PC_REG(proc_desc
) = RA_REGNUM
;
1111 register int regnum
;
1112 struct frame_info
*frame
= get_current_frame ();
1113 CORE_ADDR new_sp
= frame
->frame
;
1115 alpha_extra_func_info_t proc_desc
= frame
->proc_desc
;
1117 write_register (PC_REGNUM
, FRAME_SAVED_PC(frame
));
1118 if (frame
->saved_regs
== NULL
)
1119 alpha_find_saved_regs (frame
);
1122 for (regnum
= 32; --regnum
>= 0; )
1123 if (PROC_REG_MASK(proc_desc
) & (1 << regnum
))
1124 write_register (regnum
,
1125 read_memory_integer (frame
->saved_regs
[regnum
],
1127 for (regnum
= 32; --regnum
>= 0; )
1128 if (PROC_FREG_MASK(proc_desc
) & (1 << regnum
))
1129 write_register (regnum
+ FP0_REGNUM
,
1130 read_memory_integer (frame
->saved_regs
[regnum
+ FP0_REGNUM
], 8));
1132 write_register (SP_REGNUM
, new_sp
);
1133 flush_cached_frames ();
1135 if (proc_desc
&& (PROC_DESC_IS_DUMMY(proc_desc
)
1136 || PROC_DESC_IS_DYN_SIGTRAMP (proc_desc
)))
1138 struct linked_proc_info
*pi_ptr
, *prev_ptr
;
1140 for (pi_ptr
= linked_proc_desc_table
, prev_ptr
= NULL
;
1142 prev_ptr
= pi_ptr
, pi_ptr
= pi_ptr
->next
)
1144 if (&pi_ptr
->info
== proc_desc
)
1149 error ("Can't locate dummy extra frame info\n");
1151 if (prev_ptr
!= NULL
)
1152 prev_ptr
->next
= pi_ptr
->next
;
1154 linked_proc_desc_table
= pi_ptr
->next
;
1160 /* To skip prologues, I use this predicate. Returns either PC itself
1161 if the code at PC does not look like a function prologue; otherwise
1162 returns an address that (if we're lucky) follows the prologue. If
1163 LENIENT, then we must skip everything which is involved in setting
1164 up the frame (it's OK to skip more, just so long as we don't skip
1165 anything which might clobber the registers which are being saved.
1166 Currently we must not skip more on the alpha, but we might the lenient
1170 alpha_skip_prologue (pc
, lenient
)
1176 CORE_ADDR post_prologue_pc
;
1179 #ifdef GDB_TARGET_HAS_SHARED_LIBS
1180 /* Silently return the unaltered pc upon memory errors.
1181 This could happen on OSF/1 if decode_line_1 tries to skip the
1182 prologue for quickstarted shared library functions when the
1183 shared library is not yet mapped in.
1184 Reading target memory is slow over serial lines, so we perform
1185 this check only if the target has shared libraries. */
1186 if (target_read_memory (pc
, buf
, 4))
1190 /* See if we can determine the end of the prologue via the symbol table.
1191 If so, then return either PC, or the PC after the prologue, whichever
1194 post_prologue_pc
= after_prologue (pc
, NULL
);
1196 if (post_prologue_pc
!= 0)
1197 return max (pc
, post_prologue_pc
);
1199 /* Can't determine prologue from the symbol table, need to examine
1202 /* Skip the typical prologue instructions. These are the stack adjustment
1203 instruction and the instructions that save registers on the stack
1204 or in the gcc frame. */
1205 for (offset
= 0; offset
< 100; offset
+= 4)
1209 status
= read_memory_nobpt (pc
+ offset
, buf
, 4);
1211 memory_error (status
, pc
+ offset
);
1212 inst
= extract_unsigned_integer (buf
, 4);
1214 /* The alpha has no delay slots. But let's keep the lenient stuff,
1215 we might need it for something else in the future. */
1219 if ((inst
& 0xffff0000) == 0x27bb0000) /* ldah $gp,n($t12) */
1221 if ((inst
& 0xffff0000) == 0x23bd0000) /* lda $gp,n($gp) */
1223 if ((inst
& 0xffff0000) == 0x23de0000) /* lda $sp,n($sp) */
1225 if ((inst
& 0xffe01fff) == 0x43c0153e) /* subq $sp,n,$sp */
1228 if ((inst
& 0xfc1f0000) == 0xb41e0000
1229 && (inst
& 0xffff0000) != 0xb7fe0000)
1230 continue; /* stq reg,n($sp) */
1232 if ((inst
& 0xfc1f0000) == 0x9c1e0000
1233 && (inst
& 0xffff0000) != 0x9ffe0000)
1234 continue; /* stt reg,n($sp) */
1236 if (inst
== 0x47de040f) /* bis sp,sp,fp */
1245 /* Is address PC in the prologue (loosely defined) for function at
1249 alpha_in_lenient_prologue (startaddr
, pc
)
1250 CORE_ADDR startaddr
;
1253 CORE_ADDR end_prologue
= alpha_skip_prologue (startaddr
, 1);
1254 return pc
>= startaddr
&& pc
< end_prologue
;
1258 /* The alpha needs a conversion between register and memory format if
1259 the register is a floating point register and
1260 memory format is float, as the register format must be double
1262 memory format is an integer with 4 bytes or less, as the representation
1263 of integers in floating point registers is different. */
1265 alpha_register_convert_to_virtual (regnum
, valtype
, raw_buffer
, virtual_buffer
)
1267 struct type
*valtype
;
1269 char *virtual_buffer
;
1271 if (TYPE_LENGTH (valtype
) >= REGISTER_RAW_SIZE (regnum
))
1273 memcpy (virtual_buffer
, raw_buffer
, REGISTER_VIRTUAL_SIZE (regnum
));
1277 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1279 double d
= extract_floating (raw_buffer
, REGISTER_RAW_SIZE (regnum
));
1280 store_floating (virtual_buffer
, TYPE_LENGTH (valtype
), d
);
1282 else if (TYPE_CODE (valtype
) == TYPE_CODE_INT
&& TYPE_LENGTH (valtype
) <= 4)
1285 l
= extract_unsigned_integer (raw_buffer
, REGISTER_RAW_SIZE (regnum
));
1286 l
= ((l
>> 32) & 0xc0000000) | ((l
>> 29) & 0x3fffffff);
1287 store_unsigned_integer (virtual_buffer
, TYPE_LENGTH (valtype
), l
);
1290 error ("Cannot retrieve value from floating point register");
1294 alpha_register_convert_to_raw (valtype
, regnum
, virtual_buffer
, raw_buffer
)
1295 struct type
*valtype
;
1297 char *virtual_buffer
;
1300 if (TYPE_LENGTH (valtype
) >= REGISTER_RAW_SIZE (regnum
))
1302 memcpy (raw_buffer
, virtual_buffer
, REGISTER_RAW_SIZE (regnum
));
1306 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1308 double d
= extract_floating (virtual_buffer
, TYPE_LENGTH (valtype
));
1309 store_floating (raw_buffer
, REGISTER_RAW_SIZE (regnum
), d
);
1311 else if (TYPE_CODE (valtype
) == TYPE_CODE_INT
&& TYPE_LENGTH (valtype
) <= 4)
1314 if (TYPE_UNSIGNED (valtype
))
1315 l
= extract_unsigned_integer (virtual_buffer
, TYPE_LENGTH (valtype
));
1317 l
= extract_signed_integer (virtual_buffer
, TYPE_LENGTH (valtype
));
1318 l
= ((l
& 0xc0000000) << 32) | ((l
& 0x3fffffff) << 29);
1319 store_unsigned_integer (raw_buffer
, REGISTER_RAW_SIZE (regnum
), l
);
1322 error ("Cannot store value in floating point register");
1325 /* Given a return value in `regbuf' with a type `valtype',
1326 extract and copy its value into `valbuf'. */
1329 alpha_extract_return_value (valtype
, regbuf
, valbuf
)
1330 struct type
*valtype
;
1331 char regbuf
[REGISTER_BYTES
];
1334 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1335 alpha_register_convert_to_virtual (FP0_REGNUM
, valtype
,
1336 regbuf
+ REGISTER_BYTE (FP0_REGNUM
),
1339 memcpy (valbuf
, regbuf
+ REGISTER_BYTE (V0_REGNUM
), TYPE_LENGTH (valtype
));
1342 /* Given a return value in `regbuf' with a type `valtype',
1343 write its value into the appropriate register. */
1346 alpha_store_return_value (valtype
, valbuf
)
1347 struct type
*valtype
;
1350 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
1351 int regnum
= V0_REGNUM
;
1352 int length
= TYPE_LENGTH (valtype
);
1354 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1356 regnum
= FP0_REGNUM
;
1357 length
= REGISTER_RAW_SIZE (regnum
);
1358 alpha_register_convert_to_raw (valtype
, regnum
, valbuf
, raw_buffer
);
1361 memcpy (raw_buffer
, valbuf
, length
);
1363 write_register_bytes (REGISTER_BYTE (regnum
), raw_buffer
, length
);
1366 /* Just like reinit_frame_cache, but with the right arguments to be
1367 callable as an sfunc. */
1370 reinit_frame_cache_sfunc (args
, from_tty
, c
)
1373 struct cmd_list_element
*c
;
1375 reinit_frame_cache ();
1378 /* This is the definition of CALL_DUMMY_ADDRESS. It's a heuristic that is used
1379 to find a convenient place in the text segment to stick a breakpoint to
1380 detect the completion of a target function call (ala call_function_by_hand).
1384 alpha_call_dummy_address ()
1387 struct minimal_symbol
*sym
;
1389 entry
= entry_point_address ();
1394 sym
= lookup_minimal_symbol ("_Prelude", NULL
, symfile_objfile
);
1396 if (!sym
|| MSYMBOL_TYPE (sym
) != mst_text
)
1399 return SYMBOL_VALUE_ADDRESS (sym
) + 4;
1403 _initialize_alpha_tdep ()
1405 struct cmd_list_element
*c
;
1407 tm_print_insn
= print_insn_alpha
;
1409 /* Let the user set the fence post for heuristic_proc_start. */
1411 /* We really would like to have both "0" and "unlimited" work, but
1412 command.c doesn't deal with that. So make it a var_zinteger
1413 because the user can always use "999999" or some such for unlimited. */
1414 c
= add_set_cmd ("heuristic-fence-post", class_support
, var_zinteger
,
1415 (char *) &heuristic_fence_post
,
1417 Set the distance searched for the start of a function.\n\
1418 If you are debugging a stripped executable, GDB needs to search through the\n\
1419 program for the start of a function. This command sets the distance of the\n\
1420 search. The only need to set it is when debugging a stripped executable.",
1422 /* We need to throw away the frame cache when we set this, since it
1423 might change our ability to get backtraces. */
1424 c
->function
.sfunc
= reinit_frame_cache_sfunc
;
1425 add_show_from_set (c
, &showlist
);