public List <Breakpoint> UpdateBreakpoints( AphidDebugSession session, Response response, string scriptFile, SourceBreakpoint[] sourceBreakpoints) { // Todo: better handle forward slashes var fullScriptFile = Path.GetFullPath(scriptFile).Replace('/', '\\'); var lastWrite = new FileInfo(fullScriptFile).LastWriteTime; //if (_codeCacheTime.TryGetValue(fullScriptFile, out var time) && time < lastWrite) //{ // _astMemoizer.Remove(fullScriptFile); // _codeMemoizer.Remove(fullScriptFile); // _codeCacheTime[fullScriptFile] = lastWrite; //} //else //{ // _codeCacheTime.Add(fullScriptFile, lastWrite); //} Cli.WriteInfoMessage("Parsing {0}", fullScriptFile); //var code = _codeMemoizer.Call(File.ReadAllText, fullScriptFile); var code = File.ReadAllText(fullScriptFile); var ast = _astMemoizer.Call(x => session.Parse(response, x), fullScriptFile); if (ast == null) { return(null); } var lineResolver = new AphidLineResolver(); var breakpointExpressions = lineResolver.ResolveLineExpressions( ast, code, sourceBreakpoints); var bps = new List <Breakpoint>(); var j = 0; var bpExps = new List <AphidExpression>(); foreach (var exp in breakpointExpressions) { //var line = clientLines[j++]; Program.Log("Setting breakpoint at index {0}: {1}", exp.Index, exp.ToString()); } session.Interpreter.SetFileBreakpoints( fullScriptFile, breakpointExpressions.Select(x => x.Index).ToArray()); return(sourceBreakpoints .Select(x => new Breakpoint(true, x.line, x.column)) .ToList());; }
public override void StackTrace(Response response, dynamic arguments) { var id = 0; var lineResolver = new AphidLineResolver(); StackFrame nextFrame(AphidExpression expression) { var(line, col) = lineResolver.ResolvePosition( GetAst(response, expression), expression); return(new StackFrame( id++, expression.ToString(), GetSource(expression), line, col, "normal")); } StackFrame[] expFrames; var extraFrames = 0; if (Interpreter.CurrentExpression != null) { if (Interpreter.CurrentStatement != null && Interpreter.CurrentStatement != Interpreter.CurrentExpression) { Program.Log("Current exp and stmt added to frames"); expFrames = new[] { nextFrame(Interpreter.CurrentExpression), nextFrame(Interpreter.CurrentStatement) }; extraFrames = 2; } else { Program.Log("Current exp added to frames"); expFrames = new[] { nextFrame(Interpreter.CurrentExpression) }; extraFrames = 1; } } //if (Interpreter.CurrentExpression != null) //{ // expFrames = new[] { nextFrame(Interpreter.CurrentExpression) }; // extraFrames = 1; //} else if (Interpreter.CurrentStatement != null) { Program.Log("Current stmt added to frames"); expFrames = new[] { nextFrame(Interpreter.CurrentStatement) }; extraFrames = 1; } else { expFrames = Array.Empty <StackFrame>(); } var aphidFrames = Interpreter.GetRawStackTrace(); var stackFrames = expFrames .Concat(aphidFrames .Select(x => { var(line, col) = lineResolver.ResolvePosition( GetAst(response, x.Expression), x.Expression); return(new StackFrame( id++, x.ToString(), GetSource(x.Expression), line, col, "normal")); })) .ToList(); var frames2 = new List <StackFrame>(); _frameScopes.Clear(); var i = 0 - extraFrames; foreach (var f in stackFrames) { var scope = i < 0 ? (_exception == null ? Interpreter.CurrentScope : _exception.Data.Contains(AphidName.Scope) ? (AphidObject)_exception.Data[AphidName.Scope] : aphidFrames[0].Scope) : aphidFrames[i].Scope; if (!_frameScopes.ContainsKey(f.id)) { _frameScopes.Add(f.id, scope); } Program.Log($"Created frame {i}: {f.name}"); //frames2.Add(new StackFrame(handle, f.name, f.source, f.line, f.column, f.presentationHint)); frames2.Add(f); i++; } SendResponse(response, new StackTraceResponseBody(frames2, frames2.Count)); }