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(); } }
public override void Visit(Jint.Expressions.Program expression) { //all global vars are in fact closed on }