Пример #1
0
        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;
                    scriptOutput.SelectionStart = scriptOutput.TextLength;
                    scriptOutput.ScrollToCaret();
                }));
            }
        }
Пример #2
0
        private TracebackDelegate traceHook(TraceBackFrame frame, string result, object payload)
        {
            this._executionStatus = ExecutionStatus.InternalTrace;
            checkDebuggerStop();

            var info = DebugInfo.Create(frame, this);

            checkDebuggerPause(info);
            _onTrace?.Invoke(info);

            if (next_action == DebugAction.StepInto)
            {
                this._executionStatus = ExecutionStatus.Running;
                return(traceHook);
            }
            else if (next_action == DebugAction.StepOver)
            {
                this._executionStatus = ExecutionStatus.Running;
                return(null);
            }
            else if (next_action == DebugAction.StepOut)
            {
                this._executionStatus = ExecutionStatus.Running;
                return(traceHook);
            }

            this._executionStatus = ExecutionStatus.Running;
            return(traceHook);
        }
Пример #3
0
        private TracebackDelegate OnTracebackReceived(TraceBackFrame frame, string result, object payload)
        {
            if (TracebackEvent != null)
            {
                bool NotMyCode = frame.f_code.co_filename != Path;

                if (JMC & NotMyCode)
                {
                    Console.WriteLine("Skip");
                    return(OnTracebackReceived);
                }
                IPYTracebackEventArgs args = new IPYTracebackEventArgs();
                args.frame   = frame;
                args.result  = result;
                args.payload = payload;
                try
                {
                    //Console.WriteLine(String.Format("{0},{1},{2}",frame,result,payload));
                    TracebackEvent(this, args);
                }catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
            WaitInput();
            return(OnTracebackReceived);
        }
Пример #4
0
        internal static TraceBackFrame /*!*/ _getframeImpl(CodeContext /*!*/ context, int depth, List <FunctionStack> stack)
        {
            if (depth < stack.Count)
            {
                TraceBackFrame cur = null;

                for (int i = 0; i < stack.Count - depth; i++)
                {
                    var elem = stack[i];

                    if (elem.Frame != null)
                    {
                        // we previously handed out a frame here, hand out the same one now
                        cur = elem.Frame;
                    }
                    else
                    {
                        // create a new frame and save it for future calls
                        cur = new TraceBackFrame(
                            context,
                            Builtin.globals(elem.Context),
                            Builtin.locals(elem.Context),
                            elem.Code,
                            cur
                            );

                        stack[i] = new FunctionStack(elem.Context, elem.Code, cur);
                    }
                }
                return(cur);
            }

            throw PythonOps.ValueError("call stack is not deep enough");
        }
Пример #5
0
 private static TracebackDelegate PythonTrace(TraceBackFrame frame, string result, object payload)
 {
     if (me != null)
     {
         me.TraceCallback(frame, result, payload);
     }
     return(PythonTrace);
 }
Пример #6
0
 public BreakPoint(TraceBackFrame frame)
 {
     FunctionName = frame.f_code.co_name;
     Path         = frame.f_code.co_filename.ToLower();
     Line         = (int)frame.f_lineno;
     _span        = frame.f_code.Span;
     _backFrame   = frame.f_back;
 }
Пример #7
0
        private TracebackDelegate traceHook(TraceBackFrame frame, string result, object payload)
        {
            //TODO: better management of this hook quirk: first trace is always a call; we miss the first line hook
            if (result == "call" && _first)
            {
                result = "line";
                _first = false;
            }

            this._executionStatus = ExecutionStatus.InternalTrace;
            checkDebuggerStop();

            //temp: log on output
            execOutput.WriteLine(result + " line=" + frame.f_lineno.ToString());

            //send trace to client
            var info = DebugInfo.Create(frame, this);

            _onTrace?.Invoke(info);

            if (result == "call")
            {
                TraceDepth++;
            }
            if (result == "return")
            {
                TraceDepth--;
            }

            //decide whether we must pause execution and return control to client ide
            var must_pause = request_pause;

            if (debugger_action == DebugAction.StepInto)
            {
                must_pause = true;
            }
            else if (debugger_action == DebugAction.StepOver && TraceDepth <= DebugDepth)
            {
                must_pause = true;
            }
            else if (debugger_action == DebugAction.StepOut)
            {
            }
            else if (_onCheckBreakpoint?.Invoke(info.CurrentLine) != null)
            {
                must_pause = true;
            }

            //
            if (must_pause)
            {
                debuggerStepPause(info);
            }

            this._executionStatus = ExecutionStatus.Running;
            return(traceHook);
        }
Пример #8
0
 public TracebackDelegate OnTraceback(TraceBackFrame frame, string result, object payload)
 {
     var code = (FunctionCode)frame.f_code;
     if (result == "call")
     {
         Program.GameMess.GameDebug("[{0}:{1}]{2}", code.co_filename, (int)frame.f_lineno, code.co_name);
     }
     return this.OnTraceback;
 }
Пример #9
0
        internal static DebugInfo Create(TraceBackFrame frame, ExecutionContext executionScope)
        {
            var info = new DebugInfo();

            info.CurrentLine    = (int)frame.f_lineno;
            info.ExecutionScope = executionScope;
            info.FunctionName   = frame.f_code.ToString();
            info.IsError        = false;
            return(info);
        }
Пример #10
0
        public TracebackDelegate Trace(TraceBackFrame frame, string result, object payload)
        {
            if (Enabled)
            {
                var bt = new BreakPoint(frame);
                if (_mainpoint != null && _mainpoint.BackPoint.Equals(bt))
                {
                    Status     = StatusType.Start;
                    _mainpoint = null;
                }
                else if (!bt.Path.StartsWith("<"))
                {
                    switch (Status)
                    {
                    case StatusType.Start:
                        if (_mainpoint == null)
                        {
                            if (bt.Path.StartsWith(Workspace))
                            {
                                _mainpoint = bt;
                                Wait(frame, result, payload);
                                break;
                            }
                        }
                        break;

                    case StatusType.Continue:
                        if (_points.ContainsKey(bt.Path) && _points[bt.Path].Contains(bt))
                        {
                            Wait(frame, result, payload);
                        }
                        break;

                    case StatusType.SetpIn:
                        Wait(frame, result, payload);
                        break;

                    case StatusType.SetpOut:
                        if (bt.Equals(_currpoint.BackPoint))
                        {
                            Wait(frame, result, payload);
                        }
                        break;

                    case StatusType.Next:
                        if (bt.IsNext(_currpoint))
                        {
                            Wait(frame, result, payload);
                        }
                        break;
                    }
                }
            }
            return(Trace);
        }
Пример #11
0
        public static ValueTree GetValues(TraceBackFrame frame)
        {
            Scope  = Engine.Instance.CreateScope();
            _maxid = 0;
            _root  =
                new ValueTree(".", true, true)
            {
                new ValueTree("Globals", true, true),
                new ValueTree("Locals", true, true)
            };
            if (frame.f_globals != null)
            {
                foreach (var kv in frame.f_globals)
                {
                    string name  = kv.Key.ToString();
                    object value = kv.Value;
                    _root[0].Add(ValueBase.GetValue(name, value));
                    if (value != null)
                    {
                        Scope.SetVariable(name, value);
                    }
                }
            }

            if (frame.f_locals != null)
            {
                var dict = (PythonDictionary)frame.f_locals;
                foreach (var kv in (PythonDictionary)frame.f_locals)
                {
                    string  name  = kv.Key.ToString();
                    dynamic value = kv.Value;
                    if (value is ClosureCell)
                    {
                        if (name.EndsWith("1"))
                        {
                            var rname = name.Substring(0, name.Length - 1);
                            if (dict.keys().Cast <string>().Contains(rname))
                            {
                                name = rname;
                            }
                        }
                        try { value = value.cell_contents; }
                        catch { value = null; }
                        _root[1].Add(ValueBase.GetValue(name, value));
                        if (value != null)
                        {
                            Scope.SetVariable(name, value);
                        }
                    }
                }
            }
            return(_root);
        }
 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);
     }
 }
