Debugger Settings Visual Studio Add In– Easily Copy Breakpoints between Machines

18 Comments July 20, 2008

So there I was knee deep in a great debugging challenge. On one machine, I had set up somewhere around 15 advanced breakpoints that had all sorts of properties set such as conditionals, hit counts, and so on. As I was feeling like I was getting close to the bug, I wanted to set up an identical debugging session with those breakpoints on another machine. While I could have manually recreated all those advanced breakpoints, I tried to cheat. Your breakpoints, along with Watch window variables, window layout, and other session state items are stored in a hidden file, <Solution Name>.SUO. I copied that file over to the other machine and opened the solution file. Visual Studio promptly crashed.

The .SUO file is the bane of your existence. Nearly all the problems you encounter with Visual Studio are the result of a corrupt .SUO file. Sadly, it seems all it takes to corrupt the .SUO file is your heart beating. In other words, whenever you have Visual Studio crash, refuse to debug, or behave strangely it's the .SUO file's fault. Whenever anyone asks me about strange Visual Studio behavior, my instantaneous response is "Delete the .SUO!" When it comes to Visual Studio hygiene, deleting the .SUO file is right up there with cancer screenings.

As I am tired of manually setting my breakpoints again on other machines and sick of the .SUO corruption bug I decided to solve it once and for all. I wrote a Visual Studio 2008 add-in, Debugger Settings, which makes it easy to save and restore your solution's breakpoints. It also makes it easy to create and apply different breakpoint sets on a solution, which is something I've wanted in Visual Studio for a long time. You can download the code for Debugger Settings here.

Debugger Settings is at version 1.0 and I would love to hear your feedback. Please note that I've only done my testing on Visual Studio Team Suite, but Professional Edition and above should have no trouble. Debugger Settings will not work with the Expression versions as they do not support extensibility.

Debugger Settings currently only saves and restores breakpoints but does work with both .NET and native C++ projects. I would love to be able to get and set the Watch window variables, but it does not look like that can be done without extensive reverse engineering. However, if there's enough demand, I might be persuaded to give it a go. Another feature I'd like to add is the ability to save and restore custom Exceptions added to the debugger's Exception dialog. Please let me know if you have other features or find problems.

Installing Debugger Settings

  1. After downloading the zipped code, unzip it keeping the directory structure intact.
  2. You may not need to do this step, but I've always had problems with Visual Studio not loading my add-ins correctly if I put them in the defalt Documents\Visual Studio 2008\AddIns directory. That may be because I've got my Documents directory in a domain redirected folder. If you get a FileNotFoundException with a code of 0x80131047 attempting to load Debugger Settings, you'll want to add the <unzip dir>\DebuggerSettings\Debug directory to the Add-in file paths by going to the Options dialog, Environment, Add-in/Macros Security dialog:
  3. Because Visual Studio has a problem finding assemblies in the same directory as the .AddIn file, you'll need to edit <unzip dir>\DebuggerSettings\Debug\DebuggerSettings.AddIn and in the Assembly elements, enter the complete path to DebuggerSettings.DLL.
  4. Restart Visual Studio.

Using Debugger Settings

Debugger Settings works mainly in the background, but you can set its options in the Options dialog.

By default, Debugger Settings will save any breakpoints you have set when you close a solution to a .DebuggerSettings file in the same directory as the solution. When you open a solution, Debugger Settings will look for the .DebuggerSettings file and reset any breakpoints that were not set from an existing .SUO file.

Debugger Settings adds four commands to the IDE, which should be self explanatory:

  • DebuggerSettings.RestoreFromFile
  • DebuggerSettings.RestoreSolution
  • DebuggerSettings.SaveToFile
  • DebuggerSettings.SaveSolution

As an example, to save a set of breakpoints to a named file, you'll go to the Command window and execute the DebuggerSettings.SaveToFile command. If you don't specify a filename as the parameter to the command, you'll be prompted for the filename with the File Save dialog.

There are four types of breakpoints that Visual Studio supports: file, function, address, and data (for native C++ development). My original intent was to support all the breakpoint types, but when you attempt to set an address or data breakpoint through the Visual Studio automation model, the breakpoint is immediately set to disabled. Hopefully a future version of Visual Studio will let us automate setting those two breakpoints. The good news is that file and function breakpoints are the huge majority of breakpoints. I implemented the work to set address and data breakpoints in case this gets fixed in the upcoming Visual Studio 2008 Service Pack 1.

One other limitation of the Visual Studio automation model is that there's no way to know if a Tracepoint has the message disabled. The Breakpoint2.Message property is always set to the default string value. Thus, if you have a Tracepoint set to execute a macro, but not output the trace string, as shown below, Debugger Settings will enable the Print a message checkbox simply by setting the Message property.

