Debug Analyzer.NET - Snippets Intelligent Debugger http://debuganalyzer.net/ http://www.rssboard.org/rss-specification BlogEngine.NET 1.6.0.5 en-GB http://debuganalyzer.net/opml.axd http://www.dotnetblogengine.net/syndication.axd Sukesh Debug Analyzer.NET 0.000000 0.000000 Debug Analyzer: Bringing back the dead! <p>Debugging memory dumps are also known as Post-mortem debugging and the reason for this is simple. Memory dumps are just a snapshot of the process memory (in case of usermode dumps) and not live at the time of debugging thus the term 'post-mortem'.</p> <p>While working on Debug Analyzer.NET I was hunting for coolness, things which were never done before and thought it would be ultra-cool to give life to objects in the dumps. <br />Let me explain! Assume that you have a DateTime field for a class and available in the memory dumps. You would like to do some comparison or manipulation of that object, like we do with live objects.</p> <p>It would be very useful if we can utilize methods provided by .NET for that type of object to ease manipulation... isn't it? <br />So here it is, the power to give life to objects from the dumps!!!</p> <h4>Let's see a System.DateTime object in Windbg + SOS</h4> <pre class="brush: text;highlight: [2, 10];">[*** Dump one of the System.DateTime object ***] 0:013&gt; !do 0707e980 Name: System.DateTime MethodTable: 0f310010 EEClass: 0f3085d8 Size: 16(0x10) bytes (C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll) Fields: MT Field Offset Type VT Attr Value Name 0f344060 40000f4 4 System.UInt64 1 instance 633988790520830000 dateData </pre> <p>&nbsp;</p> <h4>Now give life to the dead object using Debug Analyzer.NET !!!</h4> <pre class="brush: csharp;">string someAddress = "0707e980"; // ConvertTo is a generic method which supports a number of different .NET types DateTime datetime = someAddress.ToClrObject().ConvertTo&lt;System.DateTime&gt;(); // You can also do this since ToClrObject is an Extension method for string type DateTime datetime = "0707e980".ToClrObject().ConvertTo&lt;System.DateTime&gt;(); </pre> <p>&nbsp;</p> <h4>Let's see the advantage... the object is alive which means you have all the methods and properties .NET provides for that object type.</h4> <p><img src="/image/2011/1/DateTime-ConvertTo.png" alt="System.DateTime ConvertTo" /></p> <p>Check method ClrExtMethods.ConvertTo in help for supported types. More support for types coming sooooon...</p> <p style="color:#0000ff"><em>Note: Please use comments to suggest the types you think would be useful!</em></p> http://debuganalyzer.net/post/Debug-Analyzer-Bringing-back-the-dead.aspx Sukesh http://debuganalyzer.net/post/Debug-Analyzer-Bringing-back-the-dead.aspx#comment http://debuganalyzer.net/post.aspx?id=b238d25b-1817-4e1c-bb04-f78afc5dd6e3 Sat, 29 Jan 2011 04:13:00 -0500 Analysis Scenario Snippets Sukesh http://debuganalyzer.net/pingback.axd http://debuganalyzer.net/post.aspx?id=b238d25b-1817-4e1c-bb04-f78afc5dd6e3 0 http://debuganalyzer.net/trackback.axd?id=b238d25b-1817-4e1c-bb04-f78afc5dd6e3 http://debuganalyzer.net/post/Debug-Analyzer-Bringing-back-the-dead.aspx#comment http://debuganalyzer.net/syndication.axd?post=b238d25b-1817-4e1c-bb04-f78afc5dd6e3 Scenario: How to find logged-in users with ASP.NET forms based authentication <p>Lets talk about a scenario here and take a look at manual way to find what we need with windbg + sos.<br />We will then see how we can automate this using Debug Analyzer.NET Analysis. <br />For learning pleasure and reuse, attached code snippet can be saved in snippets folder and used with Instant Analyzer feature too.</p> <p><strong>Scenario</strong><br />An intranet ASP.NET application becomes very slow during off-peak hours. Since it's during off peak hours we can guess that it might not be due to heavy load.<br />There are several different tools and ways to troubleshoot this issue using profiling tools etc... But since running profiler etc might not be a great idea on production servers, we will use memory dumps to get the users who are using the application and then check what they are doing during that specific time of the issue.<br /><em>(Maybe running a slow moving, large report?)</em></p> <h4>Let us see how this can be done in Windbg + SOS</h4> <pre class="brush: text;highlight: [2, 35, 44, 52, 58];">[*** Dump all the objects of type System.Web.Security.FormsAuthenticationTicket ***] 0:034&gt; !dumpheap -type System.Web.Security.FormsAuthenticationTicket ------------------------------ Heap 0 Address MT Size 10525a48 663b3f14 44 107f84f4 663b3f14 44 total 2 objects ------------------------------ Heap 1 Address MT Size 1454e4c0 663b3f14 44 145c0a00 663b3f14 44 14a04878 663b3f14 44 total 3 objects ------------------------------ Heap 2 Address MT Size 184fc27c 663b3f14 44 total 1 objects ------------------------------ Heap 3 Address MT Size 1c43ca44 663b3f14 44 1c511cfc 663b3f14 44 total 2 objects ------------------------------ total 8 objects Statistics: MT Count TotalSize Class Name 663b3f14 8 352 System.Web.Security.FormsAuthenticationTicket Total 8 objects [*** Let us dump out one of those objects ***] 0:034&gt; !do 107f84f4 Name: System.Web.Security.FormsAuthenticationTicket MethodTable: 663b3f14 EEClass: 663b3e50 Size: 44(0x2c) bytes (C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll) Fields: MT Field Offset Type VT Attr Value Name 79102290 4001e61 10 System.Int32 1 instance 2 _Version 790fd8c4 4001e62 4 System.String 0 instance 107f8520 _Name 7910c878 4001e63 18 System.DateTime 1 instance 107f850c _Expiration 7910c878 4001e64 20 System.DateTime 1 instance 107f8514 _IssueDate 7910be50 4001e65 14 System.Boolean 1 instance 0 _IsPersistent 790fd8c4 4001e66 8 System.String 0 instance 107f853c _UserData 790fd8c4 4001e67 c System.String 0 instance 107f8550 _CookiePath [*** Now dumping out the field name called '_Name' ***] 0:034&gt; !do 107f8520 Name: System.String MethodTable: 790fd8c4 EEClass: 790fd824 Size: 28(0x1c) bytes (C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll) String: USER1 &lt;=== Heyaa!!! we got the user name!!! Fields: MT Field Offset Type VT Attr Value Name 79102290 4000096 4 System.Int32 1 instance 6 m_arrayLength 79102290 4000097 8 System.Int32 1 instance 5 m_stringLength 790ff328 4000098 c System.Char 1 instance 55 m_firstChar 790fd8c4 4000099 10 System.String 0 shared static Empty &gt;&gt; Domain:Value 000f0050:790d884c 00114ca8:790d884c &lt;&lt; 7912dd40 400009a 14 System.Char[] 0 shared static WhitespaceChars &gt;&gt; Domain:Value 000f0050:142d03f4 00114ca8:142d456c &lt;&lt; </pre> <p><span style="color:#0000ff">Repeat the commands in line # 35 and 52 (8 times) for each object from the 1st command result.</span></p> <h4>Now lets see how this can be done in Debug Analyzer.NET (automation and reuse with 4 lines of code)</h4> <pre class="brush: csharp;">// Write a heading WriteHeadLine("Forms Authentication Users"); //Get all objects of type 'System.Web.Security.FormsAuthenticationTicket' IEnumerable&lt;ClrObject&gt; objs = Analyzer.CLR.GetClrObjectsByType("System.Web.Security.FormsAuthenticationTicket"); //Enumerate through all Objects of type 'System.Web.Security.FormsAuthenticationTicket' foreach (ClrObject clrobj in objs) { ClrObject cobj = clrobj.ClrObjectFieldCollection["_Name"].ToClrObject(); WriteHtmlLine("User Name : {0}", cobj.ToString()); //Shows the string value using Extension Method } </pre> <p>See the result below (all Disney characters on your intranet?)<br /><img src="/image/2011/1/form-auth-results.png" alt="" /></p> <h4>Tip: How many lines of code&nbsp;are needed to show the ClrObject in !do format?</h4> <p><span>Answer is 1 line of code!!! (write the following line of code, inside the foreach loop).</span></p> <pre class="brush: csharp">WriteHTMLLine(clrobj.ToHtml()); </pre> <p>How cool is that? !!! <img title="Cool" src="/editors/tiny_mce3/plugins/emotions/img/smiley-cool.gif" border="0" alt="Cool" /></p> <p>(Use right-click and Save Target As...)<br />Download <a href="/file/2011/1/FormsAuthUsers.cs">FormsAuthUsers.cs (850.00 bytes)</a></p> http://debuganalyzer.net/post/Scenario-How-to-find-logged-in-users-with-ASPNET-forms-based-authentication.aspx Sukesh http://debuganalyzer.net/post/Scenario-How-to-find-logged-in-users-with-ASPNET-forms-based-authentication.aspx#comment http://debuganalyzer.net/post.aspx?id=57597617-9f77-47d5-b853-f8d010d6cc0d Fri, 21 Jan 2011 03:52:00 -0500 Analysis Snippets Scenario Sukesh http://debuganalyzer.net/pingback.axd http://debuganalyzer.net/post.aspx?id=57597617-9f77-47d5-b853-f8d010d6cc0d 0 http://debuganalyzer.net/trackback.axd?id=57597617-9f77-47d5-b853-f8d010d6cc0d http://debuganalyzer.net/post/Scenario-How-to-find-logged-in-users-with-ASPNET-forms-based-authentication.aspx#comment http://debuganalyzer.net/syndication.axd?post=57597617-9f77-47d5-b853-f8d010d6cc0d How Instant Analyzer works? <p>Instant Analyzer is more like SQL Query Analyzer, you write your analysis and hit F5 ("Compile &amp; Execute")&nbsp;and it shows the results in the window below.<br />You can also save and load snippets, which&nbsp;are saved and kept under the 'snippets' folder. The 2nd icon for loading and 3rd icon for saving.</p> <p>The following things happen when you hit F5 or "Compile &amp; Execute"</p> <ul> <li>Complete&nbsp;Analysis Plug source is generated&nbsp;by merging the source&nbsp;in the Code Editor&nbsp;below</li> <li>The Analysis Plug is compiled (C# for now) to generate an in-memory Analysis Plug (assembly)</li> <li>Plug Framework evaluates the Analysis Plug to get the Attributes</li> <li>In-memory Plug is then instantiated and Invoked&nbsp;by the Debug Analyzer Engine</li> <li>Debug Analyzer Engine invokes the Data Access Component for the relevant Data</li> <li>Uses the Debugger to get the required data from memory dump&nbsp;requested by the Plug</li> <li>Executes the Entry-point function of the Plug and generates the HTML report content</li> <li>Debug Analyzer Engine gives back the HTML report content</li> <li>Report window at the bottom, shows the HTML report content</li> </ul> <p>Below&nbsp;screenshot shows powerful reporting capability with Graph to display Top 5 .NET Heaps details.<br /><img src="/image/2011/1/InstantAnalyzer-HeapGraph.png" alt="" /></p> <p>&nbsp;</p> <p>Below screenshot shows powerful Analysis capabilities using <span style="color:#0000ff">.NET Lambda expression syntax</span><br /><img src="/image/2011/1/InstantAnalyzer-HeapGraph1.png" alt="" /></p> <p>The above snippets are already included in the download.</p> <p>VB.NET support and <span style="color:#0000ff">'Compile and Publish'</span> option coming soon... <br /><span style="color:#0000ff">'Compile and Publish'</span> option would allow you to convert snippet into Analysis Plug directly with the click of a button.</p> http://debuganalyzer.net/post/InstantAnalyzer.aspx Sukesh http://debuganalyzer.net/post/InstantAnalyzer.aspx#comment http://debuganalyzer.net/post.aspx?id=5a2c24db-e55d-465a-9cab-b25e06e06d33 Sun, 02 Jan 2011 02:13:00 -0500 Analysis Debug Analyzer Snippets Sukesh http://debuganalyzer.net/pingback.axd http://debuganalyzer.net/post.aspx?id=5a2c24db-e55d-465a-9cab-b25e06e06d33 0 http://debuganalyzer.net/trackback.axd?id=5a2c24db-e55d-465a-9cab-b25e06e06d33 http://debuganalyzer.net/post/InstantAnalyzer.aspx#comment http://debuganalyzer.net/syndication.axd?post=5a2c24db-e55d-465a-9cab-b25e06e06d33