예제 #1
0
        internal static PythonBreakpoint AddBreakpointByFileExtension(this PythonProcess newproc, int line, string finalBreakFilename)
        {
            PythonBreakpoint breakPoint;
            var ext = Path.GetExtension(finalBreakFilename);

            if (String.Equals(ext, ".html", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(ext, ".htm", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(ext, ".djt", StringComparison.OrdinalIgnoreCase))
            {
                breakPoint = newproc.AddDjangoBreakpoint(finalBreakFilename, line);
            }
            else
            {
                breakPoint = newproc.AddBreakpoint(finalBreakFilename, line);
            }
            return(breakPoint);
        }
예제 #2
0
        public async Task AttachPtvsd()
        {
            var expectedOutput = new[] { "stdout", "stderr" };

            string script = TestData.GetPath(@"TestData\DebuggerProject\AttachPtvsd.py");
            var    psi    = new ProcessStartInfo(Version.InterpreterPath, PtvsdInterpreterArguments + " \"" + script + "\"")
            {
                WorkingDirectory       = TestData.GetPath(),
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                CreateNoWindow         = true
            };

            var p = Process.Start(psi);

            try {
                PythonProcess proc = null;
                for (int i = 0; ; ++i)
                {
                    Thread.Sleep(1000);
                    try {
                        proc = await PythonRemoteProcess.AttachAsync(
                            new Uri("tcp://secret@localhost?opt=" + PythonDebugOptions.RedirectOutput),
                            false, TimeoutToken());

                        break;
                    } catch (SocketException) {
                        // Failed to connect - the process might have not started yet, so keep trying a few more times.
                        if (i >= 5 || p.HasExited)
                        {
                            throw;
                        }
                    }
                }

                try {
                    var attached = new AutoResetEvent(false);
                    proc.ProcessLoaded += async(sender, e) => {
                        Console.WriteLine("Process loaded");

                        var bp = proc.AddBreakpoint(script, 10);
                        await bp.AddAsync(TimeoutToken());

                        await proc.ResumeAsync(TimeoutToken());

                        attached.Set();
                    };

                    var actualOutput = new List <string>();
                    proc.DebuggerOutput += (sender, e) => {
                        actualOutput.Add(e.Output);
                    };

                    var bpHit = new AutoResetEvent(false);
                    proc.BreakpointHit += async(sender, args) => {
                        Console.WriteLine("Breakpoint hit");
                        bpHit.Set();
                        await proc.ResumeAsync(TimeoutToken());
                    };

                    await proc.StartListeningAsync();

                    Assert.IsTrue(attached.WaitOne(20000), "Failed to attach within 20s");
                    Assert.IsTrue(bpHit.WaitOne(20000), "Failed to hit breakpoint within 20s");

                    p.WaitForExit(DefaultWaitForExitTimeout);
                    AssertUtil.ArrayEquals(expectedOutput, actualOutput);
                } finally {
                    await DetachProcessAsync(proc);
                }
            } finally {
                Console.WriteLine(p.StandardOutput.ReadToEnd());
                Console.WriteLine(p.StandardError.ReadToEnd());
                DisposeProcess(p);
            }
        }