diff mbox

[pushed] infcall: refactor 'call_function_by_hand_dummy'

Message ID 20191023190504.73D7B238BC@gnutoolchain-gerrit.osci.io
State New
Headers show

Commit Message

Simon Marchi (Code Review) Oct. 23, 2019, 7:05 p.m. UTC
Sourceware to Gerrit sync has submitted this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/138
......................................................................

infcall: refactor 'call_function_by_hand_dummy'

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 commit (e71585ffe2e "Use
gdb:array_view in call_function_by_hand & friends").

gdb/ChangeLog:
2019-10-23  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	* infcall.c (call_function_by_hand_dummy): Fix the function
	comment.  And extract out a code section into...
	(reserve_stack_space): ...this new function.

Change-Id: I8938ef4134aff68a0a21724aaa2406bfe453438a
---
M gdb/ChangeLog
M gdb/infcall.c
2 files changed, 45 insertions(+), 25 deletions(-)
diff mbox

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 52aea37..a976d8f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@ 
 2019-10-23  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
 
+	* infcall.c (call_function_by_hand_dummy): Fix the function
+	comment.  And extract out a code section into...
+	(reserve_stack_space): ...this new function.
+
+2019-10-23  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+
 	* infcall.c (value_arg_coerce): Remove an unused parameter.
 	(call_function_by_hand_dummy): Update the call to
 	'value_arg_coerce'.
diff --git a/gdb/infcall.c b/gdb/infcall.c
index b83f1bf..583f0de 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -668,6 +668,42 @@ 
   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 *
@@ -689,7 +725,7 @@ 
    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
@@ -989,8 +1025,7 @@ 
     }
 
   /* 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
@@ -1005,28 +1040,7 @@ 
 
   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<struct value *> new_args;
   if (return_method == return_method_hidden_param)