Home > Back-end >  Customize Visual Studio debugger to skip constructors
Customize Visual Studio debugger to skip constructors

Time:09-25

I know it is possible to use .natvis files to customize how objects are displayed in Visual Studio while debugging.

Is there a way to modify the behavior of the debugger to step over certain member functions instead of stepping into them?

For example:

class pt{
    double x, y;
    pt::pt(double x, double y) : x(x), y(y){}  // <--- I don't want to step into this stuff in debugger
}

void some_function(pt const &point){
    // stuff that I want to step through in the debugger
}

int main(){

    // this will call the constructor for pt.  I want to step into 'some_function'
    // but I don't want to step into the pt constructor
    some_function({1, 2});  // I would like to step into this function without stepping into pt::pt first

    return 0;
}

Is there a way with something like the natvis file to specify that I don't want to step into the constructor of a class like 'pt' in the example, when I step into the call to some_function?

(I know that it is possible to do step into specific, but I would like to not have to do that for cases like this.)

CodePudding user response:

This is possible, but not with the same flexibility as natvis files.

Specifying the functions that the debugger 'skips over' is handled via the natstepfilter file. Look for the section Customize C stepping behavior independent of Just My Code settings on the linked page:

  • To specify non-user code for all local Visual Studio users, add the .natstepfilter file to the%VsInstallDirectory%\Common7\Packages\Debugger\Visualizers folder.

  • To specify non-user code for an individual user, add the .natstepfilter file to the %USERPROFILE%\My Documents\<Visual Studio version>\Visualizers folder.

A .natstepfilter file is an XML file with this syntax:

<?xml version="1.0" encoding="utf-8"?>
<StepFilter xmlns="http://schemas.microsoft.com/vstudio/debugger/natstepfilter/2010">
    <Function>
        <Name>FunctionSpec</Name>
        <Action>StepAction</Action>
    </Function>
    <Function>
        <Name>FunctionSpec</Name>
        <Module>ModuleSpec</Module>
        <Action>StepAction</Action>
    </Function>
</StepFilter>

Currently this can only be done through the global Visual Studio configuration and, unlike natvis, cannot be included as part of the project.

There is already an open issue in the Visual Studio bugtracker requesting support for per-project natstepfilter files.

  • Related