{"id":30425,"date":"2022-04-20T20:20:17","date_gmt":"2022-04-20T20:20:17","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=30425"},"modified":"2022-04-20T20:23:17","modified_gmt":"2022-04-20T20:23:17","slug":"whats-new-for-c-debugging-in-visual-studio-code","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/whats-new-for-c-debugging-in-visual-studio-code\/","title":{"rendered":"What\u2019s new for C++ Debugging in Visual Studio Code"},"content":{"rendered":"<p>It\u2019s been a minute since our last blog post about C++ in VS Code, but we\u2019ve been working hard on new features and bug fixes! Today, we\u2019re excited to fill you in on the latest and greatest C++ debugger improvements in VS Code, including support for the Apple M1 chip, data breakpoints, and a new run\/debug play button!<\/p>\n<h2>Apple Silicon ARM64 (M1 chip)<\/h2>\n<p>Last year, we enabled language server support for Apple Silicon ARM64 architecture, which meant you could run the C++ extension\u2019s language server (responsible for things like IntelliSense, code navigation, and autocomplete) natively on the Apple M1 chip. At the time, the C++ extension\u2019s debugger binaries did not run natively on the M1 chip. Now, they do!<\/p>\n<p>With <a href=\"https:\/\/github.com\/microsoft\/vscode-cpptools\/releases\/tag\/v1.9.7\">this latest release<\/a> of the C++ extension, you can seamlessly debug C++ programs when running VS Code on the M1 chip. Give it a try and let us know what you think! If you run into any issues, please follow up on the <a href=\"https:\/\/github.com\/microsoft\/vscode-cpptools\/issues\/7035\">GitHub tracking issue (#7035)<\/a>.<\/p>\n<h2>Data breakpoints<\/h2>\n<p>In case you missed it, version 1.8.4 of the C++ extension brought support for <a href=\"https:\/\/github.com\/microsoft\/vscode-cpptools\/issues\/1410\">data breakpoints (#1410)<\/a> while debugging C++ programs with GDB in VS Code. Data breakpoints break execution when a value stored at a specified memory address changes.<\/p>\n<p>To set a data breakpoint while debugging in VS Code, right click on a variable in the debug pane and select <strong>Break on Value Change<\/strong>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/break-on-value-change.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-30430\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/break-on-value-change.png\" alt=\"Screenshot of the context menu that appears when a user right clicks on a local variable in the Debug pane. The Break on Value Change menu item is selected.\" width=\"2626\" height=\"1808\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/break-on-value-change.png 2626w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/break-on-value-change-300x207.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/break-on-value-change-1024x705.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/break-on-value-change-768x529.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/break-on-value-change-1536x1058.png 1536w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/break-on-value-change-2048x1410.png 2048w\" sizes=\"(max-width: 2626px) 100vw, 2626px\" \/><\/a><\/p>\n<p>Immediately, you\u2019ll see the data breakpoint listed in the <strong>Breakpoints<\/strong> section of the debug pane.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/data-breakpoint-in-window.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-30429\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/data-breakpoint-in-window.png\" alt=\"Screenshot of the data breakpoint listed in the Breakpoints section of the Debug pane\" width=\"948\" height=\"304\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/data-breakpoint-in-window.png 948w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/data-breakpoint-in-window-300x96.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/data-breakpoint-in-window-768x246.png 768w\" sizes=\"(max-width: 948px) 100vw, 948px\" \/><\/a><\/p>\n<p>In this example, if we continue running the program, the next time it breaks will be when local variable <code>i<\/code> changes value. Use the debug control panel to continue running the program.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/debug-continue.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-30427\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/debug-continue.png\" alt=\"screenshot of the debug control panel, hovering over the continue button.\" width=\"598\" height=\"144\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/debug-continue.png 598w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/debug-continue-300x72.png 300w\" sizes=\"(max-width: 598px) 100vw, 598px\" \/><\/a><\/p>\n<p>Sure enough, execution breaks when <code>i<\/code> changes value from 1 to 2.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/broke-when-i-changed.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-30428\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/broke-when-i-changed.png\" alt=\"Screenshot of the debugger pausing when local variable i changes value\" width=\"2308\" height=\"1630\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/broke-when-i-changed.png 2308w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/broke-when-i-changed-300x212.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/broke-when-i-changed-1024x723.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/broke-when-i-changed-768x542.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/broke-when-i-changed-1536x1085.png 1536w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/broke-when-i-changed-2048x1446.png 2048w\" sizes=\"(max-width: 2308px) 100vw, 2308px\" \/><\/a><\/p>\n<h2>Troubleshooting data breakpoints<\/h2>\n<p>In this same example program, if you set a data breakpoint on <code>msg<\/code> of type string, you might see an error message in the Debug Console that says: <code>Unable to set data breakpoint: Value does not fall within the expected range. (Parameter \u2018size\u2019)<\/code>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/data-breakpoint-size-error.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-30426\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/data-breakpoint-size-error.png\" alt=\"Screenshot of the error message seen when a user tries to set a data breakpoint on a data type that is too large, like string.\" width=\"3030\" height=\"1878\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/data-breakpoint-size-error.png 3030w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/data-breakpoint-size-error-300x186.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/data-breakpoint-size-error-1024x635.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/data-breakpoint-size-error-768x476.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/data-breakpoint-size-error-1536x952.png 1536w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/data-breakpoint-size-error-2048x1269.png 2048w\" sizes=\"(max-width: 3030px) 100vw, 3030px\" \/><\/a><\/p>\n<p>This is because the string type is 32 bytes, and there\u2019s a limitation on the size we can set data breakpoints on. This limitation comes from the fact that the architecture that your program runs on has a limited number of hardware data breakpoints it can use. The table below shows how many registers are available to use per architecture.<\/p>\n<table width=\"613\">\n<thead>\n<tr>\n<td colspan=\"3\"><strong>DATA BREAKPOINT HARDWARE LIMITATIONS<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>Architecture<\/strong><\/td>\n<td><strong>Number of hardware supported data breakpoints<\/strong><\/td>\n<td><strong>Max byte size<\/strong><\/td>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>x86<\/td>\n<td>4<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>x64<\/td>\n<td>4<\/td>\n<td>8<\/td>\n<\/tr>\n<tr>\n<td>ARM<\/td>\n<td>1<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>ARM64<\/td>\n<td>2<\/td>\n<td>8<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><\/h2>\n<h2>Quick run\/debug play button<\/h2>\n<p>We know that setting up tasks.json and launch.json to run and debug C++ files isn\u2019t always fun. We\u2019re excited to announce that, thanks to this latest release, running and debugging C++ files in VS Code has never been easier!<\/p>\n<p>With the <a href=\"https:\/\/github.com\/microsoft\/vscode-cpptools\/releases\/tag\/v1.9.7\">1.9.7 update<\/a>, you\u2019ll see a play button in the top right corner of the editor whenever a C or C++ file is active. It\u2019s the same play button used by the Python extension, Java extension, and Code Runner extension.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/run-play-button.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-30433\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/run-play-button.png\" alt=\"Screenshot of helloworld.cpp active in the editor with the run and debug play button in the title bar\" width=\"3188\" height=\"1996\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/run-play-button.png 3188w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/run-play-button-300x188.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/run-play-button-1024x641.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/run-play-button-768x481.png 768w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/run-play-button-1536x962.png 1536w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/run-play-button-2048x1282.png 2048w\" sizes=\"(max-width: 3188px) 100vw, 3188px\" \/><\/a><\/p>\n<p>The play button has two modes: \u201cRun C\/C++ File\u201d and \u201cDebug C\/C++ File.\u201d The default mode is \u201cRun C\/C++ File,\u201d and you can use the drop-down to switch modes.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/run-debug-drop-down.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-30432\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/run-debug-drop-down.png\" alt=\"Screenshot of the drop-down menu in the run and debug play button\" width=\"446\" height=\"270\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/run-debug-drop-down.png 446w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2022\/04\/run-debug-drop-down-300x182.png 300w\" sizes=\"(max-width: 446px) 100vw, 446px\" \/><\/a><\/p>\n<p>If you already have a launch.json file in your workspace, the play button will read from it when figuring out how to run and debug your C++ file. If you don\u2019t have launch.json, the play button will create a temporary \u201cquick debug\u201d configuration on the fly, eliminating the need for launch.json altogether!<\/p>\n<p>We also simplified <strong>F5<\/strong> (<strong>Run &gt; Start Debugging<\/strong>) to use the same temporary \u201cquick debug\u201d configurations as the play button when your project doesn\u2019t have launch.json. If you need to create launch.json to customize debugging, select <strong>Run &gt; Add Configuration&#8230; <\/strong>from the main menu.<\/p>\n<p><strong>Note: <\/strong>We&#8217;re still rolling out the run\/debug play button, so you might not see it by default, but you can opt in by enabling <strong>C_Cpp: Debug Shortcut<\/strong> in User settings.<\/p>\n<h2>What do you think?<\/h2>\n<p><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscode.cpptools\">Download the C++ extension for Visual Studio Code<\/a>\u202ftoday, give it a try, and let us know what you think. If you run into any issues, or have any suggestions, please report them in the\u202f<a href=\"https:\/\/github.com\/Microsoft\/vscode-cpptools\/issues\">Issues section of our GitHub repository<\/a>. We can be reached via the comments below or in email at\u202f<a href=\"mailto:visualcpp@microsoft.com\">visualcpp@microsoft.com<\/a>. You can also find our team on Twitter at\u202f<a href=\"https:\/\/twitter.com\/visualc\">@<\/a><a href=\"https:\/\/twitter.com\/visualc\">VisualC<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It\u2019s been a minute since our last blog post about C++ in VS Code, but we\u2019ve been working hard on new features and bug fixes! Today, we\u2019re excited to fill you in on the latest and greatest C++ debugger improvements in VS Code, including support for the Apple M1 chip, data breakpoints, and a new [&hellip;]<\/p>\n","protected":false},"author":27203,"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-30425","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>It\u2019s been a minute since our last blog post about C++ in VS Code, but we\u2019ve been working hard on new features and bug fixes! Today, we\u2019re excited to fill you in on the latest and greatest C++ debugger improvements in VS Code, including support for the Apple M1 chip, data breakpoints, and a new [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/30425","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\/27203"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=30425"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/30425\/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=30425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=30425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=30425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}