{"id":31762,"date":"2023-02-22T18:30:37","date_gmt":"2023-02-22T18:30:37","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=31762"},"modified":"2023-03-14T17:18:13","modified_gmt":"2023-03-14T17:18:13","slug":"cmake-debugger-allows-you-to-debug-your-cmake-scripts-and-more","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/cmake-debugger-allows-you-to-debug-your-cmake-scripts-and-more\/","title":{"rendered":"CMake debugger allows you to debug your CMake scripts and more"},"content":{"rendered":"<p><span class=\"TextRun SCXW117586504 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun CommentStart CommentHighlightPipeRest CommentHighlightRest SCXW117586504 BCX8\">The VS <\/span><span class=\"NormalTextRun SpellingErrorV2Themed CommentHighlightRest SCXW117586504 BCX8\">CMake<\/span> <span class=\"NormalTextRun CommentHighlightPipeRest SCXW117586504 BCX8\">team has been working in close collaboration with <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW117586504 BCX8\">Kitware<\/span><span class=\"NormalTextRun SCXW117586504 BCX8\"> on <\/span><span class=\"NormalTextRun CommentStart CommentHighlightPipeRest CommentHighlightRest SCXW117586504 BCX8\">developing <\/span><span class=\"NormalTextRun CommentHighlightPipeRest SCXW117586504 BCX8\">a <\/span><span class=\"NormalTextRun SCXW117586504 BCX8\">debugger <\/span><span class=\"NormalTextRun SCXW117586504 BCX8\">for <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW117586504 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW117586504 BCX8\"> scripts in the Visual Studio IDE <\/span><span class=\"NormalTextRun SCXW117586504 BCX8\">(<\/span><span class=\"NormalTextRun SCXW117586504 BCX8\">s<\/span><span class=\"NormalTextRun SCXW117586504 BCX8\">ee <\/span><\/span><a class=\"Hyperlink SCXW117586504 BCX8\" href=\"https:\/\/gitlab.kitware.com\/cmake\/cmake\/-\/issues\/21510\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"TextRun Underlined SCXW117586504 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW117586504 BCX8\" data-ccp-charstyle=\"Hyperlink\">this open Kitware issue for more details<\/span><\/span><\/a><span class=\"TextRun Underlined SCXW117586504 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW117586504 BCX8\" data-ccp-charstyle=\"Hyperlink\">)<\/span><\/span><span class=\"TextRun SCXW117586504 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW117586504 BCX8\">. <\/span><span class=\"NormalTextRun CommentStart CommentHighlightPipeRest CommentHighlightRest SCXW117586504 BCX8\">We <\/span><span class=\"NormalTextRun CommentHighlightRest SCXW117586504 BCX8\">will be<\/span><span class=\"NormalTextRun CommentHighlightRest SCXW117586504 BCX8\">\u00a0<\/span><span class=\"NormalTextRun CommentHighlightPipeRest SCXW117586504 BCX8\">contributing this work back <\/span><span class=\"NormalTextRun CommentStart CommentHighlightPipeRest CommentHighlightRest SCXW117586504 BCX8\">upstream<\/span><span class=\"NormalTextRun CommentHighlightRest SCXW117586504 BCX8\"> (targeting the 3.27 release) <\/span><span class=\"NormalTextRun CommentHighlightPipeRest SCXW117586504 BCX8\">so that the developer community can have it and work to improve it together, by adding new features and <\/span><span class=\"NormalTextRun SCXW117586504 BCX8\">support f<\/span><span class=\"NormalTextRun SCXW117586504 BCX8\">or <\/span><span class=\"NormalTextRun SCXW117586504 BCX8\">additional<\/span><span class=\"NormalTextRun SCXW117586504 BCX8\"> DAP capabilities.<\/span><\/span><span class=\"EOP SCXW117586504 BCX8\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">We are excited to announce that a preview of the CMake debugger is now available to debug your CMake scripts and CMakeLists.txt file for any CMake project in <\/span><a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\"><span data-contrast=\"none\">Visual Studio 17.6 Preview 1<\/span><\/a><span data-contrast=\"auto\">.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">To initiate a CMake debugging session, you can select \u201cConfigure [Project Name] with CMake Debugger\u201d from the context menu when right-clicking on your CMakeLists.txt file in the Solution Explorer or from the \u201cProject\u201d dropdown menu<\/span><span data-contrast=\"auto\">.<\/span><\/p>\n<p style=\"text-align: center;\"><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\"> <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMakeDebugger-dropdownv2.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-31763\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMakeDebugger-dropdownv2.png\" alt=\"&quot;Configure CMake Project with CMake Debugger&quot; selection from Project Dropdown\" width=\"576\" height=\"412\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMakeDebugger-dropdownv2.png 576w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMakeDebugger-dropdownv2-300x215.png 300w\" sizes=\"(max-width: 576px) 100vw, 576px\" \/><\/a><\/span><\/p>\n<p><span class=\"TextRun SCXW228008529 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW228008529 BCX8\">When CMake cache generation on your project fails, a \u201cDebug\u201d link will also be available<\/span><span class=\"NormalTextRun SCXW228008529 BCX8\"> to start <\/span><span class=\"NormalTextRun SCXW228008529 BCX8\">a <\/span><span class=\"NormalTextRun SpellingErrorV2Themed SCXW228008529 BCX8\">CMake<\/span><span class=\"NormalTextRun SCXW228008529 BCX8\"> debugg<\/span><span class=\"NormalTextRun SCXW228008529 BCX8\">er session<\/span><span class=\"NormalTextRun SCXW228008529 BCX8\"> in the Solution Explorer.<\/span><\/span><span class=\"EOP SCXW228008529 BCX8\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMakeDebugger-infobar.png\"><img decoding=\"async\" class=\"size-full wp-image-31764 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMakeDebugger-infobar.png\" alt=\"Debug link in the Info Bar in Solution Explorer when CMake cache generation fails\" width=\"507\" height=\"343\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMakeDebugger-infobar.png 507w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMakeDebugger-infobar-300x203.png 300w\" sizes=\"(max-width: 507px) 100vw, 507px\" \/><\/a><\/p>\n<h3 aria-level=\"2\"><span data-contrast=\"none\">CMake Debugger Functionality<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">You can set breakpoints based on file names, line numbers, or when CMake errors and warnings are triggered in your CMakeLists.txt file by clicking in the margin to the left of the line numbers like normally or by using the Breakpoint and Exception Settings. Using these breakpoints, you can step into, over, and out of them, as well as pause or continue the executing scope like a normal debugger.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMake-Debugger-Side-Bar-Breakpoint.png\"><img decoding=\"async\" class=\"wp-image-31768 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMake-Debugger-Side-Bar-Breakpoint.png\" alt=\"Adding a breakpoint in the sidebar to a CMakeLists.txt file\" width=\"829\" height=\"367\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMake-Debugger-Side-Bar-Breakpoint.png 1074w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMake-Debugger-Side-Bar-Breakpoint-300x133.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMake-Debugger-Side-Bar-Breakpoint-1024x453.png 1024w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMake-Debugger-Side-Bar-Breakpoint-768x340.png 768w\" sizes=\"(max-width: 829px) 100vw, 829px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMakeDebugger-in-action.png\"><img decoding=\"async\" class=\"size-full wp-image-31766 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMakeDebugger-in-action.png\" alt=\"CMake Debugger paused on exception status and able to view the call stack\" width=\"846\" height=\"667\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMakeDebugger-in-action.png 846w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMakeDebugger-in-action-300x237.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/CMakeDebugger-in-action-768x606.png 768w\" sizes=\"(max-width: 846px) 100vw, 846px\" \/><\/a><\/p>\n<p><span data-contrast=\"auto\">As you can see above, you can use the call stack in the CMake debugger to see filenames and lines associated with your debugging process. You can also decide which types of errors and warnings you\u2019d like the debugger you automatically break on.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">You can view the state of different CMake Cache variables through the Locals window.\u00a0 Then, you can set a watch on defined variables by right-clicking on them or through the Watch window. For now, this excludes function or macro arguments.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/WatchVariable.png\"><img decoding=\"async\" class=\"alignnone wp-image-31769\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/WatchVariable.png\" alt=\"Set a watch on local variables through this view\" width=\"888\" height=\"442\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/WatchVariable.png 1002w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/WatchVariable-300x149.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/WatchVariable-768x382.png 768w\" sizes=\"(max-width: 888px) 100vw, 888px\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/Status-of-Watch-Variables.png\"><img decoding=\"async\" class=\" wp-image-31770 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/Status-of-Watch-Variables.png\" alt=\"Viewing the status of watch variables\" width=\"753\" height=\"158\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/Status-of-Watch-Variables.png 1000w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/Status-of-Watch-Variables-300x63.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/Status-of-Watch-Variables-768x161.png 768w\" sizes=\"(max-width: 753px) 100vw, 753px\" \/><\/a><\/p>\n<p>Additionally, through the Locals window, you can view the state of currently defined targets and tests with their properties.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/cmake-debugger-targets.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-31946\" src=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/cmake-debugger-targets.png\" alt=\"You can view targets in the Cmake Debugger Locals view\" width=\"935\" height=\"406\" srcset=\"https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/cmake-debugger-targets.png 935w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/cmake-debugger-targets-300x130.png 300w, https:\/\/devblogs.microsoft.com\/cppblog\/wp-content\/uploads\/sites\/9\/2023\/02\/cmake-debugger-targets-768x333.png 768w\" sizes=\"(max-width: 935px) 100vw, 935px\" \/><\/a><\/p>\n<h3 aria-level=\"2\"><span data-contrast=\"none\">Limitations<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">Currently, the CMake debugger only works with the version of CMake bundled with Visual Studio. Projects targeting WSL or remote machines are also not supported yet. When our debugger work goes into upstream CMake, we will make this feature available to both WSL and remote machines.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h3 aria-level=\"2\"><span data-contrast=\"none\">Future Work<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">We are working to add functionality to: <\/span><\/p>\n<ul>\n<li><span data-contrast=\"auto\">Set breakpoints when variable values are read or written <\/span><\/li>\n<li><span data-contrast=\"auto\">View the state of currently defined targets, directories, and tests with their properties<\/span><\/li>\n<li><span data-contrast=\"auto\">Add general improvements to the debugger experience<\/span><\/li>\n<\/ul>\n<p><span data-contrast=\"auto\">If there\u2019s anything else you\u2019d like to see, please add to the suggestion ticket <a href=\"https:\/\/developercommunity.visualstudio.com\/t\/CMake-Debugger-Suggestions\/10288163?space=8&amp;entry=suggestion\">here<\/a>.<\/span><\/p>\n<h3 aria-level=\"2\"><span data-contrast=\"none\">Send us your feedback!<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">We hope this helps your CMake workflows in Visual Studio. Download the latest preview version of Visual Studio and give it a try. Let us know your thoughts and whether there is anything you\u2019d like to see added. We are actively improving this feature and are very interested in your feedback. <\/span><span data-contrast=\"none\">The comments below are open, or you can find us on Twitter (<\/span><a href=\"https:\/\/twitter.com\/visualc\"><span data-contrast=\"none\">@VisualC<\/span><\/a><span data-contrast=\"none\">) or via email at\u202f<\/span><a href=\"mailto:visualcpp@microsoft.com\"><span data-contrast=\"none\">visualcpp@microsoft.com<\/span><\/a><span data-contrast=\"none\">.\u202fTo open a bug, please see \u202f<\/span><a href=\"https:\/\/developercommunity.visualstudio.com\/report?space=8&amp;entry=problem%22%20\\t%20%22_blank\"><span data-contrast=\"none\">Visual Studio Feedback.<\/span><\/a><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p style=\"text-align: center;\">\n","protected":false},"excerpt":{"rendered":"<p>The VS CMake team has been working in close collaboration with Kitware on developing a debugger for CMake scripts in the Visual Studio IDE (see this open Kitware issue for more details). We will be\u00a0contributing this work back upstream (targeting the 3.27 release) so that the developer community can have it and work to improve [&hellip;]<\/p>\n","protected":false},"author":85413,"featured_media":31766,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,266,230],"tags":[],"class_list":["post-31762","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus","category-cmake","category-new-feature"],"acf":[],"blog_post_summary":"<p>The VS CMake team has been working in close collaboration with Kitware on developing a debugger for CMake scripts in the Visual Studio IDE (see this open Kitware issue for more details). We will be\u00a0contributing this work back upstream (targeting the 3.27 release) so that the developer community can have it and work to improve [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/31762","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\/85413"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=31762"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/31762\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/31766"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=31762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=31762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=31762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}