public static ICorDebug GetDebuggerForProcess(int processID, string minimumVersion, DebuggerCallBacks callBacks = null)
        {
            CLRMetaHost mh = new CLRMetaHost();
            CLRRuntimeInfo highestLoadedRuntime = null;
            foreach (var runtime in mh.EnumerateLoadedRuntimes(processID))
            {
                if (highestLoadedRuntime == null ||
                    string.Compare(highestLoadedRuntime.GetVersionString(), runtime.GetVersionString(), StringComparison.OrdinalIgnoreCase) < 0)
                    highestLoadedRuntime = runtime;
            }
            if (highestLoadedRuntime == null)
                throw new ApplicationException("Could not enumerate .NET runtimes on the system.");

            var runtimeVersion = highestLoadedRuntime.GetVersionString();
            if (string.Compare(runtimeVersion, minimumVersion, StringComparison.OrdinalIgnoreCase) < 0)
                throw new ApplicationException("Runtime in process " + runtimeVersion + " below the minimum of " + minimumVersion);

            ICorDebug rawDebuggingAPI = highestLoadedRuntime.GetLegacyICorDebugInterface();
            if (rawDebuggingAPI == null)
                throw new ArgumentException("Cannot be null.", "rawDebugggingAPI");
            rawDebuggingAPI.Initialize();
            if (callBacks == null)
                callBacks = new DebuggerCallBacks();
            rawDebuggingAPI.SetManagedHandler(callBacks);
            return rawDebuggingAPI;
        }
Esempio n. 2
0
        public static ICorDebug GetDebuggerForProcess(int processID, string minimumVersion, DebuggerCallBacks callBacks = null)
        {
            CLRMetaHost    mh = new CLRMetaHost();
            CLRRuntimeInfo highestLoadedRuntime = null;

            foreach (CLRRuntimeInfo runtime in mh.EnumerateLoadedRuntimes(processID))
            {
                if (highestLoadedRuntime == null ||
                    string.Compare(highestLoadedRuntime.GetVersionString(), runtime.GetVersionString(), StringComparison.OrdinalIgnoreCase) < 0)
                {
                    highestLoadedRuntime = runtime;
                }
            }

            if (highestLoadedRuntime == null)
            {
                throw new Exception("Could not enumerate .NET runtimes on the system.");
            }

            string runtimeVersion = highestLoadedRuntime.GetVersionString();

            if (string.Compare(runtimeVersion, minimumVersion, StringComparison.OrdinalIgnoreCase) < 0)
            {
                throw new Exception("Runtime in process " + runtimeVersion + " below the minimum of " + minimumVersion);
            }

            ICorDebug rawDebuggingAPI = highestLoadedRuntime.GetLegacyICorDebugInterface();

            if (rawDebuggingAPI == null)
            {
                throw new ArgumentNullException(nameof(rawDebuggingAPI));
            }

            rawDebuggingAPI.Initialize();
            if (callBacks == null)
            {
                callBacks = new DebuggerCallBacks();
            }
            rawDebuggingAPI.SetManagedHandler(callBacks);
            return(rawDebuggingAPI);
        }