3.2 KiB
Windows PowerShell Debugger API Sample
This sample shows how to use the PowerShell Debugger API.
This sample shows how to use the PowerShell debugging API to handle debugger events and process debug commands. It also demonstrates Workflow debugging. Workflow debugging is new for PowerShell version 4 and is an opt-in feature. In order to debug Workflow script functions the debugger DebugMode must include the DebugModes.LocalScript flag. Note that Workflow is not supported for WOW (Windows on Windows) and so this sample should be built using x64 CPU if building on an x64 platform.
The DebuggerSample class contains a single public Run method that creates a sample script file, sets a single breakpoint in the script Workflow function, and runs the script. There are two event handlers that handle the debugger Debugger.BreakpointUpdated and Debugger.DebuggerStop events. There is also a simple Read, Evaluate, Print Loop (REPL) that handles user debugger commands.
Sample Objectives
This sample demonstrates the following:
- Creating a sample script file to debug that includes a Workflow function.
- How to handle a Debugger.BreakpointUpdated event.
- How to handle a Debugger.DebuggerStop event.
- How to process user debugger commands in a simple REPL.
Related topics
Reference
Operating system requirements
Client
Windows 8.1
Server
Windows Server 2012 R2
Build the sample
-
If you are building on an x64 platform make sure your are building to an x64 CPU.
-
Start Microsoft Visual Studio and select File > Open > Project/Solution.
-
Go to the directory named for the sample, and double-click the Visual Studio Solution (.sln) file.
-
Make sure the DebuggerSample project references the System.Management.Automation.dll assembly.
-
Press F7 or use Build > Build Solution to build the sample.
The library will be built in the default \bin or \bin\Debug directory.
Run the sample
- Build the project as described above and run it.
- A console will appear that runs the sample script file and stops at the breakpoint on line 10.
- Type
'h'to get the debugger help list. - Type
'k' to see the call stack. - Type
'list'to see the script and the current line of execution. - Type
'v'to step through the Workflow script. - Type
'$Title'to see the Title variable. - Type
'$JobId'to see the Workflow job id. - Type
'Get-PSBreakpoint'to see the breakpoints. You can also add a new breakpoint with Set-PSBreakpoint. - Type
'o'to step out of the Workflow function. - Type
'c'to finish running the script.