Пример #1
0
        public void IntValues(int value, bool isTruthy)
        {
            var remoteValue = RemoteValueFakeUtil.CreateSimpleInt("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));
            }
        }
        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 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());
        }
        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"));
        }
Пример #6
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));
        }
        public void Stack()
        {
            var remoteValue = RemoteValueFakeUtil.CreateSimpleInt("dummyType", 123);

            remoteValue.SetAddressOf(RemoteValueFakeUtil.CreateAddressOf(remoteValue, 0xDEADC0DE));
            Assert.That(RemoteValueExtensions.GetMemoryAddressAssignExpression(remoteValue),
                        Is.EqualTo("(*((int*)0xDEADC0DE))"));
        }
        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 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"));
        }
Пример #10
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(""));
        }
Пример #11
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);
        }
Пример #12
0
        public void ValueForNonEmptySummary()
        {
            var remoteValue = RemoteValueFakeUtil.CreateSimpleInt("x", 17);

            remoteValue.SetSummary("Summary For X");

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

            Assert.That(varInfo.Value, Is.EqualTo("Summary For X"));
        }
Пример #13
0
        void CheckFormat(string formatSpecifier, ValueFormat expectedFormat, int valueInt,
                         string expectedValue)
        {
            var remoteValue           = RemoteValueFakeUtil.CreateSimpleInt("test", valueInt);
            IRemoteValueFormat format = RemoteValueFormatProvider.Get(formatSpecifier);

            Assert.AreEqual(format.FormatValue(remoteValue, ValueFormat.Default), expectedValue);
            Assert.AreEqual(remoteValue.GetFormat(), expectedFormat);
            Assert.IsTrue(format.ShouldInheritFormatSpecifier());
        }
Пример #14
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);
        }
Пример #15
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);
        }
        public void DereferencePointer()
        {
            var remoteValue = RemoteValueFakeUtil.CreatePointer("int*", "xPtr", _memAddress);
            var pointee     = RemoteValueFakeUtil.CreateSimpleInt("x", 1);

            remoteValue.SetDereference(pointee);

            var varInfo = _varInfoFactory.Create(remoteValue);

            Assert.That(remoteValue.Dereference(), Is.EqualTo(pointee));
        }
Пример #17
0
        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\"}"));
        }
Пример #18
0
        public async Task Build_PointerClassValueAsync()
        {
            string          address = $"0x{_pointerAddress:x16}";
            RemoteValueFake pointer =
                RemoteValueFakeUtil.CreatePointer("C*", "pc", _pointerAddress.ToString());

            pointer.AddChild(RemoteValueFakeUtil.CreateSimpleInt("f", 42));
            pointer.AddChild(RemoteValueFakeUtil.CreateSimpleString("g", "\"s\""));

            IVariableInformation varInfo = CreateVarInfo(pointer, "");
            string result = await ValueStringBuilder.BuildAsync(varInfo);

            Assert.That(result, Is.EqualTo($"0x{_pointerAddress:x16} {{f=42 g=\"s\"}}"));
        }
        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 async Task DeclareVariableAsync()
        {
            RemoteValueFake remoteValue  = RemoteValueFakeUtil.CreateSimpleChar("testVar", 'c');
            RemoteValueFake createdValue = RemoteValueFakeUtil.CreateSimpleInt("$test", 22);

            remoteValue.AddValueFromExpression("auto $test=var1+var2; $test", createdValue);
            remoteValue.AddValueFromExpression("$test", createdValue);

            var natvisScope = new NatvisScope();

            natvisScope.AddScopedName("test", "$test");

            IVariableInformation varInfo = _varInfoFactory.Create(remoteValue);
            await _evaluator.DeclareVariableAsync(varInfo, "test", "var1+var2", natvisScope);

            Assert.That(natvisScope.ContextVariables, Does.ContainKey("$test"));
            Assert.That(natvisScope.ContextVariables["$test"], Is.EqualTo(createdValue));
        }
        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"));
        }
Пример #24
0
        void SetupLocalAndArguments()
        {
            var local1 = RemoteValueFakeUtil.CreateSimpleInt("value1", 5);
            var local2 = RemoteValueFakeUtil.CreateSimpleInt("value2", 7);
            var arg1   = RemoteValueFakeUtil.CreateSimpleInt("intVal", 5);
            var arg2   = RemoteValueFakeUtil.CreateSimpleBool("boolVal", true);

            _mockRemoteFrame.GetVariables(false, true, false, true).Returns(
                new List <RemoteValue> {
                local1, local2
            });
            _mockRemoteFrame.GetVariables(true, false, false, true).Returns(
                new List <RemoteValue> {
                arg1, arg2
            });
            _mockRemoteFrame.GetVariables(true, true, false, true).Returns(
                new List <RemoteValue> {
                arg1, arg2, local1, local2
            });
        }
Пример #25
0
        public void SetUp()
        {
            _compRoot = new MediumTestDebugEngineFactoryCompRoot(new JoinableTaskContext());

            _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);

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

            for (uint i = 0; i < 5; i++)
            {
                _pointerValue.SetCreateValueFromAddress(
                    _pointerAddress + i * elementSize,
                    RemoteValueFakeUtil.CreateSimpleInt($"[{i}]", (int)(i) + 20));
            }
        }