From patchwork Wed Mar 22 17:13:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Bouhaouel, Mohamed" X-Patchwork-Id: 66757 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA218385B50D for ; Wed, 22 Mar 2023 17:14:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DA218385B50D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679505282; bh=PJ7PXZbs3cneS1OjJJh4YbT+IHzC/FdsuMRceG7qn9E=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=YWeb2geuZcyqvguJ6xwJArWzmg+zzuYMC6GZM9bd6W+19t6GxKGnL/puwXMP+GekB 30AnWeVpuTXa4SkrDWr2lI+qhDrBWSXJ8ye45W5fiRScuJFMwjxIG0lGtL8IeXJwlY sFpxkIV7kaOCz2BUGIxI1sWmXsySdm5YaVJ8aXNk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by sourceware.org (Postfix) with ESMTPS id A245B3857C45 for ; Wed, 22 Mar 2023 17:14:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A245B3857C45 X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="323124759" X-IronPort-AV: E=Sophos;i="5.98,282,1673942400"; d="scan'208";a="323124759" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2023 10:14:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="675359496" X-IronPort-AV: E=Sophos;i="5.98,282,1673942400"; d="scan'208";a="675359496" Received: from mbouhaou-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.63.83]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2023 10:14:15 -0700 To: gdb-patches@sourceware.org Subject: [PATCH 1/2] gdb, gdbarch, infcall: Add value_arg_coerce method to gdbarch. Date: Wed, 22 Mar 2023 18:13:51 +0100 Message-Id: <20230322171352.9087-2-mohamed.bouhaouel@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230322171352.9087-1-mohamed.bouhaouel@intel.com> References: <20230322171352.9087-1-mohamed.bouhaouel@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mohamed Bouhaouel via Gdb-patches From: "Bouhaouel, Mohamed" Reply-To: Mohamed Bouhaouel Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Change the 'value_arg_coerce' function from a static common method to a target-dependent method. Signed-off-by: Mohamed Bouhaouel --- gdb/gdbarch-gen.h | 7 +++++++ gdb/gdbarch.c | 22 ++++++++++++++++++++++ gdb/gdbarch.h | 1 + gdb/gdbarch_components.py | 16 ++++++++++++++++ gdb/infcall.c | 16 ++++++---------- gdb/infcall.h | 8 ++++++++ 6 files changed, 60 insertions(+), 10 deletions(-) diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index 76d12a15317..a9b0fe26837 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -319,6 +319,13 @@ typedef struct frame_id (gdbarch_dummy_id_ftype) (struct gdbarch *gdbarch, frame extern struct frame_id gdbarch_dummy_id (struct gdbarch *gdbarch, frame_info_ptr this_frame); extern void set_gdbarch_dummy_id (struct gdbarch *gdbarch, gdbarch_dummy_id_ftype *dummy_id); +/* Perform the standard coercions that are specified for arguments to + be passed to C, Ada or Fortran functions. */ + +typedef value * (gdbarch_value_arg_coerce_ftype) (struct gdbarch *gdbarch, value *arg, type *param_type, int is_prototyped); +extern value * gdbarch_value_arg_coerce (struct gdbarch *gdbarch, value *arg, type *param_type, int is_prototyped); +extern void set_gdbarch_value_arg_coerce (struct gdbarch *gdbarch, gdbarch_value_arg_coerce_ftype *value_arg_coerce); + /* Implement DUMMY_ID and PUSH_DUMMY_CALL, then delete deprecated_fp_regnum. */ diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index b4763aa6bf4..a411e5bbac7 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -91,6 +91,7 @@ struct gdbarch gdbarch_register_name_ftype *register_name = nullptr; gdbarch_register_type_ftype *register_type = nullptr; gdbarch_dummy_id_ftype *dummy_id = default_dummy_id; + gdbarch_value_arg_coerce_ftype *value_arg_coerce = default_value_arg_coerce; int deprecated_fp_regnum = -1; gdbarch_push_dummy_call_ftype *push_dummy_call = nullptr; enum call_dummy_location_type call_dummy_location = AT_ENTRY_POINT; @@ -346,6 +347,7 @@ verify_gdbarch (struct gdbarch *gdbarch) if (gdbarch->register_type == 0) log.puts ("\n\tregister_type"); /* Skip verify of dummy_id, invalid_p == 0 */ + /* Skip verify of value_arg_coerce, invalid_p == 0 */ /* Skip verify of deprecated_fp_regnum, invalid_p == 0 */ /* Skip verify of push_dummy_call, has predicate. */ /* Skip verify of call_dummy_location, invalid_p == 0 */ @@ -703,6 +705,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) gdb_printf (file, "gdbarch_dump: dummy_id = <%s>\n", host_address_to_string (gdbarch->dummy_id)); + gdb_printf (file, + "gdbarch_dump: value_arg_coerce = <%s>\n", + host_address_to_string (gdbarch->value_arg_coerce)); gdb_printf (file, "gdbarch_dump: deprecated_fp_regnum = %s\n", plongest (gdbarch->deprecated_fp_regnum)); @@ -2203,6 +2208,23 @@ set_gdbarch_dummy_id (struct gdbarch *gdbarch, gdbarch->dummy_id = dummy_id; } +value * +gdbarch_value_arg_coerce (struct gdbarch *gdbarch, value *arg, type *param_type, int is_prototyped) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->value_arg_coerce != NULL); + if (gdbarch_debug >= 2) + gdb_printf (gdb_stdlog, "gdbarch_value_arg_coerce called\n"); + return gdbarch->value_arg_coerce (gdbarch, arg, param_type, is_prototyped); +} + +void +set_gdbarch_value_arg_coerce (struct gdbarch *gdbarch, + gdbarch_value_arg_coerce_ftype value_arg_coerce) +{ + gdbarch->value_arg_coerce = value_arg_coerce; +} + int gdbarch_deprecated_fp_regnum (struct gdbarch *gdbarch) { diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index f0399c2fa88..cd0bcd1a6fe 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -25,6 +25,7 @@ #include "frame.h" #include "dis-asm.h" #include "gdbsupport/gdb_obstack.h" +#include "infcall.h" #include "infrun.h" #include "osabi.h" #include "displaced-stepping.h" diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index 92c501d2a72..10e8c2d52c8 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -606,6 +606,22 @@ frame. invalid=False, ) +Method( + comment=""" +Perform the standard coercions that are specified for arguments to +be passed to C, Ada or Fortran functions. +""", + type="value *", + name="value_arg_coerce", + params=[ + ("value *", "arg"), + ("type *", "param_type"), + ("int", "is_prototyped") + ], + predefault="default_value_arg_coerce", + invalid=False, +) + Value( comment=""" Implement DUMMY_ID and PUSH_DUMMY_CALL, then delete diff --git a/gdb/infcall.c b/gdb/infcall.c index 9ed17bf4f8b..b945adebc93 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -170,15 +170,11 @@ show_unwind_on_terminating_exception_p (struct ui_file *file, int from_tty, value); } -/* Perform the standard coercions that are specified - for arguments to be passed to C, Ada or Fortran functions. - - If PARAM_TYPE is non-NULL, it is the expected parameter type. - IS_PROTOTYPED is non-zero if the function declaration is prototyped. */ +/* See infcall.h. */ -static struct value * -value_arg_coerce (struct gdbarch *gdbarch, struct value *arg, - struct type *param_type, int is_prototyped) +value * +default_value_arg_coerce (gdbarch *gdbarch, value *arg, + type *param_type, int is_prototyped) { const struct builtin_type *builtin = builtin_type (gdbarch); struct type *arg_type = check_typedef (arg->type ()); @@ -1099,8 +1095,8 @@ call_function_by_hand_dummy (struct value *function, param_type = NULL; value *original_arg = args[i]; - args[i] = value_arg_coerce (gdbarch, args[i], - param_type, prototyped); + args[i] = gdbarch_value_arg_coerce (gdbarch, args[i], + param_type, prototyped); if (param_type == NULL) continue; diff --git a/gdb/infcall.h b/gdb/infcall.h index 81b0c8d3433..af3dd49220a 100644 --- a/gdb/infcall.h +++ b/gdb/infcall.h @@ -71,4 +71,12 @@ extern struct value * extern void error_call_unknown_return_type (const char *func_name); +/* Perform the standard coercions that are specified + for arguments to be passed to C, Ada or Fortran functions. + + If PARAM_TYPE is non-NULL, it is the expected parameter type. + IS_PROTOTYPED is non-zero if the function declaration is prototyped. */ + +extern value *default_value_arg_coerce (gdbarch *gdbarch, value *arg, + type *param_type, int is_prototyped); #endif From patchwork Wed Mar 22 17:13:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Bouhaouel, Mohamed" X-Patchwork-Id: 66758 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2CB79385802F for ; Wed, 22 Mar 2023 17:14:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2CB79385802F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679505299; bh=PT04HtKBhTOVoN4KLn1DxY/ae69N12myJ2rJNrooMGA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=BDRYsZII2zbULA+3ZUtOL2XEAV1NKaq5OFGWJQAmRObkDPMPlyBdKU0q8fSDLWPVL 1n11ZzwagD2+SX39dvsZF0CZBRCVBlUrRCZga8/iokr6bWn3CKEwo+Fn/cctna7JEM 8MFLOkP25MUSI5DtkT/8KHk2xou/L5adGFO5FBvk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by sourceware.org (Postfix) with ESMTPS id 37B6A385417E for ; Wed, 22 Mar 2023 17:14:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37B6A385417E X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="323124821" X-IronPort-AV: E=Sophos;i="5.98,282,1673942400"; d="scan'208";a="323124821" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2023 10:14:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10657"; a="675359524" X-IronPort-AV: E=Sophos;i="5.98,282,1673942400"; d="scan'208";a="675359524" Received: from mbouhaou-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.63.83]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Mar 2023 10:14:25 -0700 To: gdb-patches@sourceware.org Subject: [PATCH 2/2] gdb, gdbarch, infcall: Add reserve_stack_space method to gdbarch Date: Wed, 22 Mar 2023 18:13:52 +0100 Message-Id: <20230322171352.9087-3-mohamed.bouhaouel@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230322171352.9087-1-mohamed.bouhaouel@intel.com> References: <20230322171352.9087-1-mohamed.bouhaouel@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Mohamed Bouhaouel via Gdb-patches From: "Bouhaouel, Mohamed" Reply-To: Mohamed Bouhaouel Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Change the 'reserve_stack_space' function from a static common method to a target-dependent method. Signed-off-by: Mohamed Bouhaouel --- gdb/gdbarch-gen.h | 6 ++++++ gdb/gdbarch.c | 22 ++++++++++++++++++++++ gdb/gdbarch_components.py | 10 ++++++++++ gdb/infcall.c | 16 ++++++---------- gdb/infcall.h | 9 +++++++++ 5 files changed, 53 insertions(+), 10 deletions(-) diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index a9b0fe26837..ca3e074de8f 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -1687,3 +1687,9 @@ extern void set_gdbarch_get_pc_address_flags (struct gdbarch *gdbarch, gdbarch_g typedef void (gdbarch_read_core_file_mappings_ftype) (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_pre_loop_ftype pre_loop_cb, read_core_file_mappings_loop_ftype loop_cb); extern void gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_pre_loop_ftype pre_loop_cb, read_core_file_mappings_loop_ftype loop_cb); extern void set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, gdbarch_read_core_file_mappings_ftype *read_core_file_mappings); + +/* Reserve space on the stack for a value of the given type. */ + +typedef CORE_ADDR (gdbarch_reserve_stack_space_ftype) (struct gdbarch *gdbarch, const type *valtype, CORE_ADDR &sp); +extern CORE_ADDR gdbarch_reserve_stack_space (struct gdbarch *gdbarch, const type *valtype, CORE_ADDR &sp); +extern void set_gdbarch_reserve_stack_space (struct gdbarch *gdbarch, gdbarch_reserve_stack_space_ftype *reserve_stack_space); diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index a411e5bbac7..25fdfc6b4c2 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -254,6 +254,7 @@ struct gdbarch gdbarch_type_align_ftype *type_align = default_type_align; gdbarch_get_pc_address_flags_ftype *get_pc_address_flags = default_get_pc_address_flags; gdbarch_read_core_file_mappings_ftype *read_core_file_mappings = default_read_core_file_mappings; + gdbarch_reserve_stack_space_ftype *reserve_stack_space = default_reserve_stack_space; }; /* Create a new ``struct gdbarch'' based on information provided by @@ -518,6 +519,7 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of type_align, invalid_p == 0 */ /* Skip verify of get_pc_address_flags, invalid_p == 0 */ /* Skip verify of read_core_file_mappings, invalid_p == 0 */ + /* Skip verify of reserve_stack_space, invalid_p == 0 */ if (!log.empty ()) internal_error (_("verify_gdbarch: the following are invalid ...%s"), log.c_str ()); @@ -1362,6 +1364,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) gdb_printf (file, "gdbarch_dump: read_core_file_mappings = <%s>\n", host_address_to_string (gdbarch->read_core_file_mappings)); + gdb_printf (file, + "gdbarch_dump: reserve_stack_space = <%s>\n", + host_address_to_string (gdbarch->reserve_stack_space)); if (gdbarch->dump_tdep != NULL) gdbarch->dump_tdep (gdbarch, file); } @@ -5365,3 +5370,20 @@ set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, { gdbarch->read_core_file_mappings = read_core_file_mappings; } + +CORE_ADDR +gdbarch_reserve_stack_space (struct gdbarch *gdbarch, const type *valtype, CORE_ADDR &sp) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->reserve_stack_space != NULL); + if (gdbarch_debug >= 2) + gdb_printf (gdb_stdlog, "gdbarch_reserve_stack_space called\n"); + return gdbarch->reserve_stack_space (gdbarch, valtype, sp); +} + +void +set_gdbarch_reserve_stack_space (struct gdbarch *gdbarch, + gdbarch_reserve_stack_space_ftype reserve_stack_space) +{ + gdbarch->reserve_stack_space = reserve_stack_space; +} diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index 10e8c2d52c8..800054a34b4 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -2683,3 +2683,13 @@ Read core file mappings predefault="default_read_core_file_mappings", invalid=False, ) + +Method( + comment="Reserve space on the stack for a value of the given type.", + type="CORE_ADDR", + name="reserve_stack_space", + params=[("const type *", "valtype"), ("CORE_ADDR &", "sp")], + predefault="default_reserve_stack_space", + predicate=False, + invalid=False, +) diff --git a/gdb/infcall.c b/gdb/infcall.c index b945adebc93..8ef05bec3e0 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -702,16 +702,12 @@ run_inferior_call (std::unique_ptr sm, return caught_error; } -/* Reserve space on the stack for a value of the given type. - Return the address of the allocated space. - Make certain that the value is correctly aligned. - The SP argument is modified. */ +/* See infcall.h. */ -static CORE_ADDR -reserve_stack_space (const type *values_type, CORE_ADDR &sp) +CORE_ADDR +default_reserve_stack_space (gdbarch *gdbarch, const type *values_type, + CORE_ADDR &sp) { - frame_info_ptr frame = get_current_frame (); - struct gdbarch *gdbarch = get_frame_arch (frame); CORE_ADDR addr = 0; if (gdbarch_inner_than (gdbarch, 1, 2)) @@ -1116,7 +1112,7 @@ call_function_by_hand_dummy (struct value *function, /* Make a copy of the argument on the stack. If the argument is trivially copy ctor'able, copy bit by bit. Otherwise, call the copy ctor to initialize the clone. */ - CORE_ADDR addr = reserve_stack_space (param_type, sp); + CORE_ADDR addr = gdbarch_reserve_stack_space (gdbarch, param_type, sp); value *clone = value_from_contents_and_address (param_type, nullptr, addr); push_thread_stack_temporary (call_thread.get (), clone); @@ -1201,7 +1197,7 @@ call_function_by_hand_dummy (struct value *function, if (return_method != return_method_normal || (stack_temporaries && class_or_union_p (values_type))) - struct_addr = reserve_stack_space (values_type, sp); + struct_addr = gdbarch_reserve_stack_space (gdbarch, values_type, sp); std::vector new_args; if (return_method == return_method_hidden_param) diff --git a/gdb/infcall.h b/gdb/infcall.h index af3dd49220a..807d86d3989 100644 --- a/gdb/infcall.h +++ b/gdb/infcall.h @@ -79,4 +79,13 @@ extern void error_call_unknown_return_type (const char *func_name); extern value *default_value_arg_coerce (gdbarch *gdbarch, value *arg, type *param_type, int is_prototyped); + +/* Reserve space on the stack for a value of the given type. + Return the address of the allocated space. + Make certain that the value is correctly aligned. + The SP argument is modified. */ + +extern CORE_ADDR default_reserve_stack_space (gdbarch *gdbarch, + const type *values_type, + CORE_ADDR &sp); #endif