private IronPython.Runtime.Exceptions.TracebackDelegate OnTraceback(IronPython.Runtime.Exceptions.TraceBackFrame frame, string result, object payload) { setDebugInfo(frame, result); while (nextStepFlag == false) { Application.DoEvents(); Thread.Sleep(50); } nextStepFlag = false; return(this.OnTraceback); }
private void setDebugInfo(IronPython.Runtime.Exceptions.TraceBackFrame frame, string result) { if (this.InvokeRequired) { this.Invoke(new setDebugInfoCallBack(setDebugInfo), frame, result); return; } this.Focus(); int i = (int)frame.f_lineno; dataGridViewDebug.Rows.Clear(); if (i > 0 && result != "exception") { exRichTextBox.HideSelection = false; int start = 0; for (int j = 0; j < i - 1; j++) { start += exRichTextBox.TextLines[j].Length + 1; } exRichTextBox.SelectionStart = start; exRichTextBox.SelectionLength = exRichTextBox.TextLines[i - 1].Length; foreach (object o in (IronPython.Runtime.PythonDictionary)frame.f_locals) { try { KeyValuePair <object, object> kv = (KeyValuePair <object, object>)o; string key = (string)kv.Key; if (!(key.StartsWith("__") && key.EndsWith("__")) && key != ScopeName) { string value = kv.Value.ToString(); if (kv.Value is System.Int32[]) { var v = (int[])kv.Value; if (v.Length != 0) { value = ""; foreach (int n in v) { value += n + ", "; } } } dataGridViewDebug.Rows.Add(new[] { key, value }); } } catch { } } } }
protected IronPython.Runtime.Exceptions.TracebackDelegate TraceCallback(IronPython.Runtime.Exceptions.TraceBackFrame frame, string eventName, object payload) { bool abort = false; abort = abortEvent.WaitOne(0); //test abort signal int currentFrameLine = (int)frame.f_lineno; if (currentFrameLine != lastLine) { lastLine = currentFrameLine; PublishEvent(new ScriptUnitProgressEvent(this, source != null ? source.MapLine(currentFrameLine) : currentFrameLine)); } if (!abort) { bool breaking = breakEvent.WaitOne(0); //test if a break was requested if (!breaking) { int currentLine = source != null?source.MapLine(currentFrameLine) : currentFrameLine; lock (breakpoints) { breaking |= breakpoints.Contains(currentLine); } } if (breaking) { currentState = ScriptUnitState.Breaking; PublishEvent(new ScriptUnitStateEvent(this, currentState)); //break! //wait for resume event (or abort as we could want to abort while debugging) int eventIndex = AutoResetEvent.WaitAny(new WaitHandle[] { resumeEvent, abortEvent }); if (eventIndex == 1) { abort = true; } else if (eventIndex == 0) { breaking = false; currentState = ScriptUnitState.Running; PublishEvent(new ScriptUnitStateEvent(this, currentState)); } } } if (abort) { breakEvent.Reset(); requestBreakEvent.Reset(); currentState = ScriptUnitState.Aborting; PublishEvent(new ScriptUnitStateEvent(this, currentState)); throw new PythonScriptUnitAbortException(); } return(traceDelegate); }