This is the mail archive of the gdb-patches@sources.redhat.com 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]

[RFC] eval.c (evaluate_subexp_standard) Deal with c++ reference args


Hi,

I've been taking a gander at c++ testsuites, and I decided that I could
probably fix one or two of them. Here's an attempt at fixing inferior
function calls to functions containing reference arguments.

I have tested this on linux native and solaris native. The difference
between the pre-patched gdb and this new one are:

*** fails	Tue Oct 23 10:26:16 2001
--- fails2	Tue Oct 23 10:37:04 2001
*************** FAIL: gdb.base/funcargs.exp: print st
*** 3,13 ****
  FAIL: gdb.base/selftest.exp: unknown source line near main
  FAIL: gdb.base/selftest.exp: step into xmalloc call
  FAIL: gdb.c++/annota2.exp: watch triggered on a.x
- FAIL: gdb.c++/classes.exp: base class (&param)->a
- FAIL: gdb.c++/classes.exp: base class (&param)->x
- FAIL: gdb.c++/classes.exp: inherited class (&param)->a
- FAIL: gdb.c++/classes.exp: inherited class (&param)->x
- FAIL: gdb.c++/classes.exp: continue to enums2
  FAIL: gdb.c++/cplusfuncs.exp: info function for "operator*("
  FAIL: gdb.c++/cplusfuncs.exp: info function for "operator*=("
  FAIL: gdb.c++/cplusfuncs.exp: info function for "operator->*("
--- 3,8 ----

This is a nasty buglet, since it causes the inferior to SEGV, thereby
ruining any debugging session the user may have had.

This is not so nice a patch, which is why this is an RFC. The problem may
have a better solution, and I'm willing to chase suggestions. The biggest
problem with doing inferior function calls with reference arguments is
because we need to know what function we are calling before we can convert
its arguments to references. Unfortunately, eval_subexp_standard creates
the arguments before looking up the function, and we've got the old
chicken and egg problem.

This solution allows all of gdb's "normal" stuff to happen, checking
before doing the function call, for arguments that need to be converted to
reference types.

I have a followup patch to the testsuite to expand its testing of this. To
be posted shortly.

Comments, please.
Keith

ChangeLog
2001-10-23  Keith Seitz  <keiths@redhat.com>

	* eval.c (eval_subexp_standard): Convert any reference arguments
	to references for C++ inferior function calls.

Patch
Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.14
diff -u -p -r1.14 eval.c
--- eval.c	2001/10/16 01:58:07	1.14
+++ eval.c	2001/10/23 17:10:53
@@ -910,6 +910,33 @@ evaluate_subexp_standard (struct type *e
 	  /* nothing to be done; argvec already correctly set up */
 	}

+      /* Before calling a c++ function, check that reference types are
+	 passed as reference types and not something else. */
+      if (argvec[0] != NULL && exp->language_defn->la_language == language_cplus)
+	{
+	  struct type **args;
+	  args = TYPE_ARG_TYPES (VALUE_TYPE (argvec[0]));
+	  if (args != NULL)
+	    {
+	      /* args[0]   = "this" pointer
+		 args[1]   = first arg type
+		 argvec[0] = method
+		 argvec[1] = "this" pointer
+		 argvec[2] = first argument */
+	      for (ix = 1; args[ix] != NULL
+		     && TYPE_CODE (args[ix]) != TYPE_CODE_VOID; ix++)
+		{
+		  if (TYPE_CODE (args[ix]) == TYPE_CODE_REF
+		      && TYPE_CODE (VALUE_TYPE (argvec[2+ix-1])) != TYPE_CODE_REF)
+		    {
+		      struct value *v = value_addr (argvec[2+ix-1]);
+		      argvec[2+ix-1] =
+			value_cast (lookup_reference_type (VALUE_TYPE (v)), v);
+		    }
+		}
+	    }
+	}
+
     do_call_it:

       if (noside == EVAL_SKIP)




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