[binutils-gdb] Clean up arguments to evaluate_subexp_do_call

Tom Tromey tromey@sourceware.org
Wed Dec 16 01:05:44 GMT 2020


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1ab8280d7dbe01f51929d221621d38450f31895d

commit 1ab8280d7dbe01f51929d221621d38450f31895d
Author: Tom Tromey <tom@tromey.com>
Date:   Tue Dec 15 17:53:34 2020 -0700

    Clean up arguments to evaluate_subexp_do_call
    
    I noticed hat evaluate_subexp_do_call takes an array of arguments and
    a count -- but, unlike the usual convention, the count does not
    include the first element.
    
    This patch changes this function to match call_function_by_hand --
    passing the callee separately, and using an array_view for the
    arguments.  This makes it simpler to understand.
    
    Regression tested on x86-64 Fedora 28.
    
    gdb/ChangeLog
    2020-12-15  Tom Tromey  <tom@tromey.com>
    
            * f-lang.c (evaluate_subexp_f): Update.
            * expression.h (evaluate_subexp_do_call): Update.
            * eval.c (evaluate_subexp_do_call): Add callee parameter.  Replace
            nargs, argvec with array_view.
            (evaluate_funcall): Update.

Diff:
---
 gdb/ChangeLog    |  8 ++++++++
 gdb/eval.c       | 26 ++++++++++++--------------
 gdb/expression.h |  7 ++++---
 gdb/f-lang.c     |  6 ++++--
 4 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5f2c5b82aa8..464054c83cf 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2020-12-15  Tom Tromey  <tom@tromey.com>
+
+	* f-lang.c (evaluate_subexp_f): Update.
+	* expression.h (evaluate_subexp_do_call): Update.
+	* eval.c (evaluate_subexp_do_call): Add callee parameter.  Replace
+	nargs, argvec with array_view.
+	(evaluate_funcall): Update.
+
 2020-12-15  Tom Tromey  <tom@tromey.com>
 
 	* ada-lang.c (num_component_specs): Remove.
diff --git a/gdb/eval.c b/gdb/eval.c
index 3f587694776..6066a320414 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -692,11 +692,12 @@ eval_skip_value (expression *exp)
 
 value *
 evaluate_subexp_do_call (expression *exp, enum noside noside,
-			 int nargs, value **argvec,
+			 value *callee,
+			 gdb::array_view<value *> argvec,
 			 const char *function_name,
 			 type *default_return_type)
 {
-  if (argvec[0] == NULL)
+  if (callee == NULL)
     error (_("Cannot evaluate function -- may be inlined"));
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
     {
@@ -704,7 +705,7 @@ evaluate_subexp_do_call (expression *exp, enum noside noside,
 	 call an error.  This can happen if somebody tries to turn
 	 a variable into a function call.  */
 
-      type *ftype = value_type (argvec[0]);
+      type *ftype = value_type (callee);
 
       if (ftype->code () == TYPE_CODE_INTERNAL_FUNCTION)
 	{
@@ -716,10 +717,7 @@ evaluate_subexp_do_call (expression *exp, enum noside noside,
 	}
       else if (ftype->code () == TYPE_CODE_XMETHOD)
 	{
-	  type *return_type
-	    = result_type_of_xmethod (argvec[0],
-				      gdb::make_array_view (argvec + 1,
-							    nargs));
+	  type *return_type = result_type_of_xmethod (callee, argvec);
 
 	  if (return_type == NULL)
 	    error (_("Xmethod is missing return type."));
@@ -730,7 +728,7 @@ evaluate_subexp_do_call (expression *exp, enum noside noside,
 	{
 	  if (ftype->is_gnu_ifunc ())
 	    {
-	      CORE_ADDR address = value_address (argvec[0]);
+	      CORE_ADDR address = value_address (callee);
 	      type *resolved_type = find_gnu_ifunc_target_type (address);
 
 	      if (resolved_type != NULL)
@@ -751,16 +749,15 @@ evaluate_subexp_do_call (expression *exp, enum noside noside,
 	error (_("Expression of type other than "
 		 "\"Function returning ...\" used as function"));
     }
-  switch (value_type (argvec[0])->code ())
+  switch (value_type (callee)->code ())
     {
     case TYPE_CODE_INTERNAL_FUNCTION:
       return call_internal_function (exp->gdbarch, exp->language_defn,
-				     argvec[0], nargs, argvec + 1);
+				     callee, argvec.size (), argvec.data ());
     case TYPE_CODE_XMETHOD:
-      return call_xmethod (argvec[0], gdb::make_array_view (argvec + 1, nargs));
+      return call_xmethod (callee, argvec);
     default:
-      return call_function_by_hand (argvec[0], default_return_type,
-				    gdb::make_array_view (argvec + 1, nargs));
+      return call_function_by_hand (callee, default_return_type, argvec);
     }
 }
 
@@ -1165,7 +1162,8 @@ evaluate_funcall (type *expect_type, expression *exp, int *pos,
       /* Nothing to be done; argvec already correctly set up.  */
     }
 
-  return evaluate_subexp_do_call (exp, noside, nargs, argvec,
+  return evaluate_subexp_do_call (exp, noside, argvec[0],
+				  gdb::make_array_view (argvec + 1, nargs),
 				  var_func_name, expect_type);
 }
 
diff --git a/gdb/expression.h b/gdb/expression.h
index 9ac940fa4d0..0c4dc7bae17 100644
--- a/gdb/expression.h
+++ b/gdb/expression.h
@@ -153,15 +153,16 @@ enum noside
 extern struct value *evaluate_subexp_standard
   (struct type *, struct expression *, int *, enum noside);
 
-/* Evaluate a function call.  The function to be called is in ARGVEC[0] and
-   the arguments passed to the function are in ARGVEC[1..NARGS].
+/* Evaluate a function call.  The function to be called is in CALLEE and
+   the arguments passed to the function are in ARGVEC.
    FUNCTION_NAME is the name of the function, if known.
    DEFAULT_RETURN_TYPE is used as the function's return type if the return
    type is unknown.  */
 
 extern struct value *evaluate_subexp_do_call (expression *exp,
 					      enum noside noside,
-					      int nargs, value **argvec,
+					      value *callee,
+					      gdb::array_view<value *> argvec,
 					      const char *function_name,
 					      type *default_return_type);
 
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index bbece501799..28a66fdde94 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -947,8 +947,10 @@ evaluate_subexp_f (struct type *expect_type, struct expression *exp,
 	    argvec[tem] = 0;	/* signal end of arglist */
 	    if (noside == EVAL_SKIP)
 	      return eval_skip_value (exp);
-	    return evaluate_subexp_do_call (exp, noside, nargs, argvec, NULL,
-					    expect_type);
+	    return evaluate_subexp_do_call (exp, noside, argvec[0],
+					    gdb::make_array_view (argvec + 1,
+								  nargs),
+					    NULL, expect_type);
 	  }
 
 	default:


More information about the Gdb-cvs mailing list