int IDebugBoundBreakpoint2.GetHitCount(out uint pdwHitCount) { PythonRemoteProcess remoteProcess = _engine.Process as PythonRemoteProcess; if (remoteProcess != null && remoteProcess.TargetHostType == AD7Engine.TargetUwp) { // Target is UWP host and we will just assume breakpoint hit count is 1 from this // remote debug type due to issues with communicating this command pdwHitCount = 1; } else { pdwHitCount = (uint)TaskHelpers.RunSynchronouslyOnUIThread(async ct => { var timeoutToken = remoteProcess != null ? CancellationTokens.After5s : CancellationTokens.After1s; var linkedSource = CancellationTokenSource.CreateLinkedTokenSource(ct, timeoutToken); return(await _breakpoint.GetHitCountAsync(linkedSource.Token)); }); } return(VSConstants.S_OK); }
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); } }