Beispiel #1
0
 private void UpdateFrameLocals(PythonStackFrame frame)
 {
     _currentFrameLocals = frame.Locals.Union(frame.Parameters)
                           .Where(r => !string.IsNullOrEmpty(r.Expression))
                           .Select(r => new CompletionResult(r.Expression, Interpreter.PythonMemberType.Field))
                           .ToArray();
 }
 internal void SwitchFrame(PythonStackFrame frame)
 {
     _frameId              = frame.FrameId;
     _currentScopeName     = CurrentFrameScopeFixedName;
     _currentScopeFileName = null;
     WriteOutput(Strings.DebugReplFrameChanged.FormatUI(frame.FrameId));
 }
 /// <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;
 }
Beispiel #4
0
        public AD7StackFrame(AD7Engine engine, AD7Thread thread, PythonStackFrame threadContext) {
            _engine = engine;
            _thread = thread;
            _stackFrame = threadContext;

            _parameters = threadContext.Parameters.ToArray();
            _locals = threadContext.Locals.ToArray();
        }
Beispiel #5
0
        public AD7MemoryAddress(AD7Engine engine, string filename, uint lineno, PythonStackFrame frame = null) {
            _engine = engine;
            _lineNo = (uint)lineno;
            _filename = filename;

            var pos = new TEXT_POSITION { dwLine = lineno, dwColumn = 0 };
            _documentContext = new AD7DocumentContext(filename, pos, pos, this, frame != null ? frame.Kind : FrameKind.None);
        }
Beispiel #6
0
        public AD7StackFrame(AD7Engine engine, AD7Thread thread, PythonStackFrame threadContext)
        {
            _engine     = engine;
            _thread     = thread;
            _stackFrame = threadContext;

            _parameters = threadContext.Parameters.ToArray();
            _locals     = threadContext.Locals.ToArray();
        }
Beispiel #7
0
        public virtual async Task AttachAndStepWithBlankSysPrefix()
        {
            string script = TestData.GetPath(@"TestData\DebuggerProject\InfiniteRunBlankPrefix.py");
            var    p      = Process.Start(Version.InterpreterPath, "\"" + script + "\"");

            try {
                using (var dumpWriter = new MiniDumpWriter(p)) {
                    Thread.Sleep(1000);
                    var proc = PythonProcess.Attach(p.Id);
                    try {
                        var attached = new TaskCompletionSource <bool>();
                        proc.ProcessLoaded += async(sender, args) => {
                            Console.WriteLine("Process loaded");
                            await proc.ResumeAsync(TimeoutToken());

                            attached.SetResult(true);
                        };
                        await proc.StartListeningAsync();

                        await attached.Task.WithTimeout(20000, "Failed to attach within 20s");

                        var              bpHit    = new TaskCompletionSource <bool>();
                        PythonThread     thread   = null;
                        PythonStackFrame oldFrame = null;
                        proc.BreakpointHit += (sender, args) => {
                            Console.WriteLine("Breakpoint hit");
                            thread   = args.Thread;
                            oldFrame = args.Thread.Frames[0];
                            bpHit.SetResult(true);
                        };
                        var bp = proc.AddBreakpoint(script, 6);
                        await bp.AddAsync(TimeoutToken());

                        await bpHit.Task.WithTimeout(20000, "Failed to hit breakpoint within 20s");

                        var stepComplete          = new TaskCompletionSource <bool>();
                        PythonStackFrame newFrame = null;
                        proc.StepComplete += (sender, args) => {
                            newFrame = args.Thread.Frames[0];
                            stepComplete.SetResult(true);
                        };
                        await thread.StepOverAsync(TimeoutToken());

                        await stepComplete.Task.WithTimeout(20000, "Failed to complete the step within 20s");

                        Assert.AreEqual(oldFrame.FileName, newFrame.FileName);
                        Assert.IsTrue(oldFrame.LineNo + 1 == newFrame.LineNo);
                    } finally {
                        await DetachProcessAsync(proc);
                    }

                    dumpWriter.Cancel();
                }
            } finally {
                DisposeProcess(p);
            }
        }
Beispiel #8
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(functionName))
                {
                    functionName = Strings.DebugUnknownFunctionName;
                }

                if (!string.IsNullOrEmpty(filename))
                {
                    sb.AppendLine(string.IsNullOrEmpty(lineNumber)
                                                ? Strings.DebugPythonExceptionStackTraceFileOnly.FormatUI(filename, functionName)
                                                : Strings.DebugPythonExceptionStackTraceFileAndLineNumber.FormatUI(filename, lineNumber, functionName)
                                  );
                }
                else
                {
                    sb.AppendLine(functionName);
                }
            }

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

            return(sb.ToString());
        }
 /// <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;
 }
Beispiel #10
0
        public AD7MemoryAddress(AD7Engine engine, string filename, uint lineno, PythonStackFrame frame = null)
        {
            _engine   = engine;
            _lineNo   = (uint)lineno;
            _filename = filename;

            var pos = new TEXT_POSITION {
                dwLine = lineno, dwColumn = 0
            };

            _documentContext = new AD7DocumentContext(filename, pos, pos, this, frame != null ? frame.Kind : FrameKind.None);
        }
Beispiel #11
0
        public virtual void AttachAndStepWithBlankSysPrefix()
        {
            string script = TestData.GetPath(@"TestData\DebuggerProject\InfiniteRunBlankPrefix.py");
            var    p      = Process.Start(Version.InterpreterPath, "\"" + script + "\"");

            try {
                Thread.Sleep(1000);
                var proc = PythonProcess.Attach(p.Id);
                try {
                    var attached = new AutoResetEvent(false);
                    proc.ProcessLoaded += (sender, args) => {
                        Console.WriteLine("Process loaded");
                        proc.Resume();
                        attached.Set();
                    };
                    proc.StartListening();
                    Assert.IsTrue(attached.WaitOne(20000), "Failed to attach within 20s");

                    var              bpHit    = new AutoResetEvent(false);
                    PythonThread     thread   = null;
                    PythonStackFrame oldFrame = null;
                    proc.BreakpointHit += (sender, args) => {
                        Console.WriteLine("Breakpoint hit");
                        thread   = args.Thread;
                        oldFrame = args.Thread.Frames[0];
                        bpHit.Set();
                    };
                    var bp = proc.AddBreakPoint(script, 6);
                    bp.Add();
                    Assert.IsTrue(bpHit.WaitOne(20000), "Failed to hit breakpoint within 20s");

                    var stepComplete          = new AutoResetEvent(false);
                    PythonStackFrame newFrame = null;
                    proc.StepComplete += (sender, args) => {
                        newFrame = args.Thread.Frames[0];
                        stepComplete.Set();
                    };
                    thread.StepOver();
                    Assert.IsTrue(stepComplete.WaitOne(20000), "Failed to complete the step within 20s");

                    Assert.AreEqual(oldFrame.FileName, newFrame.FileName);
                    Assert.IsTrue(oldFrame.LineNo + 1 == newFrame.LineNo);
                } finally {
                    DetachProcess(proc);
                }
            } finally {
                DisposeProcess(p);
            }
        }
Beispiel #12
0
        public AD7MemoryAddress(AD7Engine engine, string filename, uint lineno, PythonStackFrame frame = null)
        {
            _engine   = engine;
            _lineNo   = (uint)lineno;
            _filename = filename;
            _frame    = frame;

            var span     = _engine.Process.GetStatementSpan(_filename, (int)_lineNo + 1, 0);
            var startPos = new TEXT_POSITION {
                dwLine = (uint)(span.Start.Line - 1), dwColumn = (uint)(span.Start.Column - 1)
            };
            var endPos = new TEXT_POSITION {
                dwLine = (uint)(span.End.Line - 1), dwColumn = (uint)(span.End.Column - 1)
            };

            _documentContext = new AD7DocumentContext(filename, startPos, endPos, this, frame != null ? frame.Kind : FrameKind.None);
        }
 internal void ChangeActiveFrame(int id)
 {
     if (_activeEvaluator != null)
     {
         PythonStackFrame frame = _activeEvaluator.GetFrames().SingleOrDefault(target => target.FrameId == id);
         if (frame != null)
         {
             _activeEvaluator.SwitchFrame(frame);
         }
         else
         {
             _window.WriteError(String.Format("Invalid frame id '{0}'.", id));
         }
     }
     else
     {
         NoProcessError();
     }
 }
 internal void ChangeActiveFrame(int id)
 {
     if (_activeEvaluator != null)
     {
         PythonStackFrame frame = _activeEvaluator.GetFrames().SingleOrDefault(target => target.FrameId == id);
         if (frame != null)
         {
             _activeEvaluator.SwitchFrame(frame);
         }
         else
         {
             CurrentWindow.WriteError(Strings.DebugReplInvalidFrameId.FormatUI(id));
         }
     }
     else
     {
         NoProcessError();
     }
 }
 internal void ChangeActiveFrame(int id)
 {
     if (_activeEvaluator != null)
     {
         PythonStackFrame frame = _activeEvaluator.GetFrames().SingleOrDefault(target => target.FrameId == id);
         if (frame != null)
         {
             _activeEvaluator.SwitchFrame(frame);
         }
         else
         {
             CurrentWindow.WriteErrorLine(Strings.DebugReplInvalidFrameId.FormatUI(id));
         }
     }
     else if (CustomDebugAdapterProtocolExtension.CanUseExperimental())
     {
         NotSupported();
     }
     else
     {
         NoProcessError();
     }
 }
 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));
 }
Beispiel #17
0
 public AD7MemoryAddress(AD7Engine engine, string filename, uint lineno, PythonStackFrame frame)
     : this(engine, filename, lineno)
 {
     _frame = frame;
 }
Beispiel #18
0
 internal void SwitchFrame(PythonStackFrame frame)
 {
     _frameId = frame.FrameId;
     _thread?.SetThreadAndFrameCommand(frame.Thread.Id, frame.FrameId, frame.Kind);
     WriteOutput(Strings.DebugReplFrameChanged.FormatUI(frame.FrameId));
 }
 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));
 }