From: Klee Dienes <kdienes@apple.com>
To: Andrew Cagney <ac131313@cygnus.com>
Cc: Klee Dienes <klee@apple.com>, Daniel Jacobowitz <drow@mvista.com>,
gdb-patches@sources.redhat.com
Subject: Re: [RFA] Function return type checking
Date: Tue, 12 Mar 2002 02:38:00 -0000 [thread overview]
Message-ID: <3B4ED0FE-35A5-11D6-A901-0030653FA4C6@apple.com> (raw)
In-Reply-To: <3C8AE16D.9000502@cygnus.com>
[-- Attachment #1: Type: text/plain, Size: 3091 bytes --]
On Saturday, March 9, 2002, at 08:30 PM, Andrew Cagney wrote:
> I've personally got reservations over introducing a change that, given
> a file like:
>
> void
> b(void)
> {
> double d;
> d = (double) bar ((float) 3);
> }
>
> radically alters gdb's behavour given:
>
> print (double) bar((float) 3)
>
> and rejects (?)
>
> print bar((float) 3)
I think that's a very valid reservation. But let me expand the example
a bit:
$ cat a.c
double foo (float f)
{
return (f + 1.0);
}
double bar (float f)
{
return (f + 1.0);
}
$ cat b.c
double foo (float);
int main ()
{
double d1, d2;
d1 = (double) foo ((float) 3);
d2 = (double) bar ((float) 3);
}
$ cc -c a.c
$ cc -g -c b.c
$ cc a.o b.o -o a
In "standard" GDB, you get the following results:
(gdb) print d1
$1 = 4
(gdb) print d2
$2 = 1 /* generic bogus value */
(gdb) print (double) foo ((float) 3)
$3 = 1 /* generic bogus value */
(gdb) print (double) bar ((float) 3)
$4 = 1 /* generic bogus value */
In GDB as patched, you get:
(gdb) print d1
$1 = 4
(gdb) print d2
$2 = 1074266112 /* generic bogus value */
(gdb) print (double) foo ((float) 3)
$3 = 4
(gdb) print (double) bar ((float) 3)
$4 = 4
I'd argue that the real problem here is that the calling conventions for
a function call are determined for GCC and for GDB in two very different
ways. In the case of GCC, it's based on what signature GCC has seen for
the function. In the case of GDB, it's based on what debugging
information is available for the function being called. This means that
it's always going to be possible for there to be a mismatch between
behavior of GCC and GDB when evaluating expressions, and my patch does
not try to address that. My patch only changes the default behavior
from two "incorrect" results (only one of which matches the behavior of
GCC), to two "correct" results (only one of which matches the behavior
of GCC). I'd argue that it's better to err on the side of returning the
correct result, if you have to err at all, and that in the case where
you do want the exact behavior of GCC,
print (float) (int) bar ((float) 3)
is much more intuitive and easy to type than
print ((float (*) ()) bar) ((float) 3)
> and rejects (?)
>
> print bar((float) 3)
Correct; this would print:
Unable to call function at 0x1df8: no return type information available.
To call this function anyway, you can cast the return type explicitly
(e.g. 'print (float) fabs (3.0)')
> Is this feature intended for C or ObjectiveC developers?
I'd intend for this to be used by everyone. We specifically added it in
response to bug reports from people making heavy use of the system math
libraries; as well as from Cocoa (Objective-C) developers making heavy
use of functions returning NSRect objects. The reason it's of interest
to me in preparing the Objective-C patches is that much of the
Objective-C GDB code makes use of being able to pass 'expected_type'
arguments to the modified functions, and I'd rather not have to
re-architect all those calls before submitting the patches.
[-- Attachment #2: Type: text/enriched, Size: 3211 bytes --]
On Saturday, March 9, 2002, at 08:30 PM, Andrew Cagney wrote:
<excerpt>I've personally got reservations over introducing a change
that, given a file like:
void
b(void)
{
double d;
d = (double) bar ((float) 3);
}
radically alters gdb's behavour given:
print (double) bar((float) 3)
and rejects (?)
print bar((float) 3)
</excerpt>
I think that's a very valid reservation. But let me expand the
example a bit:
$ cat a.c
double foo (float f)
{
return (f + 1.0);
}
double bar (float f)
{
return (f + 1.0);
}
$ cat b.c
double foo (float);
int main ()
{
double d1, d2;
d1 = (double) foo ((float) 3);
d2 = (double) bar ((float) 3);
}
$ cc -c a.c
$ cc -g -c b.c
$ cc a.o b.o -o a
In "standard" GDB, you get the following results:
(gdb) print d1
$1 = 4
(gdb) print d2
$2 = 1 /* generic bogus value */
(gdb) print (double) foo ((float) 3)
$3 = 1 /* generic bogus value */
(gdb) print (double) bar ((float) 3)
$4 = 1 /* generic bogus value */
In GDB as patched, you get:
(gdb) print d1
$1 = 4
(gdb) print d2
$2 = 1074266112 /* generic bogus value */
(gdb) print (double) foo ((float) 3)
$3 = 4
(gdb) print (double) bar ((float) 3)
$4 = 4
I'd argue that the real problem here is that the calling conventions
for a function call are determined for GCC and for GDB in two very
different ways. In the case of GCC, it's based on what signature GCC
has seen for the function. In the case of GDB, it's based on what
debugging information is available for the function being called.
This means that it's always going to be possible for there to be a
mismatch between behavior of GCC and GDB when evaluating expressions,
and my patch does not try to address that. My patch only changes the
default behavior from two "incorrect" results (only one of which
matches the behavior of GCC), to two "correct" results (only one of
which matches the behavior of GCC). I'd argue that it's better to err
on the side of returning the correct result, if you have to err at
all, and that in the case where you <italic>do</italic> want the exact
behavior of GCC,
print (float) (int) bar ((float) 3)
is much more intuitive and easy to type than
print ((float (*) ()) bar) ((float) 3)
<excerpt><color><param>0000,0000,DEDE</param>and rejects (?)
print bar((float) 3)</color>
</excerpt>
Correct; this would print:
Unable to call function at 0x1df8: no return type information
available.
To call this function anyway, you can cast the return type explicitly
(e.g. 'print (float) fabs (3.0)')
<excerpt>Is this feature intended for C or ObjectiveC developers?
</excerpt>
I'd intend for this to be used by everyone. We specifically added it
in response to bug reports from people making heavy use of the system
math libraries; as well as from Cocoa (Objective-C) developers making
heavy use of functions returning NSRect objects. The reason it's of
interest to me in preparing the Objective-C patches is that much of
the Objective-C GDB code makes use of being able to pass
'expected_type' arguments to the modified functions, and I'd rather
not have to re-architect all those calls before submitting the patches.
next prev parent reply other threads:[~2002-03-12 10:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-05 1:36 Klee Dienes
2002-02-05 3:24 ` Eli Zaretskii
2002-02-05 8:07 ` Daniel Jacobowitz
2002-02-06 13:43 ` Klee Dienes
2002-02-06 14:14 ` Daniel Jacobowitz
2002-03-09 20:30 ` Andrew Cagney
2002-03-12 2:38 ` Klee Dienes [this message]
2002-03-12 7:56 ` Andrew Cagney
2002-03-12 10:08 ` Klee Dienes
2002-03-12 10:34 ` Andrew Cagney
2002-02-08 13:41 ` Kevin Buettner
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=3B4ED0FE-35A5-11D6-A901-0030653FA4C6@apple.com \
--to=kdienes@apple.com \
--cc=ac131313@cygnus.com \
--cc=drow@mvista.com \
--cc=gdb-patches@sources.redhat.com \
--cc=klee@apple.com \
/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