2

I'm using Visual Studio 2022 Community and trying to make the debugger ignore some functions during the "Step Into" command. I have the following code in main.cpp:

#include <iostream>

void func(int x)
{
    std::cout << "func(" << x << ")\n";
}

void wrapper(int x)
{
    std::cout << "wrapper start" << "\n";
    func(x);
    std::cout << "wrapper end" << "\n";
}

int main()
{
    wrapper(10);
    wrapper(10);
}

and the following my.natstepfilter file in the same project:

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

based on examples from the documentation. There was an announcement that it's possible to have this file in a project since Visual Studio 2022 version 17.6, not user-wide/system-wide.

However, the file seems to be completely ignored. The debugger steps into both wrapper and func, and there are no errors in its "Output" window.

I've also tried putting the my.natstepfilter file to user-wide and system-wide locations to no avail.

What am I doing wrong?

yeputons
  • 8,478
  • 34
  • 67
  • There is [a very similar question from 2013](https://stackoverflow.com/q/19563738/767632), but it explicitly excluded extensions in the question's text. Moreover, ReSharper C++ was [not publicly available in 2013](https://stackoverflow.com/a/19999483/767632). I also think more details in my question will help someone else to debug their issue. – yeputons Jun 23 '23 at 23:36

1 Answers1

3

Turns out I had the ReSharper C++ extension enabled, even though it was suspended and not having any indexing or menu items.

ReSharper is known to disable .natstepfilter files completely:

Note that at the moment Visual Studio’s support for .natstepfilter files gets disabled if ReSharper C++ is installed.

Solution

There is no need to actually uninstall ReSharper, it's enough to fully disable the extension in the Extensions > Manage Extensions menu by clicking the Disable button next to it and restarting Visual Studio:

Screenshot of the "Manage Extensions" window, the "Disable" button is marked in the right part of the "JetBrains ReSharper 2023.1.3" row

Workaround 1

You can also use ReSharper's own debugging step filters described on the same page: add a filter either by pressing Alt+Enter immediately after stepping into the wrapper function, or under by added ^wrapper$ in ReSharper's Options Tools > Debugger > C++, Step filters on the right. It will work exactly like my.natstepfilter.

Screenshot of ReSharper's Options window with the list of step filters and ^wrapper$ filter selected

Workaround 2

Another option is to use .natjmc (Just My Code) files instead. They do not prevent the debugger from entering the wrapper function completely, but they mark it as "External Code" so it becomes transparent for the debugger: stepping into the wrapper function will actually step into the func directly. That may even be better depending on your goal.

Here is an example my.natjmc that you can add into the project, it works even with ReSharper C++ enabled:

<?xml version="1.0" encoding="utf-8"?>
<NonUserCode xmlns="http://schemas.microsoft.com/vstudio/debugger/jmc/2015">
  <Function Name="wrapper" />
</NonUserCode>
yeputons
  • 8,478
  • 34
  • 67
  • Hi, thanks for your sharing! Since you have found the workarounds and solutions of this issue, you can [mark yourself answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) to end this question. This will help others who meet the similar issue and searching for the solution. :) – Bowman Zhu-MSFT Jun 28 '23 at 06:37
  • 1
    @BowmanZhu-MSFT Ah, yes, thank you. Forgot about that post already and I cannot mark my own answer in the first two days, so it was left like this. – yeputons Jun 28 '23 at 08:26