{"id":95,"date":"2009-06-14T14:23:03","date_gmt":"2009-06-14T21:23:03","guid":{"rendered":"http:\/\/blog.monnet-usa.com\/?p=95"},"modified":"2009-06-14T14:23:21","modified_gmt":"2009-06-14T21:23:21","slug":"crash-and-burn-then-dump-and-debug","status":"publish","type":"post","link":"https:\/\/blog.monnet-usa.com\/?p=95","title":{"rendered":"Crash And Burn, Then Dump And Debug"},"content":{"rendered":"<h3>Managed Code Makes Us Forget The Bad Ol&#8217; Days Of Crashes<\/h3>\n<p>In the late eighties, during and after college, I earned my basic debugger stripes by analyzing mainframe cobol stack dumps and DOS\/C++ debugging (on a French videotext server product). Thank God for me, my passion was Smalltalk and then later other now traditional virtual machine-based languages like Java and C#. I do remember working with one of the awesome architects of the Digitalk Smalltalk virtual machine on analyzing VM crashes, where we would try to make our way back to a Smalltalk stack frame and find the offending method. But then, I must have been lucky, as I have not personally had to investigate a real crash OS crash myself until recently.<br \/>\nAt work, we recently purchased a package, implemented in a mix of C++, COM, and .NET. All components of the solution but one are working great. That component is a rich client built on .NET 3.5 which integrates some third party controls. So far on all our XP workstations we consistently get a crash. To help the vendor narrow down the issue I decided to investigate what the crash was all about. What I needed was to get a crash dump so I could upload it to the vendor for analysis using WinDbg, the Windows Debugger. This post summarizes my experience.<br \/>\n<\/p>\n<p>To follow along, you can reference <a href=\"http:\/\/blogs.msdn.com\/ntdebugging\/archive\/2009\/05\/18\/capturing-adplus-clr-crashes.aspx\">Trey Nash&#8217;s post<\/a> and use his test source like I did. So I created a new folder called <b>CrashAndBurn<\/b> under <b>C:Program Files<\/b>. Then I created a C# source file named <b>test.cs<\/b> and pasted Trey&#8217;s example. I then compiled it using the command: <br \/>\ncsc \/debug+ test.cs<br \/>\nNow when you run it you should get an exception. Good! We now have a test subject!\n<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.monnet-usa.com\/wp-content\/uploads\/2009\/06\/crashandburn.png\" alt=\"crashandburn\" title=\"crashandburn\" width=\"583\" height=\"189\" class=\"alignnone size-full wp-image-108\" srcset=\"https:\/\/blog.monnet-usa.com\/wp-content\/uploads\/2009\/06\/crashandburn.png 583w, https:\/\/blog.monnet-usa.com\/wp-content\/uploads\/2009\/06\/crashandburn-300x97.png 300w\" sizes=\"auto, (max-width: 583px) 100vw, 583px\" \/><\/p>\n<h3>Crash And Dump<\/h3>\n<p>To make this happen I first needed to get setup with all the necessary tools:<\/p>\n<ol>\n<li>Install the <a href=\"http:\/\/www.microsoft.com\/whdc\/devtools\/debugging\/symbolpkg.mspx#d\">Windows symbols package<\/a><\/li>\n<li>Install the <a href=\"http:\/\/www.microsoft.com\/whdc\/devtools\/debugging\/installx86.mspx#a\">Windows Debugging tools<\/a><\/li>\n<li>Add the location of the Windows Debugging tools to your Windows system PATH environment variable<\/li>\n<\/ol>\n<p>When you install the debugging tools, you get WinDbg the main Windows Debugger and ADPlus a script that will allow you to capture a crash and create a dump.<br \/>\nNow we can get started:<\/p>\n<ol>\n<li>Open a command window<\/li>\n<li>Get ADPlus to start your application and create a dump by typing the following command:<\/br><br \/>\nADPlus -crash -FullOnFirst -sc &#8220;C:Program FilesCrashAndBurntest.exe&#8221; -o &#8220;C:Program FilesCrashAndBurn&#8221;\n  <\/li>\n<li>ADPlus will kick off your app as well as a command window, then will write out the crash dump to a new directory under the one specified in the &#8220;-o&#8221; parameter<\/li>\n<li>Now navigate to the dump folder and check out its contents<\/li>\n<div id=\"attachment_111\" style=\"width: 310px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-111\" src=\"https:\/\/blog.monnet-usa.com\/wp-content\/uploads\/2009\/06\/crashandburndumps-300x144.png\" alt=\"Crash dumps\" title=\"crashandburndumps\" width=\"300\" height=\"144\" class=\"size-medium wp-image-111\" srcset=\"https:\/\/blog.monnet-usa.com\/wp-content\/uploads\/2009\/06\/crashandburndumps-300x144.png 300w, https:\/\/blog.monnet-usa.com\/wp-content\/uploads\/2009\/06\/crashandburndumps.png 553w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><p id=\"caption-attachment-111\" class=\"wp-caption-text\">Crash dumps<\/p><\/div>\n<li>Now you can kick off WinDbg, then open the latest dump file<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/blog.monnet-usa.com\/wp-content\/uploads\/2009\/06\/windbgopencrashdump.png\" alt=\"Crash dump in WinDbg\" title=\"windbgopencrashdump\" class=\"alignnone size-full wp-image-115\" \/><br \/>\nNow you&#8217;re ready to analyze the crash!<\/p>\n<h3>Analyzing The Crash<\/h3>\n<p>Let&#8217;s run the following commands in WinDbg:<br \/>\n<code><br \/>\n.loadby sos mscorwks<br \/>\n!analyze -v<br \/>\n<\/code><\/p>\n<p>This will give us a starting point in terms of figuring out where the exception was.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.monnet-usa.com\/wp-content\/uploads\/2009\/06\/windbganalyzecrashdump.png\" alt=\"windbganalyzecrashdump\" title=\"windbganalyzecrashdump\" width=\"724\" height=\"368\" class=\"alignnone size-full wp-image-114\" srcset=\"https:\/\/blog.monnet-usa.com\/wp-content\/uploads\/2009\/06\/windbganalyzecrashdump.png 724w, https:\/\/blog.monnet-usa.com\/wp-content\/uploads\/2009\/06\/windbganalyzecrashdump-300x152.png 300w\" sizes=\"auto, (max-width: 724px) 100vw, 724px\" \/><br \/>\nOf course you may have to do more &#8220;digging&#8221; for the root cause. Here is the output:\n<\/p>\n<pre>\r\n<\/pre>\n<p>Notice the following text inside the verbose output:<\/p>\n<pre>\r\nException object: 013f4a94\r\nException type: System.InvalidCastException\r\nMessage: Unable to cast object of type 'C' to type 'A'.\r\nInnerException: <none>\r\nStackTrace (generated):\r\n    SP       IP       Function\r\n    0012F418 00DC01F5 test!EntryPoint.DoSomething()+0x155\r\n    0012F480 00DC0088 test!EntryPoint.Main()+0x18\r\n<\/pre>\n<p>This tells us that a cast exception occurred, which the exception that Trey wanted to intentionally trigger.<\/p>\n<p>\nTo learn more I recommend to look up Tess Ferrandez blog since she has a ton of details and some labs.\n<\/p>\n<h3>References And Resources<\/h3>\n<p>These blogs and resources are all &#8220;must-read&#8221; and &#8220;must-bookmark&#8221;!<\/p>\n<ol>\n<li><a href=\"http:\/\/blogs.msdn.com\/tess\/\">&#8220;If broken it is, fix it you should&#8221; blog by Tess Ferrandez on MSDN<\/a><\/li>\n<li><a href=\"http:\/\/blogs.msdn.com\/ntdebugging\/archive\/2009\/05\/18\/capturing-adplus-clr-crashes.aspx\">&#8220;Capturing ADPlus CLR Crashes&#8221; by Trey Nash on MSDN<\/a><\/li>\n<li><a href=\"http:\/\/www.microsoft.com\/whdc\/devtools\/debugging\/default.mspx\">Windows Debugging Tools home page on MSDN<\/a><\/li>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/cc265639.aspx\">ADPlus Command-Line Options on MSDN<\/a><\/li>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb190764.aspx\">SOS Debugging Options<\/a><\/li>\n<li><a href=\"http:\/\/geekswithblogs.net\/.netonmymind\/archive\/2006\/03\/14\/72262.aspx\">WinDbg \/ SOS Cheat Sheet<\/a><\/li>\n<li><a href=\"http:\/\/windbg.info\/doc\/1-common-cmds.html\">Common WinDbg Commands from windbg.info<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Managed Code Makes Us Forget The Bad Ol&#8217; Days Of Crashes In the late eighties, during and after college, I earned my basic debugger stripes by analyzing mainframe cobol stack dumps and DOS\/C++ debugging (on a French videotext server product). Thank God for me, my passion was Smalltalk and then later other now traditional virtual [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-95","post","type-post","status-publish","format-standard","hentry","category-tools"],"_links":{"self":[{"href":"https:\/\/blog.monnet-usa.com\/index.php?rest_route=\/wp\/v2\/posts\/95","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.monnet-usa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.monnet-usa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.monnet-usa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.monnet-usa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=95"}],"version-history":[{"count":33,"href":"https:\/\/blog.monnet-usa.com\/index.php?rest_route=\/wp\/v2\/posts\/95\/revisions"}],"predecessor-version":[{"id":133,"href":"https:\/\/blog.monnet-usa.com\/index.php?rest_route=\/wp\/v2\/posts\/95\/revisions\/133"}],"wp:attachment":[{"href":"https:\/\/blog.monnet-usa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.monnet-usa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.monnet-usa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}