5

Ok so when debugging, for example when I set my breakpoint on simple string declaration

string a;

and then pressing f11 (step into) my debugger steps into xstring file, and I don't want it. I want it to step into JUST MY code. This works fine with C# projects, but not with C++ ones.

How I defined it for C++ projects in Visual Studio: C++

How I use it in C#, where it works well: C# and what I want it to be in C++ also

I have "Just My Code" enabled and I don't know what to do. I just dont want it to step in not my files.

Benjamin Buch
  • 4,752
  • 7
  • 28
  • 51
  • 4
    What about not pressing "step into", but pressing "step over"? – mcsim Nov 25 '17 at 18:43
  • 1
    When you press "step into" you *step into* the `std::string` constructor function. Just like "step into" is *supposed* to do. – Some programmer dude Nov 25 '17 at 18:46
  • 1
    Then it steps over my function and i want it to step into my functions but JUST my functions for example in p0->fork("p1"); it will step into xstring and i want it to just step into Process fork function which i implemented. – Aravae Aravae Nov 25 '17 at 18:59

2 Answers2

5

The C# feature you are referring to is called "Just My Code". Unfortunately, Visual Studio does not implement it in the same way for C++. As documentation says:

C++ Just My Code is different than .NET Framework and JavaScript Just My Code because the stepping behavior is independent of the call stack behavior.

There is a workaround, however:

You can create your own .natstepfilter and .natjmc to customize the stepping and call stack window behavior in the %USERPROFILE%\My Documents\Visual Studio 2015\Visualizers.

Despite of the typo in the documentation ("2015") and the horribly convoluted way this was designed, the trick actually works!

For example, with the Visual Studio 2017 installation on my machine, I can go to C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Packages\Debugger\Visualizers and a add file called .natstepfilter with the following content:

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

Now when I debug in Visual Studio and step into something, all C++ standard-library functions are skipped.

Note that the actual format of the XML file is not validated very strictly by Visual Studio. I've actually used the simpler form explained in the Visual Studio 2015 documentation.

Christian Hackl
  • 27,051
  • 3
  • 32
  • 62
0

Visual Studio 2017 Version 15.8 is shipped with an improved support of "Just My Code" for C++ projects, as described in the documentation:

Starting in Visual Studio 2017 version 15.8, Just My Code for code stepping is also supported. This feature also requires use of the /JMC (Just my code debugging) compiler switch. The switch is enabled by default in C++ projects. For Call Stack window and call stack support in Just My Code, the /JMC switch is not required.

Hence the \JMC compiler switch needs to be set for all own C++ projects in the Debug configuration:

Sample picture of compiler settings for Debug configuration

Tested with Visual Studio 2022, this compiler switch works really well and no .natstepfilter is required anymore to step over the std::.* stuff.

CKE
  • 1,533
  • 19
  • 18
  • 29