This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
[RFC] Convert STACK_ALIGN to multi-arch ....
- To: GDB Patches <gdb-patches at sourceware dot cygnus dot com>
- Subject: [RFC] Convert STACK_ALIGN to multi-arch ....
- From: Andrew Cagney <ac131313 at cygnus dot com>
- Date: Thu, 20 Apr 2000 18:08:03 +1000
- Organization: Cygnus Solutions
Hello,
The attached patch converts the STACK_ALIGN macro into a multi-arch
runtime test/call. What was:
#ifdef STACK_ALIGN
x = STACK_ALIGN (x)
#endif
becomes
if (STACK_ALIGN_P ())
x = STACK_ALIGN (x);
The need for a predicate becomes clear if you look at valops.c. How it
handles all the possible compatibility cases is pretty confusing so I'll
quickly go through each case I thought of:
!multi-arch && !defined (STACK_ALIGN)
A legacy system that doesn't define STACK_ALIGN.
STACK_ALIGN_P() is defined as gdbarch_stack_align_p()
which will always return 0 (the stack_align function is
never set).
STACK_ALIGN() is defined as gdbarch_stack_align() which
keeps things compiling.
!multi-arch && defined (STACK_ALIGN)
Legacy system providing STACK_ALIGN macro in tm.h.
multi-arch && defined (STACK_ALIGN)
Hybrid system (ex d10v) providing STACK_ALIGN macro in tm.h.
That legacy #ifdef STACK_ALIGN in gdbarch.h forces
STACK_ALIGN_P() to 1.
multi-arch && !defined (STACK_ALIGN)
normal case.
Both STACK_ALIGN_P() and STACK_ALIGN() are mapped
onto functions like any other gdbarch case.
can anyone think of any other cases (did I get these cases right :-)?
Other thoughts.
Andrew
Thu Apr 20 14:35:46 2000 Andrew Cagney <cagney@b1.cygnus.com>
* valops.c (hand_function_call): Replace #ifdef STACK_ALIGN with
run-time test for STACK_ALIGN_P.
* gdbarch.sh: Add support for function and variable predicates.
(STACK_ALIGN): Add. Implement with predicate - STACK_ALIGN_P.
Index: gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.14
diff -p -r1.14 gdbarch.c
*** gdbarch.c 2000/04/20 04:24:03 1.14
--- gdbarch.c 2000/04/20 07:49:16
*************** struct gdbarch
*** 213,218 ****
--- 213,219 ----
gdbarch_frame_locals_address_ftype *frame_locals_address;
gdbarch_saved_pc_after_call_ftype *saved_pc_after_call;
gdbarch_frame_num_args_ftype *frame_num_args;
+ gdbarch_stack_align_ftype *stack_align;
};
*************** struct gdbarch startup_gdbarch = {
*** 317,322 ****
--- 318,324 ----
0,
0,
0,
+ 0,
/* startup_gdbarch() */
};
struct gdbarch *current_gdbarch = &startup_gdbarch;
*************** verify_gdbarch (struct gdbarch *gdbarch)
*** 620,625 ****
--- 622,628 ----
if ((GDB_MULTI_ARCH >= 2)
&& (gdbarch->frame_num_args == 0))
internal_error ("gdbarch: verify_gdbarch: frame_num_args invalid");
+ /* Skip verify of stack_align, has predicate */
}
*************** gdbarch_dump (void)
*** 955,960 ****
--- 958,967 ----
"gdbarch_update: FRAME_NUM_ARGS = 0x%08lx\n",
(long) current_gdbarch->frame_num_args
/*FRAME_NUM_ARGS ()*/);
+ fprintf_unfiltered (gdb_stdlog,
+ "gdbarch_update: STACK_ALIGN = 0x%08lx\n",
+ (long) current_gdbarch->stack_align
+ /*STACK_ALIGN ()*/);
}
struct gdbarch_tdep *
*************** set_gdbarch_frame_num_args (struct gdbar
*** 2485,2490 ****
--- 2492,2520 ----
gdbarch_frame_num_args_ftype frame_num_args)
{
gdbarch->frame_num_args = frame_num_args;
+ }
+
+ int
+ gdbarch_stack_align_p (struct gdbarch *gdbarch)
+ {
+ return gdbarch->stack_align != 0;
+ }
+
+ CORE_ADDR
+ gdbarch_stack_align (struct gdbarch *gdbarch, CORE_ADDR sp)
+ {
+ if (gdbarch->stack_align == 0)
+ internal_error ("gdbarch: gdbarch_stack_align invalid");
+ if (gdbarch_debug >= 2)
+ fprintf_unfiltered (gdb_stdlog, "gdbarch_stack_align called\n");
+ return gdbarch->stack_align (sp);
+ }
+
+ void
+ set_gdbarch_stack_align (struct gdbarch *gdbarch,
+ gdbarch_stack_align_ftype stack_align)
+ {
+ gdbarch->stack_align = stack_align;
}
Index: gdbarch.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.h,v
retrieving revision 1.10
diff -p -r1.10 gdbarch.h
*** gdbarch.h 2000/04/20 04:24:04 1.10
--- gdbarch.h 2000/04/20 07:49:19
*************** extern void set_gdbarch_frame_num_args (
*** 798,803 ****
--- 798,820 ----
#endif
#endif
+ #if defined (STACK_ALIGN)
+ /* Legacy for systems yet to multi-arch STACK_ALIGN */
+ #define STACK_ALIGN_P() (1)
+ #endif
+
+ extern int gdbarch_stack_align_p (struct gdbarch *gdbarch);
+ #if (GDB_MULTI_ARCH > 1) || !defined (STACK_ALIGN_P)
+ #define STACK_ALIGN_P() (gdbarch_stack_align_p (current_gdbarch))
+ #endif
+
+ typedef CORE_ADDR (gdbarch_stack_align_ftype) (CORE_ADDR sp);
+ extern CORE_ADDR gdbarch_stack_align (struct gdbarch *gdbarch, CORE_ADDR sp);
+ extern void set_gdbarch_stack_align (struct gdbarch *gdbarch, gdbarch_stack_align_ftype *stack_align);
+ #if (GDB_MULTI_ARCH > 1) || !defined (STACK_ALIGN)
+ #define STACK_ALIGN(sp) (gdbarch_stack_align (current_gdbarch, sp))
+ #endif
+
extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch);
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.10
diff -p -r1.10 valops.c
*** valops.c 2000/04/17 02:27:37 1.10
--- valops.c 2000/04/20 07:49:30
*************** You must use a pointer to function type
*** 1534,1547 ****
arg_type = check_typedef (VALUE_ENCLOSING_TYPE (args[i]));
len = TYPE_LENGTH (arg_type);
! #ifdef STACK_ALIGN
! /* MVS 11/22/96: I think at least some of this stack_align code is
! really broken. Better to let PUSH_ARGUMENTS adjust the stack in
! a target-defined manner. */
! aligned_len = STACK_ALIGN (len);
! #else
! aligned_len = len;
! #endif
if (INNER_THAN (1, 2))
{
/* stack grows downward */
--- 1534,1547 ----
arg_type = check_typedef (VALUE_ENCLOSING_TYPE (args[i]));
len = TYPE_LENGTH (arg_type);
! if (STACK_ALIGN_P ())
! /* MVS 11/22/96: I think at least some of this
! stack_align code is really broken. Better to let
! PUSH_ARGUMENTS adjust the stack in a target-defined
! manner. */
! aligned_len = STACK_ALIGN (len);
! else
! aligned_len = len;
if (INNER_THAN (1, 2))
{
/* stack grows downward */
*************** You must use a pointer to function type
*** 1583,1594 ****
if (struct_return)
{
int len = TYPE_LENGTH (value_type);
! #ifdef STACK_ALIGN
! /* MVS 11/22/96: I think at least some of this stack_align code is
! really broken. Better to let PUSH_ARGUMENTS adjust the stack in
! a target-defined manner. */
! len = STACK_ALIGN (len);
! #endif
if (INNER_THAN (1, 2))
{
/* stack grows downward */
--- 1583,1593 ----
if (struct_return)
{
int len = TYPE_LENGTH (value_type);
! if (STACK_ALIGN_P ())
! /* MVS 11/22/96: I think at least some of this stack_align
! code is really broken. Better to let PUSH_ARGUMENTS adjust
! the stack in a target-defined manner. */
! len = STACK_ALIGN (len);
if (INNER_THAN (1, 2))
{
/* stack grows downward */
*************** You must use a pointer to function type
*** 1609,1619 ****
hppa_push_arguments */
#ifndef NO_EXTRA_ALIGNMENT_NEEDED
- #if defined(STACK_ALIGN)
/* MVS 11/22/96: I think at least some of this stack_align code is
really broken. Better to let PUSH_ARGUMENTS adjust the stack in
a target-defined manner. */
! if (INNER_THAN (1, 2))
{
/* If stack grows down, we must leave a hole at the top. */
int len = 0;
--- 1608,1617 ----
hppa_push_arguments */
#ifndef NO_EXTRA_ALIGNMENT_NEEDED
/* MVS 11/22/96: I think at least some of this stack_align code is
really broken. Better to let PUSH_ARGUMENTS adjust the stack in
a target-defined manner. */
! if (STACK_ALIGN_P () && INNER_THAN (1, 2))
{
/* If stack grows down, we must leave a hole at the top. */
int len = 0;
*************** You must use a pointer to function type
*** 1624,1630 ****
len += CALL_DUMMY_STACK_ADJUST;
sp -= STACK_ALIGN (len) - len;
}
- #endif /* STACK_ALIGN */
#endif /* NO_EXTRA_ALIGNMENT_NEEDED */
sp = PUSH_ARGUMENTS (nargs, args, sp, struct_return, struct_addr);
--- 1622,1627 ----
*************** You must use a pointer to function type
*** 1642,1649 ****
sp = PUSH_RETURN_ADDRESS (real_pc, sp);
#endif /* PUSH_RETURN_ADDRESS */
! #if defined(STACK_ALIGN)
! if (!INNER_THAN (1, 2))
{
/* If stack grows up, we must leave a hole at the bottom, note
that sp already has been advanced for the arguments! */
--- 1639,1645 ----
sp = PUSH_RETURN_ADDRESS (real_pc, sp);
#endif /* PUSH_RETURN_ADDRESS */
! if (STACK_ALIGN_P () && !INNER_THAN (1, 2))
{
/* If stack grows up, we must leave a hole at the bottom, note
that sp already has been advanced for the arguments! */
*************** You must use a pointer to function type
*** 1651,1657 ****
sp += CALL_DUMMY_STACK_ADJUST;
sp = STACK_ALIGN (sp);
}
- #endif /* STACK_ALIGN */
/* XXX This seems wrong. For stacks that grow down we shouldn't do
anything here! */
--- 1647,1652 ----