BREAKPOINTSīesides setting line breakpoints, the PowerShell debugger allows you to set function breakpoints, conditional breakpoints, and tracepoints. Keep in mind that the variables entered as a watch may not be available in all scopes. This values will always be evaluated, if possible. Simply click the + button (highlighted in the following screenshot), and type the variable name or a PowerShell expression: The WATCH section allows you to add a watch for any variable or expression. Just remember, the expression has to be valid PowerShell syntax. You can enter arbitrary expressions when setting a variable’s value, for example, $itemCount+10 or $null or $true. To change those values, double-click the value that you want to change, enter a new value, and click outside the edit box to complete the operation. You can do more than just inspect variable values. If the type is a collection or an array, the number of elements is displayed as well. For non-primitive variables, the type information is displayed. The VARIABLES section allows you to inspect variable values, including complex variables such as those shown in the following screenshot:įor primitive variable types, the value is displayed directly, typically as numbers, strings, and Booleans. Hover tips can show simple values, like numbers and strings, or complex objects as shown in the following screenshot: You can also see from the previous screenshot that you get hover tips when you hold the cursor over a variable. The BREAKPOINTS section provides a central UI to manage, that is, create, disable, enable, and delete breakpoints that you may have defined over many different script files. The CALL STACK section displays the call stack, and you can also select a different frame in the call stack to examine calling functions, scripts, and the variables that are defined in those scopes. The WATCH section allows you to specify a variable or expression whose value should always be displayed. However, if the variable you are looking for isn’t listed in Auto, you can look for it in the Local, Script, or Global groups. The Auto group weeds out the PowerShell automatic variables and leaves just the variables you’ve defined and are likely interested in seeing. The VARIABLES section of the Debug view allows easy inspection of variable values. Now, let’s look at the Debug view features that are available during a debug session. The Debug actions pane provides buttons for: First, make sure the DebugTest.ps1 file’s editor window is still the active window, and then press F5 or click the green Start Debugging button to the left of the Launch Configuration dropdown (shown in the previous screenshot).Īfter the debugger starts, you will see the Debug actions pane (shown in the following screenshot), and the debugger should pause at the breakpoint that you set. Like the PowerShell integrated scripting environment (ISE), this configuration will execute the file that’s in the active editor window under the debugger when debugging is started. In the Launch Configuration dropdown (shown in the following screenshot), select the PowerShell Launch (current file) configuration. To open the Debug view, in the View Bar select Debug from the View menu or press Ctrl + Shift + D. To set the breakpoint, either click in the left editor margin or press F9 to toggle the breakpoint on and off for the current line. After the Examples folder has loaded, open the DebugTest.ps1 file, and set a breakpoint on the line that has the Start-Sleep command. Press Ctrl+Shift+P (Cmd+Shift+P on Mac) to open the PowerShell extension’s Examples folder, type PowerShell open examples, and then press Enter. First look at the PowerShell Debugger in Visual Studio Code And, with the latest version of the PowerShell extension, you can simply restart the current PowerShell session without restarting Visual Studio Code to get going again. One advantage of this approach is that a crash of the PowerShell Editor Services process doesn’t cause Visual Studio Code to crash. PowerShell Editor Services runs in a separate process and supplies both language and debugging services to Visual Studio Code via a JSON remote procedure call (RPC) protocol that’s defined by Visual Studio Code. These features are provided by the PowerShell extension, or, more accurately, by the PowerShell Editor Services module which comes with the PowerShell extension. In the first of this two-part series, we will cover the many features of the PowerShell debugger for Visual Studio Code. If you don’t already have Visual Studio Code configured with the PowerShell extension, read those blog posts to get caught up. In previous blog posts, we covered how to get started with PowerShell development in Visual Studio Code and the editing features of Visual Studio Code and the PowerShell extension. Summary: Here’s a look at the many features of the PowerShell debugger for Visual Studio Code.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |