{"id":19835,"date":"2018-06-29T12:12:51","date_gmt":"2018-06-29T19:12:51","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=19835"},"modified":"2019-02-18T17:47:51","modified_gmt":"2019-02-18T17:47:51","slug":"announcing-jmc-stepping-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/announcing-jmc-stepping-in-visual-studio\/","title":{"rendered":"Announcing C++ Just My Code Stepping in Visual Studio"},"content":{"rendered":"<p>In Visual Studio 2017 release 15.8 Preview 3 we\u2019re announcing support for Just My Code stepping for C++. In addition to previously supported <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/just-my-code-for-c-in-vs-2013\/\">callstack filtering<\/a>, the Visual Studio debugger now also supports stepping over non-user-code. As you \u201cStep In\u201d, for example in an algorithm from the Standard library with a custom predicate or in a Win32 API that has a user callback, the debugger will conveniently step into the predicate or callback you provided rather than the library code that will eventually call your code.<\/p>\n<p>After the very warm reception of <a href=\"https:\/\/blogs.msdn.microsoft.com\/vcblog\/2017\/11\/16\/improving-the-debugging-experience-for-stdfunction\/\">our debugging improvements in stepping in std::function calls<\/a> announced last year at CppCon 2017, the team has been working on an universal solution for this debugging challenge that does not require any annotations in library code. 15.8 Preview 3 is available today with this support and we are looking forward to your feedback.<\/p>\n<h3>How to enable Just My Code stepping (JMC)<\/h3>\n<p>Just My Code stepping for C++ has the following requirements:<\/p>\n<ul>\n<li>your program is compiled with a new MSVC compiler switch: \/JMC. JMC is now on by default for MSBuild projects in all Debug configurations, so just <strong>make sure you recompile your project using the latest MSVC compilers<\/strong> in 15.8 Preview 3 or later.<\/li>\n<li>the <strong>PDB for the binary containing the user code is loaded<\/strong> by the debugger, and<\/li>\n<li>JMC is enabled in <strong>Tools<\/strong> &gt; <strong>Options<\/strong> &gt; <strong>Debugging<\/strong> &gt; <b>General &gt; Enable Just My Code<\/b> (which is the default).<\/li>\n<\/ul>\n<h3>New \u201cStep In\u201d behavior<\/h3>\n<p>When JMC is enabled, the debugger will keep track of which code is user code or system\/library code. When stepping into a function that has PDB information, execution will resume until another function that is marked as user code is reached or the current function completes its execution. What this means in practice is that to get to your code, you don\u2019t have to spend your time stepping over countless lines of library code that you\u2019re not interested in or, what happens more often, you can stop juggling giant lists of breakpoints spread all over your codebase.<\/p>\n<p>For example, in the snippet below, without JMC, if you are ambitious enough to \u201cStep In\u201d until you reach the predicate passed as a parameter to the Standard library algorithm, you will have to press F11 (Step In) 140 times! With JMC, it is just one \u201cStep In\u201d command invocation.<\/p>\n<table width=\"659\">\n<tbody>\n<tr>\n<td width=\"659\" colspan=\"2\"><strong>STL algorithms<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"329\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/jmc-stl-before-2.gif\"><img decoding=\"async\" width=\"647\" height=\"431\" class=\"alignnone size-full wp-image-19875\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/jmc-stl-before-2.gif\" \/><\/a><\/td>\n<td width=\"329\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/jmc-stl-after-3.gif\"><img decoding=\"async\" width=\"647\" height=\"429\" class=\"alignnone size-full wp-image-19865\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/jmc-stl-after-3.gif\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Another example is stepping into Win32 API callbacks. Without JMC, the debugger is not able to tell that some user code will eventually execute, so it steps over the Win32 API call completely without stepping into the user-defined callback. JMC correctly identifies the callback as user code and stops the debugger appropriately.<\/p>\n<table width=\"659\">\n<tbody>\n<tr>\n<td width=\"659\" colspan=\"2\"><strong>Win32 API callbacks<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"329\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/jmc-winsdk-before-2.gif\"><img decoding=\"async\" width=\"647\" height=\"480\" class=\"alignnone size-full wp-image-19895\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/jmc-winsdk-before-2.gif\" \/><\/a><\/td>\n<td width=\"329\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/jmc-winsdk-after-2.gif\"><img decoding=\"async\" width=\"647\" height=\"476\" class=\"alignnone size-full wp-image-19885\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/jmc-winsdk-after-2.gif\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Step Into Specific<\/h3>\n<p>To explicitly step into a call that may be non-user code, you can take advantage of the <strong>\u201cStep Into Specific\u201d<\/strong> command available in the editor\u2019s context menu. This allows you to select a specific function (user code or not) that you want to step into:<\/p>\n<p><img decoding=\"async\" width=\"1089\" height=\"567\" class=\"alignnone size-full wp-image-19845\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/step-into-specific.png\" \/><\/p>\n<h3>Configuring Just My Code for additional 3rd party libraries<\/h3>\n<p>The default set of modules and source files that the C++ debugger considers non-user code is encoded in the <strong>default.natjmc<\/strong> file under <b>%VSInstallDir%<\/b><strong>\\Common7\\Packages\\Debugger\\Visualizers<\/strong> and it specifies WinSDK, CRT, STL and ATL\/MFC among other things.<\/p>\n<p>You can customize this set of modules and source files by either:<\/p>\n<ul>\n<li>modifying the central list in <strong>%VSInstallDir%\\Common7\\Packages\\Debugger\\Visualizers\\default.natjmc<\/strong> or<\/li>\n<li>by creating any number of user-specific .natjmc files under the <strong>%USERPROFILE%\\Documents\\Visual Studio 2017\\Visualizers<\/strong> folder.<\/li>\n<\/ul>\n<p>For example, to treat all Boost libraries as non-user code, you can create a boost.natjmc in the above folder with the following content.<\/p>\n<pre class=\"prettyprint disable-colors\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\n&lt;NonUserCode&gt;\n &lt;File Name=&quot;*\\boost\\*&quot; \/&gt;\n&lt;\/NonUserCode&gt;<\/pre>\n<p>You don\u2019t need to rebuild your user code for these changes to kick in. In the next debugging session, stepping into code that uses Boost will step over the Boost library code and only stop execution if some user code is found on the callstack.<\/p>\n<p>For more details on the .natjmc file format, see the <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/debugger\/just-my-code#BKMK_CPP_Customize_call_stack_behavior\">C++ Just My Code documentation page<\/a>. Note that the .natjmc format also supports marking code as non-user code based on function name, but for stepping performance reasons, we do not recommend using this functionality for functions that are called often or for large group of functions (\u2018Function\u2019 rules are much slower than \u2018Module\u2019 or \u2018File\u2019 rules).<\/p>\n<table width=\"659\">\n<tbody>\n<tr>\n<td width=\"659\"><strong>3rd party libraries<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"659\"><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/jmc-boost-2.gif\"><img decoding=\"async\" width=\"1037\" height=\"799\" class=\"alignnone size-full wp-image-19905\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/jmc-boost-2.gif\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Under the covers<\/h3>\n<p>As mentioned above, JMC functionality is only available for user-code compiled with the new MSVC compiler switch \/JMC. This new switch is already on by default for MSBuild projects in Debug configurations. If you\u2019re using a different build system, you will want to make sure you manually add the off-by-default \/JMC switch to the debug builds of your project.<\/p>\n<p>\/JMC is supported only for binaries that link against the CRT.<\/p>\n<p>To explicitly turn off JMC, you can use the \/JMC- switch.<\/p>\n<h3>Give us your feedback!<\/h3>\n<p>This release is the first <a href=\"https:\/\/www.visualstudio.com\/vs\/preview\/\">Visual Studio 2017 Preview<\/a> supporting Just My Code stepping. Your feedback is a critical part of ensuring that we can deliver a delightful debugging experience. For any questions, reach out to us via Twitter at <a href=\"https:\/\/twitter.com\/visualc\">@visualc<\/a> or via email at <a href=\"mailto:visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>. For any issues or suggestions, please let us know via Help &gt; Send Feedback &gt; <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio-2017\">Report a Problem<\/a> in the IDE.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Visual Studio 2017 release 15.8 Preview 3 we\u2019re announcing support for Just My Code stepping for C++. In addition to previously supported callstack filtering, the Visual Studio debugger now also supports stepping over non-user-code. As you \u201cStep In\u201d, for example in an algorithm from the Standard library with a custom predicate or in a [&hellip;]<\/p>\n","protected":false},"author":308,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-19835","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>In Visual Studio 2017 release 15.8 Preview 3 we\u2019re announcing support for Just My Code stepping for C++. In addition to previously supported callstack filtering, the Visual Studio debugger now also supports stepping over non-user-code. As you \u201cStep In\u201d, for example in an algorithm from the Standard library with a custom predicate or in a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/19835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/308"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=19835"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/19835\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=19835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=19835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=19835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}