[commit/ada+testsuite] print ada boolean expression results as true/false

Joel Brobecker brobecker@adacore.com
Fri Dec 28 06:36:00 GMT 2007


This is a minor improvement, when printing the result of a boolean
expression. Right now, GDB prints:

    (gdb) print 1 = 2
    $1 = 0
    (gdb) print 3 = 3
    $2 = 1

The result should be of type boolean, which means either true or false.
So the expected output is:

    (gdb) print 1 = 2
    $1 = false
    (gdb) print 3 = 3
    $2 = true

The attached patches fixes it.

2007-12-27  Paul Hilfinger  <hilfinger@adacore.com>

        * ada-lang.c (ada_evaluate_subexp): Add cases for BINOP_LOGICAL_AND,
        BINOP_LOGICAL_OR, UNOP_LOGICAL_NOT, BINOP_BITWISE_IOR,
        BINOP_BITWISE_XOR, BINOP_BITWISE_AND.
        * language.c (lang_bool_type): Add Ada case.
    
Tested on x86-linux. Checked in.

In addition, I have written a small testcase for it:

2007-12-27  Joel Brobecker  <brobecker@adacore.com>

        * gdb.ada/boolean_expr.exp: New testcase.

Also tested on x86-linux. Fails without the ada-lang.c patch.

-- 
Joel
-------------- next part --------------
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.112
diff -u -p -r1.112 ada-lang.c
--- ada-lang.c	24 Dec 2007 16:52:24 -0000	1.112
+++ ada-lang.c	28 Dec 2007 06:09:19 -0000
@@ -8151,6 +8151,24 @@ ada_evaluate_subexp (struct type *expect
       else
         return value_neg (arg1);
 
+    case BINOP_LOGICAL_AND:
+    case BINOP_LOGICAL_OR:
+    case UNOP_LOGICAL_NOT:
+      *pos -= 1;
+      return value_cast (LA_BOOL_TYPE, 
+			 evaluate_subexp_standard (expect_type, exp,
+						   pos, noside));
+
+    case BINOP_BITWISE_AND:
+    case BINOP_BITWISE_IOR:
+    case BINOP_BITWISE_XOR:
+      arg1 = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_AVOID_SIDE_EFFECTS);
+      *pos = pc;
+      return value_cast (value_type (arg1),
+			 evaluate_subexp_standard (expect_type, exp,
+						   pos, noside));
+			 
+
     case OP_VAR_VALUE:
       *pos -= 1;
       if (noside == EVAL_SKIP)
Index: language.c
===================================================================
RCS file: /cvs/src/src/gdb/language.c,v
retrieving revision 1.70
diff -u -p -r1.70 language.c
--- language.c	4 Dec 2007 23:33:00 -0000	1.70
+++ language.c	28 Dec 2007 06:09:19 -0000
@@ -801,6 +801,7 @@ lang_bool_type (void)
       return builtin_type_f_logical_s2;
     case language_cplus:
     case language_pascal:
+    case language_ada:
       if (current_language->la_language==language_cplus)
         {sym = lookup_symbol ("bool", NULL, VAR_DOMAIN, NULL, NULL);}
       else
@@ -821,6 +822,7 @@ lang_bool_type (void)
 	    return type;
 	}
       return java_boolean_type;
+      
     default:
       return builtin_type_int;
     }
-------------- next part --------------
# Copyright 2007 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

set any_nb "\[0-9\]+"
set any_addr "0x\[0-9a-zA-Z\]+"

# 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 1 = 2" \
         "false" \
         "print 1 = 2"

gdb_test "print 3 = 3" \
         "true" \
         "print 3 = 3"



More information about the Gdb-patches mailing list