Beispiel #1
0
        /// <summary>
        /// Generic constructor.
        /// </summary>
        internal ClientData(int pid)
        {
            mPid = pid;

            mDebuggerInterest = DebuggerStatus.DEFAULT;
            mThreadMap        = new SortedDictionary <int?, ThreadInfo>();
        }
Beispiel #2
0
 public void Stop()
 {
     this.Status = DebuggerStatus.Stopped;
     try
     {
         if (this.ScriptThread != null)
         {
             this.ScriptThread.Abort();
         }
     }
     finally
     {
         this.ScriptThread = null;
     }
 }
Beispiel #3
0
 public void Pause()
 {
     this.Status = DebuggerStatus.Paused;
 }
Beispiel #4
0
        public void Play(String script, String path)
        {
            switch (this.Status)
            {
            case DebuggerStatus.Idle:
            case DebuggerStatus.Stopped:
            {
                if (this.ScriptThread != null)
                {
                    try
                    {
                        this.ScriptThread.Abort();
                    }
                    finally
                    {
                        this.ScriptThread = null;
                    }
                }

                this.Status       = DebuggerStatus.Running;
                this.ScriptThread = new Thread((ThreadStart) delegate
                    {
                        try
                        {
                            this.Script = new Script();

                            ((ScriptLoaderBase)Script.Options.ScriptLoader).ModulePaths = new string[] { path + "\\?" };

                            // LOU commands
                            foreach (var s in Enum.GetValues(typeof(CommandType)))
                            {
                                this.Script.Globals[s.ToString()] = DynValue.NewCallback(CallBack, s.ToString());
                            }

                            // LOU status variables
                            this.Script.Globals.MetaTable            = new Table(this.Script);
                            this.Script.Globals.MetaTable["__index"] = (Func <Table, DynValue, DynValue>)VarCallBack;

                            // generic helper methods
                            this.Script.Globals["sleep"] = (Action <int>)Sleep;

                            // other options
                            this.Script.Options.DebugPrint = Print;

                            this.Script.AttachDebugger(this);

                            this.Script.DoString(code: script, codeFriendlyName: this.Name);
                        }
                        catch (System.Threading.ThreadAbortException)
                        {
                            // Do nothing, we're stopping the script
                        }
                        catch (SyntaxErrorException ex)
                        {
                            MessageBoxEx.Show(MainForm.TheMainForm, ex.DecoratedMessage);
                        }
                        catch (Exception ex)
                        {
                            MessageBoxEx.Show(MainForm.TheMainForm, ex.Message);
                        }
                        finally
                        {
                            this.Status = DebuggerStatus.Stopped;
                            this.MainForm.Invoke(new MainForm.RefreshToolStripStatusDelegate(this.MainForm.RefreshToolStripStatus));
                        }
                    })
                {
                    Priority     = ThreadPriority.BelowNormal,
                    IsBackground = true
                };
                this.ScriptThread.Start();
            }
            break;

            case DebuggerStatus.Paused:
            {
                this.Status = DebuggerStatus.Running;
            }
            break;

            case DebuggerStatus.Running:
            {
                // weird
            }
            break;

            default:
                break;
            }
        }
Beispiel #5
0
 public DebuggerChangeEventArgs(DebuggerStatus status)
 {
     Status = status;
 }
