tags:

views:

50

answers:

2

I want to set a breakpoint for the System.IO.FileStream.Read() of mscorlib to trace when file reading occurs. I don't have the source code for the executable. I want to launch the trace from the entry point of MSIL code.

A: 

You can use the !BPMD command (part of SOS) to set a breakpoint on managed methods. http://msdn.microsoft.com/en-us/library/bb190764.aspx

Liran
+1  A: 

Here are the steps to use SOS extension dll to break at any managed method (I'll use System.IO.FileStream.Read() as an example).

  1. Wait for mscorwks.dll (or clr.dll in .NET 4) to load. This can be done via ".sxe ld mscorwks". This will break when mscorwks loads.
  2. ".loadby sos mscorwks". This will load the right sos extension for the version of CLR.
  3. "!name2ee mscorlib.dll System.IO.FileStream.Read"
  4. You'll get a method descriptor for the method you're interested in.
  5. Pass the md value to bpmd extension command as "!bpmd ".

This should put the breakpoint.

If you are interested in any file load, you might be interested in the blog I wrote about this problem : http://gopikrishnam.wordpress.com/2010/07/16/who-is-loading-this-file/

Gopi