【问题标题】:Is there a way to automatically avoiding stepping into certain functions in Visual Studio?有没有办法自动避免进入 Visual Studio 中的某些功能?
【发布时间】:2009-03-09 15:39:22
【问题描述】:

我知道“仅启用我的代码”调试选项,但这仅适用于托管代码。

我正在寻找一种无需单步执行函数调用的方法,例如,STL 字符串强制转换运算符,因为在函数的一个参数中存在从 char* 到字符串的隐式转换。

【问题讨论】:

    标签: c++ visual-studio debugging


    【解决方案1】:

    我发现这个blog entry 有一个解决方案。虽然我更愿意说“不要介入不属于这个项目的任何事情”,但这看起来是可行的。

    编辑:在查看了一些博客和新闻组之后,方法是在此注册表项下为您不想进入的每个功能添加一个条目(假设 VS 2005):

    32 位 Windows \\HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\8.0\NativeDE\StepOver 64 位 Windows \\HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\8.0\NativeDE\StepOver

    路径的版本号:

    视觉工作室 2005:8.0 视觉工作室 2008:9.0 视觉工作室 2010:10.0 视觉工作室 2012:11.0 视觉工作室 2013:12.0

    此键包含一组影响如何执行步进的规则。每个规则都被指定为一个单独的条目,其名称是一个十进制数,其值是一个函数名称模式,它指定我们想要影响哪些函数。例如

    "10" = "提升\:\:scoped_ptr.*\:\:.*=NoStepInto"

    防止进入 boost::scoped_ptr 函数。

    规则从高值到低值进行评估,直到找到匹配的模式,或者没有剩下的规则。在这种情况下,该函数被单步执行。

    函数名是正则表达式。

    冒号需要用反斜杠括起来。

    您可以指定 StepInto 和 NoStepInto。这为您提供了一种避免进入同一作用域/命名空间中除少数几个函数之外的所有函数的方法。

    重新启动 Visual Studio 以获取对注册表的更改。

    【讨论】:

    • 虽然 Visual Studio 2012, 2013 列在上面的详细信息中,但不再使用注册表。按照博客条目链接了解有关如何更新 default.natstepfilter 的详细信息。
    • 当你启用编辑并继续时,我认为注册表在 VS 2012 和 2013 中使用。
    【解决方案2】:

    https://docs.microsoft.com/en-us/visualstudio/debugger/just-my-code?view=vs-2019#BKMK_CPP_Customize_stepping_behavior

    在 C++ 项目中,您可以通过在 *.natstepfilter 文件中将它们列为非用户代码来指定要跳过的函数。 *.natstepfilter 文件中列出的函数不依赖于 Just My Code 设置。

    • 要为所有本地 Visual Studio 用户指定非用户代码,请将 .natstepfilter 文件添加到 %VsInstallDirectory%\Common7\Packages\Debugger\Visualizers 文件夹。
    • 要为单个用户指定非用户代码,请将 .natstepfilter 文件添加到 %USERPROFILE%\My Documents\<Visual Studio version>\Visualizers 文件夹。

    .natstepfilter 文件是具有以下语法的 XML 文件:

    <?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>
    
    Element Description
    Function Required. Specifies one or more functions as non-user functions.
    Name Required. An ECMA-262 formatted regular expression specifying the full function name to match. For example:

    &lt;Name&gt;MyNS::MyClass.*&lt;/Name&gt;

    tells the debugger that all methods in MyNS::MyClass are to be considered non-user code. The match is case-sensitive.
    Module Optional. An ECMA-262 formatted regular expression specifying the full path to the module containing the function. The match is case-insensitive.
    Action Required. One of these case-sensitive values:

    NoStepInto - tells the debugger to step over the function.
    StepInto - tells the debugger to step into the function, overriding any other NoStepInto for the matched function.

    【讨论】:

    • 至少你可以做到,我花了4个小时写python让lldb做这个精确的事情
    【解决方案3】:

    我的复制过去:

    避免介入事情

    避免踩踏通常很有用 进入一些常见的代码,如 构造函数或重载运算符。 autoexp.dat 提供了这种能力。 添加一个名为 “[执行控制]”。在哪里添加键 关键是函数名和 值为“NoStepInto”。您可以指定 星号 (*) 作为通配符 命名空间的第一组冒号或 类。

    autoexp.dat 只能在 Visual 上读取 工作室的启动。

    要忽略函数 myfunctionname, 以及对 CFoo 类的所有调用:

    [执行控制]

    myfunctionname=NoStepInto

    CFoo::*=NoStepInto

    忽略构造和赋值 MFC CStrings:(注意额外的 = 在 CString::operator=.)

    [执行控制]

    CString::CString=NoStepInto

    CString::operator==NoStepInto

    忽略所有 ATL 调用:

    [执行控制]

    ATL::*=NoStepInto

    来自这篇 (http://www.highprogrammer.com/alan/windev/visualstudio.html) 文章。

    您也可以使用弹出菜单中的“进入特定功能”。

    编辑 抱歉,看起来 autoexp.dat 在 vs 2003/2005 中不起作用。 您可以对注册表设置进行同样的操作。 http://groups.google.com/group/microsoft.public.vsnet.debugging/browse_thread/thread/b03dee5a626470c0/26addb1b539883e8

    【讨论】:

    • 似乎只有 Visual Studio 6 支持 AUTOEXP.DAT 文件。较新的版本使用注册表项。
    【解决方案4】:

    上下文菜单上还有“进入特定”条目,它将列出当前行可以进入的功能,您可以选择您想要的。

    【讨论】:

      【解决方案5】:

      VS6 曾经让你在 autoexp 文件中定义值,让你跳过进入常用函数(例如字符串构造函数)。从 VS7 开始,这些排除项已移至注册表。易用性受到严重打击。

      在 VS7 和更高版本中,Microsoft 明智地将这些排除项移到了注册表中。以下是一些示例:

      Windows Registry Editor Version 5.00
      [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\NativeDE\StepOver]
      "10"="CString\\:\\:CString=NoStepInto"
      "11"=".*\\.c_str.*=NoStepInto"
      

      键名代表搜索顺序。 键值包含要搜索的 VS 正则表达式。

      如果您创建自己的排除项,请务必从反汇编视图中获取名称。源代码中的声明可能与编译器生成的名称不匹配,尤其是对于模板函数。

      【讨论】:

        猜你喜欢
        • 2020-05-19
        • 1970-01-01
        • 2019-09-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-14
        • 2013-04-17
        • 2011-02-01
        相关资源
        最近更新 更多