private void RefreshWatch(MondDebugContext context, Watch watch) { _watchSemaphore.Wait(); try { var timer = new Timer(state => { _watchTimedOut = true; IsBreakRequested = true; }, null, -1, -1); _watchTimedOut = false; timer.Change(500, -1); watch.Refresh(context); timer.Change(-1, -1); _watchTimedOut = false; } finally { _watchSemaphore.Release(); } }
public void Refresh(MondDebugContext context) { if (context == null) { _value = null; return; } try { var result = context.Evaluate(Expression); _value = result.Serialize(); } catch (Exception e) { _value = e.Message; } }
private MondDebugAction WaitForAction() { var result = _breaker.Task.Result; lock (_sync) { _context = null; _breaker = null; } var message = new MondValue(MondValueType.Object); message["Type"] = "State"; message["Running"] = true; Broadcast(message); return(result); }
private MondDebugAction WaitForAction() { var result = _breaker.Task.Result; lock (SyncRoot) { _context = null; _breaker = null; } var message = MondValue.Object(); message["type"] = "state"; message["isRunning"] = true; Broadcast(message); return(result); }
protected override MondDebugAction OnBreak(MondDebugContext context, int address) { if (_watchTimedOut) { _watchTimedOut = false; throw new MondRuntimeException("Execution timed out"); } if (_watchSemaphore.CurrentCount == 0) { return(MondDebugAction.Run); } // if missing debug info, leave the function if (IsMissingDebugInfo(context.Program.DebugInfo)) { return(MondDebugAction.StepOut); } lock (_sync) { if (_breaker != null) { throw new InvalidOperationException("Debugger hit breakpoint while waiting on another"); } _context = context; _breaker = new TaskCompletionSource <MondDebugAction>(); } // keep track of program instances VisitProgram(context.Program); // update the current state UpdateState(context, address); // block until an action is set return(WaitForAction()); }
private void UpdateState(MondDebugContext context, int address) { var program = context.Program; var debugInfo = program.DebugInfo; // find out where we are in the source code var statement = debugInfo.FindStatement(address); if (!statement.HasValue) { var position = debugInfo.FindPosition(address); if (position.HasValue) { var line = position.Value.LineNumber; var column = position.Value.ColumnNumber; statement = new MondDebugInfo.Statement(0, line, column, line, column); } else { statement = new MondDebugInfo.Statement(0, -1, -1, -1, -1); } } // refresh all watches List <Watch> watches; lock (_sync) watches = _watches.ToList(); foreach (var watch in watches) { RefreshWatch(_context, watch); } // apply new state and broadcast it MondValue message; lock (_sync) { var stmtValue = statement.Value; var programId = FindProgramIndex(program); _position = new BreakPosition( programId, stmtValue.StartLineNumber, stmtValue.StartColumnNumber, stmtValue.EndLineNumber, stmtValue.EndColumnNumber); message = new MondValue(MondValueType.Object); message["Type"] = "State"; message["Running"] = false; message["Id"] = _position.Id; message["StartLine"] = _position.StartLine; message["StartColumn"] = _position.StartColumn; message["EndLine"] = _position.EndLine; message["EndColumn"] = _position.EndColumn; message["Watches"] = new MondValue(watches.Select(Utility.JsonWatch)); message["CallStack"] = BuildCallStackArray(_context.CallStack); } Broadcast(message); }