<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Windbg on naveen srinivasan</title><link>https://naveensrinivasan.com/categories/windbg/</link><description>Recent content in Windbg on naveen srinivasan</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 20 Jun 2011 17:45:24 +0000</lastBuildDate><atom:link href="https://naveensrinivasan.com/categories/windbg/index.xml" rel="self" type="application/rss+xml"/><item><title>Making an Image Easier to Debug</title><link>https://naveensrinivasan.com/?p=1368/</link><pubDate>Mon, 20 Jun 2011 17:45:24 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1368/</guid><description>&lt;p&gt;I am doing security review for a managed application which is obfuscated. So I am doing a lot of   disassembling code at runtime using Windbg. One of the issues is that code gets JIT optimized because of the retail build. This makes it harder for me debug when mapping it back. Realized  that I could turnoff  JIT Optimization’s using the ini file.&lt;/p&gt;&#10;&lt;p&gt;[sourcecode]&lt;/p&gt;&#10;&lt;p&gt;[.NET Framework Debugging Control]&lt;/p&gt;&#10;&lt;p&gt;GenerateTrackingInfo=1&lt;/p&gt;&#10;&lt;p&gt;AllowOptimize=0&lt;/p&gt;&#10;&lt;p&gt;[/sourcecode]&lt;/p&gt;</description></item><item><title>Updating .NET String in memory with Windbg</title><link>https://naveensrinivasan.com/?p=1353/</link><pubDate>Tue, 14 Jun 2011 16:42:24 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1353/</guid><description>&lt;p&gt;In this post I would show a simple trick to update .NET strings in memory with Windbg. The caveat is make sure the string that you’re updating is long enough to fit into the string buffer. If not there would be a memory corruption.&lt;/p&gt;&#10;&lt;p&gt;Here is a simple windows form application with title “Good”&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="http://104.197.135.42/wp-content/uploads/2011/06/updatestring13.jpg"&gt;&lt;!-- raw HTML omitted --&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;The goal is to update the title from “Good” to “Bad”.&lt;/p&gt;</description></item><item><title>Who is is blocking my UI Thread? Diagnosing the cause using Windbg</title><link>https://naveensrinivasan.com/?p=1344/</link><pubDate>Fri, 01 Apr 2011 18:59:06 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1344/</guid><description>&lt;p&gt;It so happens most of the applications block the UI thread and do sync I/O, which is most common reason for “Not Responding” window. Here is a post &lt;a href="http://blogs.msdn.com/b/nathannesbit/archive/2010/12/28/detecting-ui-thread-misuse.aspx"&gt;http://blogs.msdn.com/b/nathannesbit/archive/2010/12/28/detecting-ui-thread-misuse.aspx&lt;/a&gt; that tries helping in detecting this. I like to handle this from bottom of the stack because we have a cool tool called debugger.&lt;/p&gt;&#10;&lt;p&gt;The approach is simple as having a break-point on a function like “KERNEL32!WaitFor*” and checking if the current thread is a UI thread. This could also be done for other functions like Sleep on UI thread by having a break-point on “KERNELBASE!SleepEx”.&lt;/p&gt;</description></item><item><title>Correlating between .NET and native thread in Windbg</title><link>https://naveensrinivasan.com/?p=1324/</link><pubDate>Sun, 09 Jan 2011 01:46:06 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1324/</guid><description>&lt;p&gt;I recently saw a stackoverflow question where  someone wanted to know how they could correlate between  managed and native threads within Windbg.&lt;/p&gt;&#10;&lt;p&gt;Here is the managed thread object within the debugger&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;0:004&amp;gt; !do 02a1d6c4&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;Name:        System.Threading.Thread&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;MethodTable: 672e001c&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;EEClass:     67018ed8&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;Size:        48(0x30) bytes&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;File:        C:WindowsMicrosoft.NetassemblyGAC_32mscorlibv4.0_4.0.0.0__b77a5c561934e089mscorlib.dll&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;Fields:&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;MT    Field   Offset                 Type VT     Attr    Value Name&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;672c8a78  4000720        4 ….Contexts.Context  0 instance 00000000 m_Context&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;672db4b8  4000721        8 ….ExecutionContext  0 instance 00000000 m_ExecutionContext&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;672df9fc  4000722        c        System.String  0 instance 02a1a220 m_Name&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;672dfed0  4000723       10      System.Delegate  0 instance 00000000 m_Delegate&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;672e63f4  4000724       14 …ation.CultureInfo  0 instance 00000000 m_CurrentCulture&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;672e63f4  4000725       18 …ation.CultureInfo  0 instance 00000000 m_CurrentUICulture&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;672df638  4000726       1c        System.Object  0 instance 00000000 m_ThreadStartArg&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;&lt;!-- raw HTML omitted --&gt;&lt;!-- raw HTML omitted --&gt;672daa7c  4000727       20        System.IntPtr  1 instance   542560 DONT_USE_InternalThread&lt;!-- raw HTML omitted --&gt;&lt;!-- raw HTML omitted --&gt;&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;672e29c8  4000728       24         System.Int32  1 instance        2 m_Priority&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;672e29c8  4000729       28         System.Int32  1 instance        3 m_ManagedThreadId&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;672cb76c  400072a      18c …LocalDataStoreMgr  0   shared   static s_LocalDataStoreMgr&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;Domain:Value  0049f148:NotInit  &amp;laquo;&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;/blockquote&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;672ce328  400072b        c …alDataStoreHolder  0   shared TLstatic s_LocalDataStore&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;Thread:Value &amp;laquo;&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;/blockquote&gt;&#10;&lt;/blockquote&gt;&#10;&lt;p&gt;The present thread’s @$teb (Thread Environment Block) is &lt;!-- raw HTML omitted --&gt;&lt;!-- raw HTML omitted --&gt;7efac000&lt;!-- raw HTML omitted --&gt;&lt;!-- raw HTML omitted --&gt;&lt;/p&gt;&#10;&lt;p&gt;0:004&amp;gt; ? @$teb Evaluate expression: 2130374656 = 7efac000&lt;/p&gt;&#10;&lt;p&gt;The DONT_USE_InternalThread is pointer to the native thread. Dumping the raw memory of the pointer should give us more information we are looking for.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;0:004&amp;gt; dd poi(02a1d6c4+20)&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;00542560  67e9ee88 0000b220 00000000 056ef42c&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;00542570  00000000 00000000 00000000 00000003&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;00542580  00000000 00542588 00542588 00542588&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;00542590  00000000 00000000 baad0000 004a4f30&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;005425a0  &lt;!-- raw HTML omitted --&gt;&lt;!-- raw HTML omitted --&gt;7efac000&lt;!-- raw HTML omitted --&gt;&lt;!-- raw HTML omitted --&gt; baadf00d 00000000 00000000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;005425b0  00024dac 00000000 00000000 00000000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;005425c0  00000000 baadf00d 00541ba0 00544290&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;005425d0  00544298 00000200 00544290 00544580&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;p&gt;The pointer to teb is in the 40th offset of the  DONT_USE_InternalThread and here is the script that would get teb for each managed thread.&lt;/p&gt;&#10;&lt;p&gt;[sourcecode]&lt;/p&gt;&#10;&lt;p&gt;.foreach ($thread {!dumpheap -mt 672e001c -short}) { .if ( poi(${$thread}+20) != 0) {.printf &amp;ldquo;%p n&amp;rdquo;,dwo(poi(${$thread}+20)+40)}}&lt;/p&gt;&#10;&lt;p&gt;[/sourcecode]&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;0:004&amp;gt; .foreach ($thread {!dumpheap -mt 672e001c -short}) { .if ( poi(${$thread}+20) != 0) {.printf “%p n”,dwo(poi(${$thread}+20)+40) }}&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;7efdd000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;7efac000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;7ef9a000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;7ef97000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;7ef2f000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;7ef26000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;7efd7000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;7ef20000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;7ef1d000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;7ef1d000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;7ef0e000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;7efa3000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;7ef2c000&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;p&gt;So with the above we could dump the teb structure using dt ntdll!_TEB command. In the next post I will demonstrate how this can be used to debug some cool stuff 🙂&lt;/p&gt;</description></item><item><title>Conditional BreakPoint based on callstack within Windbg – .NET</title><link>https://naveensrinivasan.com/?p=1314/</link><pubDate>Wed, 29 Dec 2010 02:00:12 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1314/</guid><description>&lt;p&gt;Someone recently asked me “How to have a break-point on a method based on certain function in the call-stack?”&lt;/p&gt;&#10;&lt;p&gt;Here is the sample code to demonstrate this&lt;/p&gt;&#10;&lt;p&gt;[sourcecode language=”csharp”]&lt;/p&gt;&#10;&lt;p&gt;using System;&lt;/p&gt;&#10;&lt;p&gt;using System.Threading.Tasks;&lt;/p&gt;&#10;&lt;p&gt;using System.Data.SqlClient;&lt;/p&gt;&#10;&lt;p&gt;namespace Test&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;class Program&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;string connectionString = @&amp;ldquo;Data Source=.sqlexpress;Initial Catalog=Tfs_Configuration;Integrated Security=True&amp;rdquo;;&lt;/p&gt;&#10;&lt;p&gt;public void Bar()&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;using (var c = new SqlConnection(connectionString))&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;c.Open();&lt;/p&gt;&#10;&lt;p&gt;var command = new SqlCommand(@&amp;ldquo;update [tbl_AccessMapping] set [DisplayName] = @param&amp;rdquo;, c);&lt;/p&gt;&#10;&lt;p&gt;command.Parameters.Add(new SqlParameter(&amp;ldquo;param&amp;rdquo;, &amp;ldquo;Bar&amp;rdquo;));&lt;/p&gt;</description></item><item><title>Saving Dynamic Assembly in .NET 4.0 using Windbg</title><link>https://naveensrinivasan.com/?p=1298/</link><pubDate>Thu, 23 Dec 2010 23:37:45 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1298/</guid><description>&lt;p&gt;I recently had to debug a .NET 4.0 process which was loading the dependent assemblies using the &lt;!-- raw HTML omitted --&gt;AppDomain.AssemblyResolve&lt;!-- raw HTML omitted --&gt; event. The dependent assemblies were stored within the executable. I couldn’t disassemble the code to look for the dependent assembly because the exe was obfuscated. FYI the dynamic assembly cannot be saved using !SaveModule and here is the reason for &lt;a href="http://stackoverflow.com/questions/1872502/how-to-save-a-dynamically-generated-assembly-that-is-stored-in-memory/1872588#1872588"&gt;I recently had to debug a .NET 4.0 process which was loading the dependent assemblies using the &lt;!-- raw HTML omitted --&gt;AppDomain.AssemblyResolve&lt;!-- raw HTML omitted --&gt; event. The dependent assemblies were stored within the executable. I couldn’t disassemble the code to look for the dependent assembly because the exe was obfuscated. FYI the dynamic assembly cannot be saved using !SaveModule and here is the reason for&lt;/a&gt; read the comments especially from Evian. Unlike psscor2.dll the sos for .NET 4.0 does not have a !dumpdynamicassembly with a save option.&lt;/p&gt;</description></item><item><title>Dumping Generic List in .NET within Windbg</title><link>https://naveensrinivasan.com/?p=1281/</link><pubDate>Fri, 10 Dec 2010 03:15:43 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1281/</guid><description>&lt;p&gt;Most of the code uses List&lt;!-- raw HTML omitted --&gt; for storing items.  The present solutions don’ t have a way to dump List&lt;!-- raw HTML omitted --&gt; within windbg. Even though sosex has an option to dump the List&lt;!-- raw HTML omitted --&gt; using !mdt it still doesn’t meet the scripting requirements. For example here is an output using sosex “!mdt -e 029a91c0”&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;0:000&amp;gt; !mdt -e 029a91c0&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;029a91c0 (System.Collections.Generic.List`1[[Test.Foo, Test]])&lt;/p&gt;&#10;&lt;/blockquote&gt;</description></item><item><title>Why isn’t the !bpmd in sos / windbg not working?</title><link>https://naveensrinivasan.com/?p=1271/</link><pubDate>Mon, 06 Dec 2010 00:16:53 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1271/</guid><description>&lt;p&gt;I recently noticed another blog &lt;!-- raw HTML omitted --&gt;post &lt;!-- raw HTML omitted --&gt;refer to one of my &lt;!-- raw HTML omitted --&gt;post&lt;!-- raw HTML omitted --&gt;. The issue was, sos wasn’t enabling the break-points on non-jitted functions. The classic example being “Main”.  Thanks to &lt;!-- raw HTML omitted --&gt;Steve &lt;!-- raw HTML omitted --&gt; I have been using sosex and not sos for setting break-points.&lt;/p&gt;&#10;&lt;p&gt;From my previous &lt;!-- raw HTML omitted --&gt;post &lt;!-- raw HTML omitted --&gt; you can understand how CLR is using clrn/CLRNotificationException to notify sos/sosex on JIT. With this information when I looked at the rotor &lt;!-- raw HTML omitted --&gt;code&lt;!-- raw HTML omitted --&gt;, I noticed an interesting member variable “g_dacNotificationFlags”. So I decided to check the value of this variable when using !bpmd from sos and !mbm from sosex.&lt;/p&gt;</description></item><item><title>Using sosex within windbg to understand IL and Assembly code</title><link>https://naveensrinivasan.com/?p=1261/</link><pubDate>Tue, 30 Nov 2010 01:33:25 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1261/</guid><description>&lt;p&gt;Sometimes when debugging managed code within the debugger I would like to see the C# code ,the IL translation for the managed code and the Assembly code for the IL. For example I recently learned that callvirt MSIL instruction must do the null-check before invoking method.&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;C:UsersnaveenDocumentsVisual Studio 2010ProjectsConsoleApplication13Program.cs @ 18:&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;00bc26d8 8b4dec          mov     ecx,dword ptr [ebp-14h]&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;00bc26db 3909            cmp     dword ptr [ecx],ecx //NULL Check&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;00bc26dd ff1508a82900    call    dword ptr ds:[29A808h] (System.String.ToLower(), mdToken: 0600031d)&lt;/p&gt;&#10;&lt;/blockquote&gt;</description></item><item><title>Windbg trick – Having custom name for user-defined pseudo-registers</title><link>https://naveensrinivasan.com/?p=1246/</link><pubDate>Tue, 23 Nov 2010 01:07:53 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1246/</guid><description>&lt;p&gt;There are 20 &lt;a href="http://msdn.microsoft.com/en-us/library/ff553485%28VS.85%29.aspx"&gt;user-defined pseudo-registers&lt;/a&gt; (&lt;strong&gt;$t0&lt;/strong&gt;, &lt;strong&gt;$t1&lt;/strong&gt;, …, &lt;strong&gt;$t19&lt;/strong&gt;) in windbg/cdb . To have scripts with variable names as @$t0 and @$t1 isn’t helpful for readability. The trick to avoid this is by using the “aS” command.&lt;/p&gt;&#10;&lt;p&gt;Here is an example, for a loop variable I would like to use a variable name like “i” instead of “@$t0” and to use “i”  as a variable  here is the command&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;aS i “@$t0”&lt;/p&gt;&#10;&lt;/blockquote&gt;</description></item><item><title>Script to !SaveAllModules in .NET 4.0 SOS within Windbg</title><link>https://naveensrinivasan.com/?p=1202/</link><pubDate>Fri, 12 Nov 2010 19:29:06 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1202/</guid><description>&lt;p&gt;The .NET 4.0 sos doesn’t have save all modules (!SaveAllModules) command. It only has !SaveModule. Recently I was debugging a .NET 4.0 process for which I had to save all the modules. Here is a script that does !SaveAllModules.&lt;/p&gt;&#10;&lt;p&gt;[sourcecode]&lt;/p&gt;&#10;&lt;p&gt;!for_each_module .if ($spat (&amp;quot;${@#ImageName}&amp;quot;,&amp;quot;*.exe&amp;quot;)) { !SaveModule ${@#Base} c:temp${@#ModuleName}.exe } .else { !SaveModule ${@#Base} c:temp${@#ModuleName}.dll }&lt;/p&gt;&#10;&lt;p&gt;[/sourcecode]&lt;/p&gt;</description></item><item><title>Using Managed Code to debug Memory Dumps</title><link>https://naveensrinivasan.com/?p=1168/</link><pubDate>Thu, 11 Nov 2010 22:21:02 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1168/</guid><description>&lt;p&gt;I happened to notice the new &lt;a href="http://translate.google.com/translate?hl=en&amp;amp;sl=pt&amp;amp;u=http://blogs.technet.com/b/carnevale/archive/2010/10/04/debugdiag-1-2-beta1.aspx&amp;amp;ei=dwbcTOe4DIGglAfc6uWuCQ&amp;amp;sa=X&amp;amp;oi=translate&amp;amp;ct=result&amp;amp;resnum=5&amp;amp;ved=0CDkQ7gEwBA&amp;amp;prev=/search%3Fq%3Ddebugdiag%2B1.2%26hl%3Den%26client%3Dfirefox-a%26hs%3DNUZ%26rls%3Dorg.mozilla:en-US:official%26prmd%3Div"&gt;I happened to notice the new&lt;/a&gt; and it had COM based API for dbgeng. The sample code were in VB Script. I much comfortable writing managed code compared to VB script. So I  decided to use COM based API in managed code.&lt;/p&gt;&#10;&lt;p&gt;Here are couple of ways to solve certain problems using this&lt;/p&gt;&#10;&lt;ol&gt;&#10;&lt;li&gt;&lt;strong&gt;Parallel GC Roots&lt;/strong&gt; :- Getting GC Roots from memory dump is the most time consuming because SOS is single threaded. I use PFX to do them in parallel.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Reconstructing manged objects&lt;/strong&gt; :- Creating an instance of an object by reading data from the memory dump.&lt;/li&gt;&#10;&lt;/ol&gt;&#10;&lt;p&gt;Need to add reference to the COM Library&lt;/p&gt;</description></item><item><title>Dumping .NET strings to files using Windbg</title><link>https://naveensrinivasan.com/?p=1128/</link><pubDate>Mon, 01 Nov 2010 21:37:16 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1128/</guid><description>&lt;p&gt;In this post I would demonstrate how to dump strings from a memory dump /live process to a file. Recently I had to debug a process which had few big strings where I had to analyze its contents. The !dumpobj from sos would only dump partial strings.  I had to dump few hundred XML strings that I had to analyze using some automation. And hence comes the script.&lt;/p&gt;&#10;&lt;p&gt;[sourcecode]&lt;/p&gt;&#10;&lt;p&gt;$$ Dumps the managed strings to a file&lt;/p&gt;</description></item><item><title>Dumping ASP.NET Session (x86 /x64) within Windbg</title><link>https://naveensrinivasan.com/?p=1071/</link><pubDate>Wed, 27 Oct 2010 01:18:21 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1071/</guid><description>&lt;p&gt;This post is going to be about dumping ASP.NET session objects using Windbg. I had recently answered a stackoverflow question in which someone wanted to dump ASP.NET session objects for 64-bit IIS (x64). I thought why not blog about the same which might be useful to others.  The challenge is to write one script that should work in both x86/x64.  FYI there is a script from &lt;a href="http://blogs.msdn.com/b/tess/archive/2007/09/18/debugging-script-dumping-out-asp-net-session-contents.aspx"&gt;Tess&lt;/a&gt; that does dump out the session contents, AFAIK it will not work on x64 and my script iterates through the array using the array length instead of using “.foreach /pS 2 /ps 99” which is somewhat cleaner.&lt;/p&gt;</description></item><item><title>GC Start and Stop events in .NET using Windbg</title><link>https://naveensrinivasan.com/?p=1064/</link><pubDate>Wed, 08 Sep 2010 01:55:27 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1064/</guid><description>&lt;p&gt;I was recently showing someone the new ETW features in .NET especially the &lt;a href="http://msdn.microsoft.com/en-us/library/ff356162.aspx"&gt;GC Event notification&lt;/a&gt; and I was asked if we can get this using Windbg.&lt;/p&gt;&#10;&lt;p&gt;So here is the sample code for the GC Collection&lt;/p&gt;&#10;&lt;p&gt;[sourcecode language=”csharp”]&lt;/p&gt;&#10;&lt;p&gt;namespace GCStartStop&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;public partial class Form1 : Form&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;public Form1()&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;InitializeComponent();&lt;/p&gt;&#10;&lt;p&gt;button1.Click += (s, b) =&amp;gt; GC.Collect(2);&lt;/p&gt;&#10;&lt;p&gt;button1.Click += (s, b) =&amp;gt; GC.Collect(1);&lt;/p&gt;&#10;&lt;p&gt;}&lt;/p&gt;&#10;&lt;p&gt;}&lt;/p&gt;&#10;&lt;p&gt;}&lt;/p&gt;&#10;&lt;p&gt;[/sourcecode]&lt;/p&gt;&#10;&lt;p&gt;The goal is set to a break-point only when the collection count is 2. Here is a bp script for doing this.&lt;/p&gt;</description></item><item><title>Script to load sos within Windbg based on .NET Framework version</title><link>https://naveensrinivasan.com/?p=1032/</link><pubDate>Mon, 26 Jul 2010 04:33:21 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1032/</guid><description>&lt;p&gt;I often debug  .NET Framework v 2.0 / v 4.0 code within windbg. In v 2.0 the main clr dll was called “mscorwks.dll” and in v 4.0 it is called “clr.dll”.  As many of you are aware , to load sos in v 2.0 we would have to enter “.loadby sos mscorwks” and in v 4.0 it would be “.loadby sos clr” . This was a pain for me. Came up with a script to automate loading sos based on clr version&lt;/p&gt;</description></item><item><title>Debugging .NET – mystery between DEBUG versus RELEASE within windbg</title><link>https://naveensrinivasan.com/?p=1015/</link><pubDate>Thu, 22 Jul 2010 02:48:17 +0000</pubDate><guid>https://naveensrinivasan.com/?p=1015/</guid><description>&lt;p&gt;I am sure most of us have debugged applications that are build with debug turned on, which is obviously much easier compared to debugging release build (optimized code). In this post I am going to share one of my experiences of debugging release build code. I will demonstrate this with a simple Console Application.&lt;/p&gt;&#10;&lt;p&gt;Here is the code&lt;/p&gt;&#10;&lt;p&gt;[sourcecode language=”csharp”]&lt;/p&gt;&#10;&lt;p&gt;using System;&lt;/p&gt;&#10;&lt;p&gt;namespace ConsoleApplication&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;class Program&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;static void Main(string[] args)&lt;/p&gt;</description></item><item><title>Debugging Generic System.Nullable within Windbg</title><link>https://naveensrinivasan.com/?p=947/</link><pubDate>Thu, 08 Jul 2010 03:58:51 +0000</pubDate><guid>https://naveensrinivasan.com/?p=947/</guid><description>&lt;p&gt;In this post I am going to unravel the mystery of debugging the Nullable&lt;!-- raw HTML omitted --&gt; within Windbg in .NET 3.5 and also compare it with .NET 4.0. Here is the sample code and it is compiled in .NET 3.5&lt;/p&gt;&#10;&lt;p&gt;[sourcecode language=”csharp”]&lt;/p&gt;&#10;&lt;p&gt;using System;&lt;/p&gt;&#10;&lt;p&gt;namespace ConsoleApplication&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;class Program&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;Int32? test;&lt;/p&gt;&#10;&lt;p&gt;int i = 10;&lt;/p&gt;&#10;&lt;p&gt;static void Main(string[] args)&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;Nullable&lt;!-- raw HTML omitted --&gt;&lt;/p&gt;&#10;&lt;p&gt;Int32? i = 10;&lt;/p&gt;&#10;&lt;p&gt;Object o = 10;&lt;/p&gt;</description></item><item><title>Recursive !dumpmt – Windbg</title><link>https://naveensrinivasan.com/?p=928/</link><pubDate>Tue, 06 Jul 2010 01:04:53 +0000</pubDate><guid>https://naveensrinivasan.com/?p=928/</guid><description>&lt;p&gt;In this post I will be demonstrating how we could use CLR internal data-structures to recursively get the methodtable’s of an object and its base classes. The idea behind this is to understand the CLR data structure.&lt;/p&gt;&#10;&lt;p&gt;Here is the sample code&lt;/p&gt;&#10;&lt;p&gt;[sourcecode language=”csharp”]&lt;/p&gt;&#10;&lt;p&gt;using System;&lt;/p&gt;&#10;&lt;p&gt;namespace ConsoleApplication&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;class Program : B&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;string test = &amp;ldquo;cw&amp;rdquo;;&lt;/p&gt;&#10;&lt;p&gt;static void Main(string[] args)&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;var p = new Program();&lt;/p&gt;&#10;&lt;p&gt;Console.Read();&lt;/p&gt;&#10;&lt;p&gt;}&lt;/p&gt;&#10;&lt;p&gt;}&lt;/p&gt;&#10;&lt;p&gt;class B : A&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;public void TestB()&lt;/p&gt;</description></item><item><title>dumpstring – windbg</title><link>https://naveensrinivasan.com/?p=913/</link><pubDate>Wed, 30 Jun 2010 01:55:42 +0000</pubDate><guid>https://naveensrinivasan.com/?p=913/</guid><description>&lt;p&gt;Viewing strings inside the debugger has never been pretty, especially if you are using sos extension.  Here is a sample !dumpobj on a string&lt;/p&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;0:000&amp;gt; !do 00000000025f2280&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;Name:        System.String&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;MethodTable: 000007fef6e26960&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;EEClass:     000007fef69aeec8&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;Size:        32(0x20) bytes&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;String:     &lt;!-- raw HTML omitted --&gt;Foo&lt;!-- raw HTML omitted --&gt;&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;Fields:&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;MT    Field   Offset                 Type VT     Attr            Value Name&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;000007fef6e2c848  40000ed        8         System.Int32  1 instance                3 m_stringLength&lt;/p&gt;&#10;&lt;/blockquote&gt;&#10;&lt;blockquote&gt;&#10;&lt;p&gt;000007fef6e2b388  40000ee        c          System.Char  1 instance               46 m_firstChar&lt;/p&gt;&#10;&lt;/blockquote&gt;</description></item><item><title>Custom DumpArray – Windbg</title><link>https://naveensrinivasan.com/?p=885/</link><pubDate>Fri, 25 Jun 2010 00:59:42 +0000</pubDate><guid>https://naveensrinivasan.com/?p=885/</guid><description>&lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/bb190764.aspx"&gt;The&lt;/a&gt; has !dumparray for getting contents of the array. But it cannot be used for scripting or automation. Here is an example&lt;/p&gt;&#10;&lt;p&gt;[sourcecode language=”csharp”]&lt;/p&gt;&#10;&lt;p&gt;using System;&lt;/p&gt;&#10;&lt;p&gt;namespace ConsoleApplication&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;class Program&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;Test[] arr = new[] { new Test() { ID = 1, Name = &amp;ldquo;Foo&amp;rdquo; }, new Test() { ID = 2, Name = &amp;ldquo;Bar&amp;rdquo; } };&lt;/p&gt;&#10;&lt;p&gt;static void Main(string[] args)&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;var p = new Program();&lt;/p&gt;&#10;&lt;p&gt;Console.WriteLine(p.arr);&lt;/p&gt;&#10;&lt;p&gt;Console.Read();&lt;/p&gt;&#10;&lt;p&gt;}&lt;/p&gt;&#10;&lt;p&gt;}&lt;/p&gt;&#10;&lt;p&gt;class Test&lt;/p&gt;&#10;&lt;p&gt;{&lt;/p&gt;&#10;&lt;p&gt;public int ID;&lt;/p&gt;</description></item><item><title>Do I have Managed or Native memory leak?</title><link>https://naveensrinivasan.com/?p=868/</link><pubDate>Tue, 22 Jun 2010 22:38:52 +0000</pubDate><guid>https://naveensrinivasan.com/?p=868/</guid><description>&lt;p&gt;I noticed someone who couldn’t figure out the cause of memory leak in  managed application within the debugger. This person had basic debugging skills and was comfortable with sos.  FYI the leak wasn’t in the managed code, but in the native code. The managed code was using native code via PInvoke.&lt;/p&gt;&#10;&lt;p&gt;Here is how I figured out the cause. Every time I have to debug a memory leak in managed code ,the first command I run is !vmstat. The !vmstat is available in psscor2.dll for .net 3.5 and for .net 4.0 it is available in sos. This command provides summary of VM. The output is similar to the &lt;a href="http://technet.microsoft.com/en-us/sysinternals/dd535533.aspx"&gt;VMMap&lt;/a&gt; tool and here is the output from the command.&lt;/p&gt;</description></item><item><title>Debugging base class method with conditional break point in .NET using Windbg</title><link>https://naveensrinivasan.com/?p=803/</link><pubDate>Tue, 15 Jun 2010 04:40:17 +0000</pubDate><guid>https://naveensrinivasan.com/?p=803/</guid><description>&lt;p&gt;In this post I am going to be demonstrating how to have a conditional break-point on the base class method where it has been used by multiple derived classes. A classic example is Winform UI.&lt;/p&gt;&#10;&lt;p&gt;The Control base class has got methods like set_Enabled , set_Visible which could be consumed by multiple derived controls. The goal is to debug only the control instance that we are interested in. Here is the sample code.&lt;/p&gt;</description></item><item><title>Using Windows Error Reporting (WER) API in managed code to generate memory dump</title><link>https://naveensrinivasan.com/?p=750/</link><pubDate>Thu, 10 Jun 2010 03:01:09 +0000</pubDate><guid>https://naveensrinivasan.com/?p=750/</guid><description>&lt;p&gt;The WER is a pretty cool technology from Microsoft for collecting memory dumps on process crash/ hang. This can be extended to generate on demand when the application needs to. The usual reason for getting a memory dump could be based on certain conditions, for example, the customer feels the application is slow and would want to send the information to WinQual (WER server). If the application happens to be installed on hundreds / thousands of boxes then its not going to be possible to get from individual customers, the best bet is WER. To do this here is an &lt;a href="http://msdn.microsoft.com/en-us/library/bb513635%28VS.85%29.aspx"&gt;API&lt;/a&gt;. But this is unmanaged API and I didn’t see one for managed code. FYI this would work only on Vista + systems, it will not work on XP.&lt;/p&gt;</description></item><item><title>Identifying High CPU in GC (.NET) because of LOH – using Windbg</title><link>https://naveensrinivasan.com/?p=40/</link><pubDate>Mon, 15 Feb 2010 04:57:22 +0000</pubDate><guid>https://naveensrinivasan.com/?p=40/</guid><description>&lt;p&gt;I am sure most of us are aware that one of the common reasons for High CPU usage .NET is because of, percentage time spent on GC is high. There are lot of write up about this. &lt;!-- raw HTML omitted --&gt;Tess&lt;!-- raw HTML omitted --&gt; has amazing blog post  on this specifically, which explains in detail how to identify the symptoms. But one thing that I want share was the experience I had ,where in i could identify the real call stack which was causing allocation on LOH by have a break-point on the CLR Garbage collector itself. I am going to assume that you are aware of CLR GC and LOH and basic debugging using windbg.&lt;/p&gt;</description></item><item><title>Function hit count using Pseudo-Register in Windbg</title><link>https://naveensrinivasan.com/?p=30/</link><pubDate>Sat, 13 Feb 2010 01:41:01 +0000</pubDate><guid>https://naveensrinivasan.com/?p=30/</guid><description>&lt;p&gt;What if we want to know the number of times a function was invoked. We can have “.echo” or “.printf” on break-point of a function and count the output manually. The better way to do this is using pseudo-registers.&lt;/p&gt;&#10;&lt;p&gt;In my &lt;!-- raw HTML omitted --&gt;previous&lt;!-- raw HTML omitted --&gt; post I had mentioned about alias inside the debugger. The debugger also provides User defined Pseudo-Registers for scripting inside the debugger. We can use them to manipulate values within our scripts. There are 20 of them from $t0,$t1.. $t19. These are pre-defined names that we cannot change.&lt;/p&gt;</description></item><item><title>Conditional Breakpoint in .NET using Windbg</title><link>https://naveensrinivasan.com/?p=26/</link><pubDate>Thu, 11 Feb 2010 03:50:00 +0000</pubDate><guid>https://naveensrinivasan.com/?p=26/</guid><description>&lt;p&gt;With my few years of production debugging .NET code ,one thing that has really helped me a lot is Windbg. Lot us of know that using sos, sosex and Windbg we should be able to troubleshoot most of the .NET Code. But certain tips / tricks makes us productive in those crucial moments. I am assuming that you are aware of basic usage of sos and windbg.&lt;/p&gt;&#10;&lt;p&gt;We know by using !bpmd command we can stick in a break-point on a method. But the issue is we would want to break in to the debugger only on a certain condition, very similar to VS.NET break-point condition.&lt;/p&gt;</description></item><item><title>Identify and Patch .NET Code using Windbg</title><link>https://naveensrinivasan.com/?p=19/</link><pubDate>Sun, 07 Feb 2010 13:30:13 +0000</pubDate><guid>https://naveensrinivasan.com/?p=19/</guid><description>&lt;p&gt; &lt;/p&gt;&#10;&lt;p&gt;The last week was really an interesting one with debugging production code. I was debugging a Winforms application which was using .NET framework 3.5 version. The real problem was with the latest release of the code, there was bug which caused certain elements on the UI not to be displayed. This is was High priority bug and very important to the business.&lt;/p&gt;&#10;&lt;p&gt;The code that was causing this bug was an integer variable inside a class.&lt;/p&gt;</description></item></channel></rss>