自定义 Visual Studio 调试器以跳过构造函数

Customize Visual Studio debugger to skip constructors

我知道在调试时可以使用 .natvis 文件自定义对象在 Visual Studio 中的显示方式。

有没有办法修改调试器的行为以跳过某些成员函数而不是进入它们?

例如:

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;
}

当我进入打电话给 some_function?

(我知道可以执行 step into specific,但我不想在这种情况下执行此操作。)

这是可能的,但灵活性不如 natvis 文件。

指定调试器 'skips over' 处理的函数 via the natstepfilter file。在链接页面上查找 独立于“仅我的代码”设置自定义 C++ 步进行为部分:

  • 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>

目前这只能通过全局 Visual Studio 配置完成,并且与 natvis 不同,不能作为项目的一部分包含在内。

已经有 an open issue in the Visual Studio bugtracker requesting support for per-project natstepfilter files.