* Can I use -data-evaluate-expression to evaluate sin(4.1)?
@ 2006-12-19 5:55 Nikolay Molchanov
2006-12-19 7:44 ` Frederic RISS
2006-12-19 8:28 ` Nick Roberts
0 siblings, 2 replies; 7+ messages in thread
From: Nikolay Molchanov @ 2006-12-19 5:55 UTC (permalink / raw)
To: gdb
Debugger "gdb" is used in NetBeans 5.5 C/C++ Development Pack,
and it works just great, but there are several issues that look
like bugs in "gdb". One of them is a "sinus puzzle" - gdb/mi
command "-data-evaluate-expression sin(4.1)" returns a strange
result "3". I use Cygwin on Windows, but the same problem exists
on other systems (Solaris, Linux).
Here is a test program:
$ cat test_1_sin.cc
/* A test program. Uses sin(x) */
#include <math.h>
double x = 3.14;
double m (double z) {
double y1 = sin(z);
double y2 = sin(3.14);
double y3 = sin(4.1);
double y4 = sin(5.1);
double y = y1 * y2 * y3 * y4;
return y;
}
int main(int argc, char**argv) {
x = m(x);
return 0;
}
If I compile it with "-g" option and run under "gdb",
it runs just fine and all calculations are correct.
But if I ask "gdb" to evaluate sin(3.14) I get "1"
(which is not correct), and if I ask to evaluate
sin(4.1) or sin(5.1) I get "3" (?!).
Here is a log file that shows the problem:
Dev@2006nov24 /cygdrive/c/tmp/Dev/Projects/Math_1_sin
$ g++ -g -o test_1_sin test_1_sin.cc
Dev@2006nov24 /cygdrive/c/tmp/Dev/Projects/Math_1_sin
$ gdb --i mi test_1_sin
~"GNU gdb 6.5.50.20060706-cvs (cygwin-special)\n"
~"Copyright (C) 2006 Free Software Foundation, Inc.\n"
~"GDB is free software, covered by the GNU General Public License, and
you are\n"
~"welcome to change it and/or distribute copies of it under certain
conditions.\n"
~"Type \"show copying\" to see the conditions.\n"
~"There is absolutely no warranty for GDB. Type \"show warranty\" for
details.\n"
~"This GDB was configured as \"i686-pc-cygwin\"..."
~"\n"
(gdb)
-break-insert 8
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",
addr="0x00401064",func="m(double)",file="test_1_sin.cc",
fullname="/cygdrive/c/tmp/Dev/Projects/Math_1_sin/test_1_sin.cc",
line="8",times="0"}
(gdb)
-exec-run
^running
(gdb)
*stopped,reason="breakpoint-hit",bkptno="1",thread-id="1",
frame={addr="0x00401064",func="m",args=[{name="z",
value="3.1400000000000001"}],file="test_1_sin.cc",
fullname="/cygdrive/c/tmp/Dev/Projects/Math_1_sin/test_1_sin.cc",
line="8"}
(gdb)
-data-evaluate-expression sin(4.1)
^done,value="3"
(gdb)
-exec-next
^running
(gdb)
*stopped,reason="end-stepping-range",thread-id="1",
frame={addr="0x00401075",func="m",args=[{name="z",
value="3.1400000000000001"}],file="test_1_sin.cc",
ullname="/cygdrive/c/tmp/Dev/Projects/Math_1_sin/test_1_sin.cc",
line="9"}
(gdb)
-exec-next
^running
(gdb)
*stopped,reason="end-stepping-range",thread-id="1",
frame={addr="0x00401086",func="m",args=[{name="z",
value="3.1400000000000001"}],file="test_1_sin.cc",
fullname="/cygdrive/c/tmp/Dev/Projects/Math_1_sin/test_1_sin.cc",
line="10"}
(gdb)
-data-evaluate-expression y3
^done,value="-0.81827711106441026"
(gdb)
-data-evaluate-expression sin(3.14)
^done,value="1"
(gdb)
-data-evaluate-expression y2
^done,value="0.0015926529164868282"
(gdb)
-data-evaluate-expression sin(5.1)
^done,value="3"
(gdb)
Can I use "-data-evaluate-expression" to evaluate
sin(x) function? If yes, why it returns a wrong
"int" value?
Thanks in advance,
Nikolay Molchanov
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Can I use -data-evaluate-expression to evaluate sin(4.1)?
2006-12-19 5:55 Can I use -data-evaluate-expression to evaluate sin(4.1)? Nikolay Molchanov
@ 2006-12-19 7:44 ` Frederic RISS
2006-12-19 8:28 ` Nick Roberts
1 sibling, 0 replies; 7+ messages in thread
From: Frederic RISS @ 2006-12-19 7:44 UTC (permalink / raw)
To: Nikolay.Molchanov; +Cc: gdb
Hi,
On Mon, 2006-12-18 at 21:55 -0800, Nikolay Molchanov wrote:
> But if I ask "gdb" to evaluate sin(3.14) I get "1"
> (which is not correct), and if I ask to evaluate
> sin(4.1) or sin(5.1) I get "3" (?!).
I guess your system libraries aren't built with debuginfo. This means
that GDB won't know the sin function's prototype and it will interpret
the result as an int. There might also be other issues with passing
doubles to un-prototyped functions, but the previous point is sufficient
to explain your issue.
Fred
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Can I use -data-evaluate-expression to evaluate sin(4.1)?
2006-12-19 5:55 Can I use -data-evaluate-expression to evaluate sin(4.1)? Nikolay Molchanov
2006-12-19 7:44 ` Frederic RISS
@ 2006-12-19 8:28 ` Nick Roberts
2006-12-19 16:32 ` Daniel Jacobowitz
2006-12-19 17:02 ` Nikolay Molchanov
1 sibling, 2 replies; 7+ messages in thread
From: Nick Roberts @ 2006-12-19 8:28 UTC (permalink / raw)
To: Nikolay.Molchanov; +Cc: gdb
> -data-evaluate-expression sin(5.1)
> ^done,value="3"
> (gdb)
>
>
> Can I use "-data-evaluate-expression" to evaluate
> sin(x) function? If yes, why it returns a wrong
> "int" value?
By default (without debuginfo as Frederic says) it assumes sin takes an
integer argument and returns an value (I think).
You need to cast sin explicitly:
(gdb)
-data-evaluate-expression "((double ((*) (double))) sin) (5.1)"
^done,value="-0.92581468232773245"
(gdb)
-data-evaluate-expression "((double ((*) (double))) sin) (4.1)"
^done,value="-0.81827711106441026"
--
Nick http://www.inet.net.nz/~nickrob
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Can I use -data-evaluate-expression to evaluate sin(4.1)?
2006-12-19 8:28 ` Nick Roberts
@ 2006-12-19 16:32 ` Daniel Jacobowitz
2006-12-19 20:14 ` Nick Roberts
2006-12-19 17:02 ` Nikolay Molchanov
1 sibling, 1 reply; 7+ messages in thread
From: Daniel Jacobowitz @ 2006-12-19 16:32 UTC (permalink / raw)
To: Nick Roberts; +Cc: Nikolay.Molchanov, gdb
On Tue, Dec 19, 2006 at 09:23:19PM +1300, Nick Roberts wrote:
> > -data-evaluate-expression sin(5.1)
> > ^done,value="3"
> > (gdb)
> >
> >
> > Can I use "-data-evaluate-expression" to evaluate
> > sin(x) function? If yes, why it returns a wrong
> > "int" value?
>
> By default (without debuginfo as Frederic says) it assumes sin takes an
> integer argument and returns an value (I think).
What does "ptype sin" say? I'd have expected GDB to pick up the type
from the debug info in that example.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Can I use -data-evaluate-expression to evaluate sin(4.1)?
2006-12-19 8:28 ` Nick Roberts
2006-12-19 16:32 ` Daniel Jacobowitz
@ 2006-12-19 17:02 ` Nikolay Molchanov
1 sibling, 0 replies; 7+ messages in thread
From: Nikolay Molchanov @ 2006-12-19 17:02 UTC (permalink / raw)
To: gdb; +Cc: Nick Roberts
Nick Roberts wrote:
> > -data-evaluate-expression sin(5.1)
> > ^done,value="3"
> > (gdb)
> >
> >
> > Can I use "-data-evaluate-expression" to evaluate
> > sin(x) function? If yes, why it returns a wrong
> > "int" value?
>
> By default (without debuginfo as Frederic says) it assumes sin takes an
> integer argument and returns an value (I think).
>
> You need to cast sin explicitly:
>
> (gdb)
> -data-evaluate-expression "((double ((*) (double))) sin) (5.1)"
> ^done,value="-0.92581468232773245"
> (gdb)
> -data-evaluate-expression "((double ((*) (double))) sin) (4.1)"
> ^done,value="-0.81827711106441026"
>
>
>
Thank you very much for the explanation!
I verified that "ptype sin" gets wrong type ("int"):
ptype sin
&"ptype sin\n"
~"type = \n"
~" int (void)\n"
^done
And thank you for the workaround, probably we can use it for
known functions (sin, cos, ...).
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Can I use -data-evaluate-expression to evaluate sin(4.1)?
2006-12-19 16:32 ` Daniel Jacobowitz
@ 2006-12-19 20:14 ` Nick Roberts
2006-12-20 2:42 ` Daniel Jacobowitz
0 siblings, 1 reply; 7+ messages in thread
From: Nick Roberts @ 2006-12-19 20:14 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: Nikolay.Molchanov, gdb
> > By default (without debuginfo as Frederic says) it assumes sin takes an
> > integer argument and returns an value (I think).
>
> What does "ptype sin" say?
(gdb) whatis sin
type = <text variable, no debug info>
(gdb) ptype sin
type = int ()
> I'd have expected GDB to pick up the type
> from the debug info in that example.
If the executable knows what kind of function sin is, then you would think that
GDB should be able to infer it from the executable. ISTR this has come up
before (just with "print") but that you expressed no surprise then.
--
Nick http://www.inet.net.nz/~nickrob
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Can I use -data-evaluate-expression to evaluate sin(4.1)?
2006-12-19 20:14 ` Nick Roberts
@ 2006-12-20 2:42 ` Daniel Jacobowitz
0 siblings, 0 replies; 7+ messages in thread
From: Daniel Jacobowitz @ 2006-12-20 2:42 UTC (permalink / raw)
To: Nick Roberts; +Cc: Nikolay.Molchanov, gdb
On Wed, Dec 20, 2006 at 09:09:37AM +1300, Nick Roberts wrote:
> > I'd have expected GDB to pick up the type
> > from the debug info in that example.
>
> If the executable knows what kind of function sin is, then you would think that
> GDB should be able to infer it from the executable. ISTR this has come up
> before (just with "print") but that you expressed no surprise then.
It's all up to what GCC decides to include :-)
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-12-20 2:42 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-19 5:55 Can I use -data-evaluate-expression to evaluate sin(4.1)? Nikolay Molchanov
2006-12-19 7:44 ` Frederic RISS
2006-12-19 8:28 ` Nick Roberts
2006-12-19 16:32 ` Daniel Jacobowitz
2006-12-19 20:14 ` Nick Roberts
2006-12-20 2:42 ` Daniel Jacobowitz
2006-12-19 17:02 ` Nikolay Molchanov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox