我想打印出正在运行的.NET进程中加载的所有不同类型的列表。我的计划是最终在此基础上构建一个GUI应用程序,所以我想从我的代码而不是第三方工具来实现这一点。我认为最好的方法是使用MDbgCore附加到正在运行的进程,然后使用MDbgProcess.AppDomains获取CorAppDomain对象,并尝试遍历对象模型。
然而,我无论如何也不能停止另一个进程并看到任何AppDomains。我一直在使用如下代码(我基于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!");
} 这将打印:
MDbgPlayground.exe
0
Done!我尝试过不同口味的debugger.Options.Stop*。我已经考虑过遍历所有方法并在所有方法上设置断点,但我也不能遍历Modules列表。我尝试过debugger.Options.Trace,但那是为了使用TraceListeners跟踪MDbg的执行,而不是跟踪目标应用程序。
我在发布模式下运行我的noddy调试器应用程序,在调试模式下运行目标应用程序。我正在使用Visual C# 2010,我已经无计可施了。有没有人能说明这一点?
发布于 2010-04-29 05:08:56
只是做一些修补工作,试着这样做(你可能需要根据需要进行修改)……
foreach (Process process in Process.GetProcesses())
{
try
{
Assembly test = Assembly.LoadFrom(process.MainModule.FileName);
Console.WriteLine(test.FullName);
foreach (Type type in test.GetTypes())
Console.WriteLine(type.FullName);
}
catch
{
continue;
}
}发布于 2012-08-09 17:19:47
这不会那么容易。我没有这个问题的具体源代码,但我会像这样伪代码:
通过tempDomain=System.AppDomain.CreateDomain("ReflectionOnly");
发布于 2013-05-09 21:28:15
出于某些原因,您应该使用debugger.Processs.Active而不是proc变量。此外,您应该在AsyncStop之前调用debugger.Go()。所以最终的代码
[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);
proc.Go();
if (proc.IsAlive)
{
proc.AsyncStop().WaitOne();
Console.WriteLine(debugger.Process.Active.AppDomains.Count);
if ((debugger.Process.Active.AppDomains.Count > 0)
{
Console.WriteLine((debugger.Process.Active.AppDomains[0].CorAppDomain);
}
}
Console.WriteLine("Done!");
} https://stackoverflow.com/questions/2733038
复制相似问题