Code Focused

Make The Debugger Focus on Code That's Important To You

When you debug a C++ application, the debugger can take a number of detours through lots of trivial functions or code from third-party libraries. You can filter out those unnecessary paths and have the debugger focus on just the code you want.

When I introduced you to this article series, you might remember that I noted that stepping into/over/out of function calls is essential while debugging. Unfortunately, it would be very time consuming to visit all of the code. Sometimes the debugger might lead you to methods that aren't important from your perspective.

Let's look at an example:

class SimpleParam
    SimpleParam(const std::string& str, int val) : mStr(str), mVal(val) 

    void Init() { }
    std::string GetStrVal() const { return mStr + std::to_string(mVal); }

    std::string mStr;
    int mVal;

void CallBackFunction(SimpleParam p1, SimpleParam p2)
    std::cout << p1.GetStrVal() << "\n";
    std::cout << p2.GetStrVal() << "\n";
/// ...
CallBackFunction({ "Hello", 1 }, { "World", 2 });

Set a breakpoint at the line where CallBackFunction is called and then try to press Ctrl+F11 to step into it. Where will the debugger go? I see something like Figure 1.

[Click on image for larger view.] Figure 1. Debugger Takes a Side Trip

In this example, the debugger goes to the code that's available to the debugger -- in this case, it's a constructor of std::string! You can probably be sure that nothing wrong can happen in that library code.

Now, imagine what happens if you have several parameters. When you want to step into a method, you'll first need to visit all code related to the parameters creation. The whole process might be frustrating, and you lose a lot of time before going into the target function. Of course, you might just set a breakpoint at the beginning of the destination code so you can skip all of the unwanted behavior. But there is a better option.

What if you could control and filter out unwanted functions? Prior to Visual Studio 2012, it's relatively tricky to filter out the code and involves playing with some registry values. Fortunately, with Visual Studio 2012 and later, this useful feature was greatly improved. All you need to do is edit the default.natstepfilter Xml file. For Visual Studio 2015, that file is usually located in Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers (the location is similar in Visual Studio 2012 and Visual Studio 2013).

To add a functions filter, you can use regex expressions. So, in this example, when you want to skip all the std:: function call you can write the following:


and add the following line to default.natstepfilter:

    <Name>std\:\:.* </Name>

Please note that the file might be blocked for writing. The file default.natstepfilter is loaded each time a debugger session starts.

You can now set up the most common functions in your project that you don't want to visit during debugging. Usually, those are trivial functions or from third-party code (std, boost?), but just be careful: go overboard and you might filter out too much!


Microsoft Developer Blog Post: "How to Not Step Into Functions using the Visual C++ Debugger"

MSDN Library: "Just My Code"

About the Author

Bartlomiej Filipek is a software developer in Poland who specializes in C++, Windows and graphics programming. He worked for a number of companies developing multimedia, document editors, games, graphics drivers and flight planning systems, and has taught game development at local university. Follow Bart's blog at and on Twitter @fenbf.

comments powered by Disqus


  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube