[commit/ada] fix long/float assignment to convenience variable

Joel Brobecker brobecker@adacore.com
Sat May 10 13:08:00 GMT 2008


Hello,

One of our users just noticed the following regression:

    (gdb) print $xxx := 1
    $1 = void   <<<-----   Ooops!

The problem was that we were trying to force the right hand site
to have the same type as the left hand side, which in this case
didn't really have any...  The fix was to make sure that we don't
do that when the left hand side is a convenience variable.

The problem was introduced when I introduced the following code
to fix another problem:

      /* If evaluating an OP_DOUBLE and an EXPECT_TYPE was provided,
         then we need to perform the conversion manually, because
         evaluate_subexp_standard doesn't do it.  This conversion is
         necessary in Ada because the different kinds of float/fixed
         types in Ada have different representations.

         Similarly, we need to perform the conversion from OP_LONG
         ourselves.  */
      if ((op == OP_DOUBLE || op == OP_LONG) && expect_type != NULL)
        arg1 = ada_value_cast (expect_type, arg1, noside);

2008-05-09  Joel Brobecker  <brobecker@adacore.com>

        * ada-lang.c (ada_evaluate_subexp) [BINOP_ASSIGN]: Do not force
        the type of the right hand side of the assignment to the type
        of the left hand side if the left hand side is a convenience
        variable.

I've also added a new testcase:

2008-05-09  Joel Brobecker  <brobecker@adacore.com>

        * gdb.ada/assign_1.exp: New testcase.
    
Tested on x86-linux, no regression. Checked in.

-- 
Joel
-------------- next part --------------
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.141
diff -u -p -r1.141 ada-lang.c
--- ada-lang.c	5 May 2008 14:37:32 -0000	1.141
+++ ada-lang.c	9 May 2008 23:49:35 -0000
@@ -8558,7 +8558,14 @@ ada_evaluate_subexp (struct type *expect
 	    return arg1;
 	  return ada_value_assign (arg1, arg1);
 	}
-      arg2 = evaluate_subexp (value_type (arg1), exp, pos, noside);
+      /* Force the evaluation of the rhs ARG2 to the type of the lhs ARG1,
+         except if the lhs of our assignment is a convenience variable.
+         In the case of assigning to a convenience variable, the lhs
+         should be exactly the result of the evaluation of the rhs.  */
+      type = value_type (arg1);
+      if (VALUE_LVAL (arg1) == lval_internalvar)
+         type = NULL;
+      arg2 = evaluate_subexp (type, exp, pos, noside);
       if (noside == EVAL_SKIP || noside == EVAL_AVOID_SIDE_EFFECTS)
         return arg1;
       if (ada_is_fixed_point_type (value_type (arg1)))
-------------- next part --------------
# Copyright 2008 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

if $tracelevel then {
    strace $tracelevel
}

load_lib "ada.exp"

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir

# Force the language to Ada, as this will not happen automatically
# in this case (no test program).
gdb_test "set lang ada" \
         "" \
         "Changing the language to ada"

gdb_test "print \$xxx := 1" \
         "1" \
         "set convenience variable \$xxx to 1"




More information about the Gdb-patches mailing list