Sometimes setting a breakpoint is not so simple

A few days back, I was struggling with a particular issue in my application. I was using a thrid party library in the app and I had strong feeling that issue is caused by a bug in that third party library. My theory got strengthened when I insepcted this third party assembly in Reflector, however, to be 100% sure I decided  to run application through Windbg and setup a breakpoint on a particular API from that library. So far so good, you can use bp command to setup a breakpoint within Windbg.

However there was one important constraint in my scenario. The third party library is not loaded immediately with application start, rather its loaded depending upon certain actions from user input. Obviously this means that Jitting of API from that library is also dependent on those user actions.

Even with this constraint, setting up this breakpoint does not seem too challenging because SOS provides bpmd command for exactly this type of scenario. If you read the description of bpmd command at MSDN, it states,

If the specified module and method have not been loaded, this command waits for a notification that the module was loaded and just-in-time (JIT) compiled before creating a breakpoint.

I spent next few hours hitting my head against the wall to make this break point work without any luck. Everytime when I ran bpmd command, I got “Adding Pending Beakpoints…” message but actual breakpoint never get hit and Windbg never reported any errors. I got quite frustrated and decided to go over this section in my favourite Advanced .NET Debugging book by Mario Hewart and guess what Chapter 3 (page 96) has following side-bar.

At the time of writing, the module load notification mechanism in the bpmd command suffered from a bug that did not properly receive notifications and, as such, the deferred breakpoint became orphaned and never triggered.

Mario also suggested to use SOSEx for setting up break-point in this type of scenario. I probably will soon create a blog on exact steps how to do it via SOSEx, but for those of you out there who may run into same trap with bpmd, I thought of just  putting out my experience.

BTW, later I found this nice blog from Naveen as to why bpmd within SOS does not work.

This entry was posted in .NET, Debugging. Bookmark the permalink.

One Response to Sometimes setting a breakpoint is not so simple

  1. Pingback: Setting up a breakpoint using SosEx mbm command | Only way solving a problem is by Debugging it.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s