From patchwork Mon Jun 24 09:29:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aktemur, Tankut Baris" X-Patchwork-Id: 33335 Received: (qmail 13348 invoked by alias); 24 Jun 2019 09:31:16 -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 13293 invoked by uid 89); 24 Jun 2019 09:31:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.4 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=reserves, H*r:LOCAL X-HELO: mga18.intel.com Received: from mga18.intel.com (HELO mga18.intel.com) (134.134.136.126) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Jun 2019 09:31:14 +0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jun 2019 02:30:25 -0700 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 24 Jun 2019 02:30:23 -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 x5O9UNh4020930; Mon, 24 Jun 2019 10:30:23 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id x5O9UNnZ022274; Mon, 24 Jun 2019 11:30:23 +0200 Received: (from taktemur@localhost) by ulvlx001.iul.intel.com with LOCAL id x5O9UNg1022270; Mon, 24 Jun 2019 11:30:23 +0200 From: Tankut Baris Aktemur To: gdb-patches@sourceware.org Cc: andrew.burgess@embecosm.com Subject: [PATCH v2 4/8] infcall: refactor 'call_function_by_hand_dummy' Date: Mon, 24 Jun 2019 11:29:44 +0200 Message-Id: <1561368588-21858-5-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 Extract out the code region that reserves stack space to a separate function. Fix the comment of 'call_function_by_hand_dummy' to remove reference to the NARGS argument that was removed in this commit: e71585ffe2e Use gdb:array_view in call_function_by_hand & friends gdb/ChangeLog: 2019-MM-DD Tankut Baris Aktemur * infcall.c (call_function_by_hand_dummy): Refactor. (reserve_stack_space): New. 2019-06-24 Tankut Baris Aktemur --- gdb/infcall.c | 64 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/gdb/infcall.c b/gdb/infcall.c index 9b833643dcc..ea96f887c8b 100644 --- a/gdb/infcall.c +++ b/gdb/infcall.c @@ -670,6 +670,42 @@ run_inferior_call (struct call_thread_fsm *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. */ + +static CORE_ADDR +reserve_stack_space (const type *values_type, CORE_ADDR &sp) +{ + struct frame_info *frame = get_current_frame (); + struct gdbarch *gdbarch = get_frame_arch (frame); + CORE_ADDR addr = 0; + + if (gdbarch_inner_than (gdbarch, 1, 2)) + { + /* Stack grows downward. Align STRUCT_ADDR and SP after + making space. */ + sp -= TYPE_LENGTH (values_type); + if (gdbarch_frame_align_p (gdbarch)) + sp = gdbarch_frame_align (gdbarch, sp); + addr = sp; + } + else + { + /* Stack grows upward. Align the frame, allocate space, and + then again, re-align the frame??? */ + if (gdbarch_frame_align_p (gdbarch)) + sp = gdbarch_frame_align (gdbarch, sp); + addr = sp; + sp += TYPE_LENGTH (values_type); + if (gdbarch_frame_align_p (gdbarch)) + sp = gdbarch_frame_align (gdbarch, sp); + } + + return addr; +} + /* See infcall.h. */ struct value * @@ -691,7 +727,7 @@ call_function_by_hand (struct value *function, making dummy frames be different from normal frames, consider that. */ /* Perform a function call in the inferior. - ARGS is a vector of values of arguments (NARGS of them). + ARGS is a vector of values of arguments. FUNCTION is a value, the function to be called. Returns a value representing what the function returned. May fail to return, if a breakpoint or signal is hit @@ -991,8 +1027,7 @@ call_function_by_hand_dummy (struct value *function, } /* Reserve space for the return structure to be written on the - stack, if necessary. Make certain that the value is correctly - aligned. + stack, if necessary. While evaluating expressions, we reserve space on the stack for return values of class type even if the language ABI and the target @@ -1007,28 +1042,7 @@ call_function_by_hand_dummy (struct value *function, if (return_method != return_method_normal || (stack_temporaries && class_or_union_p (values_type))) - { - if (gdbarch_inner_than (gdbarch, 1, 2)) - { - /* Stack grows downward. Align STRUCT_ADDR and SP after - making space for the return value. */ - sp -= TYPE_LENGTH (values_type); - if (gdbarch_frame_align_p (gdbarch)) - sp = gdbarch_frame_align (gdbarch, sp); - struct_addr = sp; - } - else - { - /* Stack grows upward. Align the frame, allocate space, and - then again, re-align the frame??? */ - if (gdbarch_frame_align_p (gdbarch)) - sp = gdbarch_frame_align (gdbarch, sp); - struct_addr = sp; - sp += TYPE_LENGTH (values_type); - if (gdbarch_frame_align_p (gdbarch)) - sp = gdbarch_frame_align (gdbarch, sp); - } - } + struct_addr = reserve_stack_space (values_type, sp); std::vector new_args; if (return_method == return_method_hidden_param)