Example #1
0
        /// <summary>
        /// Hybrid replay mode uses windbg
        /// </summary>
        protected void _StartDebuggerHybridReplay()
        {
            if (_debuggerProcess == null || _debuggerProcess.HasExited)
            {
                using (var p = System.Diagnostics.Process.GetCurrentProcess())
                {
                    _debuggerChannelName = "PeachCore_" + p.Id + "_" + (ipcChannelCount++);
                }

                // Launch the server process
                _debuggerProcess = new System.Diagnostics.Process();
                _debuggerProcess.StartInfo.CreateNoWindow  = true;
                _debuggerProcess.StartInfo.UseShellExecute = false;
                _debuggerProcess.StartInfo.Arguments       = _debuggerChannelName;
                _debuggerProcess.StartInfo.FileName        = Path.Combine(
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                    "Peach.Core.WindowsDebugInstance.exe");
                _debuggerProcess.Start();

                // Let the process get started.
                Thread.Sleep(2000);
            }

            // Try and create instance over IPC.  We will continue trying for 1 minute.

            DateTime startTimer = DateTime.Now;

            while (true)
            {
                try
                {
                    _debugger = (DebuggerInstance)Activator.GetObject(typeof(DebuggerInstance),
                                                                      "ipc://" + _debuggerChannelName + "/DebuggerInstance");

                    _debugger.commandLine            = _commandLine;
                    _debugger.processName            = _processName;
                    _debugger.kernelConnectionString = _kernelConnectionString;
                    _debugger.service     = _service;
                    _debugger.symbolsPath = _symbolsPath;
                    _debugger.startOnCall = _startOnCall;
                    _debugger.ignoreFirstChanceGuardPage  = _ignoreFirstChanceGuardPage;
                    _debugger.ignoreSecondChanceGuardPage = _ignoreSecondChanceGuardPage;
                    _debugger.noCpuKill  = _noCpuKill;
                    _debugger.winDbgPath = _winDbgPath;

                    break;
                }
                catch
                {
                    if ((DateTime.Now - startTimer).Minutes >= 1)
                    {
                        _debuggerProcess.Kill();
                        _debuggerProcess = null;
                        throw;
                    }
                }
            }

            _debugger.StartDebugger();
        }
