public void StepStdLib() { // http://pytools.codeplex.com/workitem/504 - test option for stepping into std lib. var debugger = new PythonDebugger(); string fullPath = Path.Combine(DebuggerTestPath, "StepStdLib.py"); foreach (var steppingStdLib in new[] { false, true }) { var process = debugger.CreateProcess( Version.Version, Version.InterpreterPath, "\"" + fullPath + "\"", DebuggerTestPath, "", debugOptions: steppingStdLib ? (PythonDebugOptions.DebugStdLib | PythonDebugOptions.RedirectOutput) : PythonDebugOptions.RedirectOutput); PythonThread thread = null; process.ThreadCreated += (sender, args) => { thread = args.Thread; }; AutoResetEvent processEvent = new AutoResetEvent(false); bool processLoad = false, stepComplete = false; PythonBreakpoint bp = null; process.ProcessLoaded += (sender, args) => { bp = process.AddBreakPoint(fullPath, 2); bp.Add(); processLoad = true; processEvent.Set(); }; process.StepComplete += (sender, args) => { stepComplete = true; processEvent.Set(); }; bool breakHit = false; process.BreakpointHit += (sender, args) => { breakHit = true; bp.Disable(); processEvent.Set(); }; process.Start(); try { AssertWaited(processEvent); Assert.IsTrue(processLoad, "process did not load"); Assert.IsFalse(stepComplete, "step should not have completed"); process.Resume(); AssertWaited(processEvent); Assert.IsTrue(breakHit, "breakpoint was not hit"); thread.StepInto(); AssertWaited(processEvent); Assert.IsTrue(stepComplete, "step was not completed"); Debug.WriteLine(thread.Frames[thread.Frames.Count - 1].FileName); if (steppingStdLib) { Assert.IsTrue(thread.Frames[0].FileName.EndsWith("\\os.py"), "did not break in os.py; instead, " + thread.Frames[0].FileName); } else { Assert.IsTrue(thread.Frames[0].FileName.EndsWith("\\StepStdLib.py"), "did not break in StepStdLib.py; instead, " + thread.Frames[0].FileName); } process.Resume(); } finally { WaitForExit(process); } } }
private new PythonProcess DebugProcess(PythonDebugger debugger, string filename, Action<PythonProcess, PythonThread> onLoaded = null, bool resumeOnProcessLoaded = true, string interpreterOptions = null, PythonDebugOptions debugOptions = PythonDebugOptions.RedirectOutput, string cwd = null, string pythonExe = null) { string fullPath = Path.GetFullPath(filename); string dir = cwd ?? Path.GetFullPath(Path.GetDirectoryName(filename)); var process = debugger.CreateProcess(Version.Version, pythonExe ?? Version.InterpreterPath, "\"" + fullPath + "\"", dir, "", interpreterOptions, debugOptions); process.ProcessLoaded += (sender, args) => { if (onLoaded != null) { onLoaded(process, args.Thread); } if (resumeOnProcessLoaded) { process.Resume(); } }; return process; }