Wrap up

The implementation of Debugger Settings is very straight forward. The only moderately interesting technique I used was to work around the fact that the Breakpoints.Add method does not support setting Tracepoints directly. Visual Studio's code metrics reports only 467 lines of code so far in Debugger Settings. If I can figure out how to get the Watch window variables, I'm sure the code size will grow exponentially.

Let me know either in comments to this entry or through email (john at this company's domain) if you find Debugger Settings helpful or find problems. Also, any feature requests strongly considered.


18 Comments

  • Gravatar Image
    John Hall July 21, 2008 5:19 AM

    "Another feature I'd like to add is the ability to save and restore custom Exceptions added to the debugger's Exception dialog"

    Yes, please, that would be great.

  • Gravatar Image
    williamx July 23, 2008 1:42 AM

    Great, I will try this. I am looking for such feature for a long time.:)

  • Gravatar Image
    Visual Studio Hacks July 23, 2008 1:36 PM

    My latest in a series of the weekly, or more often, summary of interesting links I come across related to Visual Studio. Lisa Feigenbaum is looking for feedback on a potential Call Hierarchy feature on The Visual Basic Team blog. Visual Studio 2008 KB:

  • Gravatar Image
    tronda August 13, 2008 7:58 AM

    This looks great. How about a way to save and retrieve bookmarks as well? I use bookmarks as a way to store problem-specific stack traces etc.

  • Gravatar Image
    karmastic August 19, 2008 3:20 PM

    Wow. And I was just talking to reed about this and I suggested someone had already done it. Thanks for saving me the time!

  • Gravatar Image
    JonnoPonno November 26, 2008 5:53 PM

    Beautiful. Agree 100% with your opinion on the .suo file, now deleting it and getting back up again with all the breakpoints etc. is so much easier. Thanks!

  • Gravatar Image
    Sammy Smith December 15, 2008 9:50 AM

    I've put the files into an addins directory and pointed to it through Tools/Options, but my addin manager doesn't show it after i restart visual studio.

    How can I make this work in Visual Studio 2005?

    Thank you,

  • Gravatar Image
    jrobbins December 15, 2008 12:49 PM

    Sammy,

    Note the blog entry, I wrote the addin for VS 2008. I have no idea if it will work for VS 2005. At a minimum, you'll need to create a VS2005 project and recompile.

    John Robbins

  • Gravatar Image
    pablo January 1, 2009 10:47 AM

    this addin might also help http://www.codeplex.com/lazy

  • Gravatar Image
    dane January 24, 2009 3:19 PM

    nice, I was looking for something similar for bookmarks.

    This is the kind of thing that always frustrated the heck out of me and make me long for the simplicity and un heralded wisdom of unix using simple, obvious, easily readable text files for storing settings instead of opaque, hard to find, binary formated files.

  • Gravatar Image
    saurabh ramya March 2, 2009 9:26 AM

    guys check out a similar utility with some extra features...

    http://intuitlabs.com/apps/breakpoint-analyzer-for-microsoft-visual-studio

  • Gravatar Image
    John Robbins' Blog April 2, 2009 9:11 PM

    In the last two weeks I've gotten many questions about how to automate and program the exception handling

  • Gravatar Image
    J&#246;rg April 24, 2009 5:39 AM

    Could not get it installed always ends up with error message different from the one presented in the installation description.

    I am using Visual Studio 2008 SP1 German Edition

    Any ideas?

    Jörg

  • Gravatar Image
    jrobbins April 24, 2009 12:09 PM

    Jörg,

    What's the error message? Have you tried debugging the VS startup to step through the code? Let me know as I want to get this fixed.

    John Robbins

  • Gravatar Image
    jefe May 27, 2009 9:58 AM

    Thanks for this post, I have a question related to Macro security but I couldn't find any better place to post it. I can't run any macros in VS 2008, even the ones in Sample project. I have a VS 2008 with SP1 on Vista. Do you know what could be the reason? Sorry again if this is not the best place to post this comment.

  • Gravatar Image
    jrobbins May 27, 2009 11:34 AM

    Jefe,

    What are the error messages? What have you tried? What are the details?

    - John Robbins

  • Gravatar Image
    jefe May 28, 2009 12:18 PM

    Well there's no error, it just doesn't do anything, even the simplest ones. I'm guessing it might ba security related since I'm on Vista, but I disabled UAC and I'm running VS as an Administrator.

  • Gravatar Image
    Ross Presser March 16, 2011 2:11 PM

    Is there any way to assign these commands to toolbar buttons?

Have a Comment?

Archives