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);
        }
Exemple #2
0
        public void 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
            };

            var p = Process.Start(psi);

            try {
                PythonProcess proc = null;
                for (int i = 0; ; ++i)
                {
                    Thread.Sleep(1000);
                    try {
                        proc = PythonRemoteProcess.Attach(
                            new Uri("tcp://secret@localhost?opt=" + PythonDebugOptions.RedirectOutput),
                            warnAboutAuthenticationErrors: false);
                        break;
                    } catch (SocketException) {
                        // Failed to connect - the process might have not started yet, so keep trying a few more times.
                        if (i >= 5)
                        {
                            throw;
                        }
                    }
                }

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

                        var bp = proc.AddBreakPoint(script, 10);
                        bp.Add();

                        proc.Resume();
                        attached.Set();
                    };

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

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

                    proc.StartListening();
                    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 {
                    DetachProcess(proc);
                }
            } finally {
                DisposeProcess(p);
            }
        }