Thursday, May 14, 2009

Setting a command breakpoint on a managed method in windbg

This is a combination of the Tess’s entry http://blogs.msdn.com/tess/archive/2008/04/28/setting-breakpoints-in-net-code-using-bpmd.aspx and Kristoffer’s http://blogs.msdn.com/kristoffer/archive/2007/01/02/setting-a-breakpoint-in-managed-code-using-windbg.aspx

The twist is in using directly !Name2EE and !DumpMT with setting a bp breakpoint with a command

First, getting the method table:

0:003> !Name2EE *!TestRWLocks.Program
Module: 790c1000 (mscorlib.dll)
--------------------------------------
Module: 00952354 (sortkey.nlp)
--------------------------------------
Module: 00952010 (sorttbls.nlp)
--------------------------------------
Module: 00932c5c (TestRWLocks.exe)
Token: 0x02000002
MethodTable: 00933030
EEClass: 0093136c
Name: TestRWLocks.Program
--------------------------------------
Module: 7a441000 (System.dll)
--------------------------------------
Module: 64891000 (System.Configuration.dll)
--------------------------------------
Module: 637a1000 (System.Xml.dll)

Second, finding the entry address:

0:003> !DumpMT -MD 00933030
EEClass: 0093136c
Module: 00932c5c
Name: TestRWLocks.Program
mdToken: 02000002  (C:\dev\spikes\TestRWLocks\TestRWLocks\bin\Debug\TestRWLocks.exe)
BaseSize: 0xc
ComponentSize: 0x0
Number of IFaces in IFaceMap: 0
Slots in VTable: 9
--------------------------------------
MethodDesc Table
   Entry MethodDesc      JIT Name
79286aa0   79104924   PreJIT System.Object.ToString()
79286ac0   7910492c   PreJIT System.Object.Equals(System.Object)
79286b30   7910495c   PreJIT System.Object.GetHashCode()
792f7410   79104980   PreJIT System.Object.Finalize()
0093c021   00933028     NONE TestRWLocks.Program..ctor()
00c70070   00932ff8      JIT TestRWLocks.Program.Main(System.String[])
00c70160   00933004      JIT TestRWLocks.Program.RunForever()
00c701c0   00933010      JIT TestRWLocks.Program.DummyMethod(Int32)
0093c01d   0093301c     NONE TestRWLocks.Program.LockOnReaderWriterLock()

Finally, setting a breakpoint with a command:

bp 00c701c0 ".echo --> Calling DummyMethod;!clrstack -p;g"

Lets check if breakpoint is really set:

0:003> bl
0 e 00c701c0     0001 (0001)  0:****  ".echo --> Calling DummyMethod;!clrstack -p;g"

Post a Comment