+2008-04-22 Corinna Vinschen <vinschen@redhat.com>
+
+ * NEWS: Add information on calling convention and new SH CLI options.
+
+ * sh-tdep.c (sh_cc_gcc): New static string.
+ (sh_cc_renesas): Ditto.
+ (sh_cc_enum): New static string array.
+ (sh_active_calling_convention): New static string pointer denoting
+ active user chosen ABI.
+ (sh_is_renesas_calling_convention): New function to return function
+ specific ABI, or user choice if necessary.
+ (sh_use_struct_convention): Rename first argument and turn around its
+ meaning. Check for renesas ABI and return accordingly.
+ (sh_use_struct_convention_nofpu): New function.
+ (sh_next_flt_argreg): Get function type as third parameter. Check
+ for renesas ABI and choose floating registers accordingly.
+ (sh_push_dummy_call_fpu): Check for ABI and choose argument slot and
+ struct return slot accordingly.
+ (sh_push_dummy_call_nofpu): Ditto.
+ (sh_return_value_nofpu): Call sh_use_struct_convention_nofpu from here.
+ Evaluate ABI and give to sh_use_struct_convention_nofpu.
+ (sh_return_value_fpu): Evaluate ABI and give to
+ sh_use_struct_convention.
+ (show_sh_command): New function.
+ (set_sh_command): Ditto.
+ (_initialize_sh_tdep): Initialize `set/show sh calling-convention
+ CLI command.
+
+ * gdbarch.sh (return_value): Add func_type argument.
+ * gdbarch.c: Regenerate.
+ * gdbarch.h: Ditto.
+ * eval.c (evaluate_subexp_standard): Rename local variable value_type to
+ val_type so as not to collide with value_type function. Call
+ using_struct_return with additional function type argument.
+ * infcall.c (call_function_by_hand): Call using_struct_return and
+ gdbarch_return_value with additional function type argument.
+ * infcmd.c (print_return_value): Take addition func_type argument.
+ Call gdbarch_return_value with additional function type argument.
+ (finish_command_continuation): Call print_return_value with additional
+ function type argument.
+ (finish_command): Ditto.
+ * sparc-tdep.c (sparc32_push_dummy_code): Call using_struct_return with
+ additional function type argument.
+ * stack.c (return_command): Call using_struct_return and
+ gdbarch_return_value with additional function type argument.
+ * value.c (using_struct_return): Take additional function type argument.
+ * value.h (using_struct_return): Accommodate declaration.
+ * alpha-tdep.c (alpha_return_value): Add func_type argument.
+ * amd64-tdep.c (amd64_return_value): Ditto.
+ * arm-tdep.c (arm_return_value): Ditto.
+ * avr-tdep.c (avr_return_value): Ditto.
+ * cris-tdep.c (cris_return_value): Ditto.
+ * frv-tdep.c (frv_return_value): Ditto.
+ * h8300-tdep.c (h8300_return_value): Ditto.
+ (h8300h_return_value): Ditto.
+ * hppa-tdep.c (hppa32_return_value): Ditto.
+ (hppa64_return_value): Ditto.
+ * i386-tdep.c (i386_return_value): Ditto.
+ * ia64-tdep.c (ia64_return_value): Ditto.
+ * iq2000-tdep.c (iq2000_return_value): Ditto.
+ * m32c-tdep.c (m32c_return_value): Ditto.
+ * m32r-tdep.c (m32r_return_value): Ditto.
+ * m68hc11-tdep.c (m68hc11_return_value): Ditto.
+ * m68k-tdep.c (m68k_return_value): Ditto.
+ (m68k_svr4_return_value): Ditto.
+ * m88k-tdep.c (m88k_return_value): Ditto.
+ * mep-tdep.c (mep_return_value): Ditto.
+ * mips-tdep.c (mips_eabi_return_value): Ditto.
+ (mips_n32n64_return_value): Ditto.
+ (mips_o32_return_value): Ditto.
+ (mips_o64_return_value): Ditto.
+ * mn10300-tdep.c (mn10300_return_value): Ditto.
+ * mt-tdep.c (mt_return_value): Ditto.
+ * ppc-linux-tdep.c (ppc_linux_return_value): Ditto.
+ * ppc-sysv-tdep.c (ppc_sysv_abi_return_value): Ditto.
+ (ppc_sysv_abi_broken_return_value): Ditto.
+ (ppc64_sysv_abi_return_value): Ditto.
+ * ppc-tdep.h (ppc_sysv_abi_return_value): Ditto.
+ (ppc_sysv_abi_broken_return_value): Ditto.
+ (ppc64_sysv_abi_return_value): Ditto.
+ * ppcnbsd-tdep.c (ppcnbsd_return_value): Ditto.
+ * rs6000-tdep.c (rs6000_return_value): Ditto.
+ * s390-tdep.c (s390_return_value): Ditto.
+ * score-tdep.c (score_return_value): Ditto.
+ * sh-tdep.c (sh_return_value_nofpu): Ditto.
+ (sh_return_value_fpu): Ditto.
+ * sh64-tdep.c (sh64_return_value): Ditto.
+ * sparc-tdep.c (sparc32_return_value): Ditto.
+ * sparc64-tdep.c (sparc64_return_value): Ditto.
+ * spu-tdep.c (spu_return_value): Ditto.
+ * v850-tdep.c (v850_return_value): Ditto.
+ * vax-tdep.c (vax_return_value): Ditto.
+ * xstormy16-tdep.c (xstormy16_return_value): Ditto.
+ * xtensa-tdep.c (xtensa_return_value): Ditto.
+
+ * gdbtypes.h (struct type): Add calling_convention member.
+ * dwarf2read.c (read_subroutine_type): Add calling convention read
+ from DW_AT_calling_convention attribute to function type.
+
2008-04-22 Markus Deuling <deuling@de.ibm.com>
* eval.c (evaluate_subexp_standard): Use value_subscripted_rvalue for
*** Changes since GDB 6.8
+* GDB now supports multiple function calling conventions according to the
+ DWARF-2 DW_AT_calling_convention function attribute.
+
+* The SH target utilizes the aforementioned change to distinguish between gcc
+ and Renesas calling convention. It also adds the new CLI commands
+ `set/show sh calling-convention'.
+
* GDB can now read compressed debug sections, as produced by GNU gold
with the --compress-debug-sections=zlib flag.
}
static enum return_value_convention
-alpha_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+alpha_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
enum type_code code = TYPE_CODE (type);
}
static enum return_value_convention
-amd64_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache,
+amd64_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
enum amd64_reg_class class[2];
/* Handle function return values. */
static enum return_value_convention
-arm_return_value (struct gdbarch *gdbarch, struct type *valtype,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+arm_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *valtype, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
from WRITEBUF into REGCACHE. */
enum return_value_convention
-avr_return_value (struct gdbarch *gdbarch, struct type *valtype,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+avr_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *valtype, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
int struct_return = ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
|| TYPE_CODE (valtype) == TYPE_CODE_UNION
/* Handle the CRIS return value convention. */
static enum return_value_convention
-cris_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+cris_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
if (TYPE_CODE (type) == TYPE_CODE_STRUCT
|| TYPE_CODE (type) == TYPE_CODE_UNION
+2008-04-22 Corinna Vinschen <vinschen@redhat.com>
+
+ * gdb.texinfo (Set SH Calling convention): New @item.
+ (Show SH Calling convention): Ditto.
+
2008-04-22 Markus Deuling <deuling@de.ibm.com>
* gdb.texinfo (Fortran Operators): Describe '%' operator.
@item regs
@kindex regs@r{, Super-H}
Show the values of all Super-H registers.
+
+@item set sh calling-convention @var{convention}
+@kindex set sh calling-convention
+Set the calling-convention used when calling functions from @value{GDBN}.
+Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
+With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
+convention. If the DWARF-2 information of the called function specifies
+that the function follows the Renesas calling convention, the function
+is called using the Renesas calling convention. If the calling convention
+is set to @samp{renesas}, the Renesas calling convention is always used,
+regardless of the DWARF-2 information. This can be used to override the
+default of @samp{gcc} if debug information is missing, or the compiler
+does not emit the DWARF-2 calling convention entry for a function.
+
+@item show sh calling-convention
+@kindex show sh calling-convention
+Show the current calling convention setting.
+
@end table
|| cu->language == language_pascal)
TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
+ /* Store the calling convention in the type if it's available in
+ the subroutine die. Otherwise set the calling convention to
+ the default value DW_CC_normal. */
+ attr = dwarf2_attr (die, DW_AT_calling_convention, cu);
+ TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal;
+
if (die->child != NULL)
{
struct die_info *child_die;
{
struct block *b;
CORE_ADDR funaddr;
- struct type *value_type;
+ struct type *val_type;
- funaddr = find_function_addr (method, &value_type);
+ funaddr = find_function_addr (method, &val_type);
b = block_for_pc (funaddr);
- CHECK_TYPEDEF (value_type);
+ CHECK_TYPEDEF (val_type);
- if ((value_type == NULL)
- || (TYPE_CODE(value_type) == TYPE_CODE_ERROR))
+ if ((val_type == NULL)
+ || (TYPE_CODE(val_type) == TYPE_CODE_ERROR))
{
if (expect_type != NULL)
- value_type = expect_type;
+ val_type = expect_type;
}
- struct_return = using_struct_return (value_type);
+ struct_return = using_struct_return (value_type (method), val_type);
}
else if (expect_type != NULL)
{
- struct_return = using_struct_return (check_typedef (expect_type));
+ struct_return = using_struct_return (NULL,
+ check_typedef (expect_type));
}
/* Found a function symbol. Now we will substitute its
}
enum return_value_convention
-frv_return_value (struct gdbarch *gdbarch, struct type *valtype,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+frv_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *valtype, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
int struct_return = TYPE_CODE (valtype) == TYPE_CODE_STRUCT
|| TYPE_CODE (valtype) == TYPE_CODE_UNION
}
enum return_value_convention
-gdbarch_return_value (struct gdbarch *gdbarch, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
+gdbarch_return_value (struct gdbarch *gdbarch, struct type *functype, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf)
{
gdb_assert (gdbarch != NULL);
gdb_assert (gdbarch->return_value != NULL);
if (gdbarch_debug >= 2)
fprintf_unfiltered (gdb_stdlog, "gdbarch_return_value called\n");
- return gdbarch->return_value (gdbarch, valtype, regcache, readbuf, writebuf);
+ return gdbarch->return_value (gdbarch, functype, valtype, regcache, readbuf, writebuf);
}
void
extern int gdbarch_return_value_p (struct gdbarch *gdbarch);
-typedef enum return_value_convention (gdbarch_return_value_ftype) (struct gdbarch *gdbarch, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf);
-extern enum return_value_convention gdbarch_return_value (struct gdbarch *gdbarch, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf);
+typedef enum return_value_convention (gdbarch_return_value_ftype) (struct gdbarch *gdbarch, struct type *functype, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf);
+extern enum return_value_convention gdbarch_return_value (struct gdbarch *gdbarch, struct type *functype, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf);
extern void set_gdbarch_return_value (struct gdbarch *gdbarch, gdbarch_return_value_ftype *return_value);
typedef CORE_ADDR (gdbarch_skip_prologue_ftype) (struct gdbarch *gdbarch, CORE_ADDR ip);
# should take the type/value of the function to be called and not the
# return type. This is left as an exercise for the reader.
-M:enum return_value_convention:return_value:struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf:valtype, regcache, readbuf, writebuf
+M:enum return_value_convention:return_value:struct type *functype, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf:functype, valtype, regcache, readbuf, writebuf
m:CORE_ADDR:skip_prologue:CORE_ADDR ip:ip:0:0
f:int:inner_than:CORE_ADDR lhs, CORE_ADDR rhs:lhs, rhs:0:0
targets and the second is for little endian targets. */
const struct floatformat **floatformat;
+
+ /* For TYPE_CODE_FUNC types, the calling convention for targets
+ supporting multiple ABIs. Right now this is only fetched from
+ the Dwarf-2 DW_AT_calling_convention attribute. */
+ unsigned calling_convention;
} type_specific;
};
#define TYPE_TYPE_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific
#define TYPE_CPLUS_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff
#define TYPE_FLOATFORMAT(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.floatformat
+#define TYPE_CALLING_CONVENTION(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.calling_convention
#define TYPE_BASECLASS(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].type
#define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses
#define TYPE_BASECLASS_NAME(thistype,index) TYPE_MAIN_TYPE(thistype)->fields[index].name
}
static enum return_value_convention
-h8300_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache,
+h8300_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
if (h8300_use_struct_convention (type))
}
static enum return_value_convention
-h8300h_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache,
+h8300h_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
if (h8300h_use_struct_convention (type))
/* Handle 32/64-bit struct return conventions. */
static enum return_value_convention
-hppa32_return_value (struct gdbarch *gdbarch,
+hppa32_return_value (struct gdbarch *gdbarch, struct type *func_type,
struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
}
static enum return_value_convention
-hppa64_return_value (struct gdbarch *gdbarch,
+hppa64_return_value (struct gdbarch *gdbarch, struct type *func_type,
struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
from WRITEBUF into REGCACHE. */
static enum return_value_convention
-i386_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+i386_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
enum type_code code = TYPE_CODE (type);
if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
{
type = check_typedef (TYPE_FIELD_TYPE (type, 0));
- return i386_return_value (gdbarch, type, regcache, readbuf, writebuf);
+ return i386_return_value (gdbarch, func_type, type, regcache,
+ readbuf, writebuf);
}
if (readbuf)
}
static enum return_value_convention
-ia64_return_value (struct gdbarch *gdbarch, struct type *valtype,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+ia64_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *valtype, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
int struct_return = ia64_use_struct_convention (valtype);
}
else
{
- struct_return = using_struct_return (values_type);
+ struct_return = using_struct_return (value_type (function), values_type);
target_values_type = values_type;
}
}
else
{
- switch (gdbarch_return_value (gdbarch, target_values_type,
- NULL, NULL, NULL))
+ switch (gdbarch_return_value (gdbarch, value_type (function),
+ target_values_type, NULL, NULL, NULL))
{
case RETURN_VALUE_REGISTER_CONVENTION:
case RETURN_VALUE_ABI_RETURNS_ADDRESS:
case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
retval = allocate_value (values_type);
- gdbarch_return_value (gdbarch, values_type, retbuf,
- value_contents_raw (retval), NULL);
+ gdbarch_return_value (gdbarch, value_type (function), values_type,
+ retbuf, value_contents_raw (retval), NULL);
break;
case RETURN_VALUE_STRUCT_CONVENTION:
retval = value_at (values_type, struct_addr);
static void nofp_registers_info (char *, int);
-static void print_return_value (struct type *value_type);
+static void print_return_value (struct type *func_type,
+ struct type *value_type);
static void finish_command_continuation (struct continuation_arg *);
/* Print the result of a function at the end of a 'finish' command. */
static void
-print_return_value (struct type *value_type)
+print_return_value (struct type *func_type, struct type *value_type)
{
struct gdbarch *gdbarch = current_gdbarch;
struct cleanup *old_chain;
inferior function call code. In fact, when inferior function
calls are made async, this will likely be made the norm. */
- switch (gdbarch_return_value (gdbarch, value_type, NULL, NULL, NULL))
+ switch (gdbarch_return_value (gdbarch, func_type, value_type,
+ NULL, NULL, NULL))
{
case RETURN_VALUE_REGISTER_CONVENTION:
case RETURN_VALUE_ABI_RETURNS_ADDRESS:
case RETURN_VALUE_ABI_PRESERVES_ADDRESS:
value = allocate_value (value_type);
- gdbarch_return_value (gdbarch, value_type, stop_registers,
+ gdbarch_return_value (gdbarch, func_type, value_type, stop_registers,
value_contents_raw (value), NULL);
break;
case RETURN_VALUE_STRUCT_CONVENTION:
_("finish_command: function has no target type"));
if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
- print_return_value (value_type);
+ print_return_value (SYMBOL_TYPE (function), value_type);
}
do_exec_cleanups (cleanups);
_("finish_command: function has no target type"));
if (TYPE_CODE (value_type) != TYPE_CODE_VOID)
- print_return_value (value_type);
+ print_return_value (SYMBOL_TYPE (function), value_type);
}
do_cleanups (old_chain);
}
static enum return_value_convention
-iq2000_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache,
+iq2000_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
if (iq2000_use_struct_convention (type))
static enum return_value_convention
m32c_return_value (struct gdbarch *gdbarch,
+ struct type *func_type,
struct type *valtype,
struct regcache *regcache,
gdb_byte *readbuf,
}
enum return_value_convention
-m32r_return_value (struct gdbarch *gdbarch, struct type *valtype,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+m32r_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *valtype, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
if (TYPE_LENGTH (valtype) > 8)
return RETURN_VALUE_STRUCT_CONVENTION;
}
enum return_value_convention
-m68hc11_return_value (struct gdbarch *gdbarch, struct type *valtype,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+m68hc11_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *valtype, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
if (TYPE_CODE (valtype) == TYPE_CODE_STRUCT
|| TYPE_CODE (valtype) == TYPE_CODE_UNION
from WRITEBUF into REGCACHE. */
static enum return_value_convention
-m68k_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+m68k_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
enum type_code code = TYPE_CODE (type);
}
static enum return_value_convention
-m68k_svr4_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+m68k_svr4_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
enum type_code code = TYPE_CODE (type);
if (code == TYPE_CODE_STRUCT && TYPE_NFIELDS (type) == 1)
{
type = check_typedef (TYPE_FIELD_TYPE (type, 0));
- return m68k_svr4_return_value (gdbarch, type, regcache,
+ return m68k_svr4_return_value (gdbarch, func_type, type, regcache,
readbuf, writebuf);
}
from WRITEBUF into REGCACHE. */
static enum return_value_convention
-m88k_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+m88k_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
int len = TYPE_LENGTH (type);
gdb_byte buf[8];
}
enum return_value_convention
-mep_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+mep_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
if (mep_use_struct_convention (type))
{
/* Determine the return value convention being used. */
static enum return_value_convention
-mips_eabi_return_value (struct gdbarch *gdbarch,
+mips_eabi_return_value (struct gdbarch *gdbarch, struct type *func_type,
struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
}
static enum return_value_convention
-mips_n32n64_return_value (struct gdbarch *gdbarch,
+mips_n32n64_return_value (struct gdbarch *gdbarch, struct type *func_type,
struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
}
static enum return_value_convention
-mips_o32_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache,
+mips_o32_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
}
static enum return_value_convention
-mips_o64_return_value (struct gdbarch *gdbarch,
+mips_o64_return_value (struct gdbarch *gdbarch, struct type *func_type,
struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
from WRITEBUF into REGCACHE. */
static enum return_value_convention
-mn10300_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+mn10300_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
if (mn10300_use_struct_convention (type))
return RETURN_VALUE_STRUCT_CONVENTION;
values. */
static enum return_value_convention
-mt_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+mt_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
if (TYPE_LENGTH (type) > 4)
{
which were added later, do get returned in a register though. */
static enum return_value_convention
-ppc_linux_return_value (struct gdbarch *gdbarch, struct type *valtype,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+ppc_linux_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *valtype, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
|| TYPE_CODE (valtype) == TYPE_CODE_UNION)
&& TYPE_VECTOR (valtype)))
return RETURN_VALUE_STRUCT_CONVENTION;
else
- return ppc_sysv_abi_return_value (gdbarch, valtype, regcache, readbuf,
- writebuf);
+ return ppc_sysv_abi_return_value (gdbarch, func_type, valtype, regcache,
+ readbuf, writebuf);
}
/* Macros for matching instructions. Note that, since all the
}
enum return_value_convention
-ppc_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *valtype,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+ppc_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *valtype, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
return do_ppc_sysv_return_value (gdbarch, valtype, regcache, readbuf,
writebuf, 0);
enum return_value_convention
ppc_sysv_abi_broken_return_value (struct gdbarch *gdbarch,
+ struct type *func_type,
struct type *valtype,
struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
location; when READBUF is non-NULL, fill the buffer from the
corresponding register return-value location. */
enum return_value_convention
-ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *valtype,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *valtype, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
/* From ppc-linux-tdep.c... */
enum return_value_convention ppc_sysv_abi_return_value (struct gdbarch *gdbarch,
+ struct type *func_type,
struct type *valtype,
struct regcache *regcache,
gdb_byte *readbuf,
const gdb_byte *writebuf);
enum return_value_convention ppc_sysv_abi_broken_return_value (struct gdbarch *gdbarch,
+ struct type *func_type,
struct type *valtype,
struct regcache *regcache,
gdb_byte *readbuf,
const struct regset *ppc_linux_fpregset (void);
enum return_value_convention ppc64_sysv_abi_return_value (struct gdbarch *gdbarch,
+ struct type *func_type,
struct type *valtype,
struct regcache *regcache,
gdb_byte *readbuf,
the moment use the broken convention. Ulgh!. */
static enum return_value_convention
-ppcnbsd_return_value (struct gdbarch *gdbarch, struct type *valtype,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+ppcnbsd_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *valtype, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
#if 0
if ((TYPE_CODE (valtype) == TYPE_CODE_STRUCT
return RETURN_VALUE_STRUCT_CONVENTION;
else
#endif
- return ppc_sysv_abi_broken_return_value (gdbarch, valtype, regcache,
- readbuf, writebuf);
+ return ppc_sysv_abi_broken_return_value (gdbarch, func_type, valtype,
+ regcache, readbuf, writebuf);
}
\f
}
static enum return_value_convention
-rs6000_return_value (struct gdbarch *gdbarch, struct type *valtype,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+rs6000_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *valtype, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
gdb_byte buf[8];
}
static enum return_value_convention
-s390_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *out,
- const gdb_byte *in)
+s390_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *out, const gdb_byte *in)
{
int word_size = gdbarch_ptr_bit (gdbarch) / 8;
int length = TYPE_LENGTH (type);
}
static enum return_value_convention
-score_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache,
+score_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
gdb_byte * readbuf, const gdb_byte * writebuf)
{
if (TYPE_CODE (type) == TYPE_CODE_STRUCT
/* sh flags */
#include "elf/sh.h"
+#include "elf/dwarf2.h"
/* registers numbers shared with the simulator */
#include "gdb/sim-sh.h"
+/* List of "set sh ..." and "show sh ..." commands. */
+static struct cmd_list_element *setshcmdlist = NULL;
+static struct cmd_list_element *showshcmdlist = NULL;
+
+static const char sh_cc_gcc[] = "gcc";
+static const char sh_cc_renesas[] = "renesas";
+static const char *sh_cc_enum[] = {
+ sh_cc_gcc,
+ sh_cc_renesas,
+ NULL
+};
+
+static const char *sh_active_calling_convention = sh_cc_gcc;
+
static void (*sh_show_regs) (struct frame_info *);
#define SH_NUM_REGS 67
CORE_ADDR saved_sp;
};
+static int
+sh_is_renesas_calling_convention (struct type *func_type)
+{
+ return ((func_type
+ && TYPE_CALLING_CONVENTION (func_type) == DW_CC_GNU_renesas_sh)
+ || sh_active_calling_convention == sh_cc_renesas);
+}
+
static const char *
sh_sh_register_name (struct gdbarch *gdbarch, int reg_nr)
{
*/
static int
-sh_use_struct_convention (int gcc_p, struct type *type)
+sh_use_struct_convention (int renesas_abi, struct type *type)
{
int len = TYPE_LENGTH (type);
int nelem = TYPE_NFIELDS (type);
+ /* The Renesas ABI returns aggregate types always on stack. */
+ if (renesas_abi && (TYPE_CODE (type) == TYPE_CODE_STRUCT
+ || TYPE_CODE (type) == TYPE_CODE_UNION))
+ return 1;
+
/* Non-power of 2 length types and types bigger than 8 bytes (which don't
fit in two registers anyway) use struct convention. */
if (len != 1 && len != 2 && len != 4 && len != 8)
return 1;
}
+static int
+sh_use_struct_convention_nofpu (int renesas_abi, struct type *type)
+{
+ /* The Renesas ABI returns long longs/doubles etc. always on stack. */
+ if (renesas_abi && TYPE_NFIELDS (type) == 0 && TYPE_LENGTH (type) >= 8)
+ return 1;
+ return sh_use_struct_convention (renesas_abi, type);
+}
+
static CORE_ADDR
sh_frame_align (struct gdbarch *ignore, CORE_ADDR sp)
{
29) the parity of the register number is preserved, which is important
for the double register passing test (see the "argreg & 1" test below). */
static int
-sh_next_flt_argreg (struct gdbarch *gdbarch, int len)
+sh_next_flt_argreg (struct gdbarch *gdbarch, int len, struct type *func_type)
{
int argreg;
/* Doubles are always starting in a even register number. */
if (argreg & 1)
{
- flt_argreg_array[argreg] = 1;
+ /* In gcc ABI, the skipped register is lost for further argument
+ passing now. Not so in Renesas ABI. */
+ if (!sh_is_renesas_calling_convention (func_type))
+ flt_argreg_array[argreg] = 1;
++argreg;
/* Also mark the next register as used. */
flt_argreg_array[argreg + 1] = 1;
}
- else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
+ else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE
+ && !sh_is_renesas_calling_convention (func_type))
{
/* In little endian, gcc passes floats like this: f5, f4, f7, f6, ... */
if (!flt_argreg_array[argreg + 1])
int argreg = ARG0_REGNUM;
int flt_argreg = 0;
int argnum;
+ struct type *func_type = value_type (function);
struct type *type;
CORE_ADDR regval;
char *val;
int len, reg_size = 0;
int pass_on_stack = 0;
int treat_as_flt;
+ int last_reg_arg = INT_MAX;
+
+ /* The Renesas ABI expects all varargs arguments, plus the last
+ non-vararg argument to be on the stack, no matter how many
+ registers have been used so far. */
+ if (sh_is_renesas_calling_convention (func_type)
+ && (TYPE_FLAGS (func_type) & TYPE_FLAG_VARARGS))
+ last_reg_arg = TYPE_NFIELDS (func_type) - 2;
/* first force sp to a 4-byte alignment */
sp = sh_frame_align (gdbarch, sp);
- if (struct_return)
- regcache_cooked_write_unsigned (regcache,
- STRUCT_RETURN_REGNUM, struct_addr);
-
/* make room on stack for args */
sp -= sh_stack_allocsize (nargs, args);
/* Find out the next register to use for a floating point value. */
treat_as_flt = sh_treat_as_flt_p (type);
if (treat_as_flt)
- flt_argreg = sh_next_flt_argreg (gdbarch, len);
+ flt_argreg = sh_next_flt_argreg (gdbarch, len, func_type);
+ /* In Renesas ABI, long longs and aggregate types are always passed
+ on stack. */
+ else if (sh_is_renesas_calling_convention (func_type)
+ && ((TYPE_CODE (type) == TYPE_CODE_INT && len == 8)
+ || TYPE_CODE (type) == TYPE_CODE_STRUCT
+ || TYPE_CODE (type) == TYPE_CODE_UNION))
+ pass_on_stack = 1;
/* In contrast to non-FPU CPUs, arguments are never split between
registers and stack. If an argument doesn't fit in the remaining
registers it's always pushed entirely on the stack. */
{
if ((treat_as_flt && flt_argreg > FLOAT_ARGLAST_REGNUM)
|| (!treat_as_flt && (argreg > ARGLAST_REGNUM
- || pass_on_stack)))
+ || pass_on_stack))
+ || argnum > last_reg_arg)
{
/* The data goes entirely on the stack, 4-byte aligned. */
reg_size = (len + 3) & ~3;
}
}
+ if (struct_return)
+ {
+ if (sh_is_renesas_calling_convention (func_type))
+ /* If the function uses the Renesas ABI, subtract another 4 bytes from
+ the stack and store the struct return address there. */
+ write_memory_unsigned_integer (sp -= 4, 4, struct_addr);
+ else
+ /* Using the gcc ABI, the "struct return pointer" pseudo-argument has
+ its own dedicated register. */
+ regcache_cooked_write_unsigned (regcache,
+ STRUCT_RETURN_REGNUM, struct_addr);
+ }
+
/* Store return address. */
regcache_cooked_write_unsigned (regcache, PR_REGNUM, bp_addr);
int stack_offset = 0;
int argreg = ARG0_REGNUM;
int argnum;
+ struct type *func_type = value_type (function);
struct type *type;
CORE_ADDR regval;
char *val;
- int len, reg_size;
+ int len, reg_size = 0;
+ int pass_on_stack = 0;
+ int last_reg_arg = INT_MAX;
+
+ /* The Renesas ABI expects all varargs arguments, plus the last
+ non-vararg argument to be on the stack, no matter how many
+ registers have been used so far. */
+ if (sh_is_renesas_calling_convention (func_type)
+ && (TYPE_FLAGS (func_type) & TYPE_FLAG_VARARGS))
+ last_reg_arg = TYPE_NFIELDS (func_type) - 2;
/* first force sp to a 4-byte alignment */
sp = sh_frame_align (gdbarch, sp);
- if (struct_return)
- regcache_cooked_write_unsigned (regcache,
- STRUCT_RETURN_REGNUM, struct_addr);
-
/* make room on stack for args */
sp -= sh_stack_allocsize (nargs, args);
len = TYPE_LENGTH (type);
val = sh_justify_value_in_reg (gdbarch, args[argnum], len);
+ /* Some decisions have to be made how various types are handled.
+ This also differs in different ABIs. */
+ pass_on_stack = 0;
+ /* Renesas ABI pushes doubles and long longs entirely on stack.
+ Same goes for aggregate types. */
+ if (sh_is_renesas_calling_convention (func_type)
+ && ((TYPE_CODE (type) == TYPE_CODE_INT && len >= 8)
+ || (TYPE_CODE (type) == TYPE_CODE_FLT && len >= 8)
+ || TYPE_CODE (type) == TYPE_CODE_STRUCT
+ || TYPE_CODE (type) == TYPE_CODE_UNION))
+ pass_on_stack = 1;
while (len > 0)
{
- if (argreg > ARGLAST_REGNUM)
+ if (argreg > ARGLAST_REGNUM || pass_on_stack
+ || argnum > last_reg_arg)
{
/* The remainder of the data goes entirely on the stack,
4-byte aligned. */
}
}
+ if (struct_return)
+ {
+ if (sh_is_renesas_calling_convention (func_type))
+ /* If the function uses the Renesas ABI, subtract another 4 bytes from
+ the stack and store the struct return address there. */
+ write_memory_unsigned_integer (sp -= 4, 4, struct_addr);
+ else
+ /* Using the gcc ABI, the "struct return pointer" pseudo-argument has
+ its own dedicated register. */
+ regcache_cooked_write_unsigned (regcache,
+ STRUCT_RETURN_REGNUM, struct_addr);
+ }
+
/* Store return address. */
regcache_cooked_write_unsigned (regcache, PR_REGNUM, bp_addr);
}
static enum return_value_convention
-sh_return_value_nofpu (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache,
+sh_return_value_nofpu (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
- if (sh_use_struct_convention (0, type))
+ if (sh_use_struct_convention_nofpu (
+ sh_is_renesas_calling_convention (func_type), type))
return RETURN_VALUE_STRUCT_CONVENTION;
if (writebuf)
sh_store_return_value_nofpu (type, regcache, writebuf);
}
static enum return_value_convention
-sh_return_value_fpu (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache,
+sh_return_value_fpu (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
- if (sh_use_struct_convention (0, type))
+ if (sh_use_struct_convention (
+ sh_is_renesas_calling_convention (func_type), type))
return RETURN_VALUE_STRUCT_CONVENTION;
if (writebuf)
sh_store_return_value_fpu (type, regcache, writebuf);
return gdbarch;
}
+static void
+show_sh_command (char *args, int from_tty)
+{
+ help_list (showshcmdlist, "show sh ", all_commands, gdb_stdout);
+}
+
+static void
+set_sh_command (char *args, int from_tty)
+{
+ printf_unfiltered
+ ("\"set sh\" must be followed by an appropriate subcommand.\n");
+ help_list (setshcmdlist, "set sh ", all_commands, gdb_stdout);
+}
+
extern initialize_file_ftype _initialize_sh_tdep; /* -Wmissing-prototypes */
void
gdbarch_register (bfd_arch_sh, sh_gdbarch_init, NULL);
add_com ("regs", class_vars, sh_show_regs_command, _("Print all registers"));
+
+ add_prefix_cmd ("sh", no_class, set_sh_command, "SH specific commands.",
+ &setshcmdlist, "set sh ", 0, &setlist);
+ add_prefix_cmd ("sh", no_class, show_sh_command, "SH specific commands.",
+ &showshcmdlist, "show sh ", 0, &showlist);
+
+ add_setshow_enum_cmd ("calling-convention", class_vars, sh_cc_enum,
+ &sh_active_calling_convention,
+ _("Set calling convention used when calling target "
+ "functions from GDB."),
+ _("Show calling convention used when calling target "
+ "functions from GDB."),
+ _("gcc - Use GCC calling convention (default).\n"
+ "renesas - Enforce Renesas calling convention."),
+ NULL, NULL,
+ &setshcmdlist, &showshcmdlist);
}
}
static enum return_value_convention
-sh64_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache,
+sh64_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
if (sh64_use_struct_convention (type))
*bp_addr = sp - 4;
*real_pc = funcaddr;
- if (using_struct_return (value_type))
+ if (using_struct_return (SYMBOL_TYPE (find_pc_function (funcaddr)),
+ value_type))
{
gdb_byte buf[4];
}
static enum return_value_convention
-sparc32_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+sparc32_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
/* The psABI says that "...every stack frame reserves the word at
%fp+64. If a function returns a structure, union, or
}
static enum return_value_convention
-sparc64_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+sparc64_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
if (TYPE_LENGTH (type) > 32)
return RETURN_VALUE_STRUCT_CONVENTION;
/* Function return value access. */
static enum return_value_convention
-spu_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *out, const gdb_byte *in)
+spu_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *out, const gdb_byte *in)
{
enum return_value_convention rvc;
is discarded, side effects such as "return i++" still
occur. */
return_value = NULL;
- else if (using_struct_return (return_type))
+ else if (using_struct_return (SYMBOL_TYPE (thisfun), return_type))
{
query_prefix = "\
The location at which to store the function's return value is unknown.\n\
{
struct type *return_type = value_type (return_value);
struct gdbarch *gdbarch = get_regcache_arch (get_current_regcache ());
- gdb_assert (gdbarch_return_value (gdbarch, return_type, NULL, NULL, NULL)
+ gdb_assert (gdbarch_return_value (gdbarch, SYMBOL_TYPE (thisfun),
+ return_type, NULL, NULL, NULL)
== RETURN_VALUE_REGISTER_CONVENTION);
- gdbarch_return_value (gdbarch, return_type,
+ gdbarch_return_value (gdbarch, SYMBOL_TYPE (thisfun), return_type,
get_current_regcache (), NULL /*read*/,
value_contents (return_value) /*write*/);
}
}
static enum return_value_convention
-v850_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache,
+v850_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
if (v850_use_struct_convention (type))
address as a hidden first parameter). */
int
-using_struct_return (struct type *value_type)
+using_struct_return (struct type *func_type, struct type *value_type)
{
enum type_code code = TYPE_CODE (value_type);
return 0;
/* Probe the architecture for the return-value convention. */
- return (gdbarch_return_value (current_gdbarch, value_type,
+ return (gdbarch_return_value (current_gdbarch, func_type, value_type,
NULL, NULL, NULL)
!= RETURN_VALUE_REGISTER_CONVENTION);
}
extern int value_bit_index (struct type *type, const gdb_byte *addr,
int index);
-extern int using_struct_return (struct type *value_type);
+extern int using_struct_return (struct type *func_type,
+ struct type *value_type);
extern struct value *evaluate_expression (struct expression *exp);
\f
static enum return_value_convention
-vax_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache, gdb_byte *readbuf,
- const gdb_byte *writebuf)
+vax_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
+ gdb_byte *readbuf, const gdb_byte *writebuf)
{
int len = TYPE_LENGTH (type);
gdb_byte buf[8];
}
static enum return_value_convention
-xstormy16_return_value (struct gdbarch *gdbarch, struct type *type,
- struct regcache *regcache,
+xstormy16_return_value (struct gdbarch *gdbarch, struct type *func_type,
+ struct type *type, struct regcache *regcache,
gdb_byte *readbuf, const gdb_byte *writebuf)
{
if (xstormy16_use_struct_convention (type))
static enum return_value_convention
xtensa_return_value (struct gdbarch *gdbarch,
+ struct type *func_type,
struct type *valtype,
struct regcache *regcache,
gdb_byte *readbuf,