/// <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); } }
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); }
// 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); }
/// <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); } }
public void BreakpointAdded(ScriptBreakpoint breakpoint) { Log.Debug("BreakpointAdded"); if (Debugger != null) { Debugger.BreakpointManager.SetBreakpoint(breakpoint); } }
public void BreakpointEnabled(ScriptBreakpoint breakpoint, int fEnable) { Log.Debug("BreakpointEnabled"); if (Debugger != null) { Debugger.BreakpointManager.EnableBreakpoint(breakpoint, fEnable); } }
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); }
/// <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); } } } }
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); } }
/// <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); } }
// 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; }
/// <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); } } } }
public BreakPointHitEvent(ScriptBreakpoint breakpoint) { _breakpoint = breakpoint; }