Exemplo n.º 1
0
        public static ICorDebug GetDebugger(string debuggerVersion)
        {
            CLRMetaHost    mh              = new CLRMetaHost();
            CLRRuntimeInfo rti             = mh.GetRuntime(debuggerVersion);
            ICorDebug      rawDebuggingAPI = rti.GetLegacyICorDebugInterface();

            if (rawDebuggingAPI == null)
            {
                throw new ArgumentException("Cannot be null.", "rawDebugggingAPI");
            }
            rawDebuggingAPI.Initialize();
            rawDebuggingAPI.SetManagedHandler(new MyHandler());
            return(rawDebuggingAPI);
        }
Exemplo n.º 2
0
        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);
        }