From: Joel Brobecker <brobecker@adacore.com>
To: gdb-patches@sourceware.org
Subject: [commit/Ada] Print the correct type for float division/multiplication
Date: Fri, 13 Mar 2009 02:25:00 -0000 [thread overview]
Message-ID: <20090313022135.GF11284@adacore.com> (raw)
[-- 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"
next reply other threads:[~2009-03-13 2:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-13 2:25 Joel Brobecker [this message]
2009-03-13 2:32 ` 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=20090313022135.GF11284@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