Пример #13
0
        private TracebackDelegate OnTracebackReceived(TraceBackFrame frame, string result, object payload)
        {
            if (mBreaktrace)
            {
                Invoke((MethodInvoker) delegate { OnTraceback(frame, result, payload); });

                while (!mDbgContinue.WaitOne(10))
                {
                    Application.DoEvents();
                }

                return(mTraceback);
            }
            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;
            }
        }
Пример #15
0
        private void OnTraceback(TraceBackFrame frame, string result, object payload)
        {
            var code = (FunctionCode)frame.f_code;

            if (mCurCode == null || mCurCode.co_filename != code.co_filename)
            {
                sDoc.Clear();

                if (File.Exists(code.co_filename))
                {
                    sDoc.Lines = File.ReadAllLines(code.co_filename);
                }
            }

            mCurFrame   = frame;
            mCurCode    = code;
            mCurResult  = result;
            mCurPayload = 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;
            }
        }
Пример #16
0
        private void Wait(TraceBackFrame frame, string result, object payload)
        {
            _currpoint = new BreakPoint(frame);

            var pt = _currpoint;

            _frames = new List <StackFrame>();
            int i = 1000;

            while (pt != null)
            {
                var path = pt.Path;
                _frames.Add(
                    new StackFrame
                {
                    Id     = i++,
                    Name   = pt.FunctionName,
                    Line   = pt.Line,
                    Source = new Source {
                        Name = Path.GetFileName(path), Path = path
                    }
                });
                pt = pt.BackPoint;
            }

            _values = ValueTree.GetValues(frame);

            Status = StatusType.Wait;
            Stop(StoppedEvent.ReasonValue.Step);
            _resetEvent.WaitOne();

            if (Status == StatusType.Stop)
            {
                throw new System.Exception("调试中断!");
            }
        }
Пример #17
0
        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);
        }
Пример #18
0
        public static void warn(CodeContext context, object message, PythonType category = null, int stacklevel = 1)
        {
            PythonContext pContext = context.LanguageContext;
            List          argv     = pContext.GetSystemStateValue("argv") as List;

            if (PythonOps.IsInstance(message, PythonExceptions.Warning))
            {
                category = DynamicHelpers.GetPythonType(message);
            }
            if (category == null)
            {
                category = PythonExceptions.UserWarning;
            }
            if (!category.IsSubclassOf(PythonExceptions.Warning))
            {
                throw PythonOps.ValueError("category is not a subclass of Warning");
            }

            TraceBackFrame   caller = null;
            PythonDictionary globals;
            int lineno;

            if (context.LanguageContext.PythonOptions.Frames)
            {
                try {
                    caller = SysModule._getframeImpl(context, stacklevel - 1);
                } catch (ValueErrorException) { }
            }
            if (caller == null)
            {
                globals = Builtin.globals(context) as PythonDictionary;
                lineno  = 1;
            }
            else
            {
                globals = caller.f_globals;
                lineno  = (int)caller.f_lineno;
            }

            string module;
            string filename;

            if (globals != null && globals.ContainsKey("__name__"))
            {
                module = (string)globals.get("__name__");
            }
            else
            {
                module = "<string>";
            }

            filename = globals.get("__file__") as string;
            if (filename == null || filename == "")
            {
                if (module == "__main__")
                {
                    if (argv != null && argv.Count > 0)
                    {
                        filename = argv[0] as string;
                    }
                    else
                    {
                        // interpreter lacks sys.argv
                        filename = "__main__";
                    }
                }
                if (filename == null || filename == "")
                {
                    filename = module;
                }
            }

            PythonDictionary registry = (PythonDictionary)globals.setdefault("__warningregistry__", new PythonDictionary());

            warn_explicit(context, message, category, filename, lineno, module, registry, globals);
        }
Пример #19
0
 public static object default_int_handlerImpl(int signalnum, TraceBackFrame frame)
 {
     throw new KeyboardInterruptException("");
 }
Пример #20
0
 private TracebackDelegate OnTracebackReceived(TraceBackFrame frame, string result, object payload)
 {
     System.Console.WriteLine(frame.f_lineno);
     return(OnTracebackReceived);
 }