This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 91389 - Wrong result of expression in Watches window.
Summary: Wrong result of expression in Watches window.
Status: RESOLVED WONTFIX
Alias: None
Product: cnd
Classification: Unclassified
Component: Debugger (show other bugs)
Version: 5.x
Hardware: All All
: P4 blocker (vote)
Assignee: Egor Ushakov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-21 05:17 UTC by Nikolay Molchanov
Modified: 2009-12-21 05:37 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Sinus_equals_to_3.PNG (298.47 KB, text/plain)
2006-12-21 05:17 UTC, Nikolay Molchanov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nikolay Molchanov 2006-12-21 05:17:09 UTC
This problem was reported on December 17, 2006, By: Liang.Ye@Sun.COM

Background:
ACM Code Competition in China use Solaris + NetBeans + Sun Studio as the 
standard competition platform at Xi'An University of Electronics Science 
and Technology on 2006.12.15~17. More than 100 team attended,over 80% of 
which choose NetBeans with C/C++ Pack. Through the 4 days event, including 
warmup, preliminary contest and final contest, we encountered a bunch of 
questions raised by the teams. 

Problem Description:
Wrong result of expression in Watches window.
For instance, set a breakpoint randomly, start a new debug session, then 
input sin(3.14) in "New Watch" dialog. The resulting value is 2. We all know 
that sin(x) should be bigger than -1 and smaller than 1. Similarly, sin(4.1), 
sin(5.1) and etc are all bigger than 1.
Function Cos() has the same problem. This really makes us confusing.

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 start debugging,
it runs just fine and all calculations are correct.
But if I ask 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" (?!).

See attached screen shot for details.

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)
Comment 1 Nikolay Molchanov 2006-12-21 05:17:54 UTC
Created attachment 36871 [details]
Sinus_equals_to_3.PNG
Comment 2 Nikolay Molchanov 2006-12-21 05:25:20 UTC
I asked "gdb" developers about this problem. Here is a reply from Nick Roberts

----------------------------------------------------------------------
Subject: Re: Can I use -data-evaluate-expression to evaluate sin(4.1)?
Date: 	Tue, 19 Dec 2006 21:23:19 +1300
From: 	Nick Roberts <nickrob@snap.net.nz>
To: 	Nikolay.Molchanov@Sun.COM
CC: 	gdb@sourceware.org

 > -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
----------------------------------------------------------------

Please see the discussion about this problem on "gdb" mail list:
http://sources.redhat.com/ml/gdb/2006-12/msg00172.html

As there is a workaround, probably we can use it for known functions (sin, 
cos, ...).
Comment 3 Quality Engineering 2009-12-21 05:37:53 UTC
This bug was reported against NetBeans IDE 6.0 or an older release, or against a non-maintained module. NetBeans team does not have enough resources to get to this issue, therefore we are closing the issue as a WONTFIX. If you are interested in providing a patch for this bug, please see our NetFIX guidelines for how to proceed. 

We apologize for any inconvenience.


Thank you.
The NetBeans Team