Blog

Tips for using Statement Visualization

Posted by:

Statement Visualization is a new feature that we just introduced today. The key thought that led us when we were designing this feature is that debugging could be a lot easier if C# programmers had the same type of tool that air-force pilots benefit from – having a HUD display on top of the code editor as you step through code, showing you the most relevant information you need to solve the problem at hand.

See method return values, finally!

One of the most requested features of the Visual Studio debugger it for it to show the return value of a method before you step out of the method. People often end up rewriting their code to introduce a local variable so they can see that value in the debugger. With Statement Visualization,  you’ll never have to do that again. You can see how the expression was evaluated right after you step over it, like this:

Another problem that people often wrestle with is the need to see the return values of method calls you just stepped over. Again, people frequently introduce locals in their code in order to debug effectively, but this can make code harder to read and unnecessarily complex. Plus, it’s just extra work that users have to do to please the debugger. Sometimes users copy/paste the method calls into the Watch or QuickWatch window, but then they often get foiled by the side effects of executing a method in the debugger. When methods are executed in the debugger the program’s state may be inadvertently changed, leading to a very confusing and frustrating debugging session.

With Statement Visualization, all these problems go away. As you can see in the above screenshot, Statement Visualization clearly shows what each of the calls to the GetLocation method returned.

 

 LINQ Debugging gets easier

You can also use Statement Visualization to debug LINQ query comprehensions. For example, in the following scenario I put a breakpoint on the ‘where’ clause of the of the following query, so that I could see how it was evaluated for each item:

Each time the breakpoint is hit, we can step over the where clause and use Statement Visualization to see its result:

Unravel C# 3 Object Initializers

Another issue that used to be difficult is debugging C# 3′s Object Initializer syntax. The problem with stepping over statements that contain object initializers is that you often have a lot of things happening in the same statement. With BugAid, you can see see exactly what value each property being initialized received.

The following video shows how Statement Visualization handles multi-line statements, and how you can use keyboard shortcuts to control it:

<br /> <style type="text/css">.youtube_sc{background-color:#000;color:#fff;font-size:12px}.youtube_sc a{color:blue;text-decoration:underline;}.youtube_sc embed.yp{display:none;}</style> <p>The Adobe Flash Player is required for video playback.<br><a href="http://get.adobe.com/flashplayer/" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://get.adobe.com']);" title="Install from Adobe">Get the latest Flash Player</a>

 Viewing Complex Objects in Statement Visualization

When the method you called returned a complex object, you can click the magnifying glass to view that object in the Quick Watch window:

Once you open the QuickWatch window, you can star the most important fields in that object. Stars and Statement Visualization work hand in hand so that you’ll get a more convenient display  of the object without even needing to open the QuickWatch window. For example, after starring “FullName”, we’ll see:

Statement Visualization also works well with some of BugAid’s other features, accessible through the right click menu: you can take a snapshot of a method return’s value, and you can compare it with other variables.

How does it all work and a word about performance

You might be wondering, “How does all this magic work?”  BugAid’s Full Mode works by attaching a CLR Profiler to the debugee when it launches, much like Microsoft’s IntelliTrace feature. This allows us to trace the method parameters and the return value of any method you step over as you debug. The key difference between IntelliTrace and BugAid’s Full Mode is that BugAid only captures the most useful and relevant information to display to the user, thus minimizing the negative impact on the application’s performance.

One of our goals over the next few releases of BugAid’s Beta is to make the performance difference between BugAid “Standard Mode” (ie, BugAid as you know it today) and the new “Full Mode” as unnoticeable as possible. For now though, if you experience sluggish performance in Full Mode, please consider disabling the Foreach Visualization in the Options Dialog – this should give you a significant improvement.

About the Author

Omer is the co-founder of "BugAid Software".

Discussion

  1. Rory Plaire  November 16, 2011

    Ok, you guys earned my money. Especially now with the memory leak fix.

    • Vitaly Belman  November 16, 2011

      We appreciate that and hope you’ll continue enjoying using BugAid :)

  2. Allon Guralnek  December 3, 2011

    This is shaping up to be quite an interesting product. Though it is very hard to visualize how it actually works using screenshots alone. Only when seeing the video did I realize that you presenting an overlay on top of existing code (I thought they were pop up that obscured the code). You really need more videos, longer ones too.

    If you’re getting all that information using by attaching your own profiler, how would Full Mode work with other tools that do the same? For example, I spend most of my time debugging unit tests than, since they easily discover bugs, and my unit tests rely on TypeMock Isolator.NET, which is a profiler in itself. Not it has a special mechanism where it allow a profiler to be attached in addition to itself (natively the CLR doesn’t support more than one profiler), but that feature requires explicit support. Do you have it?

    Also, will your feature work with Code Contracts (it rewrites the IL to automatically introduce that pesky local variable in order to do its Contract.Ensures(..) magic)? Does it work with PostSharp? Are any toes being stepped on when using code refactoring tools such as ReSharper, CodeRush or JustCode?

    Keep up the good work!

    • Omer Raviv  December 3, 2011

      Hi Allon, thank you for your comment!
      I’ll address the points you made one by one:

      1. We’ll try to get more videos up on our site soon.

      2. No, currently BugAid will not work out of the box with TypeMock, but we’ll get in touch with them to see if that integration is possible. You are correct in that generally you can’t have more than one CLR Profiler in the same process at a time (that’s why, for example, you can’t run BugAid Full Mode and Intellitrace at the same time).

      You should also know that currently BugAid Full Mode cannot be initiated from any of the unit test runners that are integrated with Visual Studio (TestDriven.NET, Resharper, etc..), though support for the Resharper Test Runner is coming very soon, and we’ll add support for additional test-runners based on our users’ requests.

      3. AFAIK both Code Contracts and PostSharp instrument your DLLs as part of the (post-)compilation process, long before your process was even launched, and so I don’t expect any issues, though I haven’t tested it just yet. I’ll be sure to test that.

      4. We’ve tested BugAid against Resharper and CodeRush and could not find any issues. We’ll try and test it with JustCode as well.

      Again, thank you very much for your feedback!

  3. Igal Tabachnik  December 5, 2011

    Hey everyone,

    My name is Igal and until recently I used to work at Typemock.

    I recently answered a question on StackOverflow regarding integration with Typemock and another profiler, OpenCover. Typically, this should be relatively straightforward, just adding an entry to a config file. You will need the GUID of the third party profiler. Please see this post for details: http://stackoverflow.com/questions/6698290/can-opencover-be-used-with-typemock-isolator

    I also forwarded Omer’s request to Typemock support, they will test it to see if there are no issues with this solution.

    P.S. Visualizing method return values – WELL DONE!!! That couldn’t have been easy :)

Add a Comment

You must be logged in to post a comment.