Exemplo n.º 1
0
        public void GetAllInheritedTypesListCloserBaseClassesFirst()
        {
            // Class hierarchy:
            //
            // 111    211    121   221
            //   \    /        \   /
            //     011          021
            //       \         /
            //           001
            var type_001 = new SbTypeStub("type_001", TypeFlags.NONE);

            var type_011 = new SbTypeStub("type_011", TypeFlags.NONE);
            var type_021 = new SbTypeStub("type_021", TypeFlags.NONE);

            var type_111 = new SbTypeStub("type_111", TypeFlags.NONE);
            var type_211 = new SbTypeStub("type_211", TypeFlags.NONE);

            var type_121 = new SbTypeStub("type_121", TypeFlags.NONE);
            var type_221 = new SbTypeStub("type_221", TypeFlags.NONE);

            type_001.AddDirectBaseClass(type_011);
            type_001.AddDirectBaseClass(type_021);

            type_011.AddDirectBaseClass(type_111);
            type_011.AddDirectBaseClass(type_211);

            type_021.AddDirectBaseClass(type_121);
            type_021.AddDirectBaseClass(type_221);

            var remoteValue = new RemoteValueFake("leafVar", "leafValue");

            remoteValue.SetTypeInfo(type_001);

            var varInfo        = CreateVarInfo(remoteValue, "dummyDisplayName");
            var inheritedTypes = varInfo.GetAllInheritedTypes().ToList();

            Func <string, int> indexOf = typeName => inheritedTypes.IndexOf(typeName);

            Assert.That(inheritedTypes.Count, Is.EqualTo(7));

            Assert.That(indexOf("type_111"), Is.GreaterThan(indexOf("type_011")));
            Assert.That(indexOf("type_111"), Is.GreaterThan(indexOf("type_021")));
            Assert.That(indexOf("type_111"), Is.GreaterThan(indexOf("type_001")));

            Assert.That(indexOf("type_211"), Is.GreaterThan(indexOf("type_011")));
            Assert.That(indexOf("type_211"), Is.GreaterThan(indexOf("type_021")));
            Assert.That(indexOf("type_211"), Is.GreaterThan(indexOf("type_001")));

            Assert.That(indexOf("type_121"), Is.GreaterThan(indexOf("type_011")));
            Assert.That(indexOf("type_121"), Is.GreaterThan(indexOf("type_021")));
            Assert.That(indexOf("type_121"), Is.GreaterThan(indexOf("type_001")));

            Assert.That(indexOf("type_221"), Is.GreaterThan(indexOf("type_011")));
            Assert.That(indexOf("type_221"), Is.GreaterThan(indexOf("type_021")));
            Assert.That(indexOf("type_221"), Is.GreaterThan(indexOf("type_001")));

            Assert.That(indexOf("type_011"), Is.GreaterThan(indexOf("type_001")));

            Assert.That(indexOf("type_021"), Is.GreaterThan(indexOf("type_001")));
        }
Exemplo n.º 2
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);
        }
        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"));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
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));
        }
        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 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 void Pointer()
        {
            RemoteValueFake remoteValue =
                RemoteValueFakeUtil.CreatePointer("dummyType*", "dummyName", "0xDEADC0DE");

            remoteValue.SetAddressOf(RemoteValueFakeUtil.CreateAddressOf(remoteValue, 0xDEAD0000));
            Assert.That(RemoteValueExtensions.GetMemoryAddressAssignExpression(remoteValue),
                        Is.EqualTo("((dummyType*)0xDEADC0DE)"));
        }
Exemplo n.º 10
0
        public void FormatStringView()
        {
            // Value has to be quoted, so that FormatStringView recognizes it as string.
            const string    value          = "\"test \\t \\n\"";
            const string    unescapedValue = "test \t \n";
            RemoteValueFake remoteValue    = RemoteValueFakeUtil.CreateSimpleString("tmp", value);

            Assert.That(format.FormatStringView(remoteValue, ValueFormat.Default),
                        Is.EqualTo(unescapedValue));
        }
        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"));
        }
Exemplo n.º 12
0
        public void GetAllInheritedTypesWithNoBaseClass()
        {
            var remoteValue = new RemoteValueFake("dummyVar", "dummyValue");

            remoteValue.SetTypeInfo(new SbTypeStub("MyType", TypeFlags.NONE));
            var varInfo = CreateVarInfo(remoteValue, "dummyDisplayName");

            var inheritedTypes = varInfo.GetAllInheritedTypes();

            Assert.That(inheritedTypes, Is.EqualTo(new[] { "MyType" }));
        }
        public void TestExpressionNameForReferenceOfVariable()
        {
            var remoteValue = new RemoteValueFake("$1", "0x0ddba11");

            remoteValue.SetValueType(DebuggerApi.ValueType.ConstResult);
            remoteValue.SetTypeInfo(new SbTypeStub(
                                        "CustomType*",
                                        TypeFlags.HAS_CHILDREN | TypeFlags.HAS_VALUE | TypeFlags.IS_POINTER));

            Assert.That(remoteValue.GetVariableAssignExpression(), Is.Null);
        }
Exemplo n.º 14
0
        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"));
        }
