MSH: Debugging Scripts

The Monad team blog has a series of posts on debugging MSH scripts.  There are some nice trace facilities as well as single-stepping and sub-shell capabilities in MSH.  Check it out:

Here are some functions and aliases I use to support debugging scripts:

$global:__breakpointSkipCount = 0

set-alias bp Start-Debug
function Start-Ddebug
    if (-not $global:__breakpointsEnabled) { return }
    if ($global:__breakpointSkipCount -gt 0) {
    $scriptName = $MyInvocation.ScriptName
    $lineNumber = $MyInvocation.ScriptLineNumber
    function prompt
        "Bkpt: {0}:{1} ! " -f
            $(if ([String]::IsNullOrEmpty($scriptName)) {
                "globalscope", "?"
              else {
                (parse-path $scriptName -Leaf), $lineNumber
    set-mshdebug -step

set-alias sbp Skip-Breakpoints
function Skip-Breakpoints([int]$num) {
     $global:__breakpointSkipCount = $num

set-alias ebp Enable-Breakpoints
function Enable-Breakpoints {
    $global:__breakpointsEnabled = $true
    "Breakpoints enabled"

set-alias dbp Disable-Bbreakpoints
function Disable-Breakpoints {
    $global:__breakpointsEnabled = $false
    "Breakpoints disabled"

This entry was posted in Monad. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s