コード例 #1
0
ファイル: Debugger.cs プロジェクト: nickchal/pash
 internal Debugger(System.Management.Automation.ExecutionContext context)
 {
     this._context = context;
     this.InBreakpoint = false;
     this._idToBreakpoint = new Dictionary<int, Breakpoint>();
     this._pendingBreakpoints = new List<LineBreakpoint>();
     this._boundBreakpoints = new Dictionary<string, Tuple<WeakReference, List<LineBreakpoint>>>(StringComparer.OrdinalIgnoreCase);
     this._commandBreakpoints = new List<CommandBreakpoint>();
     this._variableBreakpoints = new Dictionary<string, List<VariableBreakpoint>>(StringComparer.OrdinalIgnoreCase);
     this._steppingMode = SteppingMode.None;
     this._callStack = new List<CallStackInfo>();
 }
コード例 #2
0
        private void StepperMotorTest(StepperMotorIndex motorIndex, SteppingMode steppingMode = SteppingMode.FullSteps)
        {
            if (stepperMotor.IsInitialized)
            {
                // Configure steps, and RPM
                const uint steps = 200;
                const byte rpm   = 20;

                // Set speed
                stepperMotor.SetSpeed(rpm);

                // Move motor forward
                stepperMotor.Move(motorIndex, MotorDirection.Forward, steps, steppingMode);
                //stepperMotor.MoveWithSpeedAdjustment(motorIndex, MotorDirection.Forward, steps, steppingMode);

                // ... and go back to initial position
                stepperMotor.Move(motorIndex, MotorDirection.Backward, steps, steppingMode);
                //stepperMotor.MoveWithSpeedAdjustment(motorIndex, MotorDirection.Backward, steps, steppingMode);
            }
        }
コード例 #3
0
ファイル: Debugger.cs プロジェクト: modulexcite/pash-1
        private void ResumeExecution(DebuggerResumeAction action)
        {
            switch (action)
            {
            case DebuggerResumeAction.Continue:
                break;

            case DebuggerResumeAction.StepInto:
                this._steppingMode   = SteppingMode.StepIn;
                this._overOrOutFrame = null;
                return;

            case DebuggerResumeAction.StepOut:
                if (this._callStack.Count <= 1)
                {
                    break;
                }
                this._steppingMode   = SteppingMode.StepIn;
                this._overOrOutFrame = this._callStack[this._callStack.Count - 2];
                return;

            case DebuggerResumeAction.StepOver:
                this._steppingMode   = SteppingMode.StepIn;
                this._overOrOutFrame = this._callStack.Last <CallStackInfo>();
                return;

            case DebuggerResumeAction.Stop:
                this._steppingMode   = SteppingMode.None;
                this._overOrOutFrame = null;
                throw new TerminateException();

            default:
                return;
            }
            this._steppingMode   = SteppingMode.None;
            this._overOrOutFrame = null;
        }
コード例 #4
0
        private void UpdateChannels(SteppingMode steppingMode = SteppingMode.FullSteps)
        {
            StepperMotorPhase currentPhase = null;

            switch (steppingMode)
            {
            case SteppingMode.MicroSteps:
                currentPhase = GetMicroStepControlPhase();
                break;

            default:
                currentPhase = GetFullStepControlPhase();
                break;
            }

            pcaPwmDriver.SetChannelValue(channels.PwmA, currentPhase.PwmA);
            pcaPwmDriver.SetChannelValue(channels.PwmB, currentPhase.PwmB);

            pcaPwmDriver.SetChannelValue(channels.AIn1, currentPhase.AIn1);
            pcaPwmDriver.SetChannelValue(channels.AIn2, currentPhase.AIn2);

            pcaPwmDriver.SetChannelValue(channels.BIn1, currentPhase.BIn1);
            pcaPwmDriver.SetChannelValue(channels.BIn2, currentPhase.BIn2);
        }
