【发布时间】:2009-03-09 15:39:22
【问题描述】:
我知道“仅启用我的代码”调试选项,但这仅适用于托管代码。
我正在寻找一种无需单步执行函数调用的方法,例如,STL 字符串强制转换运算符,因为在函数的一个参数中存在从 char* 到字符串的隐式转换。
【问题讨论】:
标签: c++ visual-studio debugging
我知道“仅启用我的代码”调试选项,但这仅适用于托管代码。
我正在寻找一种无需单步执行函数调用的方法,例如,STL 字符串强制转换运算符,因为在函数的一个参数中存在从 char* 到字符串的隐式转换。
【问题讨论】:
标签: c++ visual-studio debugging
我发现这个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 以获取对注册表的更改。
【讨论】:
在 C++ 项目中,您可以通过在 *.natstepfilter 文件中将它们列为非用户代码来指定要跳过的函数。 *.natstepfilter 文件中列出的函数不依赖于 Just My Code 设置。
%VsInstallDirectory%\Common7\Packages\Debugger\Visualizers 文件夹。%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:<Name>MyNS::MyClass.*</Name>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. |
【讨论】:
我的复制过去:
避免介入事情
避免踩踏通常很有用 进入一些常见的代码,如 构造函数或重载运算符。 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
【讨论】:
上下文菜单上还有“进入特定”条目,它将列出当前行可以进入的功能,您可以选择您想要的。
【讨论】:
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 正则表达式。
如果您创建自己的排除项,请务必从反汇编视图中获取名称。源代码中的声明可能与编译器生成的名称不匹配,尤其是对于模板函数。
【讨论】: