Ejemplo n.º 1
0
        public async Task <bool> ExecuteNextStatement()
        {
            int endGroupRead = 0;

            if (m_debugging.Pointer >= m_script.Length - 1)
            {
                LastResult = null;
                End        = true;
                return(true);
            }

            //int startPointer = m_debugging.Pointer;
            if (ProcessingBlock)
            {
                endGroupRead = m_debugging.GoToNextStatement();
                if (ProcessingBlock && endGroupRead > 0)
                {
                    return(true);
                }
            }

            Executing = true;
            try
            {
                LastResult = await DebuggerUtils.Execute(m_debugging);
            }
            catch (ParsingException exc)
            {
                if (m_debugging.InTryBlock)
                {
                    throw exc;
                }
                ProcessException(m_debugging, exc);
                return(true);
            }
            finally
            {
                Executing = false;
            }

            endGroupRead = m_debugging.GoToNextStatement();

            // Check if after this statement the Step In is completed and we can unwind the stack:
            bool completedSteppingIn = Completed(m_debugging) || (ProcessingBlock && endGroupRead > 0) ||
                                       LastResult.Type == Variable.VarType.CONTINUE ||
                                       LastResult.Type == Variable.VarType.BREAK ||
                                       LastResult.IsReturn;

            return(completedSteppingIn);
        }
Ejemplo n.º 2
0
        protected override Variable Evaluate(ParsingScript script)
        {
            List <Variable> args = script.GetFunctionArgs();

            Utils.CheckArgs(args.Count, 1, m_name, true);

            string filename = args[0].AsString();
            string pathname = script.GetFilePath(filename);

            EncodeFileFunction.EncodeDecode(pathname, false);
            ParsingScript tempScript    = script.GetIncludeFileScript(filename);
            string        includeScript = tempScript.String;

            EncodeFileFunction.EncodeDecode(pathname, true);

            Variable result = null;

            if (script.Debugger != null)
            {
                result = script.Debugger.StepInIncludeIfNeeded(tempScript).Result;
            }

            while (tempScript.Pointer < includeScript.Length)
            {
                result = tempScript.Execute();
                tempScript.GoToNextStatement();
            }
            return(result == null ? Variable.EmptyInstance : result);
        }
Ejemplo n.º 3
0
        async Task <string> ProcessRepl(string repl, string filename = "")
        {
            ReplMode = true;

            Dictionary <int, int> char2Line;
            string        script     = Utils.ConvertToScript(repl, out char2Line);
            ParsingScript tempScript = new ParsingScript(script, 0, char2Line);

            tempScript.OriginalScript = repl;
            tempScript.Debugger       = this;
            if (!string.IsNullOrWhiteSpace(filename))
            {
                tempScript.Filename = filename;
            }

            Variable result    = null;
            bool     excThrown = false;
            string   stringRes = "";

            try
            {
                while (tempScript.Pointer < script.Length)
                {
                    result = await DebuggerUtils.Execute(tempScript);

                    tempScript.GoToNextStatement();
                    while (tempScript.TryCurrent() == Constants.END_STATEMENT)
                    {
                        tempScript.Forward();
                    }
                }

                if (TrySendFile(result, tempScript, ref excThrown) || excThrown)
                {
                    return("");
                }

                stringRes = string.IsNullOrEmpty(Output) ? "" : Output + (Output.EndsWith("\n") ? "" : "\n");

                stringRes += result == null ? "" : result.AsString();
                stringRes += (stringRes.EndsWith("\n") ? "" : "\n");
            }
            catch (Exception exc)
            {
                Console.WriteLine("ProcessRepl Exception: " + exc);
                return(""); // The exception was already thrown and sent back.
            }
            finally
            {
                ReplMode = false;
            }


            return(stringRes);
        }
Ejemplo n.º 4
0
        public async Task <Variable> DebugBlockIfNeeded(ParsingScript stepInScript, bool done, Action <bool> doneEvent)
        {
            if (SteppingOut || Continue || ReplMode || !m_firstBlock)
            {
                return(null);
            }
            m_firstBlock = false;
            done         = stepInScript.GoToNextStatement() > 0;
            if (done)
            {
                return(Variable.EmptyInstance);
            }

            ProcessingBlock = true;

            ParsingScript tempScript = new ParsingScript(stepInScript.String, stepInScript.Pointer);

            tempScript.ParentScript = stepInScript;
            tempScript.InTryBlock   = stepInScript.InTryBlock;
            /* string body = */ Utils.GetBodyBetween(tempScript, Constants.START_GROUP, Constants.END_GROUP);

            m_blockLevel++;
            m_maxBlockLevel = System.Math.Max(m_maxBlockLevel, m_blockLevel);

            await StepIn(stepInScript);

            done = stepInScript.Pointer >= tempScript.Pointer ||
                   LastResult == null ||
                   LastResult.IsReturn ||
                   LastResult.Type == Variable.VarType.BREAK ||
                   LastResult.Type == Variable.VarType.CONTINUE;

            m_blockLevel--;
            m_maxBlockLevel = m_blockLevel == 0 ? m_blockLevel : m_maxBlockLevel;

            ProcessingBlock = m_blockLevel > 0;

            doneEvent(done);
            return(LastResult == null ? Variable.EmptyInstance : LastResult);
        }