コード例 #5
0
ファイル: Debugger.cs プロジェクト: modulexcite/pash-1
        private void OnDebuggerStop(InvocationInfo invocationInfo, List <Breakpoint> breakpoints)
        {
            LocalRunspace currentRunspace = this._context.CurrentRunspace as LocalRunspace;

            if ((currentRunspace.PulsePipeline != null) && (currentRunspace.PulsePipeline == currentRunspace.GetCurrentlyRunningPipeline()))
            {
                this._context.EngineHostInterface.UI.WriteWarningLine((breakpoints.Count > 0) ? string.Format(CultureInfo.CurrentCulture, DebuggerStrings.WarningBreakpointWillNotBeHit, new object[] { breakpoints[0] }) : new InvalidOperationException().Message);
            }
            else
            {
                this._steppingMode = SteppingMode.None;
                EventHandler <DebuggerStopEventArgs> debuggerStop = this.DebuggerStop;
                if (debuggerStop != null)
                {
                    this.InBreakpoint = true;
                    this._context.SetVariable(SpecialVariables.PSDebugContextVarPath, new PSDebugContext(invocationInfo, breakpoints));
                    FunctionInfo baseObject = null;
                    bool         flag       = false;
                    try
                    {
                        Collection <PSObject> collection = this._context.SessionState.InvokeProvider.Item.Get(@"function:\prompt");
                        if ((collection != null) && (collection.Count > 0))
                        {
                            baseObject = collection[0].BaseObject as FunctionInfo;
                            if (string.Equals(baseObject.Definition, InitialSessionState.DefaultPromptString, StringComparison.OrdinalIgnoreCase))
                            {
                                flag = true;
                            }
                        }
                    }
                    catch (ItemNotFoundException)
                    {
                    }
                    if (flag)
                    {
                        string script = "\"[DBG]: PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) \"";
                        baseObject.Update(ScriptBlock.Create(script), true, ScopedItemOptions.Unspecified);
                    }
                    PSLanguageMode languageMode = this._context.LanguageMode;
                    PSLanguageMode?nullable     = null;
                    if (this._context.UseFullLanguageModeInDebugger && (this._context.LanguageMode != PSLanguageMode.FullLanguage))
                    {
                        nullable = new PSLanguageMode?(this._context.LanguageMode);
                        this._context.LanguageMode = PSLanguageMode.FullLanguage;
                    }
                    else if (SystemPolicy.GetSystemLockdownPolicy() == SystemEnforcementMode.Enforce)
                    {
                        nullable = new PSLanguageMode?(this._context.LanguageMode);
                        this._context.LanguageMode = PSLanguageMode.ConstrainedLanguage;
                    }
                    RunspaceAvailability runspaceAvailability = this._context.CurrentRunspace.RunspaceAvailability;
                    this._context.CurrentRunspace.UpdateRunspaceAvailability((this._context.CurrentRunspace.GetCurrentlyRunningPipeline() != null) ? RunspaceAvailability.AvailableForNestedCommand : RunspaceAvailability.Available, true);
                    try
                    {
                        this._context._debuggingMode = -1;
                        if (this._callStack.Any <CallStackInfo>())
                        {
                            this._callStack.Last <CallStackInfo>().TopFrameAtBreakpoint = true;
                        }
                        DebuggerStopEventArgs e = new DebuggerStopEventArgs(invocationInfo, breakpoints);
                        debuggerStop(this, e);
                        this.ResumeExecution(e.ResumeAction);
                    }
                    finally
                    {
                        this._context._debuggingMode = 1;
                        if (this._callStack.Any <CallStackInfo>())
                        {
                            this._callStack.Last <CallStackInfo>().TopFrameAtBreakpoint = false;
                        }
                        this._context.CurrentRunspace.UpdateRunspaceAvailability(runspaceAvailability, true);
                        if (nullable.HasValue)
                        {
                            this._context.LanguageMode = nullable.Value;
                        }
                        this._context.EngineSessionState.RemoveVariable("PSDebugContext");
                        if (flag)
                        {
                            baseObject.Update(ScriptBlock.Create(InitialSessionState.DefaultPromptString), true, ScopedItemOptions.Unspecified);
                        }
                        this.InBreakpoint = false;
                    }
                }
            }
        }
