Ejemplo n.º 1
0
        private void mnuDebug_StepOver_Click(object sender, EventArgs e)
        {
            mTraceback = OnTracebackReceived;

            StartScript();
            ExecuteStep();
        }
Ejemplo n.º 2
0
            internal string Create(TracebackDelegate traceFunc)
            {
                string result = String.Empty;

                try
                {
                    m_pe     = new PythonEngine();
                    m_Engine = m_pe.engine;
                    m_Scope  = m_pe.scope;

                    var pc = Microsoft.Scripting.Hosting.Providers.HostingHelpers.GetLanguageContext(m_Engine) as PythonContext;
                    PythonDictionary hooks = (PythonDictionary)pc.SystemState.Get__dict__()["path_hooks"];
                    hooks.Clear();

                    if (traceFunc != null)
                    {
                        m_Engine.SetTrace(traceFunc);
                    }

                    result = "Created";
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                }

                return(result);
            }
Ejemplo n.º 3
0
            internal string Create(TracebackDelegate traceFunc)
            {
                string result = String.Empty;

                try
                {
                    // none of this adds to the python path but I am leaving it here because there HAS to be a way to do this
                    //Environment.SetEnvironmentVariable("IRONPYTHONPATH", Misc.CurrentScriptDirectory());
                    m_Engine = Python.CreateEngine();
                    //m_Engine.GetService<ExceptionOperations>().FormatException(exception);
                    //ICollection<string> paths = m_Engine.GetSearchPaths();
                    //paths.Add(Misc.CurrentScriptDirectory());
                    //m_Engine.SetSearchPaths(paths);
                    //
                    m_Source = m_Engine.CreateScriptSourceFromString(m_Text);
                    m_Scope  = GetRazorScope(m_Engine);

                    if (traceFunc != null)
                    {
                        m_Engine.SetTrace(traceFunc);
                    }

                    result = "Created";
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                }

                return(result);
            }
Ejemplo n.º 4
0
        private void mnuDebug_StepOut_Click(object sender, EventArgs e)
        {
            mTraceback = null;

            StartScript();
            ExecuteStep();
        }
Ejemplo n.º 5
0
 public void SetTrace(TracebackDelegate func)
 {
     foreach (var ext in Extensions)
     {
         if (ext.Engine != null)
         {
             ext.Engine._engine.SetTrace(func);
         }
     }
 }
Ejemplo n.º 6
0
        internal PythonTracebackListener(PythonContext pythonContext, object traceObject)
        {
            _pythonContext = pythonContext;

            if (traceObject != null)
            {
                _traceObject   = traceObject;
                _traceDispatch = (TracebackDelegate)Converter.ConvertToDelegate(traceObject, typeof(TracebackDelegate));
            }
        }
Ejemplo n.º 7
0
        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, null);
                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;
                }
            }
        }
Ejemplo n.º 8
0
        // 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);
        }
Ejemplo n.º 9
0
            internal string Create(TracebackDelegate traceFunc)
            {
                string result = "";

                try
                {
                    m_Engine = Python.CreateEngine();
                    m_Source = m_Engine.CreateScriptSourceFromString(m_Text);
                    m_Scope  = GetRazorScope(m_Engine);

                    if (traceFunc != null)
                    {
                        m_Engine.SetTrace(traceFunc);
                    }

                    result = "Created";
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                }

                return(result);
            }
        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;
                }
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Enables call tracing for the current thread in this ScriptEngine.
 ///
 /// TracebackDelegate will be called back for each function entry, exit, exception, and line change.
 /// </summary>
 public static void SetTrace(this ScriptEngine /*!*/ engine, TracebackDelegate traceFunc)
 {
     SysModule.settrace(GetPythonContext(engine).SharedContext, traceFunc);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Enables call tracing for the current thread for the Python engine in this ScriptRuntime.
 ///
 /// TracebackDelegate will be called back for each function entry, exit, exception, and line change.
 /// </summary>
 public static void SetTrace(this ScriptRuntime /*!*/ runtime, TracebackDelegate traceFunc)
 {
     SetTrace(GetEngine(runtime), traceFunc);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Enables call tracing for the current thread for the Python engine in this ScriptRuntime.  
 /// 
 /// TracebackDelegate will be called back for each function entry, exit, exception, and line change.
 /// </summary>
 public static void SetTrace(this ScriptRuntime/*!*/ runtime, TracebackDelegate traceFunc) {
     SetTrace(GetEngine(runtime), traceFunc);
 }
Ejemplo n.º 14
0
 public void Setf_trace(object value)
 {
     _traceObject = value;
     _trace = (TracebackDelegate)Converter.ConvertToDelegate(value, typeof(TracebackDelegate));
 }
 private void StepOutExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     _traceback = null;
     ExecuteStep();
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Enables call tracing for the current thread in this ScriptEngine.  
 /// 
 /// TracebackDelegate will be called back for each function entry, exit, exception, and line change.
 /// </summary>
 public static void SetTrace(this ScriptEngine/*!*/ engine, TracebackDelegate traceFunc) {
     SysModule.settrace(GetPythonContext(engine).SharedContext, traceFunc);
 }
Ejemplo n.º 17
0
        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 StepInExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     _traceback = this.OnTracebackReceived;
     ExecuteStep();
 }
 private void StepInExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     _traceback = this.OnTracebackReceived;
     ExecuteStep();
 }
 private void StepOutExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     _traceback = null;
     ExecuteStep();
 }
 internal static void SetTrace(object function, TracebackDelegate traceDispatch) {
     _globalTraceDispatch = traceDispatch;
     _globalTraceObject = function;
 }
Ejemplo n.º 22
0
 public void Deletef_trace() {
     f_trace = null;
 }
Ejemplo n.º 23
0
        private void DispatchTrace(List<FunctionStack> thread, TraceEventKind kind, object payload, TracebackDelegate traceDispatch, object traceDispatchObject, TraceBackFrame toFrame)
        {
            object args = null;

            // Prepare the event
            string traceEvent = String.Empty;
            switch (kind)
            {
                case TraceEventKind.FrameEnter: traceEvent = "call"; break;
                case TraceEventKind.TracePoint: traceEvent = "line"; break;
                case TraceEventKind.Exception: traceEvent = "exception";
                    throw new NotImplementedException();
                case TraceEventKind.FrameExit: traceEvent = "return";
                    args = payload;
                    break;
            }

            bool traceDispatchThrew = true;
            InTraceBack = true;
            try
            {
                TracebackDelegate dlg = traceDispatch(toFrame, traceEvent, args);
                traceDispatchThrew = false;
                toFrame.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;
                }
            }
        }
 internal void SetProfile(TracebackDelegate traceDispatch) {
     _globalTraceDispatch = traceDispatch;
     _profile = true;
 }
Ejemplo n.º 25
0
 internal static void SetTrace(object function, TracebackDelegate traceDispatch)
 {
     _globalTraceDispatch = traceDispatch;
     _globalTraceObject   = function;
 }
Ejemplo n.º 26
0
 public void Setf_trace(object value)
 {
     _traceObject = value;
     _trace       = (TracebackDelegate)Converter.ConvertToDelegate(value, typeof(TracebackDelegate));
 }
Ejemplo n.º 27
0
 internal void SetProfile(TracebackDelegate traceDispatch)
 {
     _globalTraceDispatch = traceDispatch;
     _profile             = true;
 }