/// <summary> /// Creates an instance of the <see cref="CommandBreakpointDetails"/> class from a /// PowerShell CommandBreakpoint object. /// </summary> /// <param name="breakpoint">The Breakpoint instance from which details will be taken.</param> /// <returns>A new instance of the BreakpointDetails class.</returns> public static CommandBreakpointDetails Create(Breakpoint breakpoint) { Validate.IsNotNull("breakpoint", breakpoint); CommandBreakpoint commandBreakpoint = breakpoint as CommandBreakpoint; if (commandBreakpoint == null) { throw new ArgumentException( "Unexpected breakpoint type: " + breakpoint.GetType().Name); } var breakpointDetails = new CommandBreakpointDetails { Verified = true, Name = commandBreakpoint.Command, Condition = commandBreakpoint.Action?.ToString() }; return(breakpointDetails); }
protected override void ProcessRecord() { FilterSelector <string> selector = null; List <Breakpoint> breakpoints = base.Context.Debugger.GetBreakpoints(); if (!base.ParameterSetName.Equals("Script", StringComparison.OrdinalIgnoreCase)) { if (base.ParameterSetName.Equals("Id", StringComparison.OrdinalIgnoreCase)) { breakpoints = this.Filter <int>(breakpoints, this._id, (breakpoint, id) => breakpoint.Id == id); } else if (base.ParameterSetName.Equals("Command", StringComparison.OrdinalIgnoreCase)) { breakpoints = this.Filter <string>(breakpoints, this._command, delegate(Breakpoint breakpoint, string command) { CommandBreakpoint breakpoint2 = breakpoint as CommandBreakpoint; if (breakpoint2 == null) { return(false); } return(breakpoint2.Command.Equals(command, StringComparison.OrdinalIgnoreCase)); }); } else if (base.ParameterSetName.Equals("Variable", StringComparison.OrdinalIgnoreCase)) { breakpoints = this.Filter <string>(breakpoints, this._variable, delegate(Breakpoint breakpoint, string variable) { VariableBreakpoint breakpoint2 = breakpoint as VariableBreakpoint; if (breakpoint2 == null) { return(false); } return(breakpoint2.Variable.Equals(variable, StringComparison.OrdinalIgnoreCase)); }); } else if (base.ParameterSetName.Equals("Type", StringComparison.OrdinalIgnoreCase)) { breakpoints = this.Filter <BreakpointType>(breakpoints, this._type, delegate(Breakpoint breakpoint, BreakpointType type) { switch (type) { case BreakpointType.Line: if (breakpoint is LineBreakpoint) { return(true); } break; case BreakpointType.Variable: if (breakpoint is VariableBreakpoint) { return(true); } break; case BreakpointType.Command: if (breakpoint is CommandBreakpoint) { return(true); } break; } return(false); }); } } if (this._script != null) { if (selector == null) { selector = delegate(Breakpoint breakpoint, string script) { if (breakpoint.Script == null) { return(false); } return(string.Compare(base.SessionState.Path.GetUnresolvedProviderPathFromPSPath(breakpoint.Script), base.SessionState.Path.GetUnresolvedProviderPathFromPSPath(script), StringComparison.OrdinalIgnoreCase) == 0); }; } breakpoints = this.Filter <string>(breakpoints, this._script, selector); } foreach (Breakpoint breakpoint in breakpoints) { base.WriteObject(breakpoint); } }
/// <summary> /// Remove breakpoints. /// </summary> protected override void ProcessRecord() { List <Breakpoint> breakpoints = Context.Debugger.GetBreakpoints(); // // Filter by parameter set // if (this.ParameterSetName.Equals("Script", StringComparison.OrdinalIgnoreCase)) { // no filter } else if (this.ParameterSetName.Equals("Id", StringComparison.OrdinalIgnoreCase)) { breakpoints = Filter( breakpoints, _id, delegate(Breakpoint breakpoint, int id) { return(breakpoint.Id == id); } ); } else if (this.ParameterSetName.Equals("Command", StringComparison.OrdinalIgnoreCase)) { breakpoints = Filter( breakpoints, _command, delegate(Breakpoint breakpoint, string command) { CommandBreakpoint commandBreakpoint = breakpoint as CommandBreakpoint; if (commandBreakpoint == null) { return(false); } return(commandBreakpoint.Command.Equals(command, StringComparison.OrdinalIgnoreCase)); }); } else if (this.ParameterSetName.Equals("Variable", StringComparison.OrdinalIgnoreCase)) { breakpoints = Filter( breakpoints, _variable, delegate(Breakpoint breakpoint, string variable) { VariableBreakpoint variableBreakpoint = breakpoint as VariableBreakpoint; if (variableBreakpoint == null) { return(false); } return(variableBreakpoint.Variable.Equals(variable, StringComparison.OrdinalIgnoreCase)); }); } else if (this.ParameterSetName.Equals("Type", StringComparison.OrdinalIgnoreCase)) { breakpoints = Filter( breakpoints, _type, delegate(Breakpoint breakpoint, BreakpointType type) { switch (type) { case BreakpointType.Line: if (breakpoint is LineBreakpoint) { return(true); } break; case BreakpointType.Command: if (breakpoint is CommandBreakpoint) { return(true); } break; case BreakpointType.Variable: if (breakpoint is VariableBreakpoint) { return(true); } break; } return(false); }); } else { Diagnostics.Assert(false, "Invalid parameter set: {0}", this.ParameterSetName); } // // Filter by script // if (_script != null) { breakpoints = Filter( breakpoints, _script, delegate(Breakpoint breakpoint, string script) { if (breakpoint.Script == null) { return(false); } return(string.Compare( SessionState.Path.GetUnresolvedProviderPathFromPSPath(breakpoint.Script), SessionState.Path.GetUnresolvedProviderPathFromPSPath(script), StringComparison.OrdinalIgnoreCase ) == 0); }); } // // Output results // foreach (Breakpoint b in breakpoints) { WriteObject(b); } }
/// <summary> /// Remove breakpoints. /// </summary> protected override void ProcessRecord() { List <Breakpoint> breakpoints = Runspace.Debugger.GetBreakpoints(); // Filter by parameter set if (ParameterSetName.Equals(LineParameterSetName, StringComparison.OrdinalIgnoreCase)) { // no filter } else if (ParameterSetName.Equals(IdParameterSetName, StringComparison.OrdinalIgnoreCase)) { breakpoints = Filter( breakpoints, Id, delegate(Breakpoint breakpoint, int id) { return(breakpoint.Id == id); } ); } else if (ParameterSetName.Equals(CommandParameterSetName, StringComparison.OrdinalIgnoreCase)) { breakpoints = Filter( breakpoints, Command, delegate(Breakpoint breakpoint, string command) { CommandBreakpoint commandBreakpoint = breakpoint as CommandBreakpoint; if (commandBreakpoint is null) { return(false); } return(commandBreakpoint.Command.Equals(command, StringComparison.OrdinalIgnoreCase)); }); } else if (ParameterSetName.Equals(VariableParameterSetName, StringComparison.OrdinalIgnoreCase)) { breakpoints = Filter( breakpoints, Variable, delegate(Breakpoint breakpoint, string variable) { VariableBreakpoint variableBreakpoint = breakpoint as VariableBreakpoint; if (variableBreakpoint is null) { return(false); } return(variableBreakpoint.Variable.Equals(variable, StringComparison.OrdinalIgnoreCase)); }); } else if (ParameterSetName.Equals(TypeParameterSetName, StringComparison.OrdinalIgnoreCase)) { breakpoints = Filter( breakpoints, Type, delegate(Breakpoint breakpoint, BreakpointType type) { switch (type) { case BreakpointType.Line: if (breakpoint is LineBreakpoint) { return(true); } break; case BreakpointType.Command: if (breakpoint is CommandBreakpoint) { return(true); } break; case BreakpointType.Variable: if (breakpoint is VariableBreakpoint) { return(true); } break; } return(false); }); } else { Diagnostics.Assert(false, "Invalid parameter set: {0}", this.ParameterSetName); } // Filter by script if (Script != null) { breakpoints = Filter( breakpoints, Script, delegate(Breakpoint breakpoint, string script) { if (breakpoint.Script is null) { return(false); } return(string.Equals( SessionState.Path.GetUnresolvedProviderPathFromPSPath(breakpoint.Script), SessionState.Path.GetUnresolvedProviderPathFromPSPath(script), StringComparison.OrdinalIgnoreCase )); }); } // Output results foreach (Breakpoint b in breakpoints) { ProcessBreakpoint(b); } }
public DebuggerDialog(DebuggerStopEventArgs e) { _InvocationInfo = e.InvocationInfo; int maxLine = 0; string[] lines = null; if (!string.IsNullOrEmpty(e.InvocationInfo.ScriptName) && File.Exists(e.InvocationInfo.ScriptName)) { try { lines = File.ReadAllLines(e.InvocationInfo.ScriptName, Encoding.Default); foreach (string s in lines) { if (s.Length > maxLine) { maxLine = s.Length; } } } catch (IOException) { } } int dw = Math.Max(Math.Min(Far.Api.UI.WindowSize.X - 7, maxLine + 12), 73); int dh = 22; string title; int h1; if (e.Breakpoints.Count > 0) { title = "DEBUG: Hit breakpoint(s)"; h1 = e.Breakpoints.Count + 2; } else { title = "DEBUG: Step"; h1 = 2; } _Dialog = Far.Api.CreateDialog(-1, -1, dw, dh); _Dialog.HelpTopic = Far.Api.GetHelpTopic("DebuggerDialog"); _Dialog.AddBox(3, 1, dw - 4, dh - 2, title); _List1 = _Dialog.AddListBox(4, 2, dw - 5, h1 + 1, null); _List1.Disabled = true; _List1.NoBox = true; _List1.NoClose = true; _List1.NoFocus = true; if (e.Breakpoints.Count > 0) { foreach (Breakpoint bp in e.Breakpoints) { CommandBreakpoint bpc = bp as CommandBreakpoint; if (bpc != null && Kit.Equals(bpc.Command, Commands.AssertFarCommand.MyName)) { A.InvokeCode("Remove-PSBreakpoint -Breakpoint $args[0]", bpc); } } } foreach (string s in e.InvocationInfo.PositionMessage.Trim().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)) { _List1.Add(s); } _Dialog.AddText(0, -_List1.Rect.Height, 0, null).Separator = 1; _List2 = _Dialog.AddListBox(4, _List1.Rect.Bottom + 2, dw - 5, dh - 5, null); _List2.NoBox = true; _List2.NoClose = true; if (lines != null) { foreach (string s in lines) { _List2.Add(s); } int i = e.InvocationInfo.ScriptLineNumber - 1; _List2.Items[i].Checked = true; } _Dialog.AddText(0, -_List2.Rect.Height, 0, null).Separator = 1; _Step = _Dialog.AddButton(0, -1, BtnStep); _Step.CenterGroup = true; _Over = _Dialog.AddButton(0, 0, BtnOver); _Over.CenterGroup = true; _Out = _Dialog.AddButton(0, 0, BtnOut); _Out.CenterGroup = true; _Console = _Dialog.AddButton(0, 0, BtnInteractive); _Console.CenterGroup = true; _Console.NoBrackets = true; _Edit = _Dialog.AddButton(0, 0, BtnEdit); _Edit.CenterGroup = true; _Edit.NoBrackets = true; // to be completed on show _View = _Dialog.AddButton(0, 0, BtnView); _View.CenterGroup = true; _View.NoBrackets = true; _View.NoClose = true; _Goto = _Dialog.AddButton(0, 0, BtnLine); _Goto.CenterGroup = true; _Goto.NoBrackets = true; _Goto.NoClose = true; _Goto.ButtonClicked += OnGoto; _Quit = _Dialog.AddButton(0, 0, BtnQuit); _Quit.CenterGroup = true; _Quit.NoBrackets = true; _Dialog.Initialized += OnInitialized; }