我必须做什么才能让 Visual Studio 2017 使用 natstepfilter 文件来避免单步执行 std 库函数和类方法?
首先,我通过有意编辑default.natstepfilter 文件来测试此功能。我意识到现在 Visual Studio 中内置了我的代码功能以及关联的编译器设置 /JMC。然而,我有一个遗留项目,它仍然使用旧的 VS2013 工具构建,因此我无法仅使用新的代码功能来避免进入 STL 和其他库函数。因此,我设置了一个简单的 hello world 示例来了解如何使用接下来两篇文章中描述的技术。
读完这两篇文章后,发现过滤器略有不同。我尝试了两种方法,无论是否转义冒号字符,但似乎都不起作用。 https://blog.wholetomato.com/2020/08/18/prevent-debugger-from-stepping-into-unwanted-functions-in-visual-studio/ https://www.asawicki.info/news_1486_how_to_make_visual_studio_debugger_not_step_into_stl.html
考虑此代码。当单步进入采用 c 字符串的 printGreeting 时,我不想单步进入 std::string 的 c_str() 方法,但我必须单击 f-11 才能单步进入 printGreeting,所以这是我用于验证更改的测试用例default.natstepfilter 有效。
我已经尝试过上述网站推荐的这两行,但似乎都没有效果。我认为不需要转义冒号,但这就是一个例子的展示方式。
<Function><Name>std::.+ </Name><Action>NoStepInto</Action>
<Function><Name>std\:\:.* </Name><Action>NoStepInto</Action>
这是示例代码。
#include "pch.h"
#include <iostream>
using namespace std;
void printGreeting(const char* greeting) {
std::cout << greeting << std::endl;
}
int main()
{
std::string greeting("Hello World!\n");
printGreeting(greeting.c_str());
}
我还尝试在编辑 .natstepfilter 后重新启动 Visual Studio 2017,但没有效果。调试器仍然进入 std::string 的构造函数和 c_str() 方法。
First, I am testing this capability by editing the default.natstepfilter file on purpose. I realize that there is a just my code feature built into visual studio now and an associated compiler setting /JMC. However I have a legacy project that is built using the older VS2013 tools still so I can't use the newer just my code feature to avoid stepping into STL and other library functions. Therefore I have setup a simple hello world example to figure out how to use the technique described in these next two articles.
Having read these two articles, the filters are slightly different. I have tried both ways with and without escaping the colon character but neither seems to work.
https://blog.wholetomato.com/2020/08/18/prevent-debugger-from-stepping-into-unwanted-functions-in-visual-studio/
https://www.asawicki.info/news_1486_how_to_make_visual_studio_debugger_not_step_into_stl.html
Consider this code. When stepping into printGreeting that takes the c-string I do not want to step into c_str() method of std::string, but I have to click f-11 to step into printGreeting so this is my test case for verifying that the change to default.natstepfilter works.
I've tried these two lines recommended by the aforementioned sites but neither seems to have an effect. I don't think the escape of the colon is needed but that is how one example showed it.
<Function><Name>std::.+ </Name><Action>NoStepInto</Action>
<Function><Name>std\:\:.* </Name><Action>NoStepInto</Action>
Here is the sample code.
#include "pch.h"
#include <iostream>
using namespace std;
void printGreeting(const char* greeting) {
std::cout << greeting << std::endl;
}
int main()
{
std::string greeting("Hello World!\n");
printGreeting(greeting.c_str());
}
I have also tried restarting visual studio 2017 after editing the .natstepfilter which had no effect. The debugger still steps into the constructor of std::string and the c_str() method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我通过重新开始并创建一个扩展名为 .natstepfilter 的新文件解决了我自己的问题。我无法证明文件中的错误是问题所在,因为我尝试的先前文件已被更改或删除。不过,我相当有信心我编辑的 .natstepfilter 文件中存在错误。通过故意插入错误,我能够再次重现该问题。在我原来的帖子中,我的 xml 示例条目是错误的。它缺少尾随标签。当我从浏览器窗口复制并粘贴示例时,我可能没有复制整行,或者复制了额外的内容。也有可能我没有从编辑的文件中正确复制并粘贴到原始问题中。 当文件包含错误时,它将自动加载失败。我在任何地方都找不到显示加载该文件问题的诊断输出。
我还从 Microsoft 文档中了解到,您可以使用您喜欢的任何名称创建一个新的 .natstepfilter 文件,而不是修改默认值,因此更喜欢这种方法可以避免在原文中引入错误。这是我创建的文件的内容,它对我有用。
此外,您可以将这些文件放在 %USERPROFILE%\Documents\Visual Studio 2017\Visualizers 目录中,这样您就不必将文件添加到系统安装目录中。我确实必须手动创建 Visualizers 目录,然后创建文件。如果您想组织多个文件中的条目,您可以添加带有扩展名的多个文件。
I think I solved my own issue by starting over and creating a new file with the .natstepfilter extension. I can't prove that a mistake in the file was the problem because the previous files I tried were changed or deleted already. However I am fairly confident that there was an error in my edited .natstepfilter file. I was able to reproduce the problem again by purposefully inserting an error. In my original post my xml sample entries were wrong. It was missing the trailing tag . It's possible when I copy and pasted examples from a browser window that I didn't copy the entire line or that I copied something extra. It's also possible that I didn't copy and paste correctly from my edited file into the original question. When the file contains an error, it will silently fail to be loaded. I couldn't find a diagnostic output anywhere that showed the problem loading that file.
I also learned from the Microsoft documentation that you can create a new .natstepfilter file with any name that you like instead of modifying the default so prefer that approach to avoid introducing an error into the original. Here is the content of the file I created which did work for me.
Moreover you can put these files in your %USERPROFILE%\Documents\Visual Studio 2017\Visualizers directory so that you do not have to add a file to a system installation directory. I did have to manually create the Visualizers directory and then create the file. You can add multiple files with the extension if you'd like to organize the entries across multiple files.