Ejemplo n.º 1
0
        // creates ICorDebug instance from ICLRRuntimeInfo
        private static CorDebugger CreateDebugger(ICLRRuntimeInfo runtime, CorDebuggerOptions options)
        {
            Object res;

            runtime.GetInterface(ref CLSID_ICorDebug, ref IID_ICorDebug, out res);

            return(new CorDebugger((ICorDebug)res, options));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Attaches debugger to the running process.
        /// </summary>
        /// <param name="pid">Process id</param>
        /// <param name="desiredVersion">the desired version of the runtime - you don't need to
        /// provide the whole version string as only the first n letters
        /// are compared, for example version string: "v2.0" will match
        /// runtimes versioned "v2.0.1234" or "v2.0.50727". If <code>null</code>
        /// is given, the first found runtime will be returned.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public static CorDebugger CreateDebuggerForProcess(Int32 pid, String desiredVersion = null, CorDebuggerOptions options = null)
        {
            ICLRMetaHost metahost = NativeMethods.CLRCreateInstance(ref CLSID_ICLRMetahost, ref IID_ICLRMetahost);

            Process         proc     = Process.GetProcessById(pid);
            IEnumUnknown    runtimes = metahost.EnumerateLoadedRuntimes(proc.Handle);
            ICLRRuntimeInfo runtime  = GetRuntime(runtimes, desiredVersion);

            if (runtime == null)
            {
                throw new RuntimeNotFoundException();
            }

            return(CreateDebugger(runtime, options ?? new CorDebuggerOptions()));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates new process under the debugger.
        /// </summary>
        /// <param name="exepath">executable path</param>
        /// <param name="desiredVersion">the desired version of the runtime - you don't need to
        /// provide the whole version string as only the first n letters
        /// are compared, for example version string: "v2.0" will match
        /// runtimes versioned "v2.0.1234" or "v2.0.50727". If <code>null</code>
        /// is given, the first found runtime will be returned.</param>
        /// <param name="options">The options.</param>
        /// <returns></returns>
        public static CorDebugger CreateDebuggerForExecutable(String exepath, String desiredVersion = null, CorDebuggerOptions options = null)
        {
            ICLRMetaHost metahost = NativeMethods.CLRCreateInstance(ref CLSID_ICLRMetahost, ref IID_ICLRMetahost);

            IEnumUnknown    runtimes = metahost.EnumerateInstalledRuntimes();
            ICLRRuntimeInfo runtime  = GetRuntime(runtimes, desiredVersion);

            if (runtime == null)
            {
                throw new RuntimeNotFoundException();
            }

            return(CreateDebugger(runtime, options ?? new CorDebuggerOptions()));
        }