Stop wasting time stepping into functions you don't care about in Microsoft Visual Studio (C++)

— richardwb on Monday, March 09, 2009 @ 17:58

The Visual Studio debugger is amazingly useful. However, you soon learn to sigh the moment you come into contact with something like this:

boost::scoped_ptr<Startup> dlg(
    new Startup(settings->GetWindowPosition()));

You want to step into the Startup constructor, but there is a lot of stuff in your way.

  1. First you will step into shared_ptr::operator-> (did I mention that settings was a shared_ptr?).
  2. Then you will step into GetWindowPosition().
  3. Then into operator new.
  4. And then into your Startup constructor. Yes!
  5. And finally you'll finish with the scoped_ptr constructor if you so choose.

If you've done this a lot you've probably gotten really good at the Step Out shortcut (Shift-F11).

Well, here are two alternatives!

First, while program execution is paused, right-click anywhere in the source window and look for the Step Into Specific item. You can select any of these functions to instantly step inside.

Alternatively, there is a special undocumented (and unsupported) registry key that you can use to specify functions that you always want to skip. Navigate to HKLM\SOFTWARE\Microsoft\VisualStudio\9.0\NativeDE\StepOver (users of a 64-bit variant of Windows will want to check HKLM\SOFTWARE\Wow6432Node\Microsoft\... instead) and add some string values like this example:

Name: 50 (priority, higher values have greater priority)
Value: std\:\:.*=NoStepInto

Name: 60
Value: operator new=NoStepInto

Name: 70
Value: boost\:\:.*=NoStepInto

The backslashes are necessary because : (colon) is a special character in Visual Studio regex. You sometimes see two backslashes used in other examples, this is only necessary if you are directly editing a .reg file (which I don't recommend). These rules will adjust the behaviour of the Step-Into command and make it skip anything from the std or boost namespaces, as well as the basic operator new. It will still step into an overloaded operator new, so don't fear. There are more details on this blog post, as well as microsoft.public.vsnet.debugging.

One more thing: you can combine these two approaches. Say that you've added a skip for the entire boost namespace, but you decide you really want to take a peek inside one particular line and see exactly what is happening to your parameters. Pause execution on that line, and then right-click and use Step Into Specific. This is still the same list as before and it works the same as before, regardless of any NoStepInto rules.

comments powered by Disqus