Patchwork [5/8] infcall: move assertions in 'call_function_by_hand_dummy' to an earlier spot

login
register
mail settings
Submitter Tankut Baris Aktemur
Date April 23, 2019, 2:31 p.m.
Message ID <1556029914-21250-6-git-send-email-tankut.baris.aktemur@intel.com>
Download mbox | patch
Permalink /patch/32388/
State New
Headers show

Comments

Tankut Baris Aktemur - April 23, 2019, 2:31 p.m.
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:

	* infcall.c (call_function_by_hand_dummy): Refactor.

---
 gdb/infcall.c | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

Patch

diff --git a/gdb/infcall.c b/gdb/infcall.c
index fd0fef185d5..e562790bd0d 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -767,6 +767,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 ());
@@ -872,23 +893,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))
@@ -966,9 +970,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;