{"id":12255,"date":"2016-12-12T12:17:52","date_gmt":"2016-12-12T19:17:52","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/vcblog\/?p=12255"},"modified":"2019-02-18T18:04:31","modified_gmt":"2019-02-18T18:04:31","slug":"december-update-for-the-visual-studio-code-cc-extension","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/december-update-for-the-visual-studio-code-cc-extension\/","title":{"rendered":"December Update for the Visual Studio Code C\/C++ extension"},"content":{"rendered":"<p>At \/\/Build this year we launched the C\/C++ extension for<span>\u00a0<\/span><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/cc-extension-for-visual-studio-code\/\">Visual Studio Code<\/a>. Keeping with the monthly release cadence and goal to continuously respond to your feedback, this December update introduces the following features:<\/p>\n<ul>\n<li><a href=\"#visualize\">Debugger visualizations by default with Pretty Printing for GDB users<\/a><\/li>\n<li><a href=\"#map\">Ability to map source files during debugging<\/a><\/li>\n<\/ul>\n<p>If you haven\u2019t already provided us feedback, please take this<span>\u00a0<\/span><a href=\"https:\/\/www.research.net\/r\/ZZMWSXV\">quick survey<\/a><span>\u00a0<\/span>to help shape this extension for your needs. The<span>\u00a0<\/span><a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/cc-extension-for-visual-studio-code\/\">original blog post<\/a> has already been updated with these new feature additions. Let\u2019s learn more about each one of them now!<\/p>\n<h4 id=\"visualize\">Debugger Visualizations by default with Pretty Printing for GDB users<\/h4>\n<p>Pretty printers can be used to make the output of GDB more usable and hence debugging easier. \u2018launch.json\u2019 now comes pre-configured with Pretty Printing enabled as a result of the \u2018-enable-pretty-printing\u2019 flag in the \u2018setupCommands\u2019 section. This flag is passed to GDB MI enabling Pretty Printing.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/debug1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/debug1.png\" alt=\"debug1\" width=\"477\" height=\"194\" class=\"alignnone size-full wp-image-12265\" \/><\/a><\/p>\n<p>To demonstrate the advantages of pretty printing let\u2019s take the following example.<\/p>\n<p>#include &lt;iostream&gt;\n#include &lt;string&gt;\n#include &lt;vector&gt;<\/p>\n<p>using namespace std;<\/p>\n<p>int main()\n{\nvector&lt;float&gt; testvector(5,1.0);\nstring str = &#8220;Hello World&#8221;;\ncout &lt;&lt; str;\nreturn 0;\n}<\/p>\n<p>In a live debugging session let us evaluate \u2018str\u2019 and \u2018testvector\u2019 without pretty printing enabled:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/debug2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/debug2.png\" alt=\"debug2\" width=\"802\" height=\"247\" class=\"alignnone size-full wp-image-12267\" \/><\/a><\/p>\n<p>Look at the value for \u2018str\u2019 and \u2018testvector\u2019. It looks very cryptic\u2026<\/p>\n<p>Let us now evaluate \u2018str\u2019 and \u2018testvector\u2019 <strong><em>with pretty printing enabled<\/em><\/strong>:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/debug3.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/debug3.png\" alt=\"debug3\" width=\"661\" height=\"205\" class=\"alignnone size-full wp-image-12275\" \/><\/a><\/p>\n<p>There is some instant gratification right there!<\/p>\n<p>There is a selection of pre-defined pretty printers for STL containers which come as a part of the default GDB distribution. You can also <a href=\"https:\/\/sourceware.org\/gdb\/onlinedocs\/gdb\/Writing-a-Pretty_002dPrinter.html\">create your very own pretty printer by following this guide<\/a>.<\/p>\n<h4 id=\"map\">Ability to map source files during debugging<\/h4>\n<p>Visual Studio Code displays code files during debugging based on what the debugger returns as the path of the code file. The debugger embeds source location during compilation but if you debug an executable with source files that have been moved, Visual Studio Code will display a message stating that the code file cannot be found. An example of this is when your debugging session occurs on a machine different from where the binaries are compiled . You can now use the \u2018sourceFileMap\u2019 option to override the paths returned by the debugger and replace it with directories that you specify.<\/p>\n<pre>#include \"stdafx.h\"\n#include \"..\\bar\\shape.h\"\nint main()\n{\n      shape triangle;\n      triangle.getshapetype();\n      return 0;\n}\n<\/pre>\n<p>Let us assume post compilation the directory \u2018bar\u2019 was moved, this would mean when we are stepping into \u2018triangle.getshapetype()\u2019 function, the mapping source file \u2018shape.cpp\u2019 would not be found. This can now be fixed by using the \u2018sourceFileMap\u2019 option in your launch.json file as shown below:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/debug4.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/9\/2019\/02\/debug4.png\" alt=\"debug4\" width=\"436\" height=\"63\" class=\"alignnone size-full wp-image-12285\" \/><\/a><\/p>\n<p>We currently require that both the key and the value be a full path and not a relative path. You may use as many key\/value pairs as you would like. They are parsed from first to last and the first match it finds, it will use the replacement value. In entering the mappings, it would be best to start with the most specific to the least specific. You may also specify the full path to a file to change the mapping.<\/p>\n<h4>Update your extension now!<\/h4>\n<p>If you are already using the C\/C++ extension, you can update your extension easily by using the extensions tab. This will display any available updates for your currently installed extensions. To install the update, simply click the Update button in the extension window.<\/p>\n<p>Please refer to the\u00a0<a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/cc-extension-for-visual-studio-code\/\">original blog post for links to documentation<span>\u00a0<\/span><\/a>and for more information about the overall experience of Visual Studio Code C\/C++. Please help us by continuing to file issues at our<span>\u00a0<\/span><a href=\"https:\/\/github.com\/microsoft\/vscode-cpptools\">Github page<\/a><span>\u00a0<\/span>and keep trying out this experience and if you would like to shape the future of this extension please join our<span>\u00a0<\/span><a href=\"http:\/\/landinghub.visualstudio.com\/c-nonwin\">Cross-Platform C++ Insiders group<\/a>, where you can speak with us directly and help make this product the best for your needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At \/\/Build this year we launched the C\/C++ extension for\u00a0Visual Studio Code. Keeping with the monthly release cadence and goal to continuously respond to your feedback, this December update introduces the following features: Debugger visualizations by default with Pretty Printing for GDB users Ability to map source files during debugging If you haven\u2019t already provided [&hellip;]<\/p>\n","protected":false},"author":265,"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-12255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cplusplus"],"acf":[],"blog_post_summary":"<p>At \/\/Build this year we launched the C\/C++ extension for\u00a0Visual Studio Code. Keeping with the monthly release cadence and goal to continuously respond to your feedback, this December update introduces the following features: Debugger visualizations by default with Pretty Printing for GDB users Ability to map source files during debugging If you haven\u2019t already provided [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/12255","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\/265"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=12255"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/12255\/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=12255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=12255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=12255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}