public static void ProcessException(ParsingScript script, ParsingException exc) { Debugger debugger = script != null && script.Debugger != null ? script.Debugger : MainInstance; if (debugger == null) { return; } if (debugger.ReplMode) { string replResult = DebuggerUtils.ResponseMainToken(DebuggerUtils.DebugAction.REPL) + "Exception thrown: " + exc.Message + "\n"; debugger.SendBack(replResult, false); debugger.LastResult = null; ParserFunction.InvalidateStacksAfterLevel(0); return; } string stack = exc.ExceptionStack; string vars = debugger.GetAllVariables(script); int varsCount = vars.Split('\n').Length; string result = "exc\n" + exc.Message + "\n"; //result += exc. + "\n"; result += varsCount + "\n"; result += vars + "\n"; result += stack + "\n"; debugger.SendBack(result, !debugger.ReplMode); debugger.LastResult = null; ParserFunction.InvalidateStacksAfterLevel(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); }
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); }