コード例 #6
0
ファイル: Debugger.cs プロジェクト: nickchal/pash
        private void ResumeExecution(DebuggerResumeAction action)
        {
            switch (action)
            {
                case DebuggerResumeAction.Continue:
                    break;

                case DebuggerResumeAction.StepInto:
                    this._steppingMode = SteppingMode.StepIn;
                    this._overOrOutFrame = null;
                    return;

                case DebuggerResumeAction.StepOut:
                    if (this._callStack.Count <= 1)
                    {
                        break;
                    }
                    this._steppingMode = SteppingMode.StepIn;
                    this._overOrOutFrame = this._callStack[this._callStack.Count - 2];
                    return;

                case DebuggerResumeAction.StepOver:
                    this._steppingMode = SteppingMode.StepIn;
                    this._overOrOutFrame = this._callStack.Last<CallStackInfo>();
                    return;

                case DebuggerResumeAction.Stop:
                    this._steppingMode = SteppingMode.None;
                    this._overOrOutFrame = null;
                    throw new TerminateException();

                default:
                    return;
            }
            this._steppingMode = SteppingMode.None;
            this._overOrOutFrame = null;
        }
コード例 #7
0
ファイル: Debugger.cs プロジェクト: nickchal/pash
 private void OnDebuggerStop(InvocationInfo invocationInfo, List<Breakpoint> breakpoints)
 {
     LocalRunspace currentRunspace = this._context.CurrentRunspace as LocalRunspace;
     if ((currentRunspace.PulsePipeline != null) && (currentRunspace.PulsePipeline == currentRunspace.GetCurrentlyRunningPipeline()))
     {
         this._context.EngineHostInterface.UI.WriteWarningLine((breakpoints.Count > 0) ? string.Format(CultureInfo.CurrentCulture, DebuggerStrings.WarningBreakpointWillNotBeHit, new object[] { breakpoints[0] }) : new InvalidOperationException().Message);
     }
     else
     {
         this._steppingMode = SteppingMode.None;
         EventHandler<DebuggerStopEventArgs> debuggerStop = this.DebuggerStop;
         if (debuggerStop != null)
         {
             this.InBreakpoint = true;
             this._context.SetVariable(SpecialVariables.PSDebugContextVarPath, new PSDebugContext(invocationInfo, breakpoints));
             FunctionInfo baseObject = null;
             bool flag = false;
             try
             {
                 Collection<PSObject> collection = this._context.SessionState.InvokeProvider.Item.Get(@"function:\prompt");
                 if ((collection != null) && (collection.Count > 0))
                 {
                     baseObject = collection[0].BaseObject as FunctionInfo;
                     if (string.Equals(baseObject.Definition, InitialSessionState.DefaultPromptString, StringComparison.OrdinalIgnoreCase))
                     {
                         flag = true;
                     }
                 }
             }
             catch (ItemNotFoundException)
             {
             }
             if (flag)
             {
                 string script = "\"[DBG]: PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) \"";
                 baseObject.Update(ScriptBlock.Create(script), true, ScopedItemOptions.Unspecified);
             }
             PSLanguageMode languageMode = this._context.LanguageMode;
             PSLanguageMode? nullable = null;
             if (this._context.UseFullLanguageModeInDebugger && (this._context.LanguageMode != PSLanguageMode.FullLanguage))
             {
                 nullable = new PSLanguageMode?(this._context.LanguageMode);
                 this._context.LanguageMode = PSLanguageMode.FullLanguage;
             }
             else if (SystemPolicy.GetSystemLockdownPolicy() == SystemEnforcementMode.Enforce)
             {
                 nullable = new PSLanguageMode?(this._context.LanguageMode);
                 this._context.LanguageMode = PSLanguageMode.ConstrainedLanguage;
             }
             RunspaceAvailability runspaceAvailability = this._context.CurrentRunspace.RunspaceAvailability;
             this._context.CurrentRunspace.UpdateRunspaceAvailability((this._context.CurrentRunspace.GetCurrentlyRunningPipeline() != null) ? RunspaceAvailability.AvailableForNestedCommand : RunspaceAvailability.Available, true);
             try
             {
                 this._context._debuggingMode = -1;
                 if (this._callStack.Any<CallStackInfo>())
                 {
                     this._callStack.Last<CallStackInfo>().TopFrameAtBreakpoint = true;
                 }
                 DebuggerStopEventArgs e = new DebuggerStopEventArgs(invocationInfo, breakpoints);
                 debuggerStop(this, e);
                 this.ResumeExecution(e.ResumeAction);
             }
             finally
             {
                 this._context._debuggingMode = 1;
                 if (this._callStack.Any<CallStackInfo>())
                 {
                     this._callStack.Last<CallStackInfo>().TopFrameAtBreakpoint = false;
                 }
                 this._context.CurrentRunspace.UpdateRunspaceAvailability(runspaceAvailability, true);
                 if (nullable.HasValue)
                 {
                     this._context.LanguageMode = nullable.Value;
                 }
                 this._context.EngineSessionState.RemoveVariable("PSDebugContext");
                 if (flag)
                 {
                     baseObject.Update(ScriptBlock.Create(InitialSessionState.DefaultPromptString), true, ScopedItemOptions.Unspecified);
                 }
                 this.InBreakpoint = false;
             }
         }
     }
 }
