NetInverse Developers Blog

April 9, 2009
Category: Debugging — Tags: , , , , — admin @ 8:29 pm

SOS Command: !BPMD

!BPMD <module name> <method name>
!BPMD -md <MethodDesc>

!BPMD provides managed breakpoint support. If it can resolve the method name to a loaded, jitted or ngen’d function it will create a breakpoint with “bp”.

If not then either the module that contains the method hasn’t been loaded yet or the module is loaded, but the function is not jitted yet. In these cases, !bpmd asks the Windows Debugger to receive CLR Notifications, and waits to receive news of module loads and JITs, at which time it will try to resolve the function to a breakpoint.

Sample output:

!bpmd LinqSelectTest.exe IEnumerableTest.Program.Main
Found 1 methods...
MethodDesc = 00933000
Setting breakpoint: bp 00FF0070 [IEnumerableTest.Program.Main(System.String[])]

This brings up a good question: “I want to set a breakpoint on the main method of my application, but SOS doesn’t work until the runtime is loaded. How can I do this?”

  1) Start the debugger and type: 

       sxe -c "" clrn

  2) g

  3) You'll get the following notification from the debugger:

     "CLR notification: module 'mscorlib' loaded"

  4) Now you can load SOS and use commands. Type

       .loadby sos mscorwks

     then

       !bpmd myapp.exe MyNamespace.MyApp.Main

  5) g

  6) You will stop at the start of MyApp.Main. If you type "bl" you will see the breakpoint listed.

!BPMD works equally well with generic types. Adding a breakpoint on a generic type sets breakpoints on all already JIT-ted generic methods and sets a pending breakpoint for any instantiation that will be JIT-ted in the future.

Example for generics:
Given the following two classes:

	class G3<T1, T2, T3>
	{
		...
		public void F(T1 p1, T2 p2, T3 p3)
		{ ... }
	}

	public class G1<T> {
		// static method
		static public void G<W>(W w)
		{ ... }
	}

One would issue the following commands to set breapoints on G3.F() and G1.G():

	!bpmd myapp.exe G3`3.F
	!bpmd myapp.exe G1`1.G

!BPMD does not accept offsets nor parameters in the method name. If there are overloaded methods, !bpmd will set a breakpoint for all of them. In the case of hosted environments such as SQL, the module name may be complex, like 'price, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.

For this case, just be sure to surround the module name with single quotes,
like: !bpmd 'price, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' Price.M2

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

©2009 NetInverse. All rights reserved. Powered by WordPress