Example #2
0
        /// <summary>
        /// Origional non-hybrid windbg only mode
        /// </summary>
        protected void _StartDebuggerNonHybrid()
        {
            logger.Debug("_StartDebuggerNonHybrid");

            if (_debuggerProcessUsage >= _debuggerProcessUsageMax && _debuggerProcess != null)
            {
                _FinishDebugger();

                _debuggerProcessUsage = 0;
            }

            if (_debuggerProcess == null || _debuggerProcess.HasExited)
            {
                _debuggerChannelName = "PeachCore_" + (new Random((uint)Environment.TickCount).NextUInt32().ToString());

                // Launch the server process
                _debuggerProcess = new System.Diagnostics.Process();
                _debuggerProcess.StartInfo.CreateNoWindow  = true;
                _debuggerProcess.StartInfo.UseShellExecute = false;
                _debuggerProcess.StartInfo.Arguments       = _debuggerChannelName;
                _debuggerProcess.StartInfo.FileName        = Path.Combine(
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                    "Peach.Core.WindowsDebugInstance.exe");

                if (logger.IsTraceEnabled)
                {
                    _debuggerProcess.EnableRaisingEvents              = true;
                    _debuggerProcess.StartInfo.Arguments             += " --debug";
                    _debuggerProcess.OutputDataReceived              += _debuggerProcess_OutputDataReceived;
                    _debuggerProcess.ErrorDataReceived               += _debuggerProcess_ErrorDataReceived;
                    _debuggerProcess.StartInfo.RedirectStandardError  = true;
                    _debuggerProcess.StartInfo.RedirectStandardOutput = true;
                }

                _debuggerProcess.Start();

                if (logger.IsTraceEnabled)
                {
                    _debuggerProcess.BeginErrorReadLine();
                    _debuggerProcess.BeginOutputReadLine();
                }
            }

            _debuggerProcessUsage++;

            // Try and create instance over IPC.  We will continue trying for 1 minute.

            DateTime startTimer = DateTime.Now;

            while (true)
            {
                try
                {
                    logger.Debug("Creating DebuggerInstance: ipc://" + _debuggerChannelName + "/DebuggerInstance");
                    _debugger = (DebuggerInstance)Activator.GetObject(typeof(DebuggerInstance),
                                                                      "ipc://" + _debuggerChannelName + "/DebuggerInstance");
                    //_debugger = new DebuggerInstance();

                    _debugger.commandLine            = _commandLine;
                    _debugger.processName            = _processName;
                    _debugger.kernelConnectionString = _kernelConnectionString;
                    _debugger.service     = _service;
                    _debugger.symbolsPath = _symbolsPath;
                    _debugger.startOnCall = _startOnCall;
                    _debugger.ignoreFirstChanceGuardPage  = _ignoreFirstChanceGuardPage;
                    _debugger.ignoreSecondChanceGuardPage = _ignoreSecondChanceGuardPage;
                    _debugger.noCpuKill  = _noCpuKill;
                    _debugger.winDbgPath = _winDbgPath;

                    // Start a thread to send heartbeats to ipc process
                    // otherwise ipc process will exit
                    _ipcHeartBeatMutex = new Mutex();
                    _ipcHeartBeatMutex.WaitOne();
                    _ipcHeartBeatThread = new Thread(new ThreadStart(IpcHeartBeat));
                    _ipcHeartBeatThread.Start();

                    break;
                }
                catch (Exception ex)
                {
                    logger.Debug("IPC Exception: " + ex.Message);
                    logger.Debug("Retrying IPC connection");

                    if ((DateTime.Now - startTimer).Minutes >= 1)
                    {
                        try
                        {
                            logger.Debug("IPC Failed");
                            _debuggerProcess.Kill();
                            _debuggerProcess.Close();
                        }
                        catch
                        {
                        }

                        throw;
                    }
                }
            }

            _debugger.StartDebugger();
        }
Example #3
0
        /// <summary>
        /// Hybrid replay mode uses windbg
        /// </summary>
        protected void _StartDebuggerHybridReplay()
        {
            if (_debuggerProcess == null || _debuggerProcess.HasExited)
            {
                using (var p = System.Diagnostics.Process.GetCurrentProcess())
                {
                    _debuggerChannelName = "PeachCore_" + p.Id + "_" + (ipcChannelCount++);
                }

                // Launch the server process
                _debuggerProcess = new System.Diagnostics.Process();

                _debuggerProcess.StartInfo.CreateNoWindow  = true;
                _debuggerProcess.StartInfo.UseShellExecute = false;
                _debuggerProcess.StartInfo.Arguments       = _debuggerChannelName;
                _debuggerProcess.StartInfo.FileName        = Path.Combine(
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                    "Peach.Core.WindowsDebugInstance.exe");

                if (logger.IsTraceEnabled)
                {
                    _debuggerProcess.EnableRaisingEvents              = true;
                    _debuggerProcess.StartInfo.Arguments             += " --debug";
                    _debuggerProcess.OutputDataReceived              += _debuggerProcess_OutputDataReceived;
                    _debuggerProcess.ErrorDataReceived               += _debuggerProcess_ErrorDataReceived;
                    _debuggerProcess.StartInfo.RedirectStandardError  = true;
                    _debuggerProcess.StartInfo.RedirectStandardOutput = true;
                }

                _debuggerProcess.Start();

                if (logger.IsTraceEnabled)
                {
                    _debuggerProcess.BeginErrorReadLine();
                    _debuggerProcess.BeginOutputReadLine();
                }

                // Let the process get started.
                Thread.Sleep(2000);
            }

            // Try and create instance over IPC.  We will continue trying for 1 minute.

            DateTime startTimer = DateTime.Now;

            while (true)
            {
                try
                {
                    logger.Debug("Trying to create DebuggerInstance: ipc://" + _debuggerChannelName + "/DebuggerInstance");

                    _debugger = (DebuggerInstance)Activator.GetObject(typeof(DebuggerInstance),
                                                                      "ipc://" + _debuggerChannelName + "/DebuggerInstance");

                    _debugger.commandLine            = _commandLine;
                    _debugger.processName            = _processName;
                    _debugger.kernelConnectionString = _kernelConnectionString;
                    _debugger.service     = _service;
                    _debugger.symbolsPath = _symbolsPath;
                    _debugger.startOnCall = _startOnCall;
                    _debugger.ignoreFirstChanceGuardPage  = _ignoreFirstChanceGuardPage;
                    _debugger.ignoreSecondChanceGuardPage = _ignoreSecondChanceGuardPage;
                    _debugger.noCpuKill  = _noCpuKill;
                    _debugger.winDbgPath = _winDbgPath;

                    // Start a thread to send heartbeats to ipc process
                    // otherwise ipc process will exit
                    _ipcHeartBeatMutex = new Mutex();
                    _ipcHeartBeatMutex.WaitOne();
                    _ipcHeartBeatThread = new Thread(new ThreadStart(IpcHeartBeat));
                    _ipcHeartBeatThread.Start();

                    logger.Debug("Created!");
                    break;
                }
                catch (Exception ex)
                {
                    logger.Debug("IPC Failed: " + ex.Message);
                    if ((DateTime.Now - startTimer).Minutes >= 1)
                    {
                        _debuggerProcess.Kill();
                        _debuggerProcess = null;
                        throw;
                    }
                }
            }

            _debugger.StartDebugger();
        }
