Using pykd, I came up with the following solution:
First, write a Python script (loadModule.py in my example) with the following content:
from pykd import *
import sys
event = lastEvent()
if event != eventType.LoadModule:
sys.exit()
# get module load event details in string format
details = dbgCommand(".lastevent")
# remove the debugger time
details = details.split("\n")[0]
# get everything behind "Load module"
details = details.split("Load module ")[1]
# remove address
details = details.split(" at ")[0]
# remove full path
details = details.split("\\")[-1]
# remove extension
details = ".".join(details.split(".")[0:-1])
# compare case-insensitive
details = details.upper()
if details in [x.upper() for x in sys.argv[1:]]:
breakin()
Then set a breakpoint on the load event like this:
sxe -c "!py loadModule.py clr mscorwks coreclr;g" ld
This will execute the Python script on every module load event. The script breaks into the debugger (breakin() in Python script) if the module is found, otherwise it continues (g in WinDbg).
You can use any number of modules. The comparison is performed case insensitive.
Please note that this may not be the most elegant solution. There seems to be another way: subclassing eventHandler::onModuleLoad.