{"id":226160,"date":"2019-08-19T09:00:07","date_gmt":"2019-08-19T16:00:07","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=226160"},"modified":"2019-08-19T09:58:08","modified_gmt":"2019-08-19T16:58:08","slug":"find-solutions-faster-by-analyzing-crash-dumps-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/find-solutions-faster-by-analyzing-crash-dumps-in-visual-studio\/","title":{"rendered":"Find solutions faster by analyzing crash dumps in Visual Studio"},"content":{"rendered":"<p><span>When unexpected crashes occur in your managed application you are often left with little evidence of the issue; capturing and analyzing memory dumps may be your last best option. Thankfully Visual Studio is a great tool for analyzing your apps memory dumps! In this post we show you how easy it is to get important insights from a crash dump, and the steps to resolve the issue using Visual Studio.<\/span><\/p>\n<h3>What is a crash?<\/h3>\n<p>There are several different things that might be causing your managed application to crash, the most common are typically unhandled exceptions. These occurs where an exception is raised (First Chance Exception), but your code does not handle it (typically using a try-catch code construct). The exception goes up the stack and becomes, what we refer to as, a <strong>S<em>econd Chance Exception<\/em><\/strong> and crashes your app\u2019s process.<\/p>\n<p><strong>Out of Memory Exceptions<\/strong>, <strong>Stack Overflow Exceptions<\/strong> and <strong>Execution Engine Exceptions<\/strong> also cause crashes. <strong>Stack Overflow Exceptions<\/strong> and <strong>Out of Memory Exceptions<\/strong> can occur when your app has insufficient memory space for any function to handle the exception, which again causes the process to crash.<\/p>\n<h3>Capturing a memory dump<\/h3>\n<p>Memory dumps are a great diagnostic tool because they are a complete snapshot of what a process is doing at the time the dump is captured. There are several tools available for capturing memory dumps including <a href=\"https:\/\/visualstudio.microsoft.com\/downloads\/\">Visual Studio<\/a>, <a href=\"https:\/\/docs.microsoft.com\/en-us\/sysinternals\/downloads\/procdump\">ProcDump<\/a>, <a href=\"https:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=49924\">DebugDiag<\/a> and <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-hardware\/drivers\/debugger\/debugger-download-tools\">WinDbg<\/a>. The relative strength of each tool depends on your environment and the scenario you are investigating (e.g. high CPU, memory leaks, first\/second chance exceptions, etc.).<\/p>\n<p>In the following example, I use the versatile <a href=\"https:\/\/www.poppastring.com\/blog\/taking-a-hang-dump-or-crash-dump-with-procdump\"><strong>ProcDump<\/strong> command-line utility from Sysinternals<\/a> to capture a <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-hardware\/drivers\/debugger\/user-mode-dump-files#full\">full user-mode dump<\/a> (-ma) when an unhandled exception (-e) occurs (1145 is the process id of my application).<\/p>\n<pre class=\"theme:dark-terminal font-size:16 toolbar:2 lang:default decode:true \">procdump.exe -ma -e 1145<\/pre>\n<p>Once the crash occurs ProcDump immediately writes the memory dump to disk (*.dmp).<\/p>\n<p>Debugging crashes is made easier with the Visual Studio memory tools, so let me show you how I debug a Stack Overflow Exception in my application, and how the tools navigate me directly to the line of code that caused the problem.<\/p>\n<h3>Analyzing a crash dump with Visual Studio<\/h3>\n<p>I can open my memory dump directly in Visual Studio and will be presented with the <strong>Dump Summary<\/strong> page.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-226165\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-summary-page.png\" alt=\"Visual Studio - Dump Summary Page\" width=\"1085\" height=\"822\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-summary-page.png 1085w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-summary-page-300x227.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-summary-page-768x582.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-summary-page-1024x776.png 1024w\" sizes=\"(max-width: 1085px) 100vw, 1085px\" \/><\/p>\n<p>The Dump Summary page highlights several pieces of important information from the dump file including the <strong>OS Version<\/strong> and <strong>CLR Version<\/strong>. I can also search through a list of the modules that were loaded into memory at the time I captured the memory dump.<\/p>\n<p>In this example the <strong>Exception Code<\/strong> and <strong>Exception Information<\/strong> state that the problem is <em>\u201cThe thread used up its stack\u201d<\/em>. Simply put, we have a stack overflow exception. Knowing the problem is one half of the equation, but I also want to know the root cause of the issue, and this is where I think Visual Studio shines.<\/p>\n<p>On the right side of the Dump Summary page, I can choose from several <strong>Actions<\/strong>, but as this is a managed application, I will select the <strong>Debug with Managed Only<\/strong> option and Visual Studio immediately drops me onto the thread and code line that caused the stack overflow exception!<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-226163\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-line-of-code.png\" alt=\"Visual Studio - Crash Dump Exception\" width=\"1800\" height=\"1154\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-line-of-code.png 1800w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-line-of-code-300x192.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-line-of-code-768x492.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-line-of-code-1024x656.png 1024w\" sizes=\"(max-width: 1800px) 100vw, 1800px\" \/><\/p>\n<p>I now have a more complete view of the problem, it\u2019s as if I had managed to set a break point at the exact moment of the stack overflow. This also presents me with the opportunity to review my Call Stack (which confirms the issue), review other threads, and even verify the state of any Local variables at that point in time.<\/p>\n<p>In this instance Visual Studio is pointing me to a clear error on my definition of the get property. Instead of returning the private variable <em>m_MyText<\/em> I have mistakenly returned the public property <em>MyText<\/em>. This circular reference is the cause of the stack overflow exception.<\/p>\n<p>Finding the root cause of the problem may not always be this clear, so you could also collaborate with a colleague directly from the exception by using <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/liveshare\/\">Visual Studio Live Share<\/a>. This gives you the ability to co-debug in real time without teammates needing to set up their environment.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-226164 size-medium\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-start-live-share-300x126.png\" alt=\"Visual Studio - Start Live Share Session from an Exception\" width=\"300\" height=\"126\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-start-live-share-300x126.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-start-live-share-768x323.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2019\/08\/visual-studio-dump-start-live-share.png 867w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<h3>Conclusion<\/h3>\n<p>Over the years Visual Studio has developed first class support for handling and debugging memory dumps. It allows you to consider the impact your code is having during the exact moment of a catastrophic failure. Having the ability to investigate a problem with the same tools used for developing code can help save time determining and providing a solution.<\/p>\n<p>Please let us know what you\u2019d like to see next by <a href=\"https:\/\/developercommunity.visualstudio.com\/spaces\/8\/index.html\">suggesting feature requests or reporting issues via Developer Community<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When unexpected crashes occur in your managed application you are often left with little evidence of the issue; capturing and analyzing memory dumps may be your last best option. Thankfully Visual Studio is a great tool for analyzing your apps memory dumps! In this post we show you how easy it can be to resolve the issue using Visual Studio.<\/p>\n","protected":false},"author":1017,"featured_media":226165,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[155],"tags":[1665,3835],"class_list":["post-226160","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-studio","tag-debugging","tag-diagnostics"],"acf":[],"blog_post_summary":"<p>When unexpected crashes occur in your managed application you are often left with little evidence of the issue; capturing and analyzing memory dumps may be your last best option. Thankfully Visual Studio is a great tool for analyzing your apps memory dumps! In this post we show you how easy it can be to resolve the issue using Visual Studio.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/226160","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=226160"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/226160\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/226165"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=226160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=226160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=226160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}