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 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 async Task LldbEvalWithContextVarsAsync()
        {
            _optionPageGrid.ExpressionEvaluationEngine =
                ExpressionEvaluationEngineFlag.LLDB_EVAL_WITH_FALLBACK;

            RemoteValue mockVariable = CreateMockVariable();

            var natvisScope = new NatvisScope();
            var contextVar  = RemoteValueFakeUtil.CreateSimpleInt("var", 14);

            natvisScope.AddScopedName("var", "$var_0");
            natvisScope.AddContextVariable("$var_0", contextVar);

            await _evaluator.EvaluateExpressionAsync(
                "2 + var", _varInfoFactory.Create(mockVariable), natvisScope, "result");

            await mockVariable.Received(1).EvaluateExpressionLldbEvalAsync(
                Arg.Is("2 + $var_0"), Arg.Is(natvisScope.ContextVariables));

            Assert.That(natvisScope.ContextVariables.Count, Is.EqualTo(1));
            Assert.That(natvisScope.ContextVariables.ContainsKey("$var_0"));
            Assert.That(natvisScope.ContextVariables["$var_0"], Is.EqualTo(contextVar));

            await mockVariable.DidNotReceive().EvaluateExpressionAsync(Arg.Any <string>());
        }
Пример #4
0
        public void EvaluateSyncWithFormatSpecifier()
        {
            string           expressionText  = "myVar";
            string           formatSpecifier = ",x";
            string           testText        = expressionText + formatSpecifier;
            IDebugExpression expression      = CreateExpression(testText);

            RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateSimpleInt("myVar", 16);

            _mockDebuggerStackFrame.FindValue(testText, ValueType.VariableGlobal)
            .Returns((RemoteValue)null);
            _mockDebuggerStackFrame.GetValueForVariablePath(expressionText)
            .Returns((RemoteValue)null);
            _mockDebuggerStackFrame.FindValue(expressionText, ValueType.VariableGlobal)
            .Returns((RemoteValue)null);
            _mockDebuggerStackFrame.EvaluateExpressionAsync(expressionText).Returns(remoteValue);

            Assert.AreEqual(VSConstants.S_OK,
                            expression.EvaluateSync(0, 0, null, out IDebugProperty2 property));

            Assert.AreEqual(testText, GetName(property));
            Assert.AreEqual(testText, GetFullName(property));
            Assert.AreEqual("int", GetType(property));
            Assert.AreEqual("0x10", GetValue(property));
        }
Пример #5
0
        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));
        }
Пример #6
0
        public void GetPropertyInfoHexadecimalDisplay()
        {
            // 175 is hex AF!
            int    valueInt = 175;
            string valueHex = "0xaf";

            var childAdapterFactory = new RemoteValueChildAdapter.Factory();
            var remoteValue         = RemoteValueFakeUtil.CreateSimpleInt("test", valueInt);
            var varInfo             = new RemoteValueVariableInformation(
                null, "", RemoteValueFormat.Default, ValueFormat.Default, remoteValue, "test",
                CustomVisualizer.None, childAdapterFactory);

            var debugProperty = createPropertyDelegate.Invoke(varInfo);
            var propertyInfos = new DEBUG_PROPERTY_INFO[1];

            // Radix 16 -> Int should be formatted as hex.
            debugProperty.GetPropertyInfo(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE, 16, 0,
                                          null, 0, propertyInfos);

            Assert.AreEqual(propertyInfos[0].bstrValue, valueHex);

            // Radix 10 -> Int should be formatted as decimal.
            debugProperty.GetPropertyInfo(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE, 10, 0,
                                          null, 0, propertyInfos);

            Assert.AreEqual(propertyInfos[0].bstrValue, valueInt.ToString());

            // Radix 8 -> Not supported, should fall back to decimal.
            debugProperty.GetPropertyInfo(enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE, 8, 0,
                                          null, 0, propertyInfos);

            Assert.AreEqual(propertyInfos[0].bstrValue, valueInt.ToString());
        }
Пример #7
0
        public void DoubleValues(double value, bool isTruthy)
        {
            var remoteValue = RemoteValueFakeUtil.CreateSimpleDouble("myVar", value);
            var varInfo     = varInfoBuilder.Create(remoteValue);

            Assert.That(varInfo.IsTruthy, Is.EqualTo(isTruthy));
        }
        public void SetUp()
        {
            logSpy = new LogSpy();
            logSpy.Attach();

            childValues = new int[] { 20, 21, 22, 23, 24 };
            remoteValue = RemoteValueFakeUtil.CreateSimpleIntArray("myArray", childValues);

            ulong elementSize = 4;
            var   pointeeType = new SbTypeStub("int", TypeFlags.IS_INTEGER);

            pointeeType.SetByteSize(elementSize);
            var   pointerType = new SbTypeStub("int*", TypeFlags.IS_POINTER, pointeeType);
            ulong address     = 1234;

            pointerValue = RemoteValueFakeUtil.CreatePointer("int*", "myPtr", $"{address}");
            pointerValue.SetTypeInfo(pointerType);

            for (uint i = 0; i < 5; i++)
            {
                pointerValue.SetCreateValueFromAddress(
                    address + i * elementSize,
                    RemoteValueFakeUtil.CreateSimpleInt($"[{i}]", (int)(i) + 20));
            }
        }
