Пример #1
0
        public void RunClient(Object threadContext)
        {
            m_client = (TcpClient)threadContext;
            m_stream = m_client.GetStream();

            string remoteAddress = m_client.Client.RemoteEndPoint.ToString();
            var items = remoteAddress.Split(':');
            m_remoteHost = items[0];

            if (m_remoteHost != "127.0.0.1" && DebuggerServer.AllowedClients != "*" &&
                !DebuggerServer.AllowedClients.Contains(m_remoteHost))
            {
                Console.WriteLine("Host [" + m_remoteHost + "] is not allowed.");
                return;
            }

            Connected = true;

            Byte[] bytes = new Byte[4096];
            string data = null;
            Console.WriteLine("Starting client {0}", m_client.Client.RemoteEndPoint);

#if UNITY_EDITOR == false && UNITY_STANDALONE == false && __ANDROID__ == false && __IOS__ == false
      Interpreter.Instance.Init ();
#endif

            m_debugger = new Debugger();

            int i;
            try
            {
                while ((i = m_stream.Read(bytes, 0, bytes.Length)) != 0 && Connected)
                {
                    data = System.Text.Encoding.UTF8.GetString(bytes, 0, i);
                    string rest = "";
                    DebuggerUtils.DebugAction action = DebuggerUtils.StringToAction(data, ref rest);

                    if (action == DebuggerUtils.DebugAction.BYE)
                    {
                        break;
                    }
                    else if (m_debugger.CanProcess(action))
                    {
                        ThreadPool.QueueUserWorkItem(DebuggerServer.RunRequestBlocked, data);
                    }
                    else
                    {
                        DebuggerServer.Queue.Add(data);
                    }
                }
            }
            catch (Exception exc)
            {
                Console.Write("Client disconnected: {0}", exc.Message);
            }

            // Shutdown and end connection
            Console.Write("Closed connection.");
            Disconnect();
        }
Пример #2
0
        public void RunClient(Object threadContext)
        {
            m_client = (TcpClient)threadContext;
            m_stream = m_client.GetStream();
            Connected = true;

            Byte[] bytes = new Byte[4096];
            string data = null;
            Console.WriteLine("Starting client {0}", m_client.Client.RemoteEndPoint);

#if UNITY_EDITOR == false && UNITY_STANDALONE == false && __ANDROID__ == false && __IOS__ == false
      Interpreter.Instance.Init ();
#endif

            m_debugger = new Debugger();

            int i;
            try
            {
                while ((i = m_stream.Read(bytes, 0, bytes.Length)) != 0 && Connected)
                {
                    data = System.Text.Encoding.UTF8.GetString(bytes, 0, i);
                    string rest = "";
                    DebuggerUtils.DebugAction action = DebuggerUtils.StringToAction(data, ref rest);

                    if (action == DebuggerUtils.DebugAction.BYE)
                    {
                        break;
                    }
                    else if (action == DebuggerUtils.DebugAction.REPL)
                    {
                        m_isRepl = true;
                        DebuggerServer.Queue.Add(data);
                    }
                    else if (m_debugger.CanProcess(action))
                    {
                        ThreadPool.QueueUserWorkItem(DebuggerServer.RunRequestBlocked, data);
                    }
                    else
                    {
                        DebuggerServer.Queue.Add(data);
                    }
                }
            }
            catch (Exception exc)
            {
                Console.Write("Client disconnected: {0}", exc.Message);
            }

            if (m_debugger == Debugger.MainInstance)
            {
                Debugger.MainInstance = null;
            }

            // Shutdown and end connection
            Console.Write("Closed connection.");
            Disconnect();
        }
