编程分离调试

2023-09-04 10:09:30 作者:꧁遇见꧂、

我有一个是做内部的东西,导致它会大大地减缓在调试器附着,即使在释放模式第三方库。

I have a 3rd party library that is doing something internally that causes it to slow down greatly when the debugger is attached, even in release mode.

我已经找到100家如何手动在Visual Studio中分离调试程序解释转到调试 - >分离过程。不过,我还没有看到任何人提供了一个例子,其中一个程序可以脱离任何连接调试器本身。

I have found 100's of explanations of how to detach the debugger manually in Visual Studio by going to Debug -> Detach process. However I have yet to see anyone provide a example where a program could detach any attached debuggers to itself.

基本上是有 Debugger.Launch的分离版本()?

推荐答案

据的在互操作调试你为什么不能分离?中,CLR不支持分离的过程。但是Visual Studio中能做到这一点。但文章为5岁,所以能您使用的 DebugActiveProcessStop 从Windows API的通过PInvoke的?

According to Why can't you detach in interop-debugging?, the CLR doesn't support detaching of processes. However Visual Studio can do it. But the article is 5 years old so can you use DebugActiveProcessStop from the Windows Api via pinvoke?

BOOL WINAPI DebugActiveProcessStop(
  __in  DWORD dwProcessId
);


[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DebugActiveProcessStop([In] int Pid );

编辑:刚才试了这一点:在目前的过程中,它提供了访问被拒绝,即使升高

Just tried this: On the current process it gives Access Denied even if elevated.

也有在任何CLR托管调试器(MDBG)样本2006年或 2011版

最后本文解释了你所需要的做使用ICorDebug ::分离我猜想视觉工作室确实做到这一点。

Finally this article explains what you need to do to use ICorDebug::Detach and I suppose visual studio does do this.

相关推荐