Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [commit/Ada] Print the correct type for float  division/multiplication
@ 2009-03-13  2:25 Joel Brobecker
  2009-03-13  2:32 ` Joel Brobecker
  0 siblings, 1 reply; 2+ messages in thread
From: Joel Brobecker @ 2009-03-13  2:25 UTC (permalink / raw)
  To: gdb-patches

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

This is a bug that we (actually Pierre Muller) found by code inspection.
We don't need to debug any program in order to reproduce the problem:

    (gdb) set lang ada
    (gdb) ptype 3 / 2.0
    type = <4-byte integer>

The debugger was using the type of the left hand operand in order
to determine the type of the result.  Although the expression is
strictly illegal in Ada, we try to be accepting in what the user
can enter, and we already do handle the case where the user prints
the actual result instead of querying the result type:

    (gdb) print 3 / 2.0
    $1 = 1.5
    (gdb) ptype $
    type = <12-byte float>

So it seems reasonable and even expected that the ptype above
should return:

    (gdb) ptype 3 / 2.0
    type = <12-byte float>

Especially since this was very easy to do.

2009-03-12  Joel Brobecker  <brobecker@adacore.com>

        * ada-lang.c (ada_evaluate_subexp) <BINOP_DIV>: make sure to
        promote the operands when noside is EVAL_AVOID_SIDE_EFFECTS.

2009-03-12  Joel Brobecker  <brobecker@adacore.com>

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

Tested on amd64-linux. Checked in.

(I do realize now that I forgot to remove some commented out code
in the .exp file, so I'll fix that next. Sorry!)

-- 
Joel

[-- Attachment #2: 11-div.diff --]
[-- Type: text/x-diff, Size: 663 bytes --]

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index aa5dece..f1a4268 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -8458,7 +8458,10 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
         goto nosideret;
       else if (noside == EVAL_AVOID_SIDE_EFFECTS
                && (op == BINOP_DIV || op == BINOP_REM || op == BINOP_MOD))
-        return value_zero (value_type (arg1), not_lval);
+        {
+          binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+          return value_zero (value_type (arg1), not_lval);
+        }
       else
         {
           type = builtin_type (exp->gdbarch)->builtin_double;

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

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

# set testdir "array_bounds"
# set testfile "${testdir}/bar"
# set srcfile ${srcdir}/${subdir}/${testfile}.adb
# set binfile ${objdir}/${subdir}/${testfile}
# 
# file mkdir ${objdir}/${subdir}/${testdir}
# if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
#   return -1
# }

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
# gdb_load ${binfile}

#set bp_location [gdb_get_line_number "STOP" ${testdir}/bar.adb]
#if ![runto "bar.adb:$bp_location" ] then {
#  perror "Couldn't run ${testfile}"
#  return
#} 

gdb_test "set lang ada" \
         "" \
         "set lang ada"

gdb_test "ptype 3 * 2.0" \
         "= <\[0-9\]+-byte float>" \
         "ptype 3 * 2.0"

gdb_test "ptype 3 / 2.0" \
         "= <\[0-9\]+-byte float>" \
         "ptype 3 / 2.0"



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [commit/Ada] Print the correct type for float  division/multiplication
  2009-03-13  2:25 [commit/Ada] Print the correct type for float division/multiplication Joel Brobecker
@ 2009-03-13  2:32 ` Joel Brobecker
  0 siblings, 0 replies; 2+ messages in thread
From: Joel Brobecker @ 2009-03-13  2:32 UTC (permalink / raw)
  To: gdb-patches

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

> (I do realize now that I forgot to remove some commented out code
> in the .exp file, so I'll fix that next. Sorry!)

Fixed thusly:

2009-03-12  Joel Brobecker  <brobecker@adacore.com>

        * gdb.ada/ptype_arith_binop.exp: Remove some commented-out code
        that was checked in by mistake. Remove loading of ada.exp, since
        this is not necessary in this case.

Tested on amd64-linux. Checked in.

-- 
Joel

[-- Attachment #2: 12-erratum.diff --]
[-- Type: text/x-diff, Size: 1750 bytes --]

Index: gdb.ada/ptype_arith_binop.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.ada/ptype_arith_binop.exp,v
retrieving revision 1.1
diff -u -p -r1.1 ptype_arith_binop.exp
--- gdb.ada/ptype_arith_binop.exp	13 Mar 2009 02:15:36 -0000	1.1
+++ gdb.ada/ptype_arith_binop.exp	13 Mar 2009 02:23:54 -0000
@@ -17,28 +17,9 @@ if $tracelevel then {
     strace $tracelevel
 }
 
-load_lib "ada.exp"
-
-# set testdir "array_bounds"
-# set testfile "${testdir}/bar"
-# set srcfile ${srcdir}/${subdir}/${testfile}.adb
-# set binfile ${objdir}/${subdir}/${testfile}
-# 
-# file mkdir ${objdir}/${subdir}/${testdir}
-# if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
-#   return -1
-# }
-
 gdb_exit
 gdb_start
 gdb_reinitialize_dir $srcdir/$subdir
-# gdb_load ${binfile}
-
-#set bp_location [gdb_get_line_number "STOP" ${testdir}/bar.adb]
-#if ![runto "bar.adb:$bp_location" ] then {
-#  perror "Couldn't run ${testfile}"
-#  return
-#} 
 
 gdb_test "set lang ada" \
          "" \
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/ChangeLog,v
retrieving revision 1.1824
diff -u -p -r1.1824 ChangeLog
--- ChangeLog	13 Mar 2009 02:15:36 -0000	1.1824
+++ ChangeLog	13 Mar 2009 02:24:00 -0000
@@ -1,5 +1,11 @@
 2009-03-12  Joel Brobecker  <brobecker@adacore.com>
 
+	* gdb.ada/ptype_arith_binop.exp: Remove some commented-out code
+	that was checked in by mistake. Remove loading of ada.exp, since
+	this is not necessary in this case.
+
+2009-03-12  Joel Brobecker  <brobecker@adacore.com>
+
 	* gdb.ada/ptype_arith_binop.exp: New testcase.
 
 2009-03-12  Joel Brobecker  <brobecker@adacore.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-03-13  2:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-13  2:25 [commit/Ada] Print the correct type for float division/multiplication Joel Brobecker
2009-03-13  2:32 ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox