Ejemplo n.º 1
0
        private void HandleThreadFrameList(Socket socket)
        {
            // list of thread frames
            var frames = new List <PythonStackFrame>();
            int tid    = socket.ReadInt();
            var thread = _threads[tid];

            int frameCount = socket.ReadInt();

            for (int i = 0; i < frameCount; i++)
            {
                int    startLine = socket.ReadInt();
                int    endLine   = socket.ReadInt();
                int    lineNo    = socket.ReadInt();
                string frameName = socket.ReadString();
                string filename  = socket.ReadString();
                int    argCount  = socket.ReadInt();
                int    varCount  = socket.ReadInt();
                PythonEvaluationResult[] variables = new PythonEvaluationResult[varCount];
                var frame = new PythonStackFrame(thread, frameName, filename, startLine, endLine, lineNo, argCount, i);
                for (int j = 0; j < variables.Length; j++)
                {
                    string name = socket.ReadString();
                    variables[j] = ReadPythonObject(socket, name, "", false, frame);
                }
                frame.SetVariables(variables);
                frames.Add(frame);
            }

            Debug.WriteLine("Received frames for thread {0}", tid);
            _frames = frames;
            _frameEvent.Set();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a PythonObject for an expression which raised an exception instead of returning a value.
 /// </summary>
 public PythonEvaluationResult(PythonProcess process, string exceptionText, string expression, PythonStackFrame frame)
 {
     _process       = process;
     _expression    = expression;
     _frame         = frame;
     _exceptionText = exceptionText;
 }
Ejemplo n.º 3
0
        internal static string ReformatStackTrace(PythonProcess process, string data)
        {
            var lines = new Stack <IEnumerable <string> >();
            var sb    = new StringBuilder();

            using (var reader = new StringReader(data)) {
                for (var line = reader.ReadLine(); line != null; line = reader.ReadLine())
                {
                    lines.Push(SplitReprs(line).ToArray());
                }
            }

            foreach (var line in lines)
            {
                var filename     = line.ElementAtOrDefault(0);
                var lineNumber   = line.ElementAtOrDefault(1);
                var functionName = line.ElementAtOrDefault(2);
                //var text = stackLine.ElementAtOrDefault(3);

                int lineNo;
                if (process != null &&
                    !string.IsNullOrEmpty(filename) &&
                    !string.IsNullOrEmpty(lineNumber) &&
                    int.TryParse(lineNumber, out lineNo) &&
                    !string.IsNullOrEmpty(functionName))
                {
                    functionName = PythonStackFrame.GetQualifiedFunctionName(process, filename, lineNo, functionName);
                }

                if (!string.IsNullOrEmpty(filename))
                {
                    sb.Append(filename);
                    if (!string.IsNullOrEmpty(lineNumber))
                    {
                        sb.Append(":");
                        sb.Append(lineNumber);
                    }
                    sb.Append(" in ");
                }

                if (string.IsNullOrEmpty(functionName))
                {
                    sb.AppendLine("<unknown>");
                }
                else
                {
                    sb.AppendLine(functionName);
                }
            }

            while (sb.Length > 0 && char.IsWhiteSpace(sb[sb.Length - 1]))
            {
                sb.Length -= 1;
            }

            return(sb.ToString());
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a PythonObject for an expression which successfully returned a value.
 /// </summary>
 public PythonEvaluationResult(PythonProcess process, string objRepr, string hexRepr, string typeName, long length, string expression, string childName, PythonStackFrame frame, PythonEvaluationResultFlags flags) {
     _process = process;
     _objRepr = objRepr;
     _hexRepr = hexRepr;
     _typeName = typeName;
     _length = length;
     _expression = expression;
     _childName = childName;
     _frame = frame;
     _flags = flags;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a PythonObject for an expression which successfully returned a value.
 /// </summary>
 public PythonEvaluationResult(PythonProcess process, string objRepr, string typeName, string expression, string childText, bool childIsIndex, PythonStackFrame frame, bool isExpandable)
 {
     _process      = process;
     _expression   = expression;
     _frame        = frame;
     _objRepr      = objRepr;
     _typeName     = typeName;
     _isExpandable = isExpandable;
     _childText    = childText;
     _childIsIndex = childIsIndex;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a PythonObject for an expression which successfully returned a value.
 /// </summary>
 public PythonEvaluationResult(PythonProcess process, string objRepr, string hexRepr, string typeName, long length, string expression, string childName, PythonStackFrame frame, PythonEvaluationResultFlags flags)
 {
     _process    = process;
     _objRepr    = objRepr;
     _hexRepr    = hexRepr;
     _typeName   = typeName;
     _length     = length;
     _expression = expression;
     _childName  = childName;
     _frame      = frame;
     _flags      = flags;
 }
Ejemplo n.º 7
0
        internal void EnumChildren(string text, PythonStackFrame pythonStackFrame, Action <PythonEvaluationResult[]> completion)
        {
            DebugWriteCommand("Enum Children");
            _socket.Send(GetChildrenCommandBytes);
            SendString(_socket, text);
            int executeId = _ids.Allocate();

            lock (_pendingChildEnums) {
                _socket.Send(BitConverter.GetBytes(pythonStackFrame.Thread.Id));
                _socket.Send(BitConverter.GetBytes(pythonStackFrame.FrameId));
                _socket.Send(BitConverter.GetBytes(executeId));
                _pendingChildEnums[executeId] = new ChildrenInfo(completion, text, pythonStackFrame);
            }
        }
Ejemplo n.º 8
0
        internal bool SetLineNumber(PythonStackFrame pythonStackFrame, int lineNo)
        {
            DebugWriteCommand("Set Line Number");
            _setLineResult = false;
            _socket.Send(SetLineNumberCommand);
            _socket.Send(BitConverter.GetBytes(pythonStackFrame.Thread.Id));
            _socket.Send(BitConverter.GetBytes(pythonStackFrame.FrameId));
            _socket.Send(BitConverter.GetBytes(lineNo));

            // wait up to 2 seconds for line event...
            for (int i = 0; i < 20 &&
                 _socket.Connected &&
                 WaitForSingleObject(_frameEvent.SafeWaitHandle, 100) != 0; i++)
            {
            }

            return(_setLineResult);
        }
Ejemplo n.º 9
0
 public ChildrenInfo(Action<PythonEvaluationResult[]> completion, string text, PythonStackFrame frame) {
     Completion = completion;
     Text = text;
     Frame = frame;
 }
Ejemplo n.º 10
0
        internal bool SetLineNumber(PythonStackFrame pythonStackFrame, int lineNo) {
            if (_stoppedForException) {
                return false;
            }

            DebugWriteCommand("Set Line Number");
            lock (_streamLock) {
                _setLineResult = false;
                _stream.Write(SetLineNumberCommand);
                _stream.WriteInt64(pythonStackFrame.Thread.Id);
                _stream.WriteInt32(pythonStackFrame.FrameId);
                _stream.WriteInt32(lineNo);
            }

            // wait up to 2 seconds for line event...
            for (int i = 0; i < 20 && _stream != null; i++) {
                if (NativeMethods.WaitForSingleObject(_lineEvent.SafeWaitHandle, 100) == 0) {
                    break;
                }
            }

            return _setLineResult;
        }
Ejemplo n.º 11
0
        internal void EnumChildren(string text, PythonStackFrame pythonStackFrame, Action<PythonEvaluationResult[]> completion) {
            DebugWriteCommand("Enum Children");
            int executeId = _ids.Allocate();
            lock (_pendingChildEnums) {
                _pendingChildEnums[executeId] = new ChildrenInfo(completion, text, pythonStackFrame);
            }

            lock (_streamLock) {
                _stream.Write(GetChildrenCommandBytes);
                _stream.WriteString(text);
                _stream.WriteInt64(pythonStackFrame.Thread.Id);
                _stream.WriteInt32(pythonStackFrame.FrameId);
                _stream.WriteInt32(executeId);
                _stream.WriteInt32((int)pythonStackFrame.Kind);
            }
        }
Ejemplo n.º 12
0
        internal void ExecuteText(string text, PythonEvaluationResultReprKind reprKind, PythonStackFrame pythonStackFrame, Action<PythonEvaluationResult> completion) {
            int executeId = _ids.Allocate();
            DebugWriteCommand("ExecuteText to thread " + pythonStackFrame.Thread.Id + " " + executeId);
            lock (_pendingExecutes) {
                _pendingExecutes[executeId] = new CompletionInfo(completion, text, pythonStackFrame);
            }

            lock (_streamLock) {
                _stream.Write(ExecuteTextCommandBytes);
                _stream.WriteString(text);
                _stream.WriteInt64(pythonStackFrame.Thread.Id);
                _stream.WriteInt32(pythonStackFrame.FrameId);
                _stream.WriteInt32(executeId);
                _stream.WriteInt32((int)pythonStackFrame.Kind);
                _stream.WriteInt32((int)reprKind);
            }
        }
Ejemplo n.º 13
0
 internal void SwitchFrame(PythonStackFrame frame) {
     _frameId = frame.FrameId;
     _thread?.SetThreadAndFrameCommand(frame.Thread.Id, frame.FrameId, frame.Kind);
     WriteOutput(string.Format("Current frame changed to {0}", frame.FrameId));
 }
Ejemplo n.º 14
0
 public ChildrenInfo(Action <PythonEvaluationResult[]> completion, string text, PythonStackFrame frame)
 {
     Completion = completion;
     Text       = text;
     Frame      = frame;
 }
Ejemplo n.º 15
0
        private PythonEvaluationResult ReadPythonObject(Stream stream, string expr, string childName, PythonStackFrame frame) {
            string objRepr = stream.ReadString();
            string hexRepr = stream.ReadString();
            string typeName = stream.ReadString();
            long length = stream.ReadInt64();
            var flags = (PythonEvaluationResultFlags)stream.ReadInt32();

            if (!flags.HasFlag(PythonEvaluationResultFlags.Raw) && ((typeName == "unicode" && LanguageVersion.Is2x()) || (typeName == "str" && LanguageVersion.Is3x()))) {
                objRepr = objRepr.FixupEscapedUnicodeChars();
            }

            if (typeName == "bool") {
                hexRepr = null;
            }

            return new PythonEvaluationResult(this, objRepr, hexRepr, typeName, length, expr, childName, frame, flags);
        }
Ejemplo n.º 16
0
        private void HandleThreadFrameList(Stream stream) {
            // list of thread frames
            var frames = new List<PythonStackFrame>();
            long tid = stream.ReadInt64();
            PythonThread thread;
            _threads.TryGetValue(tid, out thread);
            var threadName = stream.ReadString();

            int frameCount = stream.ReadInt32();
            for (int i = 0; i < frameCount; i++) {
                int startLine = stream.ReadInt32();
                int endLine = stream.ReadInt32();
                int lineNo = stream.ReadInt32();
                string frameName = stream.ReadString();
                string filename = stream.ReadString();
                int argCount = stream.ReadInt32();
                var frameKind = (FrameKind)stream.ReadInt32();
                PythonStackFrame frame = null; 
                if (thread != null) {
                    switch (frameKind) {
                        case FrameKind.Django:
                            string sourceFile = stream.ReadString();
                            var sourceLine = stream.ReadInt32();
                            frame = new DjangoStackFrame(thread, frameName, filename, startLine, endLine, lineNo, argCount, i, sourceFile, sourceLine);
                            break;
                        default:
                            frame = new PythonStackFrame(thread, frameName, filename, startLine, endLine, lineNo, argCount, i, frameKind);
                            break;
                    }
                    
                }

                int varCount = stream.ReadInt32();
                PythonEvaluationResult[] variables = new PythonEvaluationResult[varCount];
                for (int j = 0; j < variables.Length; j++) {
                    string name = stream.ReadString();
                    if (frame != null) {
                        variables[j] = ReadPythonObject(stream, name, name, frame);
                    }
                }
                if (frame != null) {
                    frame.SetVariables(variables);
                    frames.Add(frame);
                }
            }

            Debug.WriteLine("Received frames for thread {0}", tid);
            if (thread != null) {
                thread.Frames = frames;
                if (threadName != null) {
                    thread.Name = threadName;
                }
            }
        }
Ejemplo n.º 17
0
 internal void SwitchFrame(PythonStackFrame frame) {
     _frameId = frame.FrameId;
     SetThreadAndFrameCommand(frame.Thread.Id, frame.FrameId, frame.Kind);
     Window.WriteLine(String.Format("Current frame changed to {0}", frame.FrameId));
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Creates a PythonObject for an expression which raised an exception instead of returning a value.
 /// </summary>
 public PythonEvaluationResult(PythonProcess process, string exceptionText, string expression, PythonStackFrame frame) {
     _process = process;
     _expression = expression;
     _frame = frame;
     _exceptionText = exceptionText;
 }
Ejemplo n.º 19
0
        private PythonEvaluationResult ReadPythonObject(Socket socket, string text, string childText, bool childIsIndex, PythonStackFrame frame)
        {
            string objRepr      = socket.ReadString();
            string typeName     = socket.ReadString();
            bool   isExpandable = socket.ReadInt() == 1;

            return(new PythonEvaluationResult(this, objRepr, typeName, text, childText, childIsIndex, frame, isExpandable));
        }