コード例 #1
0
        /// <summary>
        /// Remove breakpoint
        /// </summary>
        /// <param name="breakpoint">Breakpoint to be removed</param>
        public void RemoveBreakpoint(ScriptBreakpoint breakpoint)
        {
            Log.InfoFormat("RemoveBreakpoint: {0} {1} {2}", breakpoint.File, breakpoint.Line, breakpoint.Column);
            string fileName = Debugger.DebuggingService.GetTrueFileName(breakpoint.File);

            try
            {
                if (Debugger.DebuggingService.GetRunspaceAvailability() == RunspaceAvailability.Available)
                {
                    Debugger.DebuggingService.RemoveBreakpoint(new PowerShellBreakpoint(fileName, breakpoint.Line, breakpoint.Column));
                }
                else if (Debugger.IsDebuggingCommandReady)
                {
                    int id = Debugger.DebuggingService.GetPSBreakpointId(new PowerShellBreakpoint(fileName, breakpoint.Line, breakpoint.Column));
                    if (id >= 0)
                    {
                        Debugger.DebuggingService.RemoveBreakpointById(id);
                    }
                }
                _breakpoints.Remove(breakpoint);
            }
            catch (Exception ex)
            {
                Log.Error("Failed to remove breakpoint.", ex);
            }
        }
コード例 #2
0
        public void BreakpointHit(ScriptBreakpoint breakpoint, ScriptProgramNode node)
        {
            Log.Debug("BreakpointHit");
            var iid = new Guid(BreakPointHitEvent.IID);

            _callback.Event(_engine, null, node, node, new BreakPointHitEvent(breakpoint), ref iid, BreakPointHitEvent.Attributes);
        }
コード例 #3
0
        // Creates a pending breakpoint in the engine. A pending breakpoint is contains all the information needed to bind a breakpoint to
        // a location in the debuggee.
        int IDebugEngine2.CreatePendingBreakpoint(IDebugBreakpointRequest2 pBPRequest,
                                                  out IDebugPendingBreakpoint2 ppPendingBP)
        {
            Log.Debug("Engine: CreatePendingBreakPoint");

            ppPendingBP = null;

            var info = new BP_REQUEST_INFO[1];

            info[0].bpLocation.bpLocationType = (uint)enum_BP_LOCATION_TYPE.BPLT_FILE_LINE;
            if (pBPRequest.GetRequestInfo(enum_BPREQI_FIELDS.BPREQI_BPLOCATION, info) == VSConstants.S_OK)
            {
                var    position = (IDebugDocumentPosition2)Marshal.GetObjectForIUnknown(info[0].bpLocation.unionmember2);
                var    start    = new TEXT_POSITION[1];
                var    end      = new TEXT_POSITION[1];
                string fileName;

                position.GetRange(start, end);
                position.GetFileName(out fileName);

                //VS has a 0 based line\column value. PowerShell starts at 1
                var breakpoint = new ScriptBreakpoint(_node, fileName, (int)start[0].dwLine + 1, (int)start[0].dwColumn, _events);
                ppPendingBP = breakpoint;

                bps.Add(breakpoint);
            }

            return(VSConstants.S_OK);
        }