コード例 #8
0
ファイル: Debugger.cs プロジェクト: nickchal/pash
 internal void ExitScriptFunction()
 {
     if (this._callStack.Last<CallStackInfo>() == this._overOrOutFrame)
     {
         this._overOrOutFrame = null;
     }
     this._callStack.RemoveAt(this._callStack.Count - 1);
     if (this._callStack.Count == 0)
     {
         this._steppingMode = SteppingMode.None;
     }
 }
コード例 #9
0
        public void MoveWithSpeedAdjustment(StepperMotorIndex motorIndex, MotorDirection direction, uint steps, SteppingMode steppingMode = SteppingMode.FullSteps)
        {
            steps = GetTotalStepCount(steppingMode, steps);

            var speedRamp = SpeedRampHelper.GenerateTrapezoidalRamp(steps);

            for (uint i = 0; i < steps; i++)
            {
                MakeStep(motorIndex, direction, steppingMode);

                var msAutoDelay = RpmToMsDelay(speedRamp[i], steppingMode);

                Task.Delay(msAutoDelay).Wait();
            }
        }
コード例 #10
0
        public void Move(StepperMotorIndex motorIndex, MotorDirection direction, uint steps, SteppingMode steppingMode = SteppingMode.FullSteps)
        {
            var msDelay = RpmToMsDelay(Rpm, steppingMode);

            steps = GetTotalStepCount(steppingMode, steps);

            for (uint i = 0; i < steps; i++)
            {
                MakeStep(motorIndex, direction, steppingMode);

                Task.Delay(msDelay).Wait();
            }
        }
コード例 #11
0
ファイル: debugger.cs プロジェクト: 40a/PowerShell
        private Debugger PopActiveDebugger()
        {
            Debugger poppedDebugger = null;
            if (_activeDebuggers.TryPop(out poppedDebugger))
            {
                int runningJobCount;
                lock (_syncObject)
                {
                    runningJobCount = _runningJobs.Count;
                }

                if (runningJobCount == 0)
                {
                    // If we are back to the root debugger and are in step mode, ensure
                    // that the root debugger is in step mode to continue stepping.
                    switch (_lastActiveDebuggerAction)
                    {
                        case DebuggerResumeAction.StepInto:
                        case DebuggerResumeAction.StepOver:
                        case DebuggerResumeAction.StepOut:
                            // Set script debugger to step mode after the WF running
                            // script completes.
                            _steppingMode = SteppingMode.StepIn;
                            _overOrOutFrame = _nestedRunningFrame;
                            _nestedRunningFrame = null;
                            break;

                        case DebuggerResumeAction.Stop:
                            _nestedDebuggerStop = true;
                            break;

                        default:
                            ResumeExecution(DebuggerResumeAction.Continue);
                            break;
                    }

                    // Allow script debugger to continue in debugging mode.
                    _processingOutputCount = 0;
                    SetInternalDebugMode(InternalDebugMode.Enabled);
                    _currentDebuggerAction = _lastActiveDebuggerAction;
                    _lastActiveDebuggerAction = DebuggerResumeAction.Continue;
                }
            }

            return poppedDebugger;
        }
