This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Can I use -data-evaluate-expression to evaluate sin(4.1)?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]