From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jim Blandy To: gdb-patches@sources.redhat.com Subject: PATCH: S/390: improve handling of structs returned by value Date: Thu, 29 Nov 2001 14:25:00 -0000 Message-id: <20011129222647.CB0835E9D8@zwingli.cygnus.com> X-SW-Source: 2001-11/msg00575.html 2001-11-29 Jim Blandy Tighten up GDB's support for returning structs by value. * s390-tdep.c (s390_use_struct_convention): New function. (s390_gdbarch_init): Register it as the S/390's USE_STRUCT_CONVENTION method. Register generic_cannot_extract_struct_value_address as our EXTRACT_STRUCT_VALUE_ADDRESS method. * arch-utils.c (generic_cannot_extract_struct_value_address): New function. * arch-utils.h: Add corresponding prototype. * values.c (value_being_returned): Make error message a proper sentence. * s390-tdep.c (s390_frame_saved_pc_nofix): If the prologue didn't save the return address register, assume that the return address is still in there. Index: gdb/s390-tdep.c =================================================================== RCS file: /cvs/cvsfiles/devo/gdb/s390-tdep.c,v retrieving revision 2.22 diff -c -r2.22 s390-tdep.c *** gdb/s390-tdep.c 2001/11/29 05:04:17 2.22 --- gdb/s390-tdep.c 2001/11/29 22:16:23 *************** *** 1592,1597 **** --- 1592,1608 ---- return sp; } + + static int + s390_use_struct_convention (int gcc_p, struct type *value_type) + { + enum type_code code = TYPE_CODE (value_type); + + return (code == TYPE_CODE_STRUCT + || code == TYPE_CODE_UNION); + } + + /* Return the GDB type object for the "standard" data type of data in register N. */ struct type * *************** *** 1735,1746 **** set_gdbarch_cannot_fetch_register (gdbarch, s390_cannot_fetch_register); set_gdbarch_cannot_store_register (gdbarch, s390_cannot_fetch_register); set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register); ! set_gdbarch_use_struct_convention (gdbarch, generic_use_struct_convention); set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid); set_gdbarch_register_name (gdbarch, s390_register_name); set_gdbarch_stab_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); set_gdbarch_dwarf_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); /* Parameters for inferior function calls. */ set_gdbarch_call_dummy_p (gdbarch, 1); --- 1746,1759 ---- set_gdbarch_cannot_fetch_register (gdbarch, s390_cannot_fetch_register); set_gdbarch_cannot_store_register (gdbarch, s390_cannot_fetch_register); set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register); ! set_gdbarch_use_struct_convention (gdbarch, s390_use_struct_convention); set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid); set_gdbarch_register_name (gdbarch, s390_register_name); set_gdbarch_stab_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); set_gdbarch_dwarf_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); + set_gdbarch_extract_struct_value_address + (gdbarch, generic_cannot_extract_struct_value_address); /* Parameters for inferior function calls. */ set_gdbarch_call_dummy_p (gdbarch, 1); *************** *** 1756,1762 **** set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1); set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0); set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0); - set_gdbarch_extract_struct_value_address (gdbarch, 0); set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy); set_gdbarch_push_return_address (gdbarch, s390_push_return_address); set_gdbarch_sizeof_call_dummy_words (gdbarch, --- 1769,1774 ---- Index: gdb/arch-utils.c =================================================================== RCS file: /cvs/cvsfiles/devo/gdb/arch-utils.c,v retrieving revision 2.27 diff -c -r2.27 arch-utils.c *** gdb/arch-utils.c 2001/11/06 11:09:09 2.27 --- gdb/arch-utils.c 2001/11/29 22:16:25 *************** *** 240,245 **** --- 240,260 ---- } + /* Under some ABI's that specify the `struct convention' for returning + structures by value, by the time we've returned from the function, + the return value is sitting there in the caller's buffer, but GDB + has no way to find the address of that buffer. + + On such architectures, use this function as your + extract_struct_value_address method. When asked to a struct + returned by value in this fashion, GDB will print a nice error + message, instead of garbage. */ + CORE_ADDR + generic_cannot_extract_struct_value_address (char *dummy) + { + return 0; + } + int default_register_sim_regno (int num) { Index: gdb/arch-utils.h =================================================================== RCS file: /cvs/cvsfiles/devo/gdb/arch-utils.h,v retrieving revision 2.20 diff -c -r2.20 arch-utils.h *** gdb/arch-utils.h 2001/11/06 11:09:09 2.20 --- gdb/arch-utils.h 2001/11/29 22:16:25 *************** *** 27,32 **** --- 27,34 ---- /* Fallback for register convertible. */ extern gdbarch_register_convertible_ftype generic_register_convertible_not; + extern CORE_ADDR generic_cannot_extract_struct_value_address (char *dummy); + /* Helper function for targets that don't know how my arguments are being passed */ extern gdbarch_frame_num_args_ftype frame_num_args_unknown; From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3483 invoked by alias); 29 Nov 2001 22:25:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.cygnus.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 3457 invoked from network); 29 Nov 2001 22:25:31 -0000 Received: from unknown (HELO zwingli.cygnus.com) (208.245.165.35) by hostedprojects.ges.redhat.com with SMTP; 29 Nov 2001 22:25:31 -0000 Received: by zwingli.cygnus.com (Postfix, from userid 442) id CB0835E9D8; Thu, 29 Nov 2001 17:26:47 -0500 (EST) From: Jim Blandy To: gdb-patches@sources.redhat.com Subject: PATCH: S/390: improve handling of structs returned by value Message-ID: <20011129222647.CB0835E9D8@zwingli.cygnus.com> Date: Mon, 19 Nov 2001 23:17:00 -0000 X-SW-Source: 2001-11/txt/msg00360.txt.bz2 Message-ID: <20011119231700.0EwdVKbII5NDokOH6njN9s6lmYlKRhj7zGmotccAsy0@z> 2001-11-29 Jim Blandy Tighten up GDB's support for returning structs by value. * s390-tdep.c (s390_use_struct_convention): New function. (s390_gdbarch_init): Register it as the S/390's USE_STRUCT_CONVENTION method. Register generic_cannot_extract_struct_value_address as our EXTRACT_STRUCT_VALUE_ADDRESS method. * arch-utils.c (generic_cannot_extract_struct_value_address): New function. * arch-utils.h: Add corresponding prototype. * values.c (value_being_returned): Make error message a proper sentence. * s390-tdep.c (s390_frame_saved_pc_nofix): If the prologue didn't save the return address register, assume that the return address is still in there. Index: gdb/s390-tdep.c =================================================================== RCS file: /cvs/cvsfiles/devo/gdb/s390-tdep.c,v retrieving revision 2.22 diff -c -r2.22 s390-tdep.c *** gdb/s390-tdep.c 2001/11/29 05:04:17 2.22 --- gdb/s390-tdep.c 2001/11/29 22:16:23 *************** *** 1592,1597 **** --- 1592,1608 ---- return sp; } + + static int + s390_use_struct_convention (int gcc_p, struct type *value_type) + { + enum type_code code = TYPE_CODE (value_type); + + return (code == TYPE_CODE_STRUCT + || code == TYPE_CODE_UNION); + } + + /* Return the GDB type object for the "standard" data type of data in register N. */ struct type * *************** *** 1735,1746 **** set_gdbarch_cannot_fetch_register (gdbarch, s390_cannot_fetch_register); set_gdbarch_cannot_store_register (gdbarch, s390_cannot_fetch_register); set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register); ! set_gdbarch_use_struct_convention (gdbarch, generic_use_struct_convention); set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid); set_gdbarch_register_name (gdbarch, s390_register_name); set_gdbarch_stab_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); set_gdbarch_dwarf_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); /* Parameters for inferior function calls. */ set_gdbarch_call_dummy_p (gdbarch, 1); --- 1746,1759 ---- set_gdbarch_cannot_fetch_register (gdbarch, s390_cannot_fetch_register); set_gdbarch_cannot_store_register (gdbarch, s390_cannot_fetch_register); set_gdbarch_get_saved_register (gdbarch, generic_get_saved_register); ! set_gdbarch_use_struct_convention (gdbarch, s390_use_struct_convention); set_gdbarch_frame_chain_valid (gdbarch, func_frame_chain_valid); set_gdbarch_register_name (gdbarch, s390_register_name); set_gdbarch_stab_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); set_gdbarch_dwarf_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum); + set_gdbarch_extract_struct_value_address + (gdbarch, generic_cannot_extract_struct_value_address); /* Parameters for inferior function calls. */ set_gdbarch_call_dummy_p (gdbarch, 1); *************** *** 1756,1762 **** set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1); set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0); set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0); - set_gdbarch_extract_struct_value_address (gdbarch, 0); set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy); set_gdbarch_push_return_address (gdbarch, s390_push_return_address); set_gdbarch_sizeof_call_dummy_words (gdbarch, --- 1769,1774 ---- Index: gdb/arch-utils.c =================================================================== RCS file: /cvs/cvsfiles/devo/gdb/arch-utils.c,v retrieving revision 2.27 diff -c -r2.27 arch-utils.c *** gdb/arch-utils.c 2001/11/06 11:09:09 2.27 --- gdb/arch-utils.c 2001/11/29 22:16:25 *************** *** 240,245 **** --- 240,260 ---- } + /* Under some ABI's that specify the `struct convention' for returning + structures by value, by the time we've returned from the function, + the return value is sitting there in the caller's buffer, but GDB + has no way to find the address of that buffer. + + On such architectures, use this function as your + extract_struct_value_address method. When asked to a struct + returned by value in this fashion, GDB will print a nice error + message, instead of garbage. */ + CORE_ADDR + generic_cannot_extract_struct_value_address (char *dummy) + { + return 0; + } + int default_register_sim_regno (int num) { Index: gdb/arch-utils.h =================================================================== RCS file: /cvs/cvsfiles/devo/gdb/arch-utils.h,v retrieving revision 2.20 diff -c -r2.20 arch-utils.h *** gdb/arch-utils.h 2001/11/06 11:09:09 2.20 --- gdb/arch-utils.h 2001/11/29 22:16:25 *************** *** 27,32 **** --- 27,34 ---- /* Fallback for register convertible. */ extern gdbarch_register_convertible_ftype generic_register_convertible_not; + extern CORE_ADDR generic_cannot_extract_struct_value_address (char *dummy); + /* Helper function for targets that don't know how my arguments are being passed */ extern gdbarch_frame_num_args_ftype frame_num_args_unknown;