Esempio n. 1
0
 public void OnStep(DebugInformation info)
 {
     if (Step != null && info.CurrentStatement != null && info.CurrentStatement.Source != null)
     {
         Step(this, info);
     }
 }
Esempio n. 2
0
        public DebugInformation CreateDebugInformation(Statement statement)
        {
            DebugInformation info = new DebugInformation();
            info.CurrentStatement = statement;
            info.CallStack = CallStack;
            info.Locals = new JsObject() { Prototype = JsUndefined.Instance };
            DebugMode = false;
            foreach (JsDictionaryObject scope in Scopes.ToArray())
            {
                foreach (var property in scope.GetKeys())
                {
                    if (!info.Locals.HasProperty(property))
                    {
                        info.Locals[property] = scope[property];
                    }
                }
            }
            DebugMode = true;

            return info;
        }
Esempio n. 3
0
 protected void OnBreak(object sender, DebugInformation info) {
     if (Break != null) {
         Break(this, info);
     }
 }
Esempio n. 4
0
        protected void OnStep(object sender, DebugInformation info) {
            if (Step != null) {
                Step(this, info);
            }

            if (Break != null) {
                BreakPoint breakpoint = BreakPoints.FirstOrDefault(l => {
                    bool afterStart, beforeEnd;

                    afterStart = l.Line > info.CurrentStatement.Source.Start.Line
                        || (l.Line == info.CurrentStatement.Source.Start.Line && l.Char >= info.CurrentStatement.Source.Start.Char);

                    if (!afterStart) {
                        return false;
                    }

                    beforeEnd = l.Line < info.CurrentStatement.Source.Stop.Line
                        || (l.Line == info.CurrentStatement.Source.Stop.Line && l.Char <= info.CurrentStatement.Source.Stop.Char);

                    if (!beforeEnd) {
                        return false;
                    }

                    if (!String.IsNullOrEmpty(l.Condition)) {
                        return Convert.ToBoolean(this.Run(l.Condition));
                    }

                    return true;
                });


                if (breakpoint != null) {
                    Break(this, info);
                }
            }
        }
Esempio n. 5
0
        public DebugInformation CreateDebugInformation(Statement statement)
        {
            DebugInformation info = new DebugInformation();
            info.CurrentStatement = statement;
            info.CallStack = CallStack;
            info.Locals = new JsObject(JsNull.Instance);
            DebugMode = false;

            foreach (var property in CurrentScope.GetKeys())
                info.Locals[property] = CurrentScope[property];

            DebugMode = true;

            return info;
        }
Esempio n. 6
0
 private void OnBreakEvent(object sender, DebugInformation e)
 {
     Debugger.OnBreak(sender, e);
 }
Esempio n. 7
-1
        static bool CommandLoop(Jint.Expressions.Program program, DebugInformation information, JdbEngine debugger)
        {
            Console.ForegroundColor = ConsoleColor.White;
            Console.BackgroundColor = ConsoleColor.Black;

            if (information == null)
            {
                information = new DebugInformation();
                information.CallStack = new Stack<string>();
                information.Locals = new JsObject(JsNull.Instance);

                foreach (var property in debugger.CurrentScope.GetKeys())
                    information.Locals[property] = debugger.CurrentScope[property];
            }
            else
            {
                Console.WriteLine("{0}:{1} => {2}", information.CurrentStatement.Source.Start.Line,
                                  information.CurrentStatement.Source.Start.Char,
                                  information.CurrentStatement.Source.Code);
            }

            try
            {
                while (true)
                {
                    Console.Write(">");
                    var command = Console.ReadLine().ToLowerInvariant();

                    if (command == "bt")
                    {
                        // backtrace
                        int frame = 0;
                        foreach (string stackframe in information.CallStack)
                        {
                            Console.WriteLine("[{0}] {1}", frame++, stackframe);
                        }
                    }
                    else if (command.StartsWith("p "))
                    {
                        // find value for next word and print it
                        string varname = command.Substring(command.IndexOf(" ") + 1);
                        Console.WriteLine("{0} => {1}", varname, information.Locals[varname].Value);
                    }
                    else if (command == "l")
                    {
                        // locals
                        foreach (string key in information.Locals.GetKeys())
                        {
                            Console.WriteLine("{0} => {1}", key, information.Locals[key].Value);
                        }
                    }
                    else if (command == "n")
                    {
                        // Step
                        stepping = true;
                        return true;
                    }
                    else if (command == "c" || command == "r")
                    {
                        // continue
                        stepping = false;
                        return true;
                    }
                    else if (command == "q")
                    {
                        // quit
                        return false;
                    }
                    else if (command.StartsWith("bp "))
                    {
                        // set a breakpoint
                        string[] split = command.Split(new string[] {" "}, StringSplitOptions.RemoveEmptyEntries);
                        int line = 0;
                        int chr = 0;
                        string expr = null;
                        if (split.Length > 1)
                        {
                            line = int.Parse(split[1]);

                            if (split.Length > 2)
                            {
                                chr = int.Parse(split[2]);

                                if (split.Length > 3)
                                    expr = split[3];
                            }

                            debugger.BreakPoints.Add(new BreakPoint(line, chr, expr));
                        }
                    }
                    else if (command == "lbp")
                    {
                        // list breakpoints
                        int bpcount = 0;
                        foreach (BreakPoint bp in debugger.BreakPoints)
                        {
                            Console.WriteLine("{0} => {1}:{2} {3}", bpcount++, bp.Line, bp.Char, bp.Condition);
                        }
                    }
                    else if (command.StartsWith("dbp "))
                    {
                        // delete break point
                        int bpi = int.Parse(command.Substring(command.IndexOf(" ") + 1));
                        debugger.BreakPoints.RemoveAt(bpi);
                    }
                    else
                    {
                        // try to eval as an immediate
                        Console.WriteLine("{0}", debugger.Immediate(command));
                    }
                }
            }
            finally
            {
                Console.ResetColor();
            }
        }