Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: [commit/ada+testsuite] print ada boolean expression results as true/false
Date: Fri, 28 Dec 2007 06:36:00 -0000	[thread overview]
Message-ID: <20071228061513.GA24450@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 937 bytes --]

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

[-- Attachment #2: boolean-ada.diff --]
[-- Type: text/plain, Size: 1716 bytes --]

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;
     }

[-- Attachment #3: boolean_expr.exp --]
[-- Type: text/plain, Size: 1182 bytes --]

# 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"


             reply	other threads:[~2007-12-28  6:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-28  6:36 Joel Brobecker [this message]
2007-12-28 10:33 ` Mark Kettenis
2007-12-28 13:10   ` Joel Brobecker
2007-12-28 13:22     ` Joel Brobecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071228061513.GA24450@adacore.com \
    --to=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox