有没有一种方法可以检测附加的调试器是否为远程调试器?

3

使用System.Diagnostics.Debugger.Debugger.IsAttached,我可以判断是否已经连接了调试器。有没有办法检测连接的调试器是否是远程调试器(Visual Studio Remote Debugger Monitor)?

1个回答

3
您可以使用位于kernel32.dll中的本地CheckRemoteDebuggerPresent

根据MSDN

CheckRemoteDebuggerPresent 中的“remote”并不意味着调试器一定驻留在另一台计算机上;相反,它表示调试器驻留在一个单独且平行的进程中

您可以按以下方式使用它:

[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CheckRemoteDebuggerPresent(IntPtr hProcess, ref bool isDebuggerPresent);

public static void Main()
{
    bool isDebuggerPresent = false;
    CheckRemoteDebuggerPresent(Process.GetCurrentProcess().Handle, ref isDebuggerPresent);

    Console.WriteLine(string.Format("Debugger Attached: {0}", isDebuggerPresent));
    Console.ReadLine();
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接