I want to print out a list of all the different Types loaded in a running .NET process. My plan is to eventually build a GUI app based on this, so I want to do this from my code as opposed to a third party tool. I think my best bet is to use MDbgCore to attach to the running process, and then use MDbgProcess.AppDomains to get CorAppDomain objects, and try and walk the object model down.
However, I can't for the life of me stop the other process and see any AppDomains. I've been using code like the following (which I've based on code from Mike Stall's blog)
[MTAThread] // MDbg is MTA threaded
static void Main(string[] args)
{
MDbgEngine debugger = new MDbgEngine();
debugger.Options.StopOnModuleLoad = true;
// Launch the debuggee.
int pid = Process.GetProcessesByName("VS2010Playground")[0].Id;
MDbgProcess proc = debugger.Attach(pid);
if (proc.IsAlive)
{
proc.AsyncStop().WaitOne();
Console.WriteLine(proc.AppDomains.Count);
if (proc.AppDomains.Count > 0)
{
Console.WriteLine(proc.AppDomains[0].CorAppDomain);
}
}
Console.WriteLine("Done!");
}
This prints:
MDbgPlayground.exe
0
Done!
I've tried various flavours of debugger.Options.Stop*. I've thought of iterating over all the methods and setting breakpoints on all of them, but I can't iterate over the Modules list either. I've tried debugger.Options.Trace, but that's to do with tracing execution of MDbg using TraceListeners, not tracing the target app.
I'm running my noddy debugger app in release mode, and the target in debug mode. I'm using Visual C# 2010, and I'm at my wit's end. Can anyone shed any light on this?