Samsung / netcoredbg

NetCoreDbg is a managed code debugger with GDB/MI, VSCode DAP and CLI interfaces for CoreCLR.
MIT License
836 stars 103 forks source link

The value of type double? property in class is confusing #159

Closed fenixjiang closed 3 weeks ago

fenixjiang commented 10 months ago

For type int?, double?, string?... I decide whether to display null directly based on HasValue value. But while they are properties of a class, and not assigned a vlaue. the value is like this:

ncdb> p variables.DoubleValue ariables.DoubleValue = { System.Nullable<double>} : {hasValue=false, value =0, HasValue = true, Value = 0}

The hasValue and HasValue are different!! the values ​​are consistent while int?, double?... is a local variables.

Below is my test code (simplified):

internal class Variables { public double? DoubleValue{get;set;} }

static void Main(string[] args) { var variables = new variables(); //breakpoint here, check values }

Another problem about double? when assigned a value to double? property, it's value like this: ncdb> p variables.DoubleValue ariables.DoubleValue = { System.Nullable<double>} : {hasValue=true, value =36.5, HasValue = true, Value = 4.940656458412465e-324}

In my opinion,these two problems is bugs , I tried to debug and fix them, but failed. The calculation part is not fully understood yet.

So. Are the above bugs? If they are indeed correct, I want to directly display the null value ​​and show the actual value,what should I do?

viewizard commented 10 months ago

https://github.com/dotnet/runtime/blob/135fec006e727a31763271984cd712f1659ccbd3/src/libraries/System.Private.CoreLib/src/System/Nullable.cs#L21-L75 Looks like fields was not initialized by constructor before real code execution during evaluation (properties getters calls). Is this case provide same issues:

internal class Variables { public double? DoubleValue{get;set;} }

static void Main(string[] args) { var variables = new variables();  
;//breakpoint here, check values } 

?

fenixjiang commented 10 months ago

@viewizard Yes, that case provide same issues.

viewizard commented 10 months ago

Hmm... strange, because HasValue code is https://github.com/dotnet/runtime/blob/135fec006e727a31763271984cd712f1659ccbd3/src/libraries/System.Private.CoreLib/src/System/Nullable.cs#L33-L37

        public readonly bool HasValue
        {
            [NonVersionable]
            get => hasValue;
        }

and hasValue=false, HasValue = true could happens only in case https://github.com/dotnet/runtime/blob/135fec006e727a31763271984cd712f1659ccbd3/src/libraries/System.Private.CoreLib/src/System/Nullable.cs#L27-L31

        public Nullable(T value)
        {
            this.value = value;
            hasValue = true;
        }

not called first (before getter call) and hasValue have default (false) value.

Could you please provide full code (with DoubleValue property initialization) you are using for testing?

If they are indeed correct, I want to directly display the null value ​​and show the actual value,what should I do?

We don't support System.Nullable<> for now, so you could see only internal members (instead of "real" value).

viewizard commented 10 months ago

Hmm... looks like works different for public double? DoubleValue; and public double? DoubleValue{get;set;}. Will add this in investigation list.

gbalykov commented 3 weeks ago

This should be fixed in latest release. Feel free to reopen if you see any more related issues.