コード例 #12
0
ファイル: debugger.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Resumes execution after a breakpoint/step event has been handled
        /// </summary>
        private void ResumeExecution(DebuggerResumeAction action)
        {
            _previousDebuggerAction = _currentDebuggerAction;
            _currentDebuggerAction = action;

            switch (action)
            {
                case DebuggerResumeAction.StepInto:
                    _steppingMode = SteppingMode.StepIn;
                    _overOrOutFrame = null;
                    break;

                case DebuggerResumeAction.StepOut:
                    if (_callStack.Count > 1)
                    {
                        // When we pop to the parent frame, we'll clear _overOrOutFrame (so OnSequencePointHit
                        // will stop) and continue with a step.
                        _steppingMode = SteppingMode.StepIn;
                        _overOrOutFrame = _callStack[_callStack.Count - 2];
                    }
                    else
                    {
                        // Stepping out of the top frame is just like continue (allow hitting
                        // breakpoints in the current frame, but otherwise just go.)
                        goto case DebuggerResumeAction.Continue;
                    }
                    break;

                case DebuggerResumeAction.StepOver:
                    _steppingMode = SteppingMode.StepIn;
                    _overOrOutFrame = _callStack.Last();
                    break;

                case DebuggerResumeAction.Continue:
                    // nothing to  do, just continue
                    _steppingMode = SteppingMode.None;
                    _overOrOutFrame = null;
                    break;

                case DebuggerResumeAction.Stop:
                    _steppingMode = SteppingMode.None;
                    _overOrOutFrame = null;
                    throw new TerminateException();

                default:
                    Debug.Assert(false, "Received an unknown action: " + action);
                    break;
            }
        }
