public void AssignSuccess() { var newValue = RemoteValueFakeUtil.CreateClass("DummyType", "myVar", "newValue"); newValue.SetValueType(DebuggerApi.ValueType.VariableLocal); newValue.SetError(new SbErrorStub(true)); var remoteValue = RemoteValueFakeUtil.CreateClass( "DummyType", "myVar", "originalValue"); remoteValue.SetValueType(DebuggerApi.ValueType.VariableLocal); remoteValue.SetAddressOf(null); remoteValue.AddValueFromExpression("myVar = (newValue)", newValue); var varInfo = varInfoFactory.Create(remoteValue, "myVar"); Assert.That(varInfo.IsReadOnly, Is.False); string actualError; bool assignResult = varInfo.Assign("newValue", out actualError); Assert.That(assignResult, Is.True); Assert.That(actualError, Is.Null); }
public async Task CloneContextVariablesAsync(string expr, string transformedExpr, string expectedValue) { RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateClass("MyType", "myType", "myValue"); RemoteValueFake exprResult = RemoteValueFakeUtil.CreateSimpleInt("x", 1); exprResult.SetClone(RemoteValueFakeUtil.CreateSimpleInt("y", 2)); remoteValue.AddValueFromExpression(transformedExpr, exprResult); IVariableInformation varInfo = _varInfoFactory.Create(remoteValue); var natvisScope = new NatvisScope(); natvisScope.AddScopedName("$i", "1U"); natvisScope.AddScopedName("var", "$var_0"); natvisScope.AddContextVariable("$var_0", exprResult); IVariableInformation result = await _evaluator.EvaluateExpressionAsync(expr, varInfo, natvisScope, "myVar"); Assert.That(await result.ValueAsync(), Is.EqualTo(expectedValue)); Assert.That(result.DisplayName, Is.EqualTo("myVar")); }
public void IsNullPointerReturnsFalseIfIsNotPointer() { var remoteValue = RemoteValueFakeUtil.CreateClass("MyType", "myVar", "0x0"); var varInfo = CreateVarInfo(remoteValue, "myVar"); Assert.That(varInfo.IsNullPointer(), Is.False); }
public void DeclareVariableWithErrorRemoteValue() { RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateClass("MyType", "myType", "myValue"); remoteValue.AddValueFromExpression($"auto $test=5; $test", RemoteValueFakeUtil.CreateError("declaration error")); var natvisScope = new NatvisScope(); natvisScope.AddScopedName("test", "$test"); IVariableInformation varInfo = _varInfoFactory.Create(remoteValue); var exception = Assert.ThrowsAsync <ExpressionEvaluationFailed>( async() => await _evaluator.DeclareVariableAsync(varInfo, "test", "5", natvisScope)); Assert.That(exception.Message, Does.Contain("test")); Assert.That(exception.Message, Does.Contain("5")); Assert.That(exception.Message, Does.Contain("declaration error")); string logOutput = _nLogSpy.GetOutput(); Assert.That(logOutput, Does.Contain("test")); Assert.That(logOutput, Does.Contain("5")); Assert.That(logOutput, Does.Contain("declaration error")); }
public async Task LldbEvalWithFallbackAsync(LldbEvalErrorCode lldbEvalErrorCode) { const string expressionText = "myVar"; IDebugExpression expression = CreateExpression( expressionText, ExpressionEvaluationStrategy.LLDB_EVAL_WITH_FALLBACK); RemoteValueFake errorValue = RemoteValueFakeUtil.CreateLldbEvalError(lldbEvalErrorCode); RemoteValueFake expressionValue = RemoteValueFakeUtil.CreateClass("CustomType", "$17", "23"); _mockDebuggerStackFrame.EvaluateExpressionLldbEvalAsync(expressionText) .Returns(errorValue); _mockDebuggerStackFrame.EvaluateExpressionAsync(expressionText) .Returns(expressionValue); Assert.AreEqual(VSConstants.S_OK, expression.EvaluateSync(0, 0, null, out IDebugProperty2 property)); Assert.AreEqual(expressionText, GetName(property)); Assert.AreEqual("CustomType", GetType(property)); Assert.AreEqual("23", GetValue(property)); // Make sure that a fallback to the LLDB happened. await _mockDebuggerStackFrame.Received(1).EvaluateExpressionLldbEvalAsync( Arg.Is(expressionText)); await _mockDebuggerStackFrame.Received(1).EvaluateExpressionAsync( Arg.Is(expressionText)); }
public async Task LldbEvalAsync() { const string expressionText = "myVar"; IDebugExpression expression = CreateExpression(expressionText, ExpressionEvaluationStrategy.LLDB_EVAL); RemoteValueFake expressionValueNode = RemoteValueFakeUtil.CreateClass("CustomType", "$17", "23"); _mockDebuggerStackFrame.EvaluateExpressionLldbEvalAsync(expressionText) .Returns(expressionValueNode); int status = expression.EvaluateAsync(0, null); var debugEventVerifier = Arg.Is <DebugExpressionEvaluationCompleteEvent>( e => expressionText.Equals(GetName(GetResult(e))) && "CustomType".Equals(GetType(GetResult(e))) && "23".Equals(GetValue(GetResult(e)))); // This assumes that task executor stub works synchronously. _mockDebugEngineHandler.Received().SendEvent( debugEventVerifier, Arg.Is(_mockProgram), Arg.Is(_mockThread)); await _taskExecutor.ReceivedWithAnyArgs(1).SubmitAsync( () => Task.CompletedTask, Arg.Any <CancellationToken>(), Arg.Any <string>(), Arg.Any <Type>()); Assert.AreEqual(VSConstants.S_OK, status); }
public void GetValueForAssignmentNonRegister() { RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateClass( "customType", "var", "varValue"); remoteValue.SetValueType(ValueType.VariableLocal); remoteValue.SetSummary("varSummary"); Assert.That(format.GetValueForAssignment(remoteValue, ValueFormat.Default), Is.EqualTo("varValue")); }
public void FormatValueVectorRegister() { RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateClass( "unsigned char __attribute__((ext_vector_type(3)))", "xmm0", ""); remoteValue.SetValueType(ValueType.Register); remoteValue.SetSummary("(0x00, 0x01, 0x02)"); Assert.That(format.FormatValue(remoteValue, ValueFormat.Default), Is.EqualTo("{0x00, 0x01, 0x02}")); }
public void TestGetExpressionValueBadExpression() { RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateClass("MyType", "myType", "myValue"); IVariableInformation varInfo = _varInfoFactory.Create(remoteValue); Assert.That(async() => await _evaluator.EvaluateExpressionAsync( "test1", varInfo, new NatvisScope(), "result"), Throws.TypeOf <ExpressionEvaluationFailed>().With.Message.Contains("test1")); }
public async Task Build_ClassValueAsync() { RemoteValueFake classValue = RemoteValueFakeUtil.CreateClass("C", "c", ""); classValue.AddChild(RemoteValueFakeUtil.CreateSimpleInt("f", 42)); classValue.AddChild(RemoteValueFakeUtil.CreateSimpleString("g", "\"s\"")); IVariableInformation varInfo = CreateVarInfo(classValue, "3"); string result = await ValueStringBuilder.BuildAsync(varInfo); Assert.That(result, Is.EqualTo("{f=42 g=\"s\"}")); }
public void SetUp() { remoteValue = RemoteValueFakeUtil.CreateClass("int[]", "array", ""); remoteValue.AddChild(RemoteValueFakeUtil.CreateSimpleString("child1", "value1")); remoteValue.AddChild(RemoteValueFakeUtil.CreateSimpleString("child2", "value2")); remoteValue.AddChild(RemoteValueFakeUtil.CreateSimpleString("child3", "value3")); remoteValue.AddChild(RemoteValueFakeUtil.CreateSimpleString("child4", "value4")); var childAdapterFactory = new RemoteValueChildAdapter.Factory(); var varInfoFactory = new LLDBVariableInformationFactory(childAdapterFactory); varInfoBuilder = new VarInfoBuilder(varInfoFactory); varInfoFactory.SetVarInfoBuilder(varInfoBuilder); }
public async Task ClassMemberAccessAsync() { RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateClass("MyType", "myType", ""); remoteValue.AddChild(RemoteValueFakeUtil.CreateSimpleBool("value1", true)); remoteValue.AddChild(RemoteValueFakeUtil.CreateSimpleInt("value2", 22)); IVariableInformation varInfo = _varInfoFactory.Create(remoteValue); IVariableInformation exprVarInfo = await _evaluator.EvaluateExpressionAsync( "value1", varInfo, new NatvisScope(), null); Assert.That(exprVarInfo.DisplayName, Is.EqualTo("value1")); Assert.That(await exprVarInfo.ValueAsync(), Is.EqualTo("true")); }
public async Task EvaluateSimpleExpressionAsync() { RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateClass("MyType", "myType", "myValue"); remoteValue.AddValueFromExpression("14", RemoteValueFakeUtil.CreateSimpleInt("tmp", 14)); IVariableInformation varInfo = _varInfoFactory.Create(remoteValue); IVariableInformation result = await _evaluator.EvaluateExpressionAsync( "14", varInfo, new NatvisScope(), "myVar"); Assert.That(await result.ValueAsync(), Is.EqualTo("14")); Assert.That(result.DisplayName, Is.EqualTo("myVar")); }
public async Task GlobalExpressionAsync() { RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateClass("MyType", "myType", "myValue"); remoteValue.AddValueFromExpression("test1", RemoteValueFakeUtil.CreateSimpleInt("dummy", 66)); IVariableInformation varInfo = _varInfoFactory.Create(remoteValue); IVariableInformation exprVarInfo = await _evaluator.EvaluateExpressionAsync( "test1", varInfo, new NatvisScope(), "result"); Assert.That(exprVarInfo.DisplayName, Is.EqualTo("result")); Assert.That(await exprVarInfo.ValueAsync(), Is.EqualTo("66")); }
public void EvaluateSyncForVariablePath() { const string expressionText = "myVar"; IDebugExpression expression = CreateExpression(expressionText); RemoteValueFake variablePathValueNode = RemoteValueFakeUtil.CreateClass("CustomType", "$17", "23"); _mockDebuggerStackFrame.GetValueForVariablePath(expressionText) .Returns(variablePathValueNode); Assert.AreEqual(VSConstants.S_OK, expression.EvaluateSync(0, 0, null, out IDebugProperty2 property)); Assert.AreEqual(expressionText, GetName(property)); Assert.AreEqual("CustomType", GetType(property)); Assert.AreEqual("23", GetValue(property)); }
public async Task PointerMemberAccessEvaluationAsync() { RemoteValueFake pointerValue = RemoteValueFakeUtil.CreatePointer("MyType*", "pointer", _memAddress); RemoteValueFake classValue = RemoteValueFakeUtil.CreateClass("MyType", "myType", "myValue"); pointerValue.SetDereference(classValue); classValue.AddValueFromExpression("field + 1", RemoteValueFakeUtil.CreateSimpleInt("result", 23)); IVariableInformation varInfo = _varInfoFactory.Create(pointerValue); IVariableInformation exprVarInfo = await _evaluator.EvaluateExpressionAsync( "field + 1", varInfo, new NatvisScope(), null); Assert.That(exprVarInfo.DisplayName, Is.EqualTo("result")); Assert.That(await exprVarInfo.ValueAsync(), Is.EqualTo("23")); }