Bug 7642 - Not possible to watch static class field
Summary: Not possible to watch static class field
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Debugger ()
Version: Trunk
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Jeffrey Stedfast
URL:
Depends on:
Blocks:
 
Reported: 2012-10-04 09:08 UTC by Marek Safar
Modified: 2012-10-19 12:53 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Marek Safar 2012-10-04 09:08:45 UTC

    
Comment 1 Marek Safar 2012-10-04 09:09:47 UTC
Declare static class with some initialised private fields. There is no way how to inspect such private fields with MD
Comment 2 Jeffrey Stedfast 2012-10-17 14:07:13 UTC
this seems to work for me. Do you have a test case?
Comment 3 Marek Safar 2012-10-18 03:28:57 UTC
You probably tried debugging from inside but I usually hit it from outside of the class.

e.g.

static class S
{
public static int SomeComplexCalculatedValue;
}

class C
{
public static void Main ()
{
// How do you find out value of S.SomeComplexCalculatedValue from here ?
}
}
Comment 4 Jeffrey Stedfast 2012-10-18 09:19:00 UTC
I tried adding a watch to static fields in the class I'm in and for other static classes. (also, I tried making the fields private since I thought that's what you meant)

I just got an idea... perhaps in your case class S hasn't been initialized yet?

I had a method inside of my class S which got invoked early on (I simply reused an old test case but added some private static fields to see if I could watch them)

If class S hasn't been used yet, that might be the problem?
Comment 5 Jeffrey Stedfast 2012-10-18 11:02:06 UTC
Marek just explained to me on IRC, turns out I totally misunderstood what was meant by this bug report.


So... the problem Marek is having is that he wants to be able to watch 'S' in the watch pad, and be able to expand it and see the static fields (even if they are in an external dll).

We should look at how VS does this.
Comment 6 Jeffrey Stedfast 2012-10-18 12:09:38 UTC
Turns out I was still misunderstanding...

Let's try this again:


jeff: ok, I think I figured it out
[11:44am] jeff: I thought you were adding stuff to the watch pad
[11:44am] jeff: not hovering over members
[11:44am] jeff: anyway
[11:44am] jeff: here's what I found
[11:44am] jeff: if I have:
[11:44am] jeff: static class S { static int Fubar = 7; }
[11:45am] jeff: I can type "S" into the watch pad, expand it, and see Fubar = 7
[11:45am] jeff: if I hover over Fubar in the text editor, though, it says unknown identifier
[11:45am] jeff: unless I am in method on S
[11:46am] jeff: ALSO
[11:46am] jeff: if I make class S non-static, hovering still doesn't work unless I'm in a method invoked on S
[11:47am] jeff: *AND*
[11:47am] jeff: entering "S" in the watchpad kinda works, but expanding it shows Fubar = 0
[11:47am] jeff: which is wrong
[11:47am] jeff: probably because there's no instance of S
[11:48am] mareks: right, I think you got control over the bug 
[11:48am] jeff: ok, cool
[11:48am] jeff:
[11:49am] mareks: VS allows to hover over any type during debugging MD shows just completion info
[11:50am] mareks: that's probably the summary (+the other bugs you found meanwhile)


So there's at least 2 bugs:

1. DebugValueTooltipProvider.GetItem() needs to handle TypeResolveResults so that you can hover over a type and expand it. (easy fix)

However, that alone won't solve the problem because that will simply get us to the same level of functionality as entering the class name in the WatchPad. If the class is static, then it'll work, but if it isn't, then when you expand the class in the watchpad, it'll show the static fields but they'll all be 0/null/whatever instead of the actual values.

Which leads us to bug #2...

2. Adding a non-static type to the watchpad and expanding it does not work correctly - the static fields are not initialized as they should be.

Not sure what the deal with this is off the top of my head. Might be that the static ctor simply hasn't been called? Will have to do some checking on that.
Comment 7 Jeffrey Stedfast 2012-10-18 13:02:29 UTC
so part 2 is because the non-static class's static ctor hasn't been invoked yet.

class S
{
    static MyStaticField = 7;
}

class Program
{
    static void Main ()
    {
        S s = null;

        Console.WriteLine ("Hello world!"); // break here and add "S" in the watch pad
    }
}

If you expand "S", you'll see that MyStaticField has a value of 0

*HOWEVER*, if you change "S s = null;"  to "S s = new S ();", then expanding S in the watchpad will show MyStaticField = 7

Visual Studio works even if you've never instantiated a variable of type S, so we should too.

I'm gonna have to ask Zoltan if there is any way to tell if the static ctor on a class has been invoked or not, and how to force it to be invoked if it hasn't.
Comment 8 Jeffrey Stedfast 2012-10-19 12:53:18 UTC
all issues should now be fixed