From mboxrd@z Thu Jan 1 00:00:00 1970 From: Keith Seitz To: Subject: [RFC] eval.c (evaluate_subexp_standard) Deal with c++ reference args Date: Tue, 23 Oct 2001 11:40:00 -0000 Message-id: X-SW-Source: 2001-10/msg00301.html 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 (¶m)->a - FAIL: gdb.c++/classes.exp: base class (¶m)->x - FAIL: gdb.c++/classes.exp: inherited class (¶m)->a - FAIL: gdb.c++/classes.exp: inherited class (¶m)->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 * 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)