Example #4
0
        /// <summary>
        /// Origional non-hybrid windbg only mode
        /// </summary>
        protected void _StartDebuggerNonHybrid()
        {
            if (_debuggerProcessUsage >= _debuggerProcessUsageMax && _debuggerProcess != null)
            {
                _FinishDebugger();

                _debuggerProcessUsage = 0;
            }

            if (_debuggerProcess == null || _debuggerProcess.HasExited)
            {
                _debuggerChannelName = "PeachCore_" + (new Random((uint)Environment.TickCount).NextUInt32().ToString());

                // Launch the server process
                _debuggerProcess = new System.Diagnostics.Process();
                _debuggerProcess.StartInfo.CreateNoWindow  = true;
                _debuggerProcess.StartInfo.UseShellExecute = false;
                _debuggerProcess.StartInfo.Arguments       = _debuggerChannelName;
                _debuggerProcess.StartInfo.FileName        = Path.Combine(
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                    "Peach.Core.WindowsDebugInstance.exe");
                _debuggerProcess.Start();
            }

            _debuggerProcessUsage++;

            // Try and create instance over IPC.  We will continue trying for 1 minute.

            DateTime startTimer = DateTime.Now;

            while (true)
            {
                try
                {
                    _debugger = (DebuggerInstance)Activator.GetObject(typeof(DebuggerInstance),
                                                                      "ipc://" + _debuggerChannelName + "/DebuggerInstance");
                    //_debugger = new DebuggerInstance();

                    _debugger.commandLine            = _commandLine;
                    _debugger.processName            = _processName;
                    _debugger.kernelConnectionString = _kernelConnectionString;
                    _debugger.service     = _service;
                    _debugger.symbolsPath = _symbolsPath;
                    _debugger.startOnCall = _startOnCall;
                    _debugger.ignoreFirstChanceGuardPage  = _ignoreFirstChanceGuardPage;
                    _debugger.ignoreSecondChanceGuardPage = _ignoreSecondChanceGuardPage;
                    _debugger.noCpuKill  = _noCpuKill;
                    _debugger.winDbgPath = _winDbgPath;

                    break;
                }
                catch
                {
                    if ((DateTime.Now - startTimer).Minutes >= 1)
                    {
                        _debuggerProcess.Kill();
                        _debuggerProcess.Close();
                        throw;
                    }
                }
            }

            _debugger.StartDebugger();
        }