Beispiel #6
0
        public void Play(String script, String path)
        {
            switch (this.Status)
            {
            case DebuggerStatus.Idle:
            case DebuggerStatus.Stopped:
            {
                if (this.ScriptThread != null)
                {
                    try
                    {
                        this.ScriptThread.Abort();
                    }
                    finally
                    {
                        this.ScriptThread = null;
                    }
                }

                this.Status       = DebuggerStatus.Running;
                this.ScriptThread = new Thread((ThreadStart) delegate
                    {
                        try
                        {
                            this.Script = new Script();

                            ((ScriptLoaderBase)Script.Options.ScriptLoader).ModulePaths = new string[] { path + "\\?" };

                            // LoU commands
                            foreach (var s in Enum.GetValues(typeof(CommandType)))
                            {
                                this.Script.Globals[s.ToString()] = DynValue.NewCallback(CallBack, s.ToString());
                            }
                            this.Script.Globals["WaitForTarget"] = (Action <int?>)WaitForTarget;          // Override: this is implemented client side
                            this.Script.Globals["IsHotKeyDown"]  = (Func <string, DynValue>)IsHotKeyDown; // Override: this is implemented client side
                            this.Script.Globals["OnHotKey"]      = (Func <string, DynValue>)OnHotKey;     // Override: this is implemented client side


                            // LoU status variables
                            UserData.RegisterType <ClientStatus.FINDBUTTONStruct>();
                            UserData.RegisterType <ClientStatus.FINDINPUTStruct>();
                            UserData.RegisterType <ClientStatus.FINDITEMStruct>();
                            UserData.RegisterType <ClientStatus.FINDLABELStruct>();
                            UserData.RegisterType <ClientStatus.FINDMOBILEStruct>();
                            UserData.RegisterType <ClientStatus.FINDPANELStruct>();
                            UserData.RegisterType <ClientStatus.FINDPERMANENTStruct>();
                            UserData.RegisterType <ClientStatus.OBJStruct>();
                            UserData.RegisterType <ClientStatus.NEARBYMONSTERStruct>();
                            UserData.RegisterType <ClientStatus.HOTKEYStruct>();

                            this.Script.Globals.MetaTable            = new Table(this.Script);
                            this.Script.Globals.MetaTable["__index"] = (Func <Table, DynValue, DynValue>)VarCallBack;

                            // generic helper methods
                            this.Script.Globals["sleep"] = (Action <int>)Sleep;
                            this.Script.Globals["clear"] = (Action)Clear;
                            this.Script.Globals["write"] = (Action <string>)Write;

                            // script control methods
                            this.Script.Globals["PlayScript"]            = (Action <string>)PlayScript;
                            this.Script.Globals["PlayAllScripts"]        = (Action)PlayAllScripts;
                            this.Script.Globals["PauseScript"]           = (Action <string>)PauseScript;
                            this.Script.Globals["StopScript"]            = (Action <string>)StopScript;
                            this.Script.Globals["StopAllScripts"]        = (Action)StopAllScripts;
                            this.Script.Globals["StopAllScriptsButThis"] = (Action)StopAllScriptsButThis;

                            // other options
                            this.Script.Options.DebugPrint = Print;

                            this.Script.AttachDebugger(this);

                            this.Script.DoString(code: script, codeFriendlyName: this.Name);
                        }
                        catch (System.Threading.ThreadAbortException)
                        {
                            // Do nothing, we're stopping the script
                        }
                        catch (SyntaxErrorException ex)
                        {
                            MainForm.TheMainForm.Invoke(new Action(() => { MessageBoxEx.Show(MainForm.TheMainForm, ex.DecoratedMessage); }));
                        }
                        catch (ScriptRuntimeException ex)
                        {
                            MainForm.TheMainForm.Invoke(new Action(() => { MessageBoxEx.Show(MainForm.TheMainForm, ex.DecoratedMessage); }));
                        }
                        catch (Exception ex)
                        {
                            MainForm.TheMainForm.Invoke(new Action(() => { MessageBoxEx.Show(MainForm.TheMainForm, ex.Message); }));
                        }
                        finally
                        {
                            this.Status = DebuggerStatus.Stopped;
                            this.MainForm.Invoke(new MainForm.RefreshToolStripStatusDelegate(this.MainForm.RefreshToolStripStatus));
                        }
                    })
                {
                    Priority     = ThreadPriority.BelowNormal,
                    IsBackground = true
                };
                this.ScriptThread.Start();
            }
            break;

            case DebuggerStatus.Paused:
            {
                this.Status = DebuggerStatus.Running;
            }
            break;

            case DebuggerStatus.Running:
            {
                // weird
            }
            break;

            default:
                break;
            }
        }
Beispiel #7
0
		/// <summary>
		/// Generic constructor.
		/// </summary>
		internal ClientData(int pid)
		{
			mPid = pid;

			mDebuggerInterest = DebuggerStatus.DEFAULT;
			mThreadMap = new SortedDictionary<int?, ThreadInfo>();
		}
Beispiel #8
0
        void DebuggerTask()
        {
            try
            {
                Util.LogMemoryUsageStatistics("Inside debugger task thread");

                lock (_statusLock)
                {
                    _status.State      = DebuggerState.NotStarted;
                    _status.ExitReason = "The session terminated before it could attach to the debuggee.";
                    _status.Fatal      = true;
                }

                lock (_statusLock)
                {
                    _status.State = DebuggerState.Running;
                    _status.Fatal = false;
                }

                Stopwatch sw = new Stopwatch();
                sw.Start();

                DebuggerStatus lastStatus = DebuggerStatus.TimedOut;
#if DEBUG
                int numTicks = 0;
#endif

                while (_status.State == DebuggerState.Running)
                {
                    DebuggerStatus dbgStatus = _debuggee.Update();
                    long           now       = sw.ElapsedMilliseconds;

#if DEBUG
                    if (numTicks % 100 == 0)
                    {
                        Util.LogMemoryUsageStatistics("Tick" + numTicks);
                    }
                    ++numTicks;
#endif

                    if (_status.State != DebuggerState.ExitPending)
                    {
                        if (dbgStatus != DebuggerStatus.Ok && dbgStatus != DebuggerStatus.TimedOut)
                        {
                            if (_sessionStatus == SessionStatusFlags.SessionActive)
                            {
                                TriggerExit("The debug session terminated due to a debuggee system shutdown.");
                            }
                            else
                            {
                                // If we're waiting for an attach, we don't want to bang the COM+ server with RPC traffic.
                                // Add a bit of stabilization time.
                                _debuggerUpdatedEvent.WaitOne(PollTime);
                            }
                        }
                    }

                    lastStatus = dbgStatus;
                    _debuggerUpdatedEvent.Set();
                }

                if (!_debugKernel)
                {
                    _debuggee.DetachProcesses();
                }
            }
            catch (Exception ex)
            {
                lock (_statusLock)
                {
                    _status.ExitReason = "The debugger encountered a fatal error: " + ex.ToString();
                    _status.State      = DebuggerState.Exited;
                }

                throw;
            }
            finally
            {
                lock (_statusLock)
                {
                    _status.State = DebuggerState.Exited;
                }
            }

            Util.LogMemoryUsageStatistics("Debugger task complete");

            if (_status.Fatal)
            {
                throw new DebugMonitorException(_status.ExitReason);
            }
        }