Exemplo n.º 15
0
        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 TestExpressionNameForInvalidValueType()
        {
            var remoteValue = new RemoteValueFake("myVar", "12358");

            remoteValue.SetValueType(DebuggerApi.ValueType.Invalid);
            remoteValue.SetTypeInfo(
                new SbTypeStub("int", TypeFlags.HAS_VALUE | TypeFlags.IS_SCALAR));
            remoteValue.SetAddressOf(RemoteValueFakeUtil.CreateSimpleLong("$0", 0xDEADBEEF));

            Assert.That(remoteValue.GetVariableAssignExpression(), Is.Null);
        }
Exemplo n.º 17
0
        public void GetValueForExpressionPathFailure()
        {
            RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateSimpleArray(
                "test", "int", RemoteValueFakeUtil.CreateSimpleInt, 4);
            var varInfo = CreateVarInfo(remoteValue, "remoteValue");

            var result =
                varInfo.GetValueForExpressionPath(new VsExpression("[1]", FormatSpecifier.EMPTY));

            Assert.That(result.Error, Is.True);
        }
Exemplo n.º 18
0
        public void CanonicalBoolTypeValues(bool value)
        {
            var remoteValue = new RemoteValueFake("myVar", value ? "true" : "false");
            var boolType    = new SbTypeStub("MyBoolType", TypeFlags.IS_TYPEDEF);

            boolType.SetCanonicalType(new SbTypeStub("bool", TypeFlags.IS_SCALAR));
            remoteValue.SetTypeInfo(boolType);
            var varInfo = varInfoBuilder.Create(remoteValue);

            Assert.That(varInfo.IsTruthy, Is.EqualTo(value));
        }
Exemplo n.º 19
0
        public void GetAllInheritedTypesWhenTypeInfoIsNull()
        {
            var remoteValue = new RemoteValueFake("dummyVar", "dummyValue");

            remoteValue.SetTypeInfo(null);
            var varInfo = CreateVarInfo(remoteValue, "dummyDisplayName");

            var inheritedTypes = varInfo.GetAllInheritedTypes();

            Assert.That(inheritedTypes, Is.Empty);
        }
        public async Task IndexerAccessAsync()
        {
            RemoteValueFake remoteValue =
                RemoteValueFakeUtil.CreateSimpleIntArray("myArray", 3, 4, 5, 6);

            IVariableInformation varInfo     = _varInfoFactory.Create(remoteValue);
            IVariableInformation exprVarInfo =
                await _evaluator.EvaluateExpressionAsync("[3]", varInfo, new NatvisScope(), null);

            Assert.That(exprVarInfo.DisplayName, Is.EqualTo("[3]"));
            Assert.That(await exprVarInfo.ValueAsync(), Is.EqualTo("6"));
        }
Exemplo n.º 21
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\"}"));
        }
Exemplo n.º 22
0
        public async Task GetValueForExpressionPathSuccessAsync()
        {
            RemoteValueFake remoteValue = RemoteValueFakeUtil.CreateSimpleArray(
                "test", "int", RemoteValueFakeUtil.CreateSimpleInt, 4, 7, 74, 47);
            var varInfo = CreateVarInfo(remoteValue, "remoteValue");

            var result =
                varInfo.GetValueForExpressionPath(new VsExpression("[0]", FormatSpecifier.EMPTY));

            Assert.That(result.Error, Is.False);
            Assert.That(await result.ValueAsync(), Is.EqualTo("4"));
            Assert.That(result.DisplayName, Is.EqualTo("[0]"));
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 24
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 void EvaluateExpressionWithErrorRemoteValue()
        {
            RemoteValueFake remoteValue =
                RemoteValueFakeUtil.CreatePointer("MyType*", "myType", _memAddress);

            remoteValue.AddValueFromExpression("myVal",
                                               RemoteValueFakeUtil.CreateError("invalid expression"));

            IVariableInformation varInfo = _varInfoFactory.Create(remoteValue);
            var exception = Assert.ThrowsAsync <ExpressionEvaluationFailed>(
                async() => await _evaluator.EvaluateExpressionAsync(
                    "myVal", varInfo, new NatvisScope(), "tmp"));

            Assert.That(exception.Message, Does.Contain("myVal"));
        }
        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 IndexerAccessWithTokenReplacementAsync()
        {
            RemoteValueFake remoteValue =
                RemoteValueFakeUtil.CreateSimpleIntArray("myArray", 3, 4, 5, 6);

            var natvisScope = new NatvisScope();

            natvisScope.AddScopedName("$i", "2");

            IVariableInformation varInfo     = _varInfoFactory.Create(remoteValue);
            IVariableInformation exprVarInfo =
                await _evaluator.EvaluateExpressionAsync("[$i]", varInfo, natvisScope, null);

            Assert.That(exprVarInfo.DisplayName, Is.EqualTo("[2]"));
            Assert.That(await exprVarInfo.ValueAsync(), Is.EqualTo("5"));
        }
Exemplo n.º 30
0
        public async Task Build_ArrayLimitsOutputSizeAsync()
        {
            const int size = 100;

            _childValues = Enumerable.Range(0, size - 1).ToArray();
            _remoteValue = RemoteValueFakeUtil.CreateSimpleIntArray("myArray", _childValues);

            IVariableInformation varInfo = CreateVarInfo(_remoteValue, size.ToString());
            string result = await ValueStringBuilder.BuildAsync(varInfo);

            Assert.That(
                result,
                Is.EqualTo(
                    "{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20," +
                    " 21, ...}"));
        }