简体   繁体   中英

Debugging C++ app in Visual Studio 2017 steps into not my code. Is there a way to turn this off?

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# 以及我希望它在 C++ 中的功能

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.

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 .

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:

调试配置的编译器设置示例图片

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM