// Binds this pending breakpoint to one or more code locations. int IDebugPendingBreakpoint2.Bind() { if (CanBind()) { // Get the location in the document that the breakpoint is in. var startPosition = new TEXT_POSITION[1]; var endPosition = new TEXT_POSITION[1]; string fileName; var docPosition = (IDebugDocumentPosition2)(Marshal.GetObjectForIUnknown(_bpRequestInfo.bpLocation.unionmember2)); EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition)); EngineUtils.CheckOk(docPosition.GetFileName(out fileName)); _breakpoint = _engine.Process.AddBreakpoint( fileName, (int)startPosition[0].dwLine, (int)startPosition[0].dwColumn, _enabled, AD7BoundBreakpoint.GetBreakOnForPassCount(_bpRequestInfo.bpPassCount), _bpRequestInfo.bpCondition.bstrCondition); _bpManager.AddPendingBreakpoint(_breakpoint, this); _breakpoint.BindAsync().WaitAsync(TimeSpan.FromSeconds(2)).Wait(); return VSConstants.S_OK; } // The breakpoint could not be bound. This may occur for many reasons such as an invalid location, an invalid expression, etc... // The sample engine does not support this, but a real world engine will want to send an instance of IDebugBreakpointErrorEvent2 to the // UI and return a valid instance of IDebugErrorBreakpoint2 from IDebugPendingBreakpoint2::EnumErrorBreakpoints. The debugger will then // display information about why the breakpoint did not bind to the user. return VSConstants.S_FALSE; }
/// <summary> /// Handles break point event. /// </summary> /// <param name="sender">Sender.</param> /// <param name="e">Event arguments.</param> private void OnBreakpointEvent(object sender, BreakpointMessageEventArgs e) { IsRunning = e.Message.IsRunning; int scriptId = e.Message.ScriptId; string filename = e.Message.Filename; int lineNo = e.Message.Line; AddModuleIfNotExist(scriptId, filename); EventHandler <BreakpointHitEventArgs> breakpointHit = BreakpointHit; if (breakpointHit != null) { // Try to find break point on a line NodeBreakpoint breakpoint = _breakpoints.Values.FirstOrDefault( p => p.Line == lineNo && String.Compare(p.Filename, filename, StringComparison.OrdinalIgnoreCase) == 0); if (breakpoint != null) { breakpointHit(this, new BreakpointHitEventArgs(breakpoint, Thread)); return; } } EventHandler <ThreadEventArgs> asyncBreakpoint = AsyncBreakComplete; if (asyncBreakpoint != null) { asyncBreakpoint(this, new ThreadEventArgs(Thread)); } }
/// <summary> /// Adds a breakpoint. /// </summary> /// <param name="breakpoint">Break point.</param> public async Task AddBreakpointAsync(NodeBreakpoint breakpoint) { IResponseMessage response = await _client.SendMessage("setbreakpoint", new { type = "script", target = breakpoint.Filename, line = breakpoint.Line, column = breakpoint.Column, condition = breakpoint.Condition }).ConfigureAwait(false); var setBreakpointMessage = response as SetBreakpointMessage; if (setBreakpointMessage == null || !setBreakpointMessage.IsSuccessful) { string message = string.Format("Invalid breakpoint response: {0}", response); throw new InvalidOperationException(message); } IsRunning = response.IsRunning; breakpoint.Id = setBreakpointMessage.Id; breakpoint.Line = setBreakpointMessage.Line; breakpoint.Column = setBreakpointMessage.Column; if (!_wasContinued) { CheckWhetherFirstLineBreakpoint(breakpoint); } _breakpoints.Add(breakpoint.Id, breakpoint); }
// Binds this pending breakpoint to one or more code locations. int IDebugPendingBreakpoint2.Bind() { if (CanBind()) { // Get the location in the document that the breakpoint is in. var startPosition = new TEXT_POSITION[1]; var endPosition = new TEXT_POSITION[1]; var docPosition = (IDebugDocumentPosition2)(Marshal.GetObjectForIUnknown(this._bpRequestInfo.bpLocation.unionmember2)); EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition)); EngineUtils.CheckOk(docPosition.GetFileName(out var fileName)); this._breakpoint = this._engine.Process.AddBreakpoint( fileName, (int)startPosition[0].dwLine, (int)startPosition[0].dwColumn, this._enabled, AD7BoundBreakpoint.GetBreakOnForPassCount(this._bpRequestInfo.bpPassCount), this._bpRequestInfo.bpCondition.bstrCondition); this._bpManager.AddPendingBreakpoint(this._breakpoint, this); this._breakpoint.BindAsync().WaitAsync(TimeSpan.FromSeconds(2)).Wait(); return(VSConstants.S_OK); } // The breakpoint could not be bound. This may occur for many reasons such as an invalid location, an invalid expression, etc... // The sample engine does not support this, but a real world engine will want to send an instance of IDebugBreakpointErrorEvent2 to the // UI and return a valid instance of IDebugErrorBreakpoint2 from IDebugPendingBreakpoint2::EnumErrorBreakpoints. The debugger will then // display information about why the breakpoint did not bind to the user. return(VSConstants.S_FALSE); }
public void ProcessSetBreakpointResponse() { // Arrange const int commandId = 3; const int moduleId = 33; const int line = 2; const int column = 0; const string fileName = "module.js"; var module = new NodeModule(moduleId, fileName); var breakOn = new BreakOn(BreakOnKind.Equal, 2); var position = new FilePosition(fileName, line, column); var breakpoint = new NodeBreakpoint(null, position, true, breakOn, null); var setBreakpointCommand = new SetBreakpointCommand(commandId, module, breakpoint, false, false); JObject breakpointResponse = SerializationTestData.GetSetBreakpointResponse(); // Act setBreakpointCommand.ProcessResponse(breakpointResponse); // Assert Assert.AreEqual(2, setBreakpointCommand.BreakpointId); Assert.AreEqual(0, setBreakpointCommand.Column); Assert.AreEqual(0, setBreakpointCommand.Line); Assert.AreEqual(false, setBreakpointCommand.Running); Assert.AreEqual(33, setBreakpointCommand.ScriptId); }
internal static async Task Remove(this NodeBreakpoint breakpoint) { foreach (var binding in breakpoint.GetBindings()) { await binding.Remove().ConfigureAwait(false); } }
/// <summary> /// Removes a break point. /// </summary> /// <param name="breakpoint">Break point.</param> public Task RemoveBreakpointAsync(NodeBreakpoint breakpoint) { _breakpoints.Remove(breakpoint.Id); return(_client.SendMessage("clearbreakpoint", new { breakpoint = breakpoint.Id })); }
/// <summary> /// Removes a break point. /// </summary> /// <param name="breakpoint">Break point.</param> public Task RemoveBreakpointAsync(NodeBreakpoint breakpoint) { _breakpoints.Remove(breakpoint.Id); return _client.SendMessage("clearbreakpoint", new { breakpoint = breakpoint.Id }); }
/// <summary> /// Changes a break point. /// </summary> /// <param name="breakpoint">Break point.</param> public Task ChangeBreakpointAsync(NodeBreakpoint breakpoint) { return(_client.SendMessage("changebreakpoint", new { breakpoint = breakpoint.Id, enabled = breakpoint.Enabled, condition = breakpoint.Condition })); }
/// <summary> /// Changes a break point. /// </summary> /// <param name="breakpoint">Break point.</param> public Task ChangeBreakpointAsync(NodeBreakpoint breakpoint) { return _client.SendMessage("changebreakpoint", new { breakpoint = breakpoint.Id, enabled = breakpoint.Enabled, condition = breakpoint.Condition }); }
public AD7BoundBreakpoint(AD7Engine engine, NodeBreakpoint address, AD7PendingBreakpoint pendingBreakpoint, AD7BreakpointResolution breakpointResolution) { _engine = engine; _breakpoint = address; _pendingBreakpoint = pendingBreakpoint; _breakpointResolution = breakpointResolution; _enabled = true; _deleted = false; }
public SetBreakpointCommand(int id, NodeModule module, NodeBreakpoint breakpoint, bool withoutPredicate, bool remote, SourceMapper sourceMapper = null) : base(id, "setbreakpoint") { Utilities.ArgumentNotNull("breakpoint", breakpoint); _module = module; _breakpoint = breakpoint; _sourceMapper = sourceMapper; _position = breakpoint.GetPosition(_sourceMapper); // Zero based line numbers int line = _position.Line; // Zero based column numbers // Special case column to avoid (line 0, column 0) which // Node (V8) treats specially for script loaded via require // Script wrapping process: https://github.com/joyent/node/blob/v0.10.26-release/src/node.js#L880 int column = _position.Column; if (line == 0) { column += NodeConstants.ScriptWrapBegin.Length; } _arguments = new Dictionary<string, object> { { "line", line }, { "column", column } }; if (_module != null) { _arguments["type"] = "scriptId"; _arguments["target"] = _module.Id; } else if (remote) { _arguments["type"] = "scriptRegExp"; _arguments["target"] = CreateRemoteScriptRegExp(_position.FileName); } else { _arguments["type"] = "scriptRegExp"; _arguments["target"] = CreateLocalScriptRegExp(_position.FileName); } if (!NodeBreakpointBinding.GetEngineEnabled(_breakpoint.Enabled, _breakpoint.BreakOn, 0)) { _arguments["enabled"] = false; } if (withoutPredicate) { return; } int ignoreCount = NodeBreakpointBinding.GetEngineIgnoreCount(_breakpoint.BreakOn, 0); if (ignoreCount > 0) { _arguments["ignoreCount"] = ignoreCount; } if (!string.IsNullOrEmpty(_breakpoint.Condition)) { _arguments["condition"] = _breakpoint.Condition; } }
internal static NodeBreakpoint AddBreakPoint( NodeDebugger newproc, string fileName, int line, int column, bool enabled = true, BreakOn breakOn = new BreakOn(), string condition = "" ) { NodeBreakpoint breakPoint = newproc.AddBreakpoint(fileName, line, column, enabled, breakOn, condition); breakPoint.BindAsync().WaitAndUnwrapExceptions(); return(breakPoint); }
private void CheckWhetherFirstLineBreakpoint(NodeBreakpoint breakpoint) { if (_initialFrame == null) { return; } int scriptId = _initialFrame.ScriptId; string filename = _scripts[scriptId].Filename; if (breakpoint.Line == _initialFrame.Line && string.Equals(filename, breakpoint.Filename, StringComparison.InvariantCultureIgnoreCase)) { var eventMessage = new BreakpointMessage(scriptId, filename, breakpoint.Line, breakpoint.Column); OnBreakpointEvent(this, new BreakpointMessageEventArgs(eventMessage)); } }
// Get the document context for this pending breakpoint. A document context is a abstract representation of a source file // location. public AD7DocumentContext GetDocumentContext(NodeBreakpoint address) { var docPosition = (IDebugDocumentPosition2)(Marshal.GetObjectForIUnknown(_bpRequestInfo.bpLocation.unionmember2)); string documentName; EngineUtils.CheckOk(docPosition.GetFileName(out documentName)); // Get the location in the document that the breakpoint is in. var startPosition = new TEXT_POSITION[1]; var endPosition = new TEXT_POSITION[1]; EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition)); var codeContext = new AD7MemoryAddress(_engine, documentName, startPosition[0].dwLine); return(new AD7DocumentContext(documentName, startPosition[0], startPosition[0], codeContext)); }
// Binds this pending breakpoint to one or more code locations. int IDebugPendingBreakpoint2.Bind() { if (CanBind()) { var docPosition = (IDebugDocumentPosition2)(Marshal.GetObjectForIUnknown(_bpRequestInfo.bpLocation.unionmember2)); // Get the name of the document that the breakpoint was put in string documentName; EngineUtils.CheckOk(docPosition.GetFileName(out documentName)); // Get the location in the document that the breakpoint is in. var startPosition = new TEXT_POSITION[1]; var endPosition = new TEXT_POSITION[1]; EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition)); _breakpoint = new NodeBreakpoint(_engine.Process.Debugger, documentName, (int)startPosition[0].dwLine, (int)startPosition[0].dwColumn, _bpRequestInfo.bpCondition.bstrCondition); try { _engine.Process.Debugger.AddBreakpointAsync(_breakpoint).Wait(); } catch (Exception) { return(VSConstants.E_FAIL); } var breakpointResolution = new AD7BreakpointResolution(_engine, _breakpoint, GetDocumentContext(_breakpoint)); var boundBreakpoint = new AD7BoundBreakpoint(_engine, _breakpoint, this, breakpointResolution); _boundBreakpoints.Add(boundBreakpoint); _bpManager.AddBoundBreakpoint(_breakpoint, boundBreakpoint); return(VSConstants.S_OK); } // The breakpoint could not be bound. This may occur for many reasons such as an invalid location, an invalid expression, etc... // The sample engine does not support this, but a real world engine will want to send an instance of IDebugBreakpointErrorEvent2 to the // UI and return a valid instance of IDebugErrorBreakpoint2 from IDebugPendingBreakpoint2::EnumErrorBreakpoints. The debugger will then // display information about why the breakpoint did not bind to the user. return(VSConstants.S_FALSE); }
public void CreateSetBreakpointCommandOnRemoteFile() { // Arrange const int commandId = 3; const int line = 2; const int column = 0; const string fileName = @"module.js"; var breakOn = new BreakOn(BreakOnKind.Equal, 2); var position = new FilePosition(fileName, line, column); var breakpoint = new NodeBreakpoint(null, position, true, breakOn, null); // Act var setBreakpointCommand = new SetBreakpointCommand(commandId, null, breakpoint, false, true); // Assert Assert.AreEqual(commandId, setBreakpointCommand.Id); Assert.AreEqual( string.Format( "{{\"command\":\"setbreakpoint\",\"seq\":{0},\"type\":\"request\",\"arguments\":{{\"line\":{1},\"column\":{2},\"type\":\"scriptRegExp\",\"target\":\"^[Mm][Oo][Dd][Uu][Ll][Ee]\\\\.[Jj][Ss]$\",\"ignoreCount\":1}}}}", commandId, line, column), setBreakpointCommand.ToString()); }
public void CreateSetBreakpointCommandOnLocalFile() { // Arrange const int commandId = 3; const int line = 2; const int column = 0; const string fileName = @"c:\module.js"; var breakOn = new BreakOn(BreakOnKind.Equal, 2); var position = new FilePosition(fileName, line, column); var breakpoint = new NodeBreakpoint(null, position, true, breakOn, null); // Act var setBreakpointCommand = new SetBreakpointCommand(commandId, null, breakpoint, false, false); // Assert Assert.AreEqual(commandId, setBreakpointCommand.Id); Assert.AreEqual( string.Format( "{{\"command\":\"setbreakpoint\",\"seq\":{0},\"type\":\"request\",\"arguments\":{{\"line\":{1},\"column\":{2},\"type\":\"scriptRegExp\",\"target\":\"{3}\",\"ignoreCount\":1}}}}", commandId, line, column, SetBreakpointCommand.CreateLocalScriptRegExp(fileName).Replace(@"\", @"\\")), setBreakpointCommand.ToString()); }
// Remove all of the bound breakpoints for this pending breakpoint public void ClearBreakpointBindingResults() { if (_breakpoint != null) { lock (_breakpoint) { foreach (NodeBreakpointBinding binding in _breakpoint.GetBindings()) { var boundBreakpoint = (IDebugBoundBreakpoint2)_bpManager.GetBoundBreakpoint(binding); if (boundBreakpoint != null) { boundBreakpoint.Delete(); binding.Remove().WaitAndUnwrapExceptions(); } } } _bpManager.RemovePendingBreakpoint(_breakpoint); _breakpoint.Deleted = true; _breakpoint = null; } _breakpointErrors.Clear(); }
public void CreateSetBreakpointCommandOnFirstLine() { // Arrange const int commandId = 3; const int moduleId = 5; const int line = 0; const int column = 0; const string fileName = "c:\\module.js"; var module = new NodeModule(moduleId, fileName); var breakOn = new BreakOn(BreakOnKind.Equal, 2); var position = new FilePosition(fileName, line, column); var breakpoint = new NodeBreakpoint(null, position, true, breakOn, null); // Act var setBreakpointCommand = new SetBreakpointCommand(commandId, module, breakpoint, false, false); // Assert Assert.AreEqual(commandId, setBreakpointCommand.Id); Assert.AreEqual( string.Format( "{{\"command\":\"setbreakpoint\",\"seq\":{0},\"type\":\"request\",\"arguments\":{{\"line\":{1},\"column\":{2},\"type\":\"scriptId\",\"target\":{3},\"ignoreCount\":1}}}}", commandId, line, column + NodeConstants.ScriptWrapBegin.Length, module.Id), setBreakpointCommand.ToString()); }
public void AddBoundBreakpoint(NodeBreakpoint breakpoint, AD7BoundBreakpoint boundBreakpoint) { _breakpointMap[breakpoint] = boundBreakpoint; }
public AD7PendingBreakpoint GetPendingBreakpoint(NodeBreakpoint breakpoint) { return(this.breakpointMap.TryGetValue(breakpoint, out var pendingBreakpoint) ? pendingBreakpoint : null); }
public void RemovePendingBreakpoint(NodeBreakpoint breakpoint) { _breakpointMap.Remove(breakpoint); }
public void RemovePendingBreakpoint(NodeBreakpoint breakpoint) { this.breakpointMap.Remove(breakpoint); }
public void AddPendingBreakpoint(NodeBreakpoint breakpoint, AD7PendingBreakpoint pendingBreakpoint) { this.breakpointMap[breakpoint] = pendingBreakpoint; }
public AD7PendingBreakpoint GetPendingBreakpoint(NodeBreakpoint breakpoint) { return(this._breakpointMap[breakpoint]); }
public AD7BoundBreakpoint GetBreakpoint(NodeBreakpoint breakpoint) { return(_breakpointMap[breakpoint]); }
public SetBreakpointCommand(int id, NodeModule module, NodeBreakpoint breakpoint, bool withoutPredicate, bool remote, SourceMapper sourceMapper = null) : base(id, "setbreakpoint") { Utilities.ArgumentNotNull("breakpoint", breakpoint); _module = module; _breakpoint = breakpoint; _sourceMapper = sourceMapper; _position = breakpoint.GetPosition(_sourceMapper); // Zero based line numbers int line = _position.Line; // Zero based column numbers // Special case column to avoid (line 0, column 0) which // Node (V8) treats specially for script loaded via require // Script wrapping process: https://github.com/joyent/node/blob/v0.10.26-release/src/node.js#L880 int column = _position.Column; if (line == 0) { column += NodeConstants.ScriptWrapBegin.Length; } _arguments = new Dictionary <string, object> { { "line", line }, { "column", column } }; if (_module != null) { _arguments["type"] = "scriptId"; _arguments["target"] = _module.Id; } else if (remote) { _arguments["type"] = "scriptRegExp"; _arguments["target"] = GetCaseInsensitiveRegex(_position.FileName); } else { _arguments["type"] = "script"; _arguments["target"] = _position.FileName; } if (!NodeBreakpointBinding.GetEngineEnabled(_breakpoint.Enabled, _breakpoint.BreakOn, 0)) { _arguments["enabled"] = false; } if (withoutPredicate) { return; } int ignoreCount = NodeBreakpointBinding.GetEngineIgnoreCount(_breakpoint.BreakOn, 0); if (ignoreCount > 0) { _arguments["ignoreCount"] = ignoreCount; } if (!string.IsNullOrEmpty(_breakpoint.Condition)) { _arguments["condition"] = _breakpoint.Condition; } }
public void AddPendingBreakpoint(NodeBreakpoint breakpoint, AD7PendingBreakpoint pendingBreakpoint) { _breakpointMap[breakpoint] = pendingBreakpoint; }
public void RemoveBoundBreakpoint(NodeBreakpoint breakpoint) { _breakpointMap.Remove(breakpoint); }
public AD7PendingBreakpoint GetPendingBreakpoint(NodeBreakpoint breakpoint) { return _breakpointMap[breakpoint]; }
public AD7BreakpointResolution(AD7Engine engine, NodeBreakpoint address, AD7DocumentContext documentContext) { m_engine = engine; m_address = address; m_documentContext = documentContext; }