From patchwork Mon Jun 24 09:29:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tankut Baris Aktemur X-Patchwork-Id: 33332 Received: (qmail 10088 invoked by alias); 24 Jun 2019 09:30:31 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 10031 invoked by uid 89); 24 Jun 2019 09:30:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=H*r:LOCAL, HX-Languages-Length:2584, Refactor, refactor X-HELO: mga17.intel.com Received: from mga17.intel.com (HELO mga17.intel.com) (192.55.52.151) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Jun 2019 09:30:29 +0000 Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jun 2019 02:30:27 -0700 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga007.fm.intel.com with ESMTP; 24 Jun 2019 02:30:26 -0700 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id x5O9UQc6020938; Mon, 24 Jun 2019 10:30:26 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id x5O9UP7K022281; Mon, 24 Jun 2019 11:30:25 +0200 Received: (from taktemur@localhost) by ulvlx001.iul.intel.com with LOCAL id x5O9UPDT022277; Mon, 24 Jun 2019 11:30:25 +0200 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Cc: andrew.burgess@embecosm.com Subject: [PATCH v2 5/8] infcall: move assertions in 'call_function_by_hand_dummy' to an earlier spot Date: Mon, 24 Jun 2019 11:29:45 +0200 Message-Id: <1561368588-21858-6-git-send-email-tankut.baris.aktemur@intel.com> In-Reply-To: <1561368588-21858-1-git-send-email-tankut.baris.aktemur@intel.com> References: <1561368588-21858-1-git-send-email-tankut.baris.aktemur@intel.com> X-IsSubscribed: yes This is a refactoring that performs type assertions on the callee function at the beginning of 'call_function_by_hand_dummy' rather than at a later point. gdb/ChangeLog: 2019-MM-DD Tankut Baris Aktemur * infcall.c (call_function_by_hand_dummy): Refactor. 2019-06-24 Tankut Baris Aktemur --- gdb/infcall.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/gdb/infcall.c b/gdb/infcall.c index ea96f887c8b..f3e244620e8 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -782,6 +782,27 @@ call_function_by_hand_dummy (struct value *function, if (!gdbarch_push_dummy_call_p (gdbarch)) error (_("This target does not support function calls.")); + /* Find the function type and do a sanity check. */ + type *ftype; + type *values_type; + CORE_ADDR funaddr = find_function_addr (function, &values_type, &ftype); + + if (values_type == NULL) + values_type = default_return_type; + if (values_type == NULL) + { + const char *name = get_function_name (funaddr, + name_buf, sizeof (name_buf)); + error (_("'%s' has unknown return type; " + "cast the call to its declared return type"), + name); + } + + values_type = check_typedef (values_type); + + if (args.size () < TYPE_NFIELDS (ftype)) + error (_("Too few arguments in function call.")); + /* A holder for the inferior status. This is only needed while we're preparing the inferior function call. */ infcall_control_state_up inf_status (save_infcall_control_state ()); @@ -887,23 +908,6 @@ call_function_by_hand_dummy (struct value *function, } } - type *ftype; - type *values_type; - CORE_ADDR funaddr = find_function_addr (function, &values_type, &ftype); - - if (values_type == NULL) - values_type = default_return_type; - if (values_type == NULL) - { - const char *name = get_function_name (funaddr, - name_buf, sizeof (name_buf)); - error (_("'%s' has unknown return type; " - "cast the call to its declared return type"), - name); - } - - values_type = check_typedef (values_type); - /* Are we returning a value using a structure return? */ if (gdbarch_return_in_first_hidden_param_p (gdbarch, values_type)) @@ -981,9 +985,6 @@ call_function_by_hand_dummy (struct value *function, internal_error (__FILE__, __LINE__, _("bad switch")); } - if (args.size () < TYPE_NFIELDS (ftype)) - error (_("Too few arguments in function call.")); - for (int i = args.size () - 1; i >= 0; i--) { int prototyped;