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(); } }
// not enabled because we don't yet support tracing built-in functions. Doing so is a little // difficult because it's hard to flip tracing on/off for them w/o a perf overhead in the // non-profiling case. public static void setprofile(CodeContext /*!*/ context, TracebackDelegate o) { PythonContext pyContext = PythonContext.GetContext(context); pyContext.EnsureDebugContext(); if (o == null) { pyContext.UnregisterTracebackHandler(); } else { pyContext.RegisterTracebackHandler(); } // Register the trace func with the listener pyContext.TracebackListener.SetProfile(o); }