Breaking when a module loads
We occasionally get requests for the ability to break when a module loads. WinDbg (the other debugger that Microsoft produces) exposes this as an exception (see the 'sx' command), although it isn't really an exception. Ideally, I think this should be a special kind of breakpoint.
VS doesn't support this as a first class feature, but as long as you know what module you want to break on, this is very easy to do. I will give you two possible ways to do this:
Using a function breakpoint
Just set a function breakpoint on the DllMain function of the module in question (or _DllMainCRTStartup if you prefer). To do this:
- Open the 'Debug->New Breakpoint' Dialog (Ctrl-B)
- Set function to be '{,,<module >.dll}DllMain'
If you don't have symbols for the dll in question, this is more difficult. Do this:
Start a command prompt that has 'dumpbin.exe' on the path
Goto the module you want
Run 'dumpbin /headers <module> | findstr entry' you should get something like
1AE60 entry point (77E7AE60)Set an address breakpoint on the second number (77E7AE60 in the example)
If the dll is also reloacted, then instead you will need to add the first number (1AE60 in the example) to the address where the module will load
This won't work with '/noentry' dlls. This also may not work if you have dlls with circular references. In either case, use the registry.
Using the registry
- Open up regedit, and goto HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\<dll>
- In that key, create a new string value called "BreakOnDllLoad" and set it to "1".
Comments
Anonymous
July 08, 2004
Wondering if this is the right place to ask...did Whidbey enhance the display of function static variables and global variables? In 2003 & earlier, you can't seem to watch static/global variables properly without using some temporary variable.Anonymous
July 08, 2004
I am not aware of this problem. Is this for Native C++ or some other language? For native C++, one issue may be that you need to tell us what dll to look in (if you are interested in a different dll then the current stack frame). Use '{,,dll_name}'.Anonymous
July 08, 2004
Why not just set breakpoint on
{,,kernel32.dll}!LoadLibraryExW
You can then even specify which module to load.Anonymous
July 08, 2004
I meant to say you can specify
on which module to breakAnonymous
February 08, 2007
Every now and than while debugging I need to either determine when a dll/module is loaded or need toAnonymous
February 08, 2007
Every now and than while debugging I need to either determine when a dll/module is loaded or need to