Saturday, January 14, 2017

Tutorials : Learn .NET debugging using Windbg

This blog provides 30+ step-by-step tutorials to learn .NET debugging using WinDBG.

 Each tutorial will discuss a .NET internal concept and a small demo to prove the concept using a live debugging session. Thereby the user can solidify his  theoretical knowledge and also learn new WinDBG commands.


************ For Beginners/First time users *****************

In order to do the hands-on labs, user need to download WinDBG tool . Watch these two helper videos that will guide users to get the environment ready for debugging .

1. Download WinDBG tool ( How to install WinDBG video )
2. Make ready the debugger ( How to set the symbol file path to WinDBG debugger )

3. Make ready the debugger for .NET debugging . Load SOS DLL to WinDBG

*********************************************************************


The Hands-on labs index is provided below.

          .NET debugging Tutorial Index

Lab 1. Observe Generational heaps and their size

In this demo we familiarize with two WinDBG commands
  !EEHeap -GC and !heapstat

 Link :      Go to Hands-on Lab: 
---------------------------------------------------------------------------------------
Lab 2. Garbage collector operation on managed heap objects 

Commands Used : !Dumpheap and !GCWhere

CLR concept practical demonstration
Demo shows un-referred objects are collected by GC and the referred objects
move to next Gen

 Link :      Go to Hands-on Lab:  
--------------------------------------------------------------------------------------------
Lab 3. Generational (0,1) heaps compacts after a GC operation
  
   Commands Used : !heapstat

CLR concept practical demonstration
Demo shows the Generation 0 heap size before and after GC and proves that
heap compacts its size after GC operation.
 Link :      Go to Hands-on Lab: 
--------------------------------------------------------------------------------------------------
Lab 4. Check where the Large objects (size >= 85000 bytes) are stored at managed heap

CLR concept practical demonstration
Smaller heap objects created at Gen 0 area, but large objects are placed at
a particular space in the managed heap called LOH (large object heap).
In the demo two objects are created, One object created with larger object criteria.
then using a WinDBG session, user verify that Large object is placed at LOH
--------------------------------------------------------------------------------------------------------
Lab 5. Observe heap fragmentation happening on LOH heap

CLR concept practical demonstration
Briefly discusses about heap fragmentation, its side effects. and
show a demo heap fragmentation happening on LOH
------------------------------------------------------------------------------------------------------------
Lab 6. What is Object pinning? show pinned objects in memory

CLR concept practical demonstration
Discusses when and where object pinning is needed.
WinDBG commands used
!GCHandles -Pinned
Demo shows pinned objects in memory
-----------------------------------------------------------------------------------------------------------------------
Lab 7. The side effect of Object pinning .show the chances of heap fragmentation.

CLR concept practical demonstration
If Object pinning is not used wisely, there is a chance of heap fragmentation
using a WinDBG session, we show the heap fragmentation occurring

.Net Debugging Lab3 : Inspect Compacting the Heaps using WinDBG commands: - !heapstat

Related .NET internals: 1.        Gen 0 and Gen 1 are compacting heap regions :   When Garbage collector (GC) operates on a Gen 0 or ...