Пример #9
0
        public void FormatValue()
        {
            const string    value       = "test \t \n";
            RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateSimpleString("tmp", value);

            Assert.That(format.FormatValue(remoteValue, ValueFormat.Default), Is.EqualTo(value));
        }
Пример #10
0
        public void PointerValues(string address, bool isTruthy)
        {
            var remoteValue = RemoteValueFakeUtil.CreatePointer("MyType*", "myVar", address);
            var varInfo     = varInfoBuilder.Create(remoteValue);

            Assert.That(varInfo.IsTruthy, Is.EqualTo(isTruthy));
        }
Пример #11
0
        public void IsNullPointerReturnsFalseIfIsNotPointer()
        {
            var remoteValue = RemoteValueFakeUtil.CreateClass("MyType", "myVar", "0x0");
            var varInfo     = CreateVarInfo(remoteValue, "myVar");

            Assert.That(varInfo.IsNullPointer(), Is.False);
        }
Пример #12
0
        public void BoolValues(bool value)
        {
            var remoteValue = RemoteValueFakeUtil.CreateSimpleBool("myVar", value);
            var varInfo     = varInfoBuilder.Create(remoteValue);

            Assert.That(varInfo.IsTruthy, Is.EqualTo(value));
        }
Пример #13
0
        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);
        }
Пример #14
0
        public async Task GetChildrenReturnsMoreElementWhenMoreThanRangeSizeRequestedAsync()
        {
            remoteValue.AddChild(RemoteValueFakeUtil.CreateSimpleString("child5", "value5"));

            int _countPerRange = 2;
            var childAdapter   = new RemoteValueChildAdapter.Factory().CreateForTesting(
                remoteValue, RemoteValueFormat.Default, varInfoBuilder, noFormatSpecifier,
                _countPerRange);

            IList <IVariableInformation> children = await childAdapter.GetChildrenAsync(0, 5);

            Assert.That(children.Count, Is.EqualTo(3));
            Assert.That(children[2].DisplayName, Is.EqualTo("[More]"));

            IVariableInformation more = children[2];

            CollectionAssert.AreEqual(new[] { "child3", "child4", "[More]" },
                                      await GetAllChildNamesAsync(more.GetChildAdapter()));

            IVariableInformation nextMore =
                (await more.GetChildAdapter().GetChildrenAsync(2, 1))[0];

            CollectionAssert.AreEqual(new[] { "child5" },
                                      await GetAllChildNamesAsync(nextMore.GetChildAdapter()));
        }
Пример #15
0
        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);
        }
Пример #16
0
        public void IsNullPointerReturnsTrueIfHexValueIsZero(
            [Values("0X0000000000", "0x0000000000", "000000000")] string address)
        {
            var remoteValue = RemoteValueFakeUtil.CreatePointer("MyType", "myType", address);
            var varInfo     = CreateVarInfo(remoteValue, "myType");

            Assert.That(varInfo.IsNullPointer(), Is.True);
        }
Пример #17
0
        public void IsNullPointerReturnsFalseIfHexValueIsNotZero(
            [Values("0x0000032234", "0x00F0A32234")] string address)
        {
            var remoteValue = RemoteValueFakeUtil.CreatePointer("MyType", "myType", address);
            var varInfo     = CreateVarInfo(remoteValue, "myType");

            Assert.That(varInfo.IsNullPointer(), Is.False);
        }
        public void Stack()
        {
            var remoteValue = RemoteValueFakeUtil.CreateSimpleInt("dummyType", 123);

            remoteValue.SetAddressOf(RemoteValueFakeUtil.CreateAddressOf(remoteValue, 0xDEADC0DE));
            Assert.That(RemoteValueExtensions.GetMemoryAddressAssignExpression(remoteValue),
                        Is.EqualTo("(*((int*)0xDEADC0DE))"));
        }
