コード例 #1
0
        // Attach to an active process
        public DebuggedProcess DebugActiveProcess(int pid, bool win32Attach)
        {
            ICorDebugProcess proc = null;

            m_debugger.DebugActiveProcess((uint)pid, win32Attach ? 1 : 0, out proc);
            return(new DebuggedProcess(proc));
        }
コード例 #2
0
        public Process Attach(System.Diagnostics.Process existingProcess)
        {
            InitDebugger(GetProgramVersion(existingProcess.MainModule.FileName));
            ICorDebugProcess corDebugProcess = corDebug.DebugActiveProcess((uint)existingProcess.Id, 0);
            Process          process         = new Process(this, corDebugProcess);

            AddProcess(process);
            return(process);
        }
コード例 #3
0
        public Process Attach(System.Diagnostics.Process existingProcess)
        {
            string mainModule = existingProcess.MainModule.FileName;

            InitDebugger(GetProgramVersion(mainModule));
            ICorDebugProcess corDebugProcess = corDebug.DebugActiveProcess((uint)existingProcess.Id, 0);
            // TODO: Can we get the acutal working directory?
            Process process = new Process(this, corDebugProcess, Path.GetDirectoryName(mainModule));

            this.Processes.Add(process);
            return(process);
        }
コード例 #4
0
        // API for this class
        public void Attach(uint processId)
        {
            if (_debug == null)
            {
                Init();
            }
            _activeProcess = _debug.DebugActiveProcess(processId, 0);
            ICorDebugThreadEnum threads =
                _activeProcess.EnumerateThreads();
            uint count = 0;

            //threads.GetCount(out count);
            count = threads.GetCount();
            Console.WriteLine("thread count: " + count);

            /*
             * Type type = threads.GetType();
             * MethodInfo mi = type.GetMethod("GetCount");
             * count = (uint)mi.Invoke(threads, new Object[] { });
             * Console.WriteLine("thread count: " + count);
             */
        }
コード例 #5
0
        private void DebuggerThread()
        {
            Console.WriteLine($"Attaching to {_process.ProcessName}, pid: {_process.Id}");

            var       metahost = CorDebugHelper.GetClrMetaHost();
            var       runtimes = metahost.EnumerateLoadedRuntimes(_process.Handle);
            string    version  = null;
            ICorDebug corDebug = null;

            while (runtimes.Next(1, out var rgelt, IntPtr.Zero) == 0)
            {
                var runtimeInfo = (ICLRRuntimeInfo)rgelt;
                var pwzBuffer   = new StringBuilder(30);
                int capacity    = pwzBuffer.Capacity;
                runtimeInfo.GetVersionString(pwzBuffer, ref capacity);
                version = pwzBuffer.ToString();

                var riid   = typeof(ICorDebug).GUID;
                var rclsid = typeof(ClrDebuggingLegacy).GUID;
                corDebug = (ICorDebug)runtimeInfo.GetInterface(ref rclsid, ref riid);
            }

            if (corDebug == null)
            {
                throw new Exception("error: cannot take corDebug");
            }

            Console.WriteLine($"info: runtime: {version}");

            corDebug.Initialize();
            corDebug.SetManagedHandler(_debuggerCallbacks);
            corDebug.SetUnmanagedHandler(_debuggerCallbacks);
            corDebug.DebugActiveProcess((uint)_process.Id, 0, out _debugger);

            while (_debuggingActive)
            {
                Thread.Sleep(WAIT_INTERVAL);
            }

            if (!_process.HasExited)
            {
                _debugger.Stop(WAIT_INTERVAL);
                _debugger.Detach();
            }
        }
コード例 #6
0
        public static void AttachToProcess(Int32 pid)
        {
            Process         proc     = Process.GetProcessById(pid);
            ICLRMetaHost    metahost = NativeMethods.CLRCreateInstance(ref metahost_clsid, ref metahost_riid);
            IEnumUnknown    runtimes = metahost.EnumerateLoadedRuntimes(proc.Handle);
            ICLRRuntimeInfo runtime  = RTHelper.GetRuntime(runtimes, "v4.0");


            ICorDebug codebugger = CreateDebugger(runtime);

            codebugger.Initialize();
            codebugger.SetManagedHandler(new ManagedCallback());


            ICorDebugProcess coproc;

            codebugger.DebugActiveProcess(Convert.ToUInt32(pid), 0, out coproc);

            Console.ReadKey();
        }