| | | 1 | | |
| | | 2 | | <# |
| | | 3 | | .SYNOPSIS |
| | | 4 | | Tests if the current PowerShell session is in a debugging context. |
| | | 5 | | .DESCRIPTION |
| | | 6 | | Tests if the current PowerShell session is in a debugging context. |
| | | 7 | | This is determined by checking if a managed debugger is attached, |
| | | 8 | | .PARAMETER IgnorePSDebugContext |
| | | 9 | | If set, ignores whether the session is currently paused at a breakpoint or step. |
| | | 10 | | .PARAMETER IgnoreHostDebuggerEnabled |
| | | 11 | | If set, ignores whether the host's debugger is enabled (e.g., in VS Code). |
| | | 12 | | .EXAMPLE |
| | | 13 | | Test-KrDebugContext |
| | | 14 | | Returns $true if a managed debugger is attached, the -Debug switch is used, |
| | | 15 | | or the KESTRUN_DEBUG environment variable is set to a truthy value; otherwise, $false. |
| | | 16 | | #> |
| | | 17 | | function Test-KrDebugContext { |
| | | 18 | | [KestrunRuntimeApi('Everywhere')] |
| | | 19 | | [CmdletBinding()] |
| | | 20 | | [outputType([bool])] |
| | | 21 | | param ( |
| | | 22 | | [Parameter(Mandatory = $false)] |
| | | 23 | | [switch]$IgnorePSDebugContext, |
| | | 24 | | [Parameter(Mandatory = $false)] |
| | | 25 | | [switch]$IgnoreHostDebuggerEnabled |
| | | 26 | | ) |
| | 0 | 27 | | return ((-not $IgnorePSDebugContext.IsPresent) -and ($PSDebugContext)) -and |
| | 0 | 28 | | ((-not $IgnoreHostDebuggerEnabled.IsPresent) -and $Host.DebuggerEnabled) |
| | | 29 | | } |