public void ShouldBreakOnBreakPoint() { var engineEvents = new Mock <IEngineEvents>(); var fi = new FileInfo(".\\TestFile.ps1"); var sbps = new List <ScriptBreakpoint> { new ScriptBreakpoint(null, fi.FullName, 3, 0, engineEvents.Object) }; _debugger = new ScriptDebugger(true, null); _debugger.SetRunspace(_runspace); _debugger.SetBreakpoints(sbps); var node = new ScriptProgramNode(null); node.IsFile = true; node.FileName = fi.FullName; var mre = new ManualResetEvent(false); bool breakpointHit = false; _debugger.BreakpointHit += (sender, args) => { breakpointHit = true; _debugger.Continue(); }; _debugger.DebuggingFinished += (sender, args) => mre.Set(); _debugger.Execute(node); Assert.IsTrue(mre.WaitOne(5000)); Assert.IsTrue(breakpointHit); }
public void ShouldAcceptArguments() { var fi = new FileInfo(".\\TestFile.ps1"); var sbps = new List <ScriptBreakpoint>(); _debugger = new ScriptDebugger(true, null); _debugger.SetRunspace(_runspace); _debugger.SetBreakpoints(sbps); var node = new ScriptProgramNode(null); node.FileName = fi.FullName; node.IsFile = true; node.Arguments = "'Arg1' 'Arg2'"; var mre = new ManualResetEvent(false); _debugger.DebuggingFinished += (sender, args) => mre.Set(); _debugger.Execute(node); Assert.IsTrue(mre.WaitOne(5000)); var arg1 = _runspace.SessionStateProxy.GetVariable("Argument1"); var arg2 = _runspace.SessionStateProxy.GetVariable("Argument2"); Assert.AreEqual("Arg1", arg1); Assert.AreEqual("Arg2", arg2); }
public void ShouldSetLineBreakpoint() { var engineEvents = new Mock <IEngineEvents>(); var sbps = new List <ScriptBreakpoint> { new ScriptBreakpoint(null, ".\\TestFile.ps1", 1, 0, engineEvents.Object) }; _debugger = new ScriptDebugger(true, null); _debugger.SetRunspace(_runspace); _debugger.SetBreakpoints(sbps); using (var pipe = _runspace.CreatePipeline()) { pipe.Commands.Add("Get-PSBreakpoint"); var breakpoints = pipe.Invoke(); //Verify the breakpoint was added to the runspace. Assert.AreEqual(1, breakpoints.Count); } //Verify the callback event was triggered. engineEvents.Verify(m => m.Breakpoint(null, sbps[0]), Times.Once()); }
public void ShouldSupportRemoteSession() { var sbps = new List <ScriptBreakpoint>(); _debugger = new ScriptDebugger(true, null); _runspace.Dispose(); _runspace = RunspaceFactory.CreateRunspace(_debugger); _runspace.Open(); _debugger.SetRunspace(_runspace); _debugger.SetBreakpoints(sbps); var node = new ScriptProgramNode(null); node.FileName = "Enter-PSSession localhost"; var mre = new ManualResetEvent(false); string outputString = null; _debugger.DebuggingFinished += (sender, args) => mre.Set(); _debugger.OutputString += (sender, args) => outputString = args.Value; _debugger.Execute(node); Assert.IsTrue(mre.WaitOne(5000)); mre.Reset(); node = new ScriptProgramNode(null); node.FileName = "$host.Name"; _debugger.Execute(node); Assert.IsTrue(mre.WaitOne(5000)); Assert.AreEqual("ServerRemoteHost", outputString); }
internal override void RemoveSelf(ScriptDebugger debugger) { if (this.SequencePoints != null) { // Remove ourselves from the list of bound breakpoints in this script. It's possible the breakpoint was never // bound, in which case there is nothing to do. var boundBreakPoints = debugger.GetBoundBreakpoints(this.SequencePoints); if (boundBreakPoints != null) { Diagnostics.Assert(boundBreakPoints.Contains(this), "If we set _scriptBlock, we should have also added the breakpoint to the bound breakpoint list"); boundBreakPoints.Remove(this); if (boundBreakPoints.All(breakpoint => breakpoint.SequencePointIndex != this.SequencePointIndex)) { // No other line breakpoints are at the same sequence point, so disable the breakpoint so // we don't go looking for breakpoints the next time we hit the sequence point. // This isn't strictly necessary, but script execution will be faster. this.BreakpointBitArray.Set(SequencePointIndex, false); } } } debugger.RemoveLineBreakpoint(this); }
/// <summary> /// Initialize the PowerShell host. /// </summary> private void InitializePowerShellHost() { var page = (GeneralDialogPage)GetDialogPage(typeof(GeneralDialogPage)); ResetPowerShellSession = page.ResetPowerShellSession; OverrideExecutionPolicyConfiguration = page.OverrideExecutionPolicyConfiguration; Log.Info("InitializePowerShellHost"); _debugger = new ScriptDebugger(page.OverrideExecutionPolicyConfiguration); // Warm up the intellisense service due to the reason that the // first intellisense request is often times slower than usual // TODO: Should we move this into the HostService's initializiation? IntelliSenseService.GetDummyCompletionList(); DebuggerReadyEvent.Set(); PowerShellHostInitialized = true; if (page.ShouldLoadProfiles) { DebuggingService.LoadProfiles(); } SetReplLocationToSolutionDir(); _solutionEventsListener = new SolutionEventsListener(this); _solutionEventsListener.StartListeningForChanges(); _solutionEventsListener.SolutionOpened += _solutionEventsListener_SolutionOpened; }
public void Init() { _runspace = RunspaceFactory.CreateRunspace(); _runspace.Open(); _debuggingService = new PowerShellDebuggingService(); _debugger = new ScriptDebugger(true, _debuggingService); _debuggingService.CallbackService = new DebugServiceEventsHandlerProxy(_debugger, false); }
/// <summary> /// Registers a script with a debugger. /// </summary> public ScriptDebugger AddDebugger(LuaSourceContainer script) { var debugger = new ScriptDebugger(script); lock (_locker) { _debuggers.Add(debugger); } return(debugger); }
public void ShouldNotDieIfNoBreakpoints() { _debugger = new ScriptDebugger(true, null); _debugger.SetRunspace(_runspace); using (var pipe = _runspace.CreatePipeline()) { pipe.Commands.Add("Get-PSBreakpoint"); var breakpoints = pipe.Invoke(); Assert.AreEqual(0, breakpoints.Count); } }
private ExecutionEngine() { if (!PowerShellToolsPackage.PowerShellHostInitialized) { PowerShellToolsPackage.DebuggerReadyEvent.WaitOne(TimeSpan.FromSeconds(10)); } _debugger = PowerShellToolsPackage.Debugger; if (_debugger.HostUi != null) { _debugger.HostUi.OutputString = OutputString; } }
public ScriptDebuggerForm() { InitializeComponent(); // Setup layout SetupFormLayout(); // Start the RuntimeServer (it will compile and trigger the script to run) _runtimeServerProcess = Process.Start(PathHelper.RuntimeServerExe); FormClosed += (s, e) => { _runtimeServerProcess.CloseMainWindow(); }; // CS Parser _csParser = new CsParser(new CsSolution()); _csParser.Repository.RegisterDefaultAssemblies(TechnologyEnvironment.System); // Workaround to initialize workspace before being displayed so that references can be added before load complete. // See https://www.alternetsoft.com/ForumRetrieve.aspx?ForumID=4089&TopicID=68576 var workspace = _csParser.Repository.Solution.Workspace; // Set up ScriptRun and ScriptDebugger _scriptRun = new ScriptRun(this.components); _scriptRun.AssemblyKind = ScriptAssemblyKind.DynamicLibrary; _scriptRun.ScriptLanguage = ScriptLanguage.CSharp; _scriptRun.ScriptMode = ScriptMode.Debug; _scriptRun.ScriptSource.FromScriptFile(PathHelper.UserScriptSourceFile); _debugger = new ScriptDebugger { ScriptRun = _scriptRun, GeneratedModulesPath = PathHelper.UserScriptBuildDir }; // Wire up UI to ScriptRun and ScriptDebugger _codeEditContainer.Debugger = _debugger; _debuggerPanels.Debugger = _debugger; _debuggerUiController.Debugger = _debugger; _debuggerToolbar.Debugger = _debugger; _debuggerToolbar.CommandsListener = new AutoAttachDebuggerUICommands(_debugger, _runtimeServerProcess.Id); // Set the editor to the source file _codeEditContainer.TryActivateEditor(PathHelper.UserScriptSourceFile); }
/// <summary> /// Initialize the PowerShell host. /// </summary> private void InitializePowerShellHost() { var page = (GeneralDialogPage)GetDialogPage(typeof(GeneralDialogPage)); Log.Info("InitializePowerShellHost"); Debugger = new ScriptDebugger(page.OverrideExecutionPolicyConfiguration, (DTE2)GetService(typeof(DTE))); Debugger.HostUi.OutputProgress = (label, percentage) => { Log.DebugFormat("Output progress: {0} {1}", label, percentage); var statusBar = (IVsStatusbar)GetService(typeof(SVsStatusbar)); uint cookie = 0; statusBar.Progress(ref cookie, 1, label, (uint)percentage, 100); if (percentage == 100) { statusBar.Progress(ref cookie, 1, "", 0, 0); } }; }
public BreakpointMargin(LuaSourceContainer script, TextEditor editor) { _script = script; _editor = editor; _pen = new Pen(Brushes.White, 4); _debugger = script.Debugger; _debugger.BreakpointAdded.Event += bp => { var line = _editor.Document.GetLineByNumber(bp.Line); var offset = _editor.Document.GetOffset(bp.Line, 1); var anchor = _editor.Document.CreateAnchor(offset); anchor.MovementType = AnchorMovementType.AfterInsertion; anchor.Deleted += (s, e) => bp.Destroy(); bp.Tag = anchor; }; _debugger.BreakpointRemoved.Event += bp => { }; }
public void ShouldClearBreakpoints() { using (var pipe = _runspace.CreatePipeline()) { var command = new Command("Set-PSBreakpoint"); command.Parameters.Add("Script", ".\\TestFile.ps1"); command.Parameters.Add("Line", 1); pipe.Commands.Add(command); pipe.Invoke(); } _debugger = new ScriptDebugger(true, null); _debugger.SetRunspace(_runspace); _debugger.SetBreakpoints(new List <ScriptBreakpoint>()); using (var pipe = _runspace.CreatePipeline()) { pipe.Commands.Add("Get-PSBreakpoint"); var breakpoints = pipe.Invoke(); Assert.AreEqual(0, breakpoints.Count); } }
public void ShouldExecuteSnippet() { var sbps = new List <ScriptBreakpoint>(); _debugger = new ScriptDebugger(true, null); _debugger.SetRunspace(_runspace); _debugger.SetBreakpoints(sbps); var node = new ScriptProgramNode(null); node.FileName = "$Global:MyVariable = 'Test'"; var mre = new ManualResetEvent(false); _debugger.DebuggingFinished += (sender, args) => mre.Set(); _debugger.Execute(node); Assert.IsTrue(mre.WaitOne(5000)); var myVariable = _runspace.SessionStateProxy.GetVariable("MyVariable"); Assert.AreEqual("Test", myVariable); }
internal virtual bool RemoveSelf(ScriptDebugger debugger) => false;
public HostUi(ScriptDebugger scriptDebugger) { _scriptDebugger = scriptDebugger; }
public RawHostUi(ScriptDebugger debugger) { _debugger = debugger; }
public bool RunCLRTests() { Console.WriteLine("Run CLR tests...\n"); ScriptRunningMachine srm = new ScriptRunningMachine(); srm.WorkMode |= MachineWorkMode.AllowDirectAccess; ScriptDebugger debugMonitor = new ScriptDebugger(srm); int testCases = 0, success = 0, failed = 0; int createdObjs = 0; Stopwatch sw = Stopwatch.StartNew(); bool hasErrors = false; foreach (Type type in this.GetType().Assembly.GetTypes()) { TestSuiteAttribute[] attrs = type.GetCustomAttributes(typeof(TestSuiteAttribute), true) as TestSuiteAttribute[]; if (attrs.Length > 0) { var testName = attrs[0].Name; if (string.IsNullOrEmpty(testName)) testName = type.Name; object testSuite = System.Activator.CreateInstance(type); foreach (MethodInfo method in type.GetMethods()) { TestCaseAttribute[] caseAttrs = method.GetCustomAttributes(typeof(TestCaseAttribute), false) as TestCaseAttribute[]; if (caseAttrs.Length > 0 && !caseAttrs[0].Disabled) { testCases++; var caseName = caseAttrs[0].Desc; if (string.IsNullOrEmpty(caseName)) caseName = method.Name; Console.Write("[{0,-18}] {1,-30} : ", testName, caseName); if (testSuite is ReoScriptTestSuite) { srm.WorkMode = caseAttrs[0].WorkMode; srm.Reset(); ((ReoScriptTestSuite)testSuite).SRM = srm; } try { sw.Reset(); sw.Start(); method.Invoke(testSuite, null); sw.Stop(); success++; Console.WriteLine("{0,5} ms. {1,4} objs.", sw.ElapsedMilliseconds, debugMonitor.TotalObjectCreated - createdObjs); createdObjs = debugMonitor.TotalObjectCreated; } catch (Exception ex) { failed++; Console.WriteLine(string.IsNullOrEmpty(ex.InnerException.Message) ? "failed" : ex.InnerException.Message); hasErrors = true; } finally { sw.Stop(); } } } } } Console.WriteLine("\n {0,3} test cases, {1,3} successed, {2,3} failed, {3,3} skipped", testCases, success, failed, (testCases - success - failed)); Console.WriteLine(" {0,5} objects created.\n", debugMonitor.TotalObjectCreated); TotalCases += testCases; TotalFailures += failed; TotalSuccesses += success; TotalObjectCreates += debugMonitor.TotalObjectCreated; return hasErrors; }
public bool RunLanguageTests(List<string> ids, List<string> enabledTags) { Console.WriteLine("Run Core tests...\n"); bool hasErrors = false; ScriptRunningMachine srm = new ScriptRunningMachine(); ScriptDebugger debugMonitor = new ScriptDebugger(srm); int testCases = 0, success = 0, failed = 0; int createdObjs = 0; foreach (string filename in Directory.GetFiles("tests")) { XmlTestSuite suite = xmlSuiteSerializer.Deserialize(File.OpenRead(filename)) as XmlTestSuite; if (suite != null) { testCases += suite.TestCases.Count; } if (!string.IsNullOrEmpty(suite.Tag)) { string[] tags = suite.Tag.ToLower().Split(' '); if (!enabledTags.Any(t => tags.Contains(t))) continue; } Stopwatch sw = Stopwatch.StartNew(); suite.TestCases.ForEach(t => { string caseId = string.Format("{0,3}-{1,3}", suite.Id, t.Id); if (t.Disabled || string.IsNullOrEmpty(t.Script) || (ids.Count > 0 && !ids.Any(id => caseId.Contains(id)))) return; srm.Reset(); Console.Write("[{0,6} {1,-10}] {2,-30} : ", caseId, suite.Name, t.Name); try { sw.Reset(); sw.Start(); srm.Run(t.Script); sw.Stop(); success++; Console.WriteLine("{0,5} ms. {1,4} objs.", sw.ElapsedMilliseconds, debugMonitor.TotalObjectCreated - createdObjs); createdObjs = debugMonitor.TotalObjectCreated; } catch (Exception ex) { failed++; Console.WriteLine(string.IsNullOrEmpty(ex.Message) ? "failed" : ex.Message); hasErrors = true; } finally { sw.Stop(); } }); //Console.WriteLine(); } Console.WriteLine("\n {0,3} test cases, {1,3} successed, {2,3} failed, {3,3} skipped", testCases, success, failed, (testCases - success - failed)); Console.WriteLine(" {0,5} objects created.\n", debugMonitor.TotalObjectCreated); TotalCases += testCases; TotalFailures += failed; TotalSuccesses += success; TotalObjectCreates += debugMonitor.TotalObjectCreated; return hasErrors; }
public void Init() { _debuggingService = new PowerShellDebuggingService(); _host = new ScriptDebugger(true, _debuggingService); }
public bool RunCLRTests() { Console.WriteLine("Run CLR tests...\n"); ScriptRunningMachine srm = new ScriptRunningMachine(); srm.WorkMode |= MachineWorkMode.AllowDirectAccess; ScriptDebugger debugMonitor = new ScriptDebugger(srm); int testCases = 0, success = 0, failed = 0; int createdObjs = 0; Stopwatch sw = Stopwatch.StartNew(); bool hasErrors = false; foreach (Type type in this.GetType().Assembly.GetTypes()) { TestSuiteAttribute[] attrs = type.GetCustomAttributes(typeof(TestSuiteAttribute), true) as TestSuiteAttribute[]; if (attrs.Length > 0) { var testName = attrs[0].Name; if (string.IsNullOrEmpty(testName)) { testName = type.Name; } object testSuite = System.Activator.CreateInstance(type); foreach (MethodInfo method in type.GetMethods()) { TestCaseAttribute[] caseAttrs = method.GetCustomAttributes(typeof(TestCaseAttribute), false) as TestCaseAttribute[]; if (caseAttrs.Length > 0 && !caseAttrs[0].Disabled) { testCases++; var caseName = caseAttrs[0].Desc; if (string.IsNullOrEmpty(caseName)) { caseName = method.Name; } Console.Write("[{0,-18}] {1,-30} : ", testName, caseName); if (testSuite is ReoScriptTestSuite) { srm.WorkMode = caseAttrs[0].WorkMode; srm.Reset(); ((ReoScriptTestSuite)testSuite).SRM = srm; } try { sw.Reset(); sw.Start(); method.Invoke(testSuite, null); sw.Stop(); success++; Console.WriteLine("{0,5} ms. {1,4} objs.", sw.ElapsedMilliseconds, debugMonitor.TotalObjectCreated - createdObjs); createdObjs = debugMonitor.TotalObjectCreated; } catch (Exception ex) { failed++; Console.WriteLine(string.IsNullOrEmpty(ex.InnerException.Message) ? "failed" : ex.InnerException.Message); hasErrors = true; } finally { sw.Stop(); } } } } } Console.WriteLine("\n {0,3} test cases, {1,3} successed, {2,3} failed, {3,3} skipped", testCases, success, failed, (testCases - success - failed)); Console.WriteLine(" {0,5} objects created.\n", debugMonitor.TotalObjectCreated); TotalCases += testCases; TotalFailures += failed; TotalSuccesses += success; TotalObjectCreates += debugMonitor.TotalObjectCreated; return(hasErrors); }
public bool RunLanguageTests(List <string> ids, List <string> enabledTags) { Console.WriteLine("Run Core tests...\n"); bool hasErrors = false; ScriptRunningMachine srm = new ScriptRunningMachine(); ScriptDebugger debugMonitor = new ScriptDebugger(srm); int testCases = 0, success = 0, failed = 0; int createdObjs = 0; foreach (string filename in Directory.GetFiles("tests")) { XmlTestSuite suite = xmlSuiteSerializer.Deserialize(File.OpenRead(filename)) as XmlTestSuite; if (suite != null) { testCases += suite.TestCases.Count; } if (!string.IsNullOrEmpty(suite.Tag)) { string[] tags = suite.Tag.ToLower().Split(' '); if (!enabledTags.Any(t => tags.Contains(t))) { continue; } } Stopwatch sw = Stopwatch.StartNew(); suite.TestCases.ForEach(t => { string caseId = string.Format("{0,3}-{1,3}", suite.Id, t.Id); if (t.Disabled || string.IsNullOrEmpty(t.Script) || (ids.Count > 0 && !ids.Any(id => caseId.Contains(id)))) { return; } srm.Reset(); Console.Write("[{0,6} {1,-10}] {2,-30} : ", caseId, suite.Name, t.Name); try { sw.Reset(); sw.Start(); srm.Run(t.Script); sw.Stop(); success++; Console.WriteLine("{0,5} ms. {1,4} objs.", sw.ElapsedMilliseconds, debugMonitor.TotalObjectCreated - createdObjs); createdObjs = debugMonitor.TotalObjectCreated; } catch (Exception ex) { failed++; Console.WriteLine(string.IsNullOrEmpty(ex.Message) ? "failed" : ex.Message); hasErrors = true; } finally { sw.Stop(); } }); //Console.WriteLine(); } Console.WriteLine("\n {0,3} test cases, {1,3} successed, {2,3} failed, {3,3} skipped", testCases, success, failed, (testCases - success - failed)); Console.WriteLine(" {0,5} objects created.\n", debugMonitor.TotalObjectCreated); TotalCases += testCases; TotalFailures += failed; TotalSuccesses += success; TotalObjectCreates += debugMonitor.TotalObjectCreated; return(hasErrors); }
public TestExecutionEngine(ScriptDebugger debugger) { _debugger = debugger; }
internal override void RemoveSelf(ScriptDebugger debugger) { debugger.RemoveCommandBreakpoint(this); }
public void Init() { _host = new ScriptDebugger(true, null); }
public PowerShellReplEvaluator(ScriptDebugger debugger) { Debugger = debugger; }
internal virtual void RemoveSelf(ScriptDebugger debugger) { }
internal override bool RemoveSelf(ScriptDebugger debugger) => debugger.RemoveCommandBreakpoint(this);
internal override void RemoveSelf(ScriptDebugger debugger) { debugger.RemoveVariableBreakpoint(this); }
internal override bool RemoveSelf(ScriptDebugger debugger) => debugger.RemoveVariableBreakpoint(this);