コード例 #4
0
        /// <summary>
        /// Enable breakpoint
        /// </summary>
        /// <param name="breakpoint">Breakpoint to be added</param>
        /// <param name="fEnable">0 - disable, 1 - enable</param>
        public void EnableBreakpoint(ScriptBreakpoint breakpoint, int fEnable)
        {
            string operation = fEnable == 0 ? "Disable" : "Enable";

            Log.InfoFormat("{3} breakpoint: {0} {1} {2}", breakpoint.File, breakpoint.Line, breakpoint.Column, operation);
            string fileName = Debugger.DebuggingService.GetTrueFileName(breakpoint.File);

            try
            {
                if (Debugger.DebuggingService.GetRunspaceAvailability() == RunspaceAvailability.Available)
                {
                    Debugger.DebuggingService.EnableBreakpoint(new PowerShellBreakpoint(fileName, breakpoint.Line, breakpoint.Column), fEnable == 0 ? false : true);
                }
                else if (Debugger.IsDebuggingCommandReady)
                {
                    int id = Debugger.DebuggingService.GetPSBreakpointId(new PowerShellBreakpoint(fileName, breakpoint.Line, breakpoint.Column));
                    if (id >= 0)
                    {
                        Debugger.DebuggingService.ExecuteDebuggingCommandOutNull(
                            fEnable == 0 ?
                            string.Format(DebugEngineConstants.DisablePSBreakpoint, id) :
                            string.Format(DebugEngineConstants.EnablePSBreakpoint, id));
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("Failed to {0} breakpoint.", operation), ex);
            }
        }
コード例 #5
0
        public void BreakpointAdded(ScriptBreakpoint breakpoint)
        {
            Log.Debug("BreakpointAdded");

            if (Debugger != null)
            {
                Debugger.BreakpointManager.SetBreakpoint(breakpoint);
            }
        }
コード例 #6
0
        public void BreakpointEnabled(ScriptBreakpoint breakpoint, int fEnable)
        {
            Log.Debug("BreakpointEnabled");

            if (Debugger != null)
            {
                Debugger.BreakpointManager.EnableBreakpoint(breakpoint, fEnable);
            }
        }
コード例 #7
0
 public override bool Equals(object obj)
 {
     if (obj != null)
     {
         ScriptBreakpoint other = obj as ScriptBreakpoint;
         if (other != null)
         {
             return(other.Column == Column && other.Line == Line &&
                    File.Equals(other.File, StringComparison.InvariantCultureIgnoreCase) &&
                    _node.Equals(other._node));
         }
     }
     return(false);
 }
コード例 #8
0
        /// <summary>
        /// This event handler adds or removes breakpoints monitored by Visual Studio.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Debugger_BreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
        {
            if (_initializingRunspace)
            {
                return;
            }

            if (e.UpdateType == BreakpointUpdateType.Set)
            {
                var lbp = e.Breakpoint as LineBreakpoint;
                if (lbp != null)
                {
                    var breakpoint = new ScriptBreakpoint(_node, e.Breakpoint.Script, lbp.Line, lbp.Column, _events);
                    breakpoint.Bind();

                    var bp = bps.FirstOrDefault(
                        m =>
                        m.Column == lbp.Column && m.Line == lbp.Line &&
                        m.File.Equals(lbp.Script, StringComparison.InvariantCultureIgnoreCase));
                    if (bp == null)
                    {
                        bps.Add(breakpoint);
                    }
                }
            }

            if (e.UpdateType == BreakpointUpdateType.Removed)
            {
                var lbp = e.Breakpoint as LineBreakpoint;
                if (lbp != null)
                {
                    var bp = bps.FirstOrDefault(
                        m =>
                        m.Column == lbp.Column && m.Line == lbp.Line &&
                        m.File.Equals(lbp.Script, StringComparison.InvariantCultureIgnoreCase));

                    if (bp != null)
                    {
                        bp.Delete();
                        bps.Remove(bp);
                    }
                }
            }
        }
コード例 #9
0
        private void SetBreakpoint(ScriptBreakpoint breakpoint)
        {
            Log.InfoFormat("SetBreakpoint: {0} {1} {2}", breakpoint.File, breakpoint.Line, breakpoint.Column);

            try
            {
                using (var pipeline = (_runspace.CreatePipeline()))
                {
                    var command = new Command("Set-PSBreakpoint");
                    command.Parameters.Add("Script", breakpoint.File);
                    command.Parameters.Add("Line", breakpoint.Line);

                    pipeline.Commands.Add(command);

                    pipeline.Invoke();
                }
            }
            catch (Exception ex)
            {
                Log.Error("Failed to set breakpoint.", ex);
            }
        }
コード例 #10
0
        /// <summary>
        /// Add breakpoint
        /// </summary>
        /// <param name="breakpoint">Breakpoint to be added</param>
        public void SetBreakpoint(ScriptBreakpoint breakpoint)
        {
            Log.InfoFormat("SetBreakpoint: {0} {1} {2}", breakpoint.File, breakpoint.Line, breakpoint.Column);
            string fileName = Debugger.DebuggingService.GetTrueFileName(breakpoint.File);

            try
            {
                if (Debugger.DebuggingService.GetRunspaceAvailability() == RunspaceAvailability.Available)
                {
                    Debugger.DebuggingService.SetBreakpoint(new PowerShellBreakpoint(fileName, breakpoint.Line, breakpoint.Column));
                }
                else if (Debugger.IsDebuggingCommandReady)
                {
                    Debugger.DebuggingService.ExecuteDebuggingCommandOutNull(string.Format(DebugEngineConstants.SetPSBreakpoint, fileName, breakpoint.Line));
                }
                _breakpoints.Add(breakpoint);
            }
            catch (Exception ex)
            {
                Log.Error("Failed to set breakpoint.", ex);
            }
        }
コード例 #11
0
ファイル: Engine.cs プロジェクト: vairam-svs/poshtools
        // Creates a pending breakpoint in the engine. A pending breakpoint is contains all the information needed to bind a breakpoint to 
        // a location in the debuggee.
        int IDebugEngine2.CreatePendingBreakpoint(IDebugBreakpointRequest2 pBPRequest,
                                                  out IDebugPendingBreakpoint2 ppPendingBP)
        {
            Log.Debug("Engine: CreatePendingBreakPoint");

            ppPendingBP = null;

            var info = new BP_REQUEST_INFO[1];
            info[0].bpLocation.bpLocationType = (uint)enum_BP_LOCATION_TYPE.BPLT_FILE_LINE;
            if (pBPRequest.GetRequestInfo(enum_BPREQI_FIELDS.BPREQI_BPLOCATION, info) == VSConstants.S_OK)
            {
                var position = (IDebugDocumentPosition2)Marshal.GetObjectForIUnknown(info[0].bpLocation.unionmember2);
                var start = new TEXT_POSITION[1]; 
                var end = new TEXT_POSITION[1];
                string fileName;

                position.GetRange(start, end);
                position.GetFileName(out fileName);

                //VS has a 0 based line\column value. PowerShell starts at 1
                var breakpoint = new ScriptBreakpoint(_node, fileName, (int)start[0].dwLine + 1, (int)start[0].dwColumn, _events);
                ppPendingBP = breakpoint;

                bps.Add(breakpoint);
            }

            return VSConstants.S_OK;
        }
コード例 #12
0
ファイル: Engine.cs プロジェクト: vairam-svs/poshtools
        /// <summary>
        /// This event handler adds or removes breakpoints monitored by Visual Studio.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Debugger_BreakpointUpdated(object sender, BreakpointUpdatedEventArgs e)
        {
            if (_initializingRunspace) return;

            if (e.UpdateType == BreakpointUpdateType.Set)
            {
                var lbp = e.Breakpoint as LineBreakpoint;
                if (lbp != null)
                {
                    var breakpoint = new ScriptBreakpoint(_node, e.Breakpoint.Script, lbp.Line, lbp.Column, _events);
                    breakpoint.Bind();

                    var bp = bps.FirstOrDefault(
                                                m =>
                                                m.Column == lbp.Column && m.Line == lbp.Line &&
                                                m.File.Equals(lbp.Script, StringComparison.InvariantCultureIgnoreCase));
                    if (bp == null)
                        bps.Add(breakpoint);
                }
            }

            if (e.UpdateType == BreakpointUpdateType.Removed)
            {
                var lbp = e.Breakpoint as LineBreakpoint;
                if (lbp != null)
                {
                    var bp =bps.FirstOrDefault(
                        m =>
                        m.Column == lbp.Column && m.Line == lbp.Line &&
                        m.File.Equals(lbp.Script, StringComparison.InvariantCultureIgnoreCase));

                    if (bp != null)
                    {
                        bp.Delete();
                        bps.Remove(bp);
                    }
                }
            }
        }
コード例 #13
0
 public BreakPointHitEvent(ScriptBreakpoint breakpoint)
 {
     _breakpoint = breakpoint;
 }
コード例 #14
0
ファイル: EngineEvents.cs プロジェクト: vairam-svs/poshtools
 public BreakPointHitEvent(ScriptBreakpoint breakpoint)
 {
     _breakpoint = breakpoint;
 }
コード例 #15
0
ファイル: EngineEvents.cs プロジェクト: vairam-svs/poshtools
 public void BreakpointHit(ScriptBreakpoint breakpoint, ScriptProgramNode node)
 {
     Log.Debug("BreakpointHit");
     var iid = new Guid(BreakPointHitEvent.IID);
     _callback.Event(_engine, null, node, node, new BreakPointHitEvent(breakpoint), ref iid, BreakPointHitEvent.Attributes);
 }