Пример #19
0
        void CheckPointerFormat(string formatSpecifier, int valueInt, string expectedValue)
        {
            var remoteValue           = RemoteValueFakeUtil.CreatePointer("int*", "int", valueInt.ToString());
            IRemoteValueFormat format = RemoteValueFormatProvider.Get(formatSpecifier);

            Assert.AreEqual(format.FormatValueAsAddress(remoteValue), expectedValue);
            Assert.IsTrue(format.ShouldInheritFormatSpecifier());
        }
        public void Stack()
        {
            var remoteValue = RemoteValueFakeUtil.CreateSimpleInt("dummyType", 123);

            remoteValue.SetAddressOf(RemoteValueFakeUtil.CreateAddressOf(remoteValue, 0xDEADC0DE));
            Assert.That(RemoteValueExtensions.GetMemoryContextAddress(remoteValue),
                        Is.EqualTo(123));
        }
        public void Pointer()
        {
            RemoteValue remoteValue =
                RemoteValueFakeUtil.CreatePointer("dummyType*", "dummyName", "0xDEADC0DE");

            Assert.That(RemoteValueExtensions.GetMemoryContextAddress(remoteValue),
                        Is.EqualTo(0xDEADC0DE));
        }
Пример #22
0
        public void NoErrorWhenSbValueHasNoError()
        {
            var remoteValue = RemoteValueFakeUtil.CreateSimpleInt("test", 22);

            var varInfo = CreateVarInfo(remoteValue, "remoteValue");

            Assert.That(varInfo.Error, Is.False);
            Assert.That(varInfo.ErrorMessage, Is.EqualTo(""));
        }
Пример #23
0
        public void ErrorWhenSbValueHasError()
        {
            var remoteValue = RemoteValueFakeUtil.CreateError("Oh no!");

            var varInfo = CreateVarInfo(remoteValue, "remoteValue");

            Assert.That(varInfo.Error, Is.True);
            Assert.That(varInfo.ErrorMessage, Is.EqualTo("Oh no!"));
        }
        public void TestExpressionNameWhenFullnameExists()
        {
            var remoteValue = RemoteValueFakeUtil.CreateSimpleInt("myVar", 12358);

            remoteValue.SetValueType(DebuggerApi.ValueType.VariableLocal);
            remoteValue.SetAddressOf(RemoteValueFakeUtil.CreateSimpleLong("$0", 0xDEADBEEF));

            Assert.That(remoteValue.GetVariableAssignExpression(), Is.EqualTo("myVar"));
        }
        public void Array()
        {
            var remoteValue = RemoteValueFakeUtil.CreateSimpleCharArray("dummyName",
                                                                        "dummyValue".ToCharArray());

            remoteValue.SetAddressOf(RemoteValueFakeUtil.CreateAddressOf(remoteValue, 0xDEADC0DE));
            Assert.That(RemoteValueExtensions.GetMemoryContextAddress(remoteValue),
                        Is.EqualTo(0xDEADC0DE));
        }
        public void Reference()
        {
            var remoteValue = RemoteValueFakeUtil.Create("dummyType&",
                                                         TypeFlags.IS_REFERENCE, "dummyName", "0xDEADC0DE");

            remoteValue.SetAddressOf(RemoteValueFakeUtil.CreateAddressOf(remoteValue, 0xAAAAAAAA));
            Assert.That(RemoteValueExtensions.GetMemoryContextAddress(remoteValue),
                        Is.EqualTo(0xDEADC0DE));
        }
Пример #27
0
        public void UpdateValueFormatSetsFormatAndIgnoresFallbackFormat()
        {
            var remoteValue = RemoteValueFakeUtil.CreateSimpleInt("test", 1);
            var format      = new RemoteValueLLDBFormat(ValueFormat.Hex);

            Assert.AreEqual(remoteValue.GetFormat(), ValueFormat.Default);
            format.FormatValue(remoteValue, ValueFormat.Decimal /* This is ignored! */);
            Assert.AreEqual(remoteValue.GetFormat(), ValueFormat.Hex);
        }
        public void Pointer()
        {
            RemoteValueFake remoteValue =
                RemoteValueFakeUtil.CreatePointer("dummyType*", "dummyName", "0xDEADC0DE");

            remoteValue.SetAddressOf(RemoteValueFakeUtil.CreateAddressOf(remoteValue, 0xDEAD0000));
            Assert.That(RemoteValueExtensions.GetMemoryAddressAssignExpression(remoteValue),
                        Is.EqualTo("((dummyType*)0xDEADC0DE)"));
        }
Пример #29
0
        public void ValueWithAFullnameIsEditable()
        {
            var remoteValue = RemoteValueFakeUtil.CreateSimpleInt("myVar", 17);

            remoteValue.SetValueType(DebuggerApi.ValueType.VariableLocal);
            remoteValue.SetAddressOf(null);
            var varInfo = CreateVarInfo(remoteValue, null);

            Assert.That(varInfo.IsReadOnly, Is.False);
        }
Пример #30
0
        public void ValueWithAScratchVariableFullnameIsReadonly()
        {
            var remoteValue = RemoteValueFakeUtil.CreateSimpleInt("$3", 17);

            remoteValue.SetValueType(DebuggerApi.ValueType.VariableLocal);
            remoteValue.SetAddressOf(null);
            var varInfo = CreateVarInfo(remoteValue, null);

            Assert.That(varInfo.IsReadOnly, Is.True);
        }