I blog whenever I C#

Posts tagged ‘visual studio’

Improving current line highlighting in VS2010

Are you experiencing that VS2010 is suddenly highlighting the current line in the text editor? Do you want to get rid of it? I’ll show you how – or maybe convince you to keep it!   Line highlighting First of all, let me explain what I’m talking about in case you haven’t figured yet. Current [...]

Altering database tables with VS2010

One thing I find quite annoying in Visual Studio is when I try to modify an existing database table and get the following error dialog that prevents me from saving: “You cannot save changes that would result in one or more tables being re-created” So, what the heck is up with that? This seems to [...]

Adjust namespaces with Resharper 5

A really nice feature in Resharper 5 is the ability to adjust namespaces for code files in a directory. When you move files around in your project or between different projects the namespace no longer matches the directory structure. Updating the namespaces in the code files by hand is quite tedious and error prone. This [...]

Visual Studio debugging tricks

I learned a new Visual Studio trick today. I’m currently working on a hobby project in C++ and since the plan is to make it cross platform I’m using the excellent Juce framework.

Juce has its own string type which is very nice. It handles Unicode, reference counting and so on. Its like the CString type but cross platform. Some people may prefer the standard lib string std::string but personally I think the std lib is a bit awkward.

Anyway, so what’s my problem then? Well, the thing is that when you debug your program in Visual Studio you really want to see the contents of strings easily. By default you get this when using the juce::String type:

Visual Studio has no knowledge about the juce::String type so it just takes a guess at what we want to see and shows us some of the private members in the type. Not very helpful…

Autoexp.dat
So what can we do about it? Well I found some info about a little file containing debugger settings for Visual Studio. It’s default location is under C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger and the file is called autoexp.dat. This file controls how VS displays different types during debugging. Interesting!

If you are running Vista/Win7, make sure you edit autoexp.dat as administrator because it’s protected since it’s in your program files. Otherwise you end up writing to a file that gets placed in your VirtualStore and it won’t work (yes, I did this myself..doh!)

Note that you can change the autoexp.dat file anytime. It will be reloaded when the debugger starts, so you don’t have to restart VS.

Now lets see what we can do… Open up the file autoexp.dat and scroll down a bit to a section called [Visualizer]. This section controls the VS visualizers for STL, ATL and other stuff. This part has a large DO NOT MODIFY text so we won’t touch that part (make a backup if you’re scared…)

Just below the part with the STL and ATL container stuff add the following:

juce::String{ preview ([$e.text->text,su]) stringview ([$e.text->text,sub])}

This will tell VS about the Juce string type and explain how we want to view it. The ‘preview’ bit controls what to show in the watch window and the ‘stringview’ bit controls the popup string viewer that allows you to view the string as text, XML or HTML. Very handy feature!

The expression refers to the variable being viewed as $e and then you simply access its members as you would in normal code watch expressions. The ‘su’ part means that the value should be treated as a null terminated string in Unicode format. The ‘sub’ means that the string should be shown using “bare representation”. In this case it will display the string without the surrounding quotes (I only use this in the string viewer, as this seems to be the common practice).

Here is a screenshot of how it looks now:

Neato! Now we see the strings easily while debugging. We can also click the magnifying glass to examine the string in a popup window, even show it as formatted XML. Now the Juce type is even more juicy! Great isn’t it?

These debugger expressions can do a lot more. You can read more it here: http://www.virtualdub.org/blog/pivot/entry.php?id=120

Happy coding!

Follow

Get every new post delivered to your Inbox.