Пример #3
0
        async Task ProcessClientCommand(string data)
        {
            string load = "";

            DebuggerUtils.DebugAction action = DebuggerUtils.StringToAction(data, ref load);
            string result = "N/A";

            SteppingIn     = SteppingOut = false;
            SendBackResult = true;
            m_firstBlock   = true;
            End            = false;
            string responseToken = DebuggerUtils.ResponseMainToken(action);

            //Trace("REQUEST: " + data);
            if (action == DebuggerUtils.DebugAction.REPL ||
                action == DebuggerUtils.DebugAction._REPL)
            {
                string filename = "";
                if (action == DebuggerUtils.DebugAction.REPL)
                {
                    int ind = load.IndexOf('|');
                    if (ind >= 0)
                    {
                        if (ind > 0)
                        {
                            filename = load.Substring(0, ind);
                        }
                        if (ind + 1 < load.Length)
                        {
                            load = load.Substring(ind + 1);
                        }
                    }
                }
                result = await ProcessRepl(load, filename);

                result = responseToken + (result == null ? "" : result);
                SendBack(result, false);
                return;
            }
            if (action == DebuggerUtils.DebugAction.SET_BP)
            {
                TheBreakpoints.AddBreakpoints(this, load);
                return;
            }

            if (action == DebuggerUtils.DebugAction.FILE)
            {
                MainInstance = this;
                string filename  = load;
                string rawScript = Utils.GetFileContents(filename);

                if (string.IsNullOrWhiteSpace(rawScript))
                {
                    ProcessException(null, new ParsingException("Could not load script " + filename));
                    return;
                }

                try
                {
                    m_script = Utils.ConvertToScript(rawScript, out m_char2Line, filename);
                }
                catch (ParsingException exc)
                {
                    ProcessException(m_debugging, exc);
                    return;
                }
                m_debugging                = new ParsingScript(m_script, 0, m_char2Line);
                m_debugging.Filename       = filename;
                m_debugging.MainFilename   = m_debugging.Filename;
                m_debugging.OriginalScript = rawScript;
                m_debugging.Debugger       = this;

                m_steppingIns.Clear();
                m_completedStepIn.Reset();
                ProcessingBlock = SendBackResult = InInclude = End = false;
                m_blockLevel    = m_maxBlockLevel = 0;
            }
            else if (action == DebuggerUtils.DebugAction.VARS)
            {
                result = GetAllVariables(m_debugging);
            }
            else if (action == DebuggerUtils.DebugAction.ALL)
            {
                result = await DebugScript();
            }
            else if (action == DebuggerUtils.DebugAction.STACK)
            {
                result = GetStack();
            }
            else if (action == DebuggerUtils.DebugAction.CONTINUE)
            {
                Continue = true;
                action   = DebuggerUtils.DebugAction.NEXT;
            }
            else if (action == DebuggerUtils.DebugAction.STEP_IN)
            {
                SteppingIn = true;
                Continue   = false;
                action     = DebuggerUtils.DebugAction.NEXT;
            }
            else if (action == DebuggerUtils.DebugAction.STEP_OUT)
            {
                SteppingOut = true;
                Continue    = false;
                action      = DebuggerUtils.DebugAction.NEXT;
            }
            else if (action == DebuggerUtils.DebugAction.NEXT)
            {
                Continue = false;
            }
            else
            {
                Console.WriteLine("UNKNOWN CMD: {0}", data);
                return;
            }

            if (action == DebuggerUtils.DebugAction.NEXT)
            {
                if (m_debugging == null)
                {
                    result = "Error: Not initialized";
                    Console.WriteLine(result);
                }
                else
                {
                    Variable res = await ProcessNext();

                    //Trace("MAIN Ret:" + (LastResult != null && LastResult.IsReturn) +
                    //      " NULL:" + (res == null) + " db.sb=" + m_debugging.Debugger.SendBackResult +
                    //      " PTR:" + m_debugging.Pointer + "/" + m_script.Length);
                    if (End)
                    {
                        responseToken = DebuggerUtils.ResponseMainToken(DebuggerUtils.DebugAction.END);
                    }
                    else if (res == null || !SendBackResult)
                    {
                        // It will be processed by the stepped-out OR by completed stepped-in code.
                        return;
                    }
                    else
                    {
                        result = CreateResult(Output);
                        if (string.IsNullOrEmpty(result))
                        {
                            return;
                        }
                    }
                }
            }

            result = responseToken + result;
            SendBack(result, true);
        }
Пример #4
0
        void ProcessClientCommand(string data)
        {
            string load = "";

            DebuggerUtils.DebugAction action = DebuggerUtils.StringToAction(data, ref load);
            string result = "N/A";

            SteppingIn     = SteppingOut = false;
            SendBackResult = true;
            m_firstBlock   = true;
            string responseToken = DebuggerUtils.ResponseMainToken(action);

            Trace("REQUEST: " + data);
            if (action == DebuggerUtils.DebugAction.REPL ||
                action == DebuggerUtils.DebugAction._REPL)
            {
                result = responseToken + ProcessRepl(load);
                SendBack(result);
                return;
            }
            if (action == DebuggerUtils.DebugAction.SET_BP)
            {
                TheBreakpoints.AddBreakpoints(this, load);
                return;
            }

            if (action == DebuggerUtils.DebugAction.FILE)
            {
                MainInstance = this;
                string filename  = load;
                string rawScript = Utils.GetFileContents(filename);

                m_script                   = Utils.ConvertToScript(rawScript, out m_char2Line);
                m_debugging                = new ParsingScript(m_script, 0, m_char2Line);
                m_debugging.Filename       = filename;
                m_debugging.OriginalScript = m_script;
                m_debugging.Debugger       = this;
            }
            else if (action == DebuggerUtils.DebugAction.VARS)
            {
                result = GetAllVariables(m_debugging);
            }
            else if (action == DebuggerUtils.DebugAction.ALL)
            {
                result = DebugScript();
            }
            else if (action == DebuggerUtils.DebugAction.STACK)
            {
                result = GetStack();
            }
            else if (action == DebuggerUtils.DebugAction.CONTINUE)
            {
                Continue = true;
                action   = DebuggerUtils.DebugAction.NEXT;
            }
            else if (action == DebuggerUtils.DebugAction.STEP_IN)
            {
                SteppingIn = true;
                Continue   = false;
                action     = DebuggerUtils.DebugAction.NEXT;
            }
            else if (action == DebuggerUtils.DebugAction.STEP_OUT)
            {
                SteppingOut = true;
                Continue    = false;
                action      = DebuggerUtils.DebugAction.NEXT;
            }
            else if (action == DebuggerUtils.DebugAction.NEXT)
            {
                Continue = false;
            }
            else
            {
                Console.WriteLine("UNKNOWN CMD: {0}", data);
                return;
            }

            if (action == DebuggerUtils.DebugAction.NEXT)
            {
                if (m_debugging == null)
                {
                    result = "Error: Not initialized";
                    Console.WriteLine(result);
                }
                else
                {
                    Variable res = ProcessNext();
                    Trace("MAIN Ret:" + (LastResult != null && LastResult.IsReturn) +
                          " NULL:" + (res == null) + " db.sb=" + m_debugging.Debugger.SendBackResult +
                          " PTR:" + m_debugging.Pointer + "/" + m_script.Length);
                    if (End)
                    {
                        responseToken = DebuggerUtils.ResponseMainToken(DebuggerUtils.DebugAction.END);
                    }
                    else if (res == null || !SendBackResult)
                    {
                        // It will be processed by the stepped-out OR by completed stepped-in code.
                        return;
                    }
                    else
                    {
                        result = CreateResult(Output);
                    }
                }
            }

            result = responseToken + result;
            SendBack(result);
        }