This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: fix PR 10680


I'm checking this in on the trunk and the 7.0 branch.

This fixes PR 10680.

The bug is that an internal function can't be used in || or &&.
This is because the function-calling code did not properly handle
internal functions in the EVAL_AVOID_SIDE_EFFECTS case.

There is not really a correct way to handle these functions here,
because the return type of these functions is unknown.  I chose to
pretend that they return 'int'.  This at least lets them work a bit.

Built and regtested on x86-64.  Test case included.

Tom

2009-09-22  Tom Tromey  <tromey@redhat.com>

	PR python/10680:
	* eval.c (evaluate_subexp_standard) <do_call_it>: Handle internal
	functions in EVAL_AVOID_SIDE_EFFECTS case.

2009-09-22  Tom Tromey  <tromey@redhat.com>

	* gdb.python/py-function.exp: Add regression tests.

diff --git a/gdb/eval.c b/gdb/eval.c
index f93c774..f67e211 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1514,11 +1514,18 @@ evaluate_subexp_standard (struct type *expect_type,
 	     gdb isn't asked for it's opinion (ie. through "whatis"),
 	     it won't offer it. */
 
-	  struct type *ftype =
-	  TYPE_TARGET_TYPE (value_type (argvec[0]));
+	  struct type *ftype = value_type (argvec[0]);
 
-	  if (ftype)
-	    return allocate_value (TYPE_TARGET_TYPE (value_type (argvec[0])));
+	  if (TYPE_CODE (ftype) == TYPE_CODE_INTERNAL_FUNCTION)
+	    {
+	      /* We don't know anything about what the internal
+		 function might return, but we have to return
+		 something.  */
+	      return value_zero (builtin_type (exp->gdbarch)->builtin_int,
+				 not_lval);
+	    }
+	  else if (TYPE_TARGET_TYPE (ftype))
+	    return allocate_value (TYPE_TARGET_TYPE (ftype));
 	  else
 	    error (_("Expression of type other than \"Function returning ...\" used as function"));
 	}
diff --git a/gdb/testsuite/gdb.python/py-function.exp b/gdb/testsuite/gdb.python/py-function.exp
index 4ae519f..14cd90c 100644
--- a/gdb/testsuite/gdb.python/py-function.exp
+++ b/gdb/testsuite/gdb.python/py-function.exp
@@ -56,3 +56,16 @@ gdb_py_test_multiple "input value-returning convenience function" \
   "end" ""
 
 gdb_test "print \$double (1)" "= 2" "call value-returning function"
+
+gdb_py_test_multiple "input int-returning function" \
+  "python" "" \
+  "class Yes(gdb.Function):" "" \
+  "    def __init__(self):" "" \
+  "        gdb.Function.__init__(self, 'yes')" "" \
+  "    def invoke(self):" "" \
+  "        return 1" "" \
+  "Yes ()" "" \
+  "end" ""
+
+gdb_test "print \$yes() && \$yes()" " = 1" "call yes with &&"
+gdb_test "print \$yes() || \$yes()" " = 1" "call yes with ||"


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]