internal TraceBackFrame(PythonTracebackListener traceAdapter, FunctionCode code, TraceBackFrame back, PythonDebuggingPayload debugProperties, Func <IDictionary <object, object> > scopeCallback) { _traceAdapter = traceAdapter; _code = code; _back = back; _debugProperties = debugProperties; _scopeCallback = scopeCallback; }
internal TraceBackFrame(CodeContext /*!*/ context, PythonDictionary globals, object locals, FunctionCode code, TraceBackFrame back) { _globals = globals; _locals = locals; _code = code; _context = context; _back = back; }
public static object default_int_handlerImpl(int signalnum, TraceBackFrame frame) { throw new KeyboardInterruptException(""); }
private static TracebackDelegate PythonTrace(TraceBackFrame frame, string result, object payload) { if(me != null) me.TraceCallback(frame, result, payload); return PythonTrace; }
private void TraceCallback(TraceBackFrame frame, string result, object payload) { if (result == "exception") { System.Diagnostics.Trace.WriteLine("On line " + frame.f_lineno.ToString()); } linenum = (int)frame.f_lineno - 1; stdoutwriter.Flush(); stdout.Seek(0, SeekOrigin.Begin); string output = stdoutreader.ReadToEnd(); stdout.Seek(0, SeekOrigin.Begin); stdout.SetLength(0); if (output.Length > 0) { this.BeginInvoke(new Action(() => { scriptOutput.Text += output; })); } }
public void OnTraceEvent(Debugging.TraceEventKind kind, string name, string sourceFileName, SourceSpan sourceSpan, Func<IDictionary<object, object>> scopeCallback, object payload, object customPayload) { if (kind == Debugging.TraceEventKind.ThreadExit || // We don't care about thread-exit events #if PROFILER_SUPPORT (_profile && kind == Debugging.TraceEventKind.TracePoint) || // Ignore code execute tracebacks when in profile mode #endif kind == Debugging.TraceEventKind.ExceptionUnwind) { // and we always have a try/catch so we don't care about methods unwinding. return; } TracebackDelegate traceDispatch = null; object traceDispatchObject = null; var thread = PythonOps.GetFunctionStack(); TraceBackFrame pyFrame; if (InTraceBack) { return; } try { if (kind == Debugging.TraceEventKind.FrameEnter) { traceDispatch = _globalTraceDispatch; traceDispatchObject = _globalTraceObject; var properties = (PythonDebuggingPayload)customPayload; // push the new frame pyFrame = new TraceBackFrame( this, properties.Code, thread.Count == 0 ? null : thread[thread.Count - 1].Frame, properties, scopeCallback ); thread.Add(new FunctionStack(pyFrame)); if (traceDispatchObject == null) { return; } pyFrame.Setf_trace(traceDispatchObject); } else { if (thread.Count == 0) { return; } pyFrame = thread[thread.Count - 1].Frame; if (pyFrame == null) { // force creation of the Python frame pyFrame = SysModule._getframeImpl(thread[thread.Count - 1].Context, 0); } traceDispatch = pyFrame.TraceDelegate; traceDispatchObject = pyFrame.Getf_trace(); } // Update the current line if (kind != Debugging.TraceEventKind.FrameExit) { pyFrame._lineNo = sourceSpan.Start.Line; } if (traceDispatchObject != null && !_exceptionThrown) { DispatchTrace(thread, kind, payload, traceDispatch, traceDispatchObject, pyFrame); } } finally { if (kind == Debugging.TraceEventKind.FrameExit && thread.Count > 0) { // don't pop frames we didn't push if (thread[thread.Count - 1].Code == ((PythonDebuggingPayload)customPayload).Code) { thread.RemoveAt(thread.Count - 1); } } } }
private void DispatchTrace(List<FunctionStack> thread, Debugging.TraceEventKind kind, object payload, TracebackDelegate traceDispatch, object traceDispatchObject, TraceBackFrame pyFrame) { object args = null; // Prepare the event string traceEvent = String.Empty; switch (kind) { case Debugging.TraceEventKind.FrameEnter: traceEvent = "call"; break; case Debugging.TraceEventKind.TracePoint: traceEvent = "line"; break; case Debugging.TraceEventKind.Exception: traceEvent = "exception"; object pyException = PythonExceptions.ToPython((Exception)payload); object pyType = ((IPythonObject)pyException).PythonType; args = PythonTuple.MakeTuple(pyType, pyException, new TraceBack(null, pyFrame)); break; case Debugging.TraceEventKind.FrameExit: traceEvent = "return"; args = payload; break; } bool traceDispatchThrew = true; InTraceBack = true; try { TracebackDelegate dlg = traceDispatch(pyFrame, traceEvent, args); traceDispatchThrew = false; pyFrame.Setf_trace(dlg); } finally { InTraceBack = false; if (traceDispatchThrew) { // We're matching CPython's behavior here. If the trace dispatch throws any exceptions // we don't re-enable tracebacks. We need to leave the trace callback in place though // so that we can pop our frames. _globalTraceObject = _globalTraceDispatch = null; _exceptionThrown = true; } } }
private TracebackDelegate OnTracebackReceived(TraceBackFrame frame, string result, object payload) { //WriteResult(result); switch (this.CurrentDebugMode) { case DebugMode.StepInto: break; case DebugMode.SetpOver: if (result == "call") return null; break; case DebugMode.StepOut: if (result == "call") return null; else if (result == "line") return this.OnTracebackReceived; break; default: throw new InvalidOperationException(); } this.BeginInvoke(_tracebackAction, frame, result, payload); _dbgContinue.WaitOne(); return this.OnTracebackReceived; }
internal TraceBackFrame(PythonTracebackListener traceAdapter, FunctionCode code, TraceBackFrame back, PythonDebuggingPayload debugProperties, Func<IDictionary<object, object>> scopeCallback) { _traceAdapter = traceAdapter; _code = code; _back = back; _debugProperties = debugProperties; _scopeCallback = scopeCallback; }
internal TraceBackFrame(CodeContext/*!*/ context, PythonDictionary globals, object locals, FunctionCode code, TraceBackFrame back) { _globals = globals; _locals = locals; _code = code; _context = context; _back = back; }
public void OnTraceEvent(Debugging.TraceEventKind kind, string name, string sourceFileName, SourceSpan sourceSpan, Func<IAttributesCollection> scopeCallback, object payload, object customPayload) { if (kind == Debugging.TraceEventKind.ThreadExit || // We don't care about thread-exit events #if PROFILER_SUPPORT (_profile && kind == Debugging.TraceEventKind.TracePoint) || // Ignore code execute tracebacks when in profile mode #endif kind == Debugging.TraceEventKind.ExceptionUnwind) { // and we always have a try/catch so we don't care about methods unwinding. return; } TracebackDelegate traceDispatch = null; object traceDispatchObject = null; TraceThread thread = GetOrCreateThread(); TraceBackFrame pyFrame; try { if (kind == Debugging.TraceEventKind.FrameEnter) { traceDispatch = _globalTraceDispatch; traceDispatchObject = _globalTraceObject; /* if (thread.Frames.Count == 1 && traceDispatch != null) { // Dispatch "line" trace for <module> frame DispatchTrace(thread, Debugging.TraceEventKind.FrameEnter, null, _globalTraceDispatch, thread.Frames.Peek()); }*/ var properties = (PythonDebuggingPayload)customPayload; // push the new frame pyFrame = new TraceBackFrame( this, properties.Code, thread.Frames.Count == 0 ? null : thread.Frames[thread.Frames.Count - 1], properties, scopeCallback ); thread.Frames.Add(pyFrame); pyFrame.Setf_trace(traceDispatchObject); } else { if (thread.Frames.Count == 0) { return; } pyFrame = thread.Frames[thread.Frames.Count - 1]; traceDispatch = pyFrame.TraceDelegate; traceDispatchObject = pyFrame.Getf_trace(); } // Update the current line if (kind != Debugging.TraceEventKind.FrameExit) { pyFrame._lineNo = sourceSpan.Start.Line; } if (traceDispatchObject != null && !_exceptionThrown) { DispatchTrace(thread, kind, payload, traceDispatch, traceDispatchObject, pyFrame); } } finally { if (kind == Debugging.TraceEventKind.FrameExit && thread.Frames.Count > 0) { thread.Frames.RemoveAt(thread.Frames.Count - 1); } } }
private TracebackDelegate OnTracebackReceived(TraceBackFrame frame, string result, object payload) { if (breaktrace) { this.Dispatcher.BeginInvoke(_tracebackAction, frame, result, payload); _dbgContinue.WaitOne(); return _traceback; } else return null; }
private void OnTraceback(TraceBackFrame frame, string result, object payload) { var code = (FunctionCode)frame.f_code; if (_curCode == null || _curCode.co_filename != code.co_filename) { _source.Inlines.Clear(); foreach (var line in System.IO.File.ReadAllLines(code.co_filename)) { _source.Inlines.Add(new Run(line + "\r\n")); } } _curFrame = frame; _curCode = code; _curResult = result; _curPayload = payload; switch (result) { case "call": TracebackCall(); break; case "line": TracebackLine(); break; case "return": TracebackReturn(); break; default: MessageBox.Show(string.Format("{0} not supported!", result)); break; } }
internal TraceBackFrame(CodeContext/*!*/ context, object globals, object locals, object code, TraceBackFrame back) { _globals = globals; _locals = locals; _code = code; _context = context; _back = back; }
public TraceBack(TraceBack nextTraceBack, TraceBackFrame fromFrame) { _next = nextTraceBack; _frame = fromFrame; }
public TraceBack(TraceBack nextTraceBack, TraceBackFrame fromFrame) { _next = nextTraceBack; _frame = fromFrame; }
public static TracebackDelegate OnTraceback(TraceBackFrame frame, string result, object payload) { FunctionCode code = (FunctionCode)frame.f_code; if (result == "exception") { if (frame != lastFrame) { int line_no = (int)frame.f_lineno; String module_name = code.co_filename.Replace(".py", ""); String line = "Unknown"; try { line = System.IO.File.ReadAllLines(code.co_filename)[line_no - 1].Replace("\t", ""); } catch { // GET MODULE CODE if (module_name != "<string>") { GameVersion version = db.Versions.Find(loadedModules[module_name]); String moduleCode = version.PythonScript; string[] lines = moduleCode.Split(new string[] { "\n" }, StringSplitOptions.None); line = lines[line_no - 1].Replace("\t", ""); } } PythonTuple tuple = (PythonTuple)payload; PythonType type = (PythonType)tuple[0]; stackTrace.Push(new StackContext { Line = line_no, Code = line, Exception = PythonType.Get__name__(type), Function = code.co_name, FileName = code.co_filename }); } lastFrame = frame; } if (result == "line") { stackTrace = new Stack<StackContext>(); } return PythonScriptEngine.OnTraceback; }