コード例 #13
0
ファイル: debugger.cs プロジェクト: 40a/PowerShell
        /// <summary>
        /// Raises the DebuggerStop event
        /// </summary>
        private void OnDebuggerStop(InvocationInfo invocationInfo, List<Breakpoint> breakpoints)
        {
            Diagnostics.Assert(breakpoints != null, "The list of breakpoints should not be null");

            LocalRunspace localRunspace = _context.CurrentRunspace as LocalRunspace;

            Diagnostics.Assert(localRunspace != null, "Debugging is only supported on local runspaces");

            if (localRunspace.PulsePipeline != null && localRunspace.PulsePipeline == localRunspace.GetCurrentlyRunningPipeline())
            {
                _context.EngineHostInterface.UI.WriteWarningLine(
                    breakpoints.Count > 0
                        ? String.Format(CultureInfo.CurrentCulture, DebuggerStrings.WarningBreakpointWillNotBeHit,
                                        breakpoints[0])
                        : new InvalidOperationException().Message);
                return;
            }

            _currentInvocationInfo = invocationInfo;
            _steppingMode = SteppingMode.None;

            // Optionally wait for a debug stop event subscriber if requested.
            _inBreakpoint = true;
            if (!WaitForDebugStopSubscriber())
            {
                // No subscriber.  Ignore this debug stop event.
                _inBreakpoint = false;
                return;
            }

            _context.SetVariable(SpecialVariables.PSDebugContextVarPath, new PSDebugContext(invocationInfo, breakpoints));

            FunctionInfo defaultPromptInfo = null;
            string originalPromptString = null;
            bool hadDefaultPrompt = false;

            try
            {
                Collection<PSObject> items = _context.SessionState.InvokeProvider.Item.Get("function:\\prompt");
                if ((items != null) && (items.Count > 0))
                {
                    defaultPromptInfo = items[0].BaseObject as FunctionInfo;
                    originalPromptString = defaultPromptInfo.Definition as string;

                    if (originalPromptString.Equals(InitialSessionState.DefaultPromptFunctionText, StringComparison.OrdinalIgnoreCase) ||
                        originalPromptString.Trim().StartsWith(s_processDebugPromptMatch, StringComparison.OrdinalIgnoreCase))
                    {
                        hadDefaultPrompt = true;
                    }
                }
            }
            catch (ItemNotFoundException)
            {
                // Ignore, it means they don't have the default prompt
            }

            // Update the prompt to the debug prompt
            if (hadDefaultPrompt)
            {
                int index = originalPromptString.IndexOf("\"", StringComparison.OrdinalIgnoreCase);
                if (index > -1)
                {
                    // Fix up prompt.
                    ++index;
                    string debugPrompt = "\"[DBG]: " + originalPromptString.Substring(index, originalPromptString.Length - index);
                    defaultPromptInfo.Update(
                        ScriptBlock.Create(debugPrompt), true, ScopedItemOptions.Unspecified);
                }
                else
                {
                    hadDefaultPrompt = false;
                }
            }

            PSLanguageMode? originalLanguageMode = null;
            if (_context.UseFullLanguageModeInDebugger &&
                (_context.LanguageMode != PSLanguageMode.FullLanguage))
            {
                originalLanguageMode = _context.LanguageMode;
                _context.LanguageMode = PSLanguageMode.FullLanguage;
            }
            else if (System.Management.Automation.Security.SystemPolicy.GetSystemLockdownPolicy() ==
                System.Management.Automation.Security.SystemEnforcementMode.Enforce)
            {
                // If there is a system lockdown in place, enforce it
                originalLanguageMode = _context.LanguageMode;
                _context.LanguageMode = PSLanguageMode.ConstrainedLanguage;
            }

            RunspaceAvailability previousAvailability = _context.CurrentRunspace.RunspaceAvailability;

            _context.CurrentRunspace.UpdateRunspaceAvailability(
                _context.CurrentRunspace.GetCurrentlyRunningPipeline() != null
                    ? RunspaceAvailability.AvailableForNestedCommand
                    : RunspaceAvailability.Available,
                true);

            Diagnostics.Assert(_context._debuggingMode == 1, "Should only be stopping when debugger is on.");

            try
            {
                SetInternalDebugMode(InternalDebugMode.InScriptStop);
                if (_callStack.Any())
                {
                    // Get-PSCallStack shouldn't report any frames above this frame, so mark it.  One alternative
                    // to marking the frame would be to not push new frames while debugging, but that limits our
                    // ability to give a full callstack if there are errors during eval.
                    _callStack.Last().TopFrameAtBreakpoint = true;
                }

                // Reset list lines.
                _commandProcessor.Reset();

                // Save a copy of the stop arguments.
                DebuggerStopEventArgs copyArgs = new DebuggerStopEventArgs(invocationInfo, breakpoints);
                _debuggerStopEventArgs.Push(copyArgs);

                // Blocking call to raise debugger stop event.
                DebuggerStopEventArgs e = new DebuggerStopEventArgs(invocationInfo, breakpoints);
                RaiseDebuggerStopEvent(e);
                ResumeExecution(e.ResumeAction);
            }
            finally
            {
                SetInternalDebugMode(InternalDebugMode.Enabled);
                if (_callStack.Any())
                {
                    _callStack.Last().TopFrameAtBreakpoint = false;
                }

                _context.CurrentRunspace.UpdateRunspaceAvailability(previousAvailability, true);

                if (originalLanguageMode.HasValue)
                {
                    _context.LanguageMode = originalLanguageMode.Value;
                }

                _context.EngineSessionState.RemoveVariable(SpecialVariables.PSDebugContext);

                if (hadDefaultPrompt)
                {
                    // Restore the prompt if they had our default
                    defaultPromptInfo.Update(
                        ScriptBlock.Create(originalPromptString), true, ScopedItemOptions.Unspecified);
                }

                DebuggerStopEventArgs oldArgs;
                _debuggerStopEventArgs.TryPop(out oldArgs);

                _inBreakpoint = false;
            }
        }