private static void TestSupportedLanguages(AuthenticationContext authenticationContext) { var lister = new LookupCommand(authenticationContext); lister.Execute(); var languages = lister.Result; foreach (string language in languages) { Console.WriteLine("Language => {0}", language); } }
public void CreateLookupCommand() { // Arrange const int commandId = 3; var resultFactoryMock = new Mock<IEvaluationResultFactory>(); var handles = new[] { 25 }; // Act var lookupCommand = new LookupCommand(commandId, resultFactoryMock.Object, handles); // Assert Assert.AreEqual(commandId, lookupCommand.Id); Assert.AreEqual( string.Format( "{{\"command\":\"lookup\",\"seq\":{0},\"type\":\"request\",\"arguments\":{{\"handles\":{1},\"includeSource\":false}}}}", commandId, JsonConvert.SerializeObject(handles)), lookupCommand.ToString()); }
public void ProcessLookupResponseWithPrimitiveObject() { // Arrange const int commandId = 3; var resultFactoryMock = new Mock<IEvaluationResultFactory>(); resultFactoryMock.Setup(factory => factory.Create(It.IsAny<INodeVariable>())) .Returns(() => new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null)); const int handle = 9; var handles = new[] { handle }; var lookupCommand = new LookupCommand(commandId, resultFactoryMock.Object, handles); // Act lookupCommand.ProcessResponse(SerializationTestData.GetLookupResponseWithPrimitiveObject()); // Assert Assert.AreEqual(commandId, lookupCommand.Id); Assert.IsNotNull(lookupCommand.Results); Assert.IsTrue(lookupCommand.Results.ContainsKey(handle)); Assert.IsNotNull(lookupCommand.Results[handle]); resultFactoryMock.Verify(factory => factory.Create(It.IsAny<INodeVariable>()), Times.Once); }
/// <summary> /// Retrieves a backtrace for current execution point. /// </summary> /// <returns>Whether program execution in progress.</returns> private async Task<bool> PerformBacktraceAsync(CancellationToken cancellationToken = new CancellationToken()) { // CONSIDER: Lazy population of callstacks // Given the VS Debugger UI always asks for full callstacks, we always ask Node.js for full backtraces. // Given the nature or Node.js code, deep callstacks are expected to be rare. // Although according to the V8 docs (http://code.google.com/p/v8/wiki/DebuggerProtocol) the 'backtrace' // request takes a 'bottom' parameter, empirically, Node.js fails requests with it set. Here we // approximate 'bottom' for 'toFrame' using int.MaxValue. Node.js silently handles toFrame depths // greater than the current callstack. var backtraceCommand = new BacktraceCommand(CommandId, _resultFactory, 0, int.MaxValue); if (!await TrySendRequestAsync(backtraceCommand, cancellationToken).ConfigureAwait(false)) { return false; } // Add extracted modules AddModules(backtraceCommand.Modules.Values); // Add stack frames List<NodeStackFrame> stackFrames = GetLocalFrames(backtraceCommand.StackFrames).ToList(); // Collects results of number type which have null values and perform a lookup for actual values var numbersWithNullValue = new List<NodeEvaluationResult>(); foreach (NodeStackFrame stackFrame in stackFrames) { numbersWithNullValue.AddRange(stackFrame.Locals.Concat(stackFrame.Parameters) .Where(p => p.TypeName == NodeVariableType.Number && p.StringValue == null)); } if (numbersWithNullValue.Count > 0) { var lookupCommand = new LookupCommand(CommandId, _resultFactory, numbersWithNullValue); if (await TrySendRequestAsync(lookupCommand, cancellationToken).ConfigureAwait(false)) { foreach (NodeEvaluationResult targetResult in numbersWithNullValue) { NodeEvaluationResult lookupResult = lookupCommand.Results[targetResult.Handle][0]; targetResult.StringValue = targetResult.HexValue = lookupResult.StringValue; } } } MainThread.Frames = stackFrames; return backtraceCommand.Running; }
private void OnExceptionEvent(object sender, ExceptionEventArgs args) { DebuggerClient.RunWithRequestExceptionsHandled(async () => { ExceptionEvent exception = args.ExceptionEvent; if (exception.ErrorNumber == null) { ReportException(exception); return; } int errorNumber = exception.ErrorNumber.Value; string errorCodeFromMap; if (_errorCodes.TryGetValue(errorNumber, out errorCodeFromMap)) { ReportException(exception, errorCodeFromMap); return; } var lookupCommand = new LookupCommand(CommandId, _resultFactory, new[] { exception.ErrorNumber.Value }); string errorCodeFromLookup = null; if (await TrySendRequestAsync(lookupCommand).ConfigureAwait(false)) { errorCodeFromLookup = lookupCommand.Results[errorNumber][0].StringValue; _errorCodes[errorNumber] = errorCodeFromLookup; } ReportException(exception, errorCodeFromLookup); }); }
internal async Task<List<NodeEvaluationResult>> EnumChildrenAsync(NodeEvaluationResult nodeEvaluationResult, CancellationToken cancellationToken = new CancellationToken()) { DebugWriteCommand("Enum Children"); var lookupCommand = new LookupCommand(CommandId, _resultFactory, new List<NodeEvaluationResult> { nodeEvaluationResult }); if (!await TrySendRequestAsync(lookupCommand, cancellationToken).ConfigureAwait(false)) { return null; } return lookupCommand.Results[nodeEvaluationResult.Handle]; }