{"id":230811,"date":"2020-10-08T09:30:14","date_gmt":"2020-10-08T16:30:14","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=230811"},"modified":"2020-10-13T10:58:23","modified_gmt":"2020-10-13T17:58:23","slug":"linux-managed-memory-dump-debugging","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/linux-managed-memory-dump-debugging\/","title":{"rendered":"Cross Platform Managed Memory Dump Debugging"},"content":{"rendered":"<p><strong>I am really happy to announce that with the release of Visual Studio 16.8 Preview 3 you now have the ability to open and analyze managed dumps collected on Linux and use the best in class debugging tools available in Visual Studio.<\/strong><\/p>\n<p>Over the year\u2019s Windows developer have grown accustomed to a broad variety of tools to help diagnose issues occurring with apps and services running on remote Windows machines. More recently we have empowered our developer community with the tools to develop and deploy apps across multiple platforms including many of the popular Linux distros.<\/p>\n<p>Collecting and analyzing memory dumps remains a popular deep diagnostics technique, however, one of the primary limitations with cross platform memory analysis is that process dumps were not provided in a portable format. For example, it was not possible to directly diagnose a memory dump collected on Linux with the popular tools available on Windows.<\/p>\n<h3>Cross Platform Collection<\/h3>\n<p>Analyzing dumps is one of the most commonly used techniques to debug issues on remote machines, this is especially true when you do not have immediate access to your production environment. Developers will use a dump file from a machine when they can&#8217;t reproduce a crash or unresponsive program state on their own machine.<\/p>\n<p>Here are some of my favorite tools for collecting dumps on Linux.<\/p>\n<h5>createdump<\/h5>\n<p>The <a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/master\/docs\/design\/coreclr\/botr\/xplat-minidump-generation.md#configurationpolicy\">createdump<\/a> utility is an efficient mechanism for collecting memory dumps and can be run from the command line on any .NET Core processes.<\/p>\n<p><code>sudo createdump &lt;pid&gt; --full<\/code><\/p>\n<h5>dotnet-dump<\/h5>\n<p>The <a href=\"https:\/\/docs.microsoft.com\/dotnet\/core\/diagnostics\/dotnet-dump\">dotnet-dump<\/a> is global CLI tool (currently requires the .NET SDK) that provides a convenient way to collect Linux dumps even without a native debugger involved like lldb on Linux.<\/p>\n<p><code>dotnet-dump collect -process-id &lt;PID&gt; -type Full<\/code><\/p>\n<h5>dotnet-monitor<\/h5>\n<p>We also have the ability to capture a variety of diagnostics artifacts including dumps and traces and quickly egress them to any other environment using <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/introducing-dotnet-monitor\/\">dotnet-monitor<\/a>.<\/p>\n<p><strong>dotnet-monitor<\/strong> is an experimental tool currently available as a .NET Core global tool and as a container image via the <a href=\"https:\/\/github.com\/microsoft\/ContainerRegistry\">Microsoft Container Registry (MCR)<\/a>. The setup instructions for dotnet-monitor vary based on the target environment and platform, <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/introducing-dotnet-monitor\/\">check out this post for more details.<\/a><\/p>\n<h3>Opening the Linux Core dump in Visual Studio<\/h3>\n<p>Memory dumps created on Windows machines have well known extension (*.dmp) and thus have a straightforward association with your favorite memory analysis tools. By default, core dumps produced on Linux machines are created without an extension.<\/p>\n<p>If your managed core dump doesn&#8217;t have an extension you can drag and drop the file into your IDE and Visual Studio will automatically identify and open it as a Linux core managed memory dump.<\/p>\n<p>However, if the file was renamed to include the Windows dump extension (*.dmp) then use Visual Studio\u2019s \u201cOpen with\u201d feature in the Open File dialogue box.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-230812\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-open-file-linux-dump.png\" alt=\"Visual Studio Open Linux Dump file\" width=\"1875\" height=\"1125\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-open-file-linux-dump.png 1875w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-open-file-linux-dump-300x180.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-open-file-linux-dump-1024x614.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-open-file-linux-dump-768x461.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-open-file-linux-dump-1536x922.png 1536w\" sizes=\"(max-width: 1875px) 100vw, 1875px\" \/><\/p>\n<p>Select &#8220;Managed Linux Core Dump file summary&#8221;.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-230813\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-open-with-linux-dump.png\" alt=\"Visual Studio Open with for Linux dump file\" width=\"1124\" height=\"740\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-open-with-linux-dump.png 1124w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-open-with-linux-dump-300x198.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-open-with-linux-dump-1024x674.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-open-with-linux-dump-768x506.png 768w\" sizes=\"(max-width: 1124px) 100vw, 1124px\" \/><\/p>\n<h3>Linux Core Dump File Summary<\/h3>\n<p>The <strong>Managed Linux Core Dump File Summary<\/strong> window shows a summary and module information for the dump file, and a list of <strong>Actions<\/strong> you can take, this remains consistent with existing dump handling experiences in Visual Studio.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-230814\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-dump-file-summary-linux-dump.png\" alt=\"Image Visual Studio Dump File Summary for Linux\" width=\"2132\" height=\"1068\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-dump-file-summary-linux-dump.png 2132w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-dump-file-summary-linux-dump-300x150.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-dump-file-summary-linux-dump-1024x513.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-dump-file-summary-linux-dump-768x385.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-dump-file-summary-linux-dump-1536x769.png 1536w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2020\/10\/vs-dump-file-summary-linux-dump-2048x1026.png 2048w\" sizes=\"(max-width: 2132px) 100vw, 2132px\" \/><\/p>\n<p>From this window you can conveniently set your symbols paths, which allows you to point to program database (.pdb) files, also called symbol files. The .pdb file holds debugging and project information, and the Visual Studio debugger will use .pdb files to determine the source file name and line number. This makes it easier to determine the exact line of code being executed when the memory dump was taken.<\/p>\n<p>To start debugging, you can select <strong>Debug with Managed Only<\/strong> from the <strong>Actions<\/strong> section of the summary page and to start using the awesome debugging tools you have become accustomed to.<\/p>\n<p>You could, for example, start by reviewing the list of Threads or Tasks using the <a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/debugging-async-code-parallel-stacks-for-tasks\/\">Parallel Stacks for Tasks<\/a> window. Or dig a bit deeper by examining the most interesting frames from <strong>Calls Stacks <\/strong>view. That might also lead you to examine the value and state of variables using the <strong>Locals<\/strong> or <strong>Autos<\/strong> window. Essentially you get to examine every detail of the process just as if you set a breakpoint on your Linux box.<\/p>\n<p>Please note the following limitations in our preview:<\/p>\n<ul>\n<li>The minimum supported .NET Core version is 3.1.7<\/li>\n<li>.NET 5.0-rc1 will be the first 5.0 supported version<\/li>\n<li>Preview 3 will only support full dumps (<a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/core\/diagnostics\/dotnet-dump#options-1\">\u201dFull\u201d option using dotnet-dump<\/a>). Full support for all dump options is anticipated for Visual Studio 16.8 Preview 4 &amp; .NET 5.0-rc2.<\/li>\n<li>The ability to <a href=\"https:\/\/developercommunity.visualstudio.com\/content\/idea\/1179319\/access-the-memory-usage-tool-from-a-linux-core-dum.html\">\u201cDebug Managed Memory\u201d (view the heap) is being developed for a future release<\/a>.<\/li>\n<li>Support for <a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/decompilation-of-c-code-made-easy-with-visual-studio\/\">Decompilation<\/a> is <a href=\"https:\/\/developercommunity.visualstudio.com\/idea\/1179352\/support-decompilation-for-linux-core-dumps.html\">currently in our backlog<\/a>s and scheduled for release in Preview 4.<\/li>\n<li>Preview testing included Linux core dumps generated on the following amd64 docker .NET images:\n<ul>\n<li>buster-slim (Debian 10)<\/li>\n<li>alpine (Alpine 3.11 &amp; 3.12)<\/li>\n<li>focal (Ubuntu 20.04)<\/li>\n<li>bionic (Ubuntu 18.04)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>If you are interested in \u201cNative Only\u201d dump debugging for Linux systems for unmanaged C++ please check out the <a href=\"https:\/\/devblogs.microsoft.com\/cppblog\/debug-linux-core-dumps-in-visual-studio\/\">blog post here<\/a>.<\/p>\n<h3>Try it out!<\/h3>\n<p>Debugging managed Linux core dumps on Windows has been difficult to accomplish until now, it might mean setting up another Linux environment that exactly mirrored production and then installing a set of tools for the analysis. Thankfully with the latest Visual Studio 2019 16.8 preview you can simply drag and drop a managed Linux core dump directly into your IDE and immediately start debugging.<\/p>\n<p>Please reach out to us on the <a href=\"https:\/\/developercommunity.visualstudio.com\/content\/idea\/post.html?space=8\">Developer Community to site to suggest and\/or vote on features<\/a>, help us prioritize what is most important to you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the release of Visual Studio 16.8 Preview 3 you now have the ability to open and analyze managed dumps collected on Linux and use the best in class debugging tools available in Visual Studio.<\/p>\n","protected":false},"author":1017,"featured_media":230814,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[155],"tags":[6793,3835],"class_list":["post-230811","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-studio","tag-debugger","tag-diagnostics"],"acf":[],"blog_post_summary":"<p>With the release of Visual Studio 16.8 Preview 3 you now have the ability to open and analyze managed dumps collected on Linux and use the best in class debugging tools available in Visual Studio.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/230811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/1017"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=230811"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/230811\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/230814"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=230811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=230811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=230811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}