0

I have an application MyApp.exe. This app uses an assembly MyAssembly1.dll which itself refers to MyAssembly2.dll. Within MyAssembly2, I have a class MyClass that has a method MyMethod. This method is called after user go through several dialog etc.

If I launch this application from within Windbg, is there some way I can put a breakpoint on this method? The problem is that I don't know when the MyAssembly2 is loaded by CLR and this method get JITted?

gturri
  • 13,807
  • 9
  • 40
  • 57
imak
  • 6,489
  • 7
  • 50
  • 73
  • is this a console / winforms app..? you can get into the code if you name the assemblies the same and add the using appropriately without causing a circular reference ..does this make sense..? can you paste the code snippit from both classes showing both NameSpace – MethodMan Jan 04 '12 at 17:01
  • I cannot modify the code as most of assemblies are third parties. I am just trying to figure out an issues by reverse engineering via WinDbg. Part of it requires me to put a break-point on this part of assembly that is not loaded yet – imak Jan 04 '12 at 17:07
  • 1
    Yes I have with some Delphi apps and COM debugging in past jobs.. sorry if I didn't understand your question.. have a good day – MethodMan Jan 04 '12 at 18:48
  • $hit happens I know.. once again sorry for the confusion – MethodMan Jan 04 '12 at 18:53

2 Answers2

5

The documentation on msdn for BPMD says

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.

So you should be able to do !bpmd MyAssembly2.dll MyClass.MyMethod even if MyAssembly2.dll isn't loaded yet, and when it loads the debugger will put in the breakpoint.

jcopenha
  • 3,935
  • 1
  • 17
  • 15
  • 2
    That's what my understanding about !bpmd too. However breakpoint does not seem to get hit, although when I add a break point I get "Adding pending breakpoints...". Not sure if I might be doing something wrong – imak Jan 04 '12 at 18:42
  • that sounds right. The question would be once the assembly actually loads is the assembly, class, and method actually visible in the debugger such that the breakpoint should have been hit. another way to do this would be to go to "Debug->Event Filters" and change "Load Module" to handled, this will break into the debugger once a module loads, then you can try setting your breakpoint right when the assembly loads. – jcopenha Jan 04 '12 at 21:41
  • I changed event filters for Loaded Module to handled ( execution is still enabled). Problem is it didn't break when the assembly get loaded. I do see in windbg a message for assembly been loaded. Any other setting that I may have to change so debugger break when this assembly is loaded? – imak Jan 04 '12 at 22:35
  • hmm. yeah I meant set execution to enabled, same as doing "sxe ld:myassembly2" not sure why the debugger wouldn't break on load. – jcopenha Jan 04 '12 at 22:42
  • Actually Execution setting for Load Module was set to ouptut. Changed to enabled and now its breaking but problem is now its breaking on each and every module:) Is there anyway I can only make it break when it loads a specific assembly? – imak Jan 04 '12 at 22:44
  • I believe the "sxe ld:mysassembly2" command would set it just for a particular module, but if not just keeping hitting 'g' until you get what you want. =) – jcopenha Jan 04 '12 at 22:50
1

You can also run !sosex.mbm or, if you know the source file/line number, !sosex.mbp. You can even run these commands at the initial breakpoint. It's not necessary to wait for the CLR to be loaded. SOSEX will process the necessary notifications to set the breakpoint on the jitted code when it becomes available.

SOSEX is free at http://www.stevestechspot.com

Steve Johnson
  • 2,958
  • 13
  • 15
  • This is the correct answer as pending breakpoints feature has been broken for a long time in SOS. See: http://naveensrinivasan.com/2010/12/05/bpmdnotworking/ and https://windowsdebugging.wordpress.com/2012/01/08/bpmdissue/ – argaz Mar 28 '15 at 16:14