-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New New-PSBreakpoint cmdlet & new -Breakpoint parameter for Debug-Runspace
#8923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TravisEz13
merged 19 commits into
PowerShell:master
from
TylerLeonhardt:new-psbreakpoint
Apr 14, 2019
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9b8af17
initial New-PSBreakpoint
TylerLeonhardt dcfa770
refactor new/set-psbreakpoint
TylerLeonhardt 60eb271
Debug-Runspace -Breakpoint
TylerLeonhardt 7156b88
make constructors public and add a few more
TylerLeonhardt b4f97a6
add experimental feature
TylerLeonhardt 4e2d729
[feature] safe null check
TylerLeonhardt d2ed73f
[feature] add new-psbreakpoint tests
TylerLeonhardt ba693db
[feature] other safe null check
TylerLeonhardt 0decf0b
[feature] add experimental feature to TestMetadata.json
TylerLeonhardt c4fa356
handle feature enabled disabled
TylerLeonhardt b26675b
add nbp
TylerLeonhardt 49fac4a
address feedback
TylerLeonhardt f9fa5f0
support other debuggers
TylerLeonhardt 7e68365
no null check needed
TylerLeonhardt 699ca21
make GetBreakpoint* public and add tests
TylerLeonhardt da05432
[feature] fix test
TylerLeonhardt 986f379
[feature] codacy cleanup - make abstract constructors protected
TylerLeonhardt 77b7fec
address steve's feedback
TylerLeonhardt 1595772
Ilya's comments
TylerLeonhardt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/Microsoft.PowerShell.Commands.Utility/commands/utility/New-PSBreakpoint.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.ObjectModel; | ||
| using System.Diagnostics; | ||
| using System.IO; | ||
| using System.Management.Automation; | ||
| using System.Management.Automation.Internal; | ||
|
|
||
| namespace Microsoft.PowerShell.Commands | ||
| { | ||
| /// <summary> | ||
| /// This class implements New-PSBreakpoint command. | ||
| /// </summary> | ||
| [Experimental("Microsoft.PowerShell.Utility.PSDebugRunspaceWithBreakpoints", ExperimentAction.Show)] | ||
| [Cmdlet(VerbsCommon.New, "PSBreakpoint", DefaultParameterSetName = LineParameterSetName, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=113449")] | ||
| [OutputType(typeof(VariableBreakpoint), typeof(CommandBreakpoint), typeof(LineBreakpoint))] | ||
| public class NewPSBreakpointCommand : PSBreakpointCreationBase | ||
| { | ||
| /// <summary> | ||
| /// Create a new breakpoint. | ||
| /// </summary> | ||
| protected override void ProcessRecord() | ||
| { | ||
| // If there is a script, resolve its path | ||
| Collection<string> scripts = ResolveScriptPaths(); | ||
|
|
||
| // If it is a command breakpoint... | ||
| if (ParameterSetName.Equals(CommandParameterSetName, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| for (int i = 0; i < Command.Length; i++) | ||
| { | ||
| if (scripts.Count > 0) | ||
| { | ||
| foreach (string path in scripts) | ||
| { | ||
| WildcardPattern pattern = WildcardPattern.Get(Command[i], WildcardOptions.Compiled | WildcardOptions.IgnoreCase); | ||
| WriteObject(new CommandBreakpoint(path, pattern, Command[i], Action)); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| WildcardPattern pattern = WildcardPattern.Get(Command[i], WildcardOptions.Compiled | WildcardOptions.IgnoreCase); | ||
| WriteObject(new CommandBreakpoint(null, pattern, Command[i], Action)); | ||
| } | ||
| } | ||
| } | ||
| else if (ParameterSetName.Equals(VariableParameterSetName, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| // If it is a variable breakpoint... | ||
| for (int i = 0; i < Variable.Length; i++) | ||
| { | ||
| if (scripts.Count > 0) | ||
| { | ||
| foreach (string path in scripts) | ||
| { | ||
| WriteObject(new VariableBreakpoint(path, Variable[i], Mode, Action)); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| WriteObject(new VariableBreakpoint(null, Variable[i], Mode, Action)); | ||
| } | ||
| } | ||
| } | ||
| else | ||
| { | ||
| // Else it is the default parameter set (Line breakpoint)... | ||
| Debug.Assert(ParameterSetName.Equals(LineParameterSetName, StringComparison.OrdinalIgnoreCase)); | ||
|
|
||
| for (int i = 0; i < Line.Length; i++) | ||
| { | ||
| if (Line[i] < 1) | ||
| { | ||
| WriteError( | ||
| new ErrorRecord( | ||
| new ArgumentException(Debugger.LineLessThanOne), | ||
| "NewPSBreakpoint:LineLessThanOne", | ||
| ErrorCategory.InvalidArgument, | ||
| null)); | ||
|
|
||
| continue; | ||
| } | ||
|
|
||
| foreach (string path in scripts) | ||
| { | ||
| if (Column != 0) | ||
| { | ||
| WriteObject(new LineBreakpoint(path, Line[i], Column, Action)); | ||
| } | ||
| else | ||
| { | ||
| WriteObject(new LineBreakpoint(path, Line[i], Action)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
122 changes: 122 additions & 0 deletions
122
src/Microsoft.PowerShell.Commands.Utility/commands/utility/PSBreakpointCreationBase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.ObjectModel; | ||
| using System.IO; | ||
| using System.Management.Automation; | ||
| using System.Management.Automation.Internal; | ||
|
|
||
| namespace Microsoft.PowerShell.Commands | ||
| { | ||
| /// <summary> | ||
| /// Base class for Set/New-PSBreakpoint. | ||
| /// </summary> | ||
| public class PSBreakpointCreationBase : PSCmdlet | ||
| { | ||
| internal const string CommandParameterSetName = "Command"; | ||
| internal const string LineParameterSetName = "Line"; | ||
| internal const string VariableParameterSetName = "Variable"; | ||
|
|
||
| #region parameters | ||
|
|
||
| /// <summary> | ||
| /// The action to take when hitting this breakpoint. | ||
| /// </summary> | ||
| [Parameter(ParameterSetName = CommandParameterSetName)] | ||
| [Parameter(ParameterSetName = LineParameterSetName)] | ||
| [Parameter(ParameterSetName = VariableParameterSetName)] | ||
| public ScriptBlock Action { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The column to set the breakpoint on. | ||
| /// </summary> | ||
| [Parameter(Position = 2, ParameterSetName = LineParameterSetName)] | ||
| [ValidateRange(1, int.MaxValue)] | ||
| public int Column { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The command(s) to set the breakpoint on. | ||
| /// </summary> | ||
| [Alias("C")] | ||
| [Parameter(ParameterSetName = CommandParameterSetName, Mandatory = true)] | ||
| public string[] Command { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The line to set the breakpoint on. | ||
| /// </summary> | ||
| [Parameter(Position = 1, ParameterSetName = LineParameterSetName, Mandatory = true)] | ||
| public int[] Line { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The script to set the breakpoint on. | ||
| /// </summary> | ||
| [Parameter(ParameterSetName = CommandParameterSetName, Position = 0)] | ||
| [Parameter(ParameterSetName = LineParameterSetName, Mandatory = true, Position = 0)] | ||
| [Parameter(ParameterSetName = VariableParameterSetName, Position = 0)] | ||
| [ValidateNotNull] | ||
| public string[] Script { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The variables to set the breakpoint(s) on. | ||
| /// </summary> | ||
| [Alias("V")] | ||
| [Parameter(ParameterSetName = VariableParameterSetName, Mandatory = true)] | ||
| public string[] Variable { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The access type for variable breakpoints to break on. | ||
| /// </summary> | ||
| [Parameter(ParameterSetName = VariableParameterSetName)] | ||
| public VariableAccessMode Mode { get; set; } = VariableAccessMode.Write; | ||
|
|
||
| #endregion parameters | ||
|
|
||
| internal Collection<string> ResolveScriptPaths() | ||
| { | ||
| Collection<string> scripts = new Collection<string>(); | ||
|
|
||
| if (Script != null) | ||
| { | ||
| foreach (string script in Script) | ||
| { | ||
| Collection<PathInfo> scriptPaths = SessionState.Path.GetResolvedPSPathFromPSPath(script); | ||
|
|
||
| for (int i = 0; i < scriptPaths.Count; i++) | ||
| { | ||
| string providerPath = scriptPaths[i].ProviderPath; | ||
|
|
||
| if (!File.Exists(providerPath)) | ||
| { | ||
| WriteError( | ||
| new ErrorRecord( | ||
| new ArgumentException(StringUtil.Format(Debugger.FileDoesNotExist, providerPath)), | ||
| "NewPSBreakpoint:FileDoesNotExist", | ||
| ErrorCategory.InvalidArgument, | ||
| null)); | ||
|
|
||
| continue; | ||
| } | ||
|
|
||
| string extension = Path.GetExtension(providerPath); | ||
|
|
||
| if (!extension.Equals(".ps1", StringComparison.OrdinalIgnoreCase) && !extension.Equals(".psm1", StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| WriteError( | ||
| new ErrorRecord( | ||
| new ArgumentException(StringUtil.Format(Debugger.WrongExtension, providerPath)), | ||
| "NewPSBreakpoint:WrongExtension", | ||
| ErrorCategory.InvalidArgument, | ||
| null)); | ||
| continue; | ||
| } | ||
|
|
||
| scripts.Add(Path.GetFullPath(providerPath)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return scripts; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add useful doc comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed