public static void settrace(CodeContext /*!*/ context, object o) { PythonContext pyContext = PythonContext.GetContext(context); pyContext.EnsureDebugContext(); if (o == null) { pyContext.UnregisterTracebackHandler(); PythonTracebackListener.SetTrace(null, null); } else { // We're following CPython behavior here. // If CurrentPythonFrame is not null then we're currently inside a traceback, and // enabling trace while inside a traceback is only allowed through sys.call_tracing() var pyThread = PythonOps.GetFunctionStackNoCreate(); if (pyThread == null || !PythonTracebackListener.InTraceBack) { pyContext.PushTracebackHandler(new PythonTracebackListener((PythonContext)context.LanguageContext)); pyContext.RegisterTracebackHandler(); PythonTracebackListener.SetTrace(o, (TracebackDelegate)Converter.ConvertToDelegate(o, typeof(TracebackDelegate))); } } }
public static void call_tracing(CodeContext /*!*/ context, object func, PythonTuple args) { PythonContext pyContext = (PythonContext)context.LanguageContext; pyContext.EnsureDebugContext(); pyContext.UnregisterTracebackHandler(); pyContext.PushTracebackHandler(new PythonTracebackListener((PythonContext)context.LanguageContext)); pyContext.RegisterTracebackHandler(); try { PythonCalls.Call(func, args.ToArray()); } finally { pyContext.PopTracebackHandler(); pyContext.UnregisterTracebackHandler(); } }