Exemple #1
0
        public void NamesAndDynamic()
        {
            var source =
                @"class C
{
    (dynamic A, (int B, dynamic C)[] D, dynamic E, (int F, dynamic G, int H, int I, int J, int K, int L, int M, int N) O) F =
        (1, new (int, dynamic)[] { (2, 3) }, (4, 5), (6, 7, 8, 9, 10, 11, 12, 13, 14));
}";
            var assembly0    = GenerateTupleAssembly();
            var reference0   = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1    = compilation1.EmitToArray();
            var runtime      = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children   = GetChildren(evalResult);
                Verify(children,
                       EvalResult(
                           "F",
                           "(1, {(int, object)[1]}, (4, 5), (6, 7, 8, 9, 10, 11, 12, 13, 14))",
                           "(dynamic A, (int B, dynamic C)[] D, dynamic E, (int F, dynamic G, int H, int I, int J, int K, int L, int M, int N) O) {(object, (int, object)[], object, (int, object, int, int, int, int, int, int, int))}",
                           "o.F",
                           DkmEvaluationResultFlags.Expandable));
            }
        }
Exemple #2
0
        public void Keywords()
        {
            var source =
                @"namespace @namespace
{
    struct @struct
    {
    }
}
class async
{
    (async @var, @namespace.@struct @class) F;
}";
            var assembly0    = GenerateTupleAssembly();
            var reference0   = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib(source, references: new[] { reference0 });
            var assembly1    = compilation1.EmitToArray();
            var runtime      = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("async");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                       EvalResult("o", "{async}", "async", "o", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult);
                Verify(children,
                       EvalResult("F", "(null, {namespace.struct})", "(async, namespace.struct)", "o.F", DkmEvaluationResultFlags.Expandable));
            }
        }
Exemple #3
0
        public void NoQuotes_DebuggerDisplay()
        {
            var source =
                @"using System.Diagnostics;
[DebuggerDisplay(""{F}+{G}"")]
class C
{
    string F = ""f"";
    object G = 'g';
}";
            var runtime = new DkmClrRuntimeInstance(
                ReflectionUtilities.GetMscorlib(GetAssembly(source))
                );

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult(
                    "o",
                    value,
                    inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.NoQuotes)
                    );
                Verify(
                    evalResult,
                    EvalResult("o", "f+103 g", "C", "o", DkmEvaluationResultFlags.Expandable)
                    );
            }
        }
Exemple #4
0
        public void ResultsView_IEnumerable()
        {
            var source =
                @"using System.Collections;
class C : IEnumerable
{
    public IEnumerator GetEnumerator()
    {
        yield return new C();
    }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", "o, results, d", value, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                Verify(evalResult,
                       EvalResult("o", "{C}", "C", "o, results, d", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Method));
                var children = GetChildren(evalResult);
                // ResultsOnly is not inherited.
                Verify(children,
                       EvalResult("[0]", "{C}", "object {C}", "new System.Linq.SystemCore_EnumerableDebugView(o).Items[0]"));
            }
        }
Exemple #5
0
        public void DebuggerDisplayAttribute()
        {
            var source =
                @"using System.Diagnostics;
[DebuggerDisplay(""F={F}"")]
class A
{
    internal object F;
}
class B
{
    (A, A) F = (new A() { F = 1 }, new A() { F = 2 });
}";
            var assembly0    = GenerateTupleAssembly();
            var reference0   = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib(source, references: new[] { reference0 });
            var assembly1    = compilation1.EmitToArray();
            var runtime      = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("B");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children   = GetChildren(evalResult);
                Verify(children,
                       EvalResult("F", "({A}, {A})", "(A, A)", "o.F", DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[0]);
                Verify(children,
                       EvalResult("Item1", "F=1", "A", "o.F.Item1", DkmEvaluationResultFlags.Expandable),
                       EvalResult("Item2", "F=2", "A", "o.F.Item2", DkmEvaluationResultFlags.Expandable));
            }
        }
Exemple #6
0
        public void ResultsView_NoSystemCore()
        {
            var source =
                @"using System.Collections;
class C : IEnumerable
{
    public IEnumerator GetEnumerator()
    {
        yield return 1;
    }
}";
            var runtime = new DkmClrRuntimeInstance(
                ReflectionUtilities.GetMscorlib(GetAssembly(source))
                );

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult(
                    "o",
                    "o, results",
                    value,
                    inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly)
                    );
                Verify(
                    evalResult,
                    EvalFailedResult("o", "Results View requires System.Core.dll to be referenced")
                    );
            }
        }
Exemple #7
0
        public void Member()
        {
            var source =
                @"unsafe class C
{
    internal C(long p)
    {
        this.pfn = (int*)p;
    }
    int* pfn;
}";
            var        assembly = GetUnsafeAssembly(source);
            const long ptr      = 0x0;

            DkmClrValue getMemberValue(DkmClrValue v, string m) => (m == "pfn") ? GetFunctionPointerField(v, m) : null;

            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(assembly), getMemberValue: getMemberValue);

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate(ptr);
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                       EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable, DkmEvaluationResultCategory.Other));
                var children = GetChildren(evalResult);
                Verify(children,
                       EvalResult("pfn", PointerToString(new IntPtr(ptr)), "int*", "o.pfn", DkmEvaluationResultFlags.None, DkmEvaluationResultCategory.Other));
            }
        }
        public void Error()
        {
            var source =
                @"using System.Diagnostics;
[DebuggerDisplay(""Value"", Name=""Name"", Type=""Type"")]
class A
{
}
class B
{
    bool f;
    internal A P { get { return new A(); } }
    internal A Q { get { while(f) { } return new A(); } }
}
";
            DkmClrRuntimeInstance  runtime        = null;
            GetMemberValueDelegate getMemberValue = (v, m) => (m == "Q") ? CreateErrorValue(runtime.GetType("A"), "Function evaluation timed out") : null;

            runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)), getMemberValue: getMemberValue);
            using (runtime.Load())
            {
                var type       = runtime.GetType("B");
                var value      = CreateDkmClrValue(type.Instantiate(), type: type);
                var evalResult = FormatResult("o", value);
                var children   = GetChildren(evalResult);
                Verify(children,
                       EvalResult("Name", "Value", "Type", "o.P", DkmEvaluationResultFlags.ReadOnly),
                       EvalFailedResult("Q", "Function evaluation timed out", "A", "o.Q"),
                       EvalResult("f", "false", "bool", "o.f", DkmEvaluationResultFlags.Boolean));
            }
        }
Exemple #9
0
        public void Cast()
        {
            var source =
                @"class C
{
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));

            using (runtime.Load())
            {
                IDkmClrFullNameProvider fullNameProvider = new CSharpFormatter();
                var inspectionContext = CreateDkmInspectionContext();
                var type = runtime.GetType("C");

                Assert.Equal("(C)o", fullNameProvider.GetClrCastExpression(inspectionContext, "o", type, null, DkmClrCastExpressionOptions.None));
                Assert.Equal("o as C", fullNameProvider.GetClrCastExpression(inspectionContext, "o", type, null, DkmClrCastExpressionOptions.ConditionalCast));
                Assert.Equal("(C)(o)", fullNameProvider.GetClrCastExpression(inspectionContext, "o", type, null, DkmClrCastExpressionOptions.ParenthesizeArgument));
                Assert.Equal("(o) as C", fullNameProvider.GetClrCastExpression(inspectionContext, "o", type, null, DkmClrCastExpressionOptions.ParenthesizeArgument | DkmClrCastExpressionOptions.ConditionalCast));
                Assert.Equal("((C)o)", fullNameProvider.GetClrCastExpression(inspectionContext, "o", type, null, DkmClrCastExpressionOptions.ParenthesizeEntireExpression));
                Assert.Equal("(o as C)", fullNameProvider.GetClrCastExpression(inspectionContext, "o", type, null, DkmClrCastExpressionOptions.ParenthesizeEntireExpression | DkmClrCastExpressionOptions.ConditionalCast));
                Assert.Equal("((C)(o))", fullNameProvider.GetClrCastExpression(inspectionContext, "o", type, null, DkmClrCastExpressionOptions.ParenthesizeEntireExpression | DkmClrCastExpressionOptions.ParenthesizeArgument));
                Assert.Equal("((o) as C)", fullNameProvider.GetClrCastExpression(inspectionContext, "o", type, null, DkmClrCastExpressionOptions.ParenthesizeEntireExpression | DkmClrCastExpressionOptions.ParenthesizeArgument | DkmClrCastExpressionOptions.ConditionalCast));

                // Some of the same tests with "..." as the expression ("..." is used
                // by the debugger when the expression cannot be determined).
                Assert.Equal("(C)...", fullNameProvider.GetClrCastExpression(inspectionContext, "...", type, null, DkmClrCastExpressionOptions.None));
                Assert.Equal("... as C", fullNameProvider.GetClrCastExpression(inspectionContext, "...", type, null, DkmClrCastExpressionOptions.ConditionalCast));
                Assert.Equal("(... as C)", fullNameProvider.GetClrCastExpression(inspectionContext, "...", type, null, DkmClrCastExpressionOptions.ParenthesizeEntireExpression | DkmClrCastExpressionOptions.ConditionalCast));
            }
        }
Exemple #10
0
        public void Names_LongTuple()
        {
            var source =
                @"class C
{
    ((int A, (int B, int C) D, int E, int F, int G, int H, int I, int J) K, (int L, int M, int N) O) F =
        ((1, (2, 3), 4, 5, 6, 7, 8, 9), (10, 11, 12));
}";
            var assembly0    = GenerateTupleAssembly();
            var reference0   = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1    = compilation1.EmitToArray();
            var runtime      = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children   = GetChildren(evalResult);
                Verify(children,
                       EvalResult(
                           "F",
                           "((1, (2, 3), 4, 5, 6, 7, 8, 9), (10, 11, 12))",
                           "((int A, (int B, int C) D, int E, int F, int G, int H, int I, int J) K, (int L, int M, int N) O)",
                           "o.F",
                           DkmEvaluationResultFlags.Expandable));
            }
        }
Exemple #11
0
        public void DynamicBaseTypeArgument()
        {
            var source =
                @"class A<T>
{
#pragma warning disable 0169
    internal T F;
#pragma warning restore 0169
}
class B : A<dynamic>
{
    B() { F = 1; }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("B");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children   = GetChildren(evalResult);
                Verify(children,
                       EvalResult("F", "1", "dynamic {int}", "o.F"));
            }
        }
Exemple #12
0
        public void ResultsView_TypeProxy()
        {
            var source =
                @"using System.Collections;
using System.Diagnostics;
[DebuggerTypeProxy(typeof(P))]
class C : IEnumerable
{
    public IEnumerator GetEnumerator()
    {
        yield return 1;
    }
}
class P
{
    public P(C c)
    {
    }
    public object F
    {
        get { return 2; }
    }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", "o, results", value, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                Verify(evalResult,
                       EvalResult("o", "{C}", "C", "o, results", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Method));
            }
        }
Exemple #13
0
        public void Dynamic()
        {
            var source =
                @"class C
{
    (dynamic, (object, dynamic)) F = (1, (2, 3));
    (object, object, object, object, object, object, dynamic[], dynamic[]) G = (1, 2, 3, 4, 5, 6, new object[] { 7 }, new object[] { 8 });
}";
            var assembly0    = GenerateTupleAssembly();
            var reference0   = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1    = compilation1.EmitToArray();
            var runtime      = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children   = GetChildren(evalResult);
                Verify(children,
                       EvalResult(
                           "F",
                           "(1, (2, 3))",
                           "(dynamic, (object, dynamic)) {(object, (object, object))}",
                           "o.F",
                           DkmEvaluationResultFlags.Expandable),
                       EvalResult(
                           "G",
                           "(1, 2, 3, 4, 5, 6, {object[1]}, {object[1]})",
                           "(object, object, object, object, object, object, dynamic[], dynamic[]) {(object, object, object, object, object, object, object[], object[])}",
                           "o.G",
                           DkmEvaluationResultFlags.Expandable));
            }
        }
Exemple #14
0
        public void IsTupleCompatible_InvalidName()
        {
            var source =
                @".class sealed System.ValueTuple`3<T1, T2> extends [mscorlib]System.ValueType
{
  .method public hidebysig specialname rtspecialname instance void .ctor() cil managed
  {
    ldarg.0
    call       instance void [mscorlib]System.Object::.ctor()
    ret
  }
}";
            ImmutableArray <byte> assemblyBytes;
            ImmutableArray <byte> pdbBytes;

            CSharpTestBase.EmitILToArray(source, appendDefaultHeader: true, includePdb: false, assemblyBytes: out assemblyBytes, pdbBytes: out pdbBytes);
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assemblyBytes)));

            using (runtime.Load())
            {
                var type = runtime.GetType("System.ValueTuple`3", typeof(object), typeof(int));
                int cardinality;
                Assert.False(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(0, cardinality);
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                       EvalResult("o", "{System.ValueTuple<object, int>}", "System.ValueTuple<object, int>", "o"));
            }
        }
Exemple #15
0
        public void IsTupleCompatible_Other()
        {
            var source =
                @"namespace System
{
    struct ValueTuple<T1, T2>
    {
        public struct S { }
    }
    struct ValueTuple2<T1, T2> { }
}
namespace Other
{
    struct ValueTuple<T1, T2> { }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));

            using (runtime.Load())
            {
                var type = runtime.GetType("System.ValueTuple`2+S", typeof(object), typeof(object));
                int cardinality;
                Assert.False(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(0, cardinality);

                type = runtime.GetType("System.ValueTuple2`2", typeof(object), typeof(object));
                Assert.False(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(0, cardinality);

                type = runtime.GetType("Other.ValueTuple`2", typeof(object), typeof(object));
                Assert.False(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(0, cardinality);
            }
        }
Exemple #16
0
        public void ResultsView_IEnumerableOfT()
        {
            var source =
                @"using System;
using System.Collections;
using System.Collections.Generic;
struct S<T> : IEnumerable<T>
{
    private readonly T t;
    internal S(T t)
    {
        this.t = t;
    }
    IEnumerator<T> IEnumerable<T>.GetEnumerator()
    {
        yield return t;
    }
    IEnumerator IEnumerable.GetEnumerator()
    {
        throw new NotImplementedException();
    }
}";
            var runtime = new DkmClrRuntimeInstance(
                ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source))
                );

            using (runtime.Load())
            {
                var type       = runtime.GetType("S`1").MakeGenericType(runtime.GetType(typeof(int)));
                var value      = type.Instantiate(2);
                var evalResult = FormatResult(
                    "o",
                    "o, results",
                    value,
                    inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly)
                    );
                Verify(
                    evalResult,
                    EvalResult(
                        "o",
                        "{S<int>}",
                        "S<int>",
                        "o, results",
                        DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly,
                        DkmEvaluationResultCategory.Method
                        )
                    );
                var children = GetChildren(evalResult);
                Verify(
                    children,
                    EvalResult(
                        "[0]",
                        "2",
                        "int",
                        "new System.Linq.SystemCore_EnumerableDebugView<int>(o).Items[0]"
                        )
                    );
            }
        }
Exemple #17
0
        public void LongTuple()
        {
            var source =
                @"class C
{
    (short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short) _17 =
        (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
}";
            var assembly0    = GenerateTupleAssembly();
            var reference0   = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib(source, references: new[] { reference0 });
            var assembly1    = compilation1.EmitToArray();
            var runtime      = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));

            using (runtime.Load())
            {
                var inspectionContext = CreateDkmInspectionContext(radix: 16);
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value, inspectionContext: inspectionContext);
                Verify(evalResult,
                       EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult, inspectionContext);
                Verify(children,
                       EvalResult(
                           "_17",
                           "(0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011)",
                           "(short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short, short)",
                           "o._17",
                           DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[0], inspectionContext);
                Assert.Equal(8, children.Length); // Should be 18. https://github.com/dotnet/roslyn/issues/13421
                var child = children[children.Length - 1];
                Verify(child,
                       EvalResult(
                           "Rest",
                           "(0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, 0x0010, 0x0011)",
                           "(short, short, short, short, short, short, short, short, short, short)",
                           "o._17.Rest",
                           DkmEvaluationResultFlags.Expandable));
                children = GetChildren(child, inspectionContext);
                Assert.Equal(8, children.Length); // Should be 11. https://github.com/dotnet/roslyn/issues/13421
                child = children[children.Length - 1];
                Verify(child,
                       EvalResult(
                           "Rest",
                           "(0x000f, 0x0010, 0x0011)",
                           "(short, short, short)",
                           "o._17.Rest.Rest",
                           DkmEvaluationResultFlags.Expandable));
            }
        }
Exemple #18
0
        public void ObjectId()
        {
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(GenerateTupleAssembly())));

            using (runtime.Load())
            {
                var type       = runtime.GetType("System.ValueTuple`2", typeof(object), typeof(int));
                var value      = type.Instantiate(new object[0], alias: "$3", evalFlags: DkmEvaluationResultFlags.HasObjectId);
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                       EvalResult("o", "(null, 0) {$3}", "(object, int)", "o", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.HasObjectId));
            }
        }
Exemple #19
0
        public void ResultsView_Error()
        {
            var source =
                @"using System.Collections;
class C
{
    bool f;
    internal ArrayList P
    {
        get { while (!this.f) { } return new ArrayList(); }
    }
    internal int Q
    {
        get { while (!this.f) { } return 3; }
    }
}";
            DkmClrRuntimeInstance  runtime        = null;
            GetMemberValueDelegate getMemberValue = (v, m) =>
            {
                switch (m)
                {
                case "P":
                    return(CreateErrorValue(runtime.GetType(typeof(System.Collections.ArrayList)), "Property 'P' evaluation timed out"));

                case "Q":
                    return(CreateErrorValue(runtime.GetType(typeof(string)), "Property 'Q' evaluation timed out"));

                default:
                    return(null);
                }
            };

            runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)), getMemberValue: getMemberValue);
            using (runtime.Load())
            {
                var type        = runtime.GetType("C");
                var value       = CreateDkmClrValue(type.Instantiate(), type: type);
                var memberValue = value.GetMemberValue("P", (int)System.Reflection.MemberTypes.Property, "C").
                                  WithInspectionContext(CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                var evalResult = FormatResult("o.P", "o.P, results", memberValue);
                Verify(evalResult,
                       EvalFailedResult("o.P", "Property 'P' evaluation timed out"));
                memberValue = value.GetMemberValue("Q", (int)System.Reflection.MemberTypes.Property, "C").
                              WithInspectionContext(CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                evalResult = FormatResult("o.Q", "o.Q, results", memberValue);
                Verify(evalResult,
                       EvalFailedResult("o.Q", "Property 'Q' evaluation timed out"));
            }
        }
Exemple #20
0
        public void RootHidden_Exception()
        {
            var source =
                @"using System;
using System.Diagnostics;
class E : Exception
{
}
class F : E
{
    object G = 1;
}
class C
{
    [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
    object P { get { throw new F(); } }
}";

            using (new EnsureEnglishUICulture())
            {
                var runtime = new DkmClrRuntimeInstance(
                    ReflectionUtilities.GetMscorlib(GetAssembly(source))
                    );
                using (runtime.Load())
                {
                    var type       = runtime.GetType("C");
                    var value      = type.Instantiate();
                    var evalResult = FormatResult("o", value);
                    Verify(
                        evalResult,
                        EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable)
                        );
                    var children = GetChildren(evalResult);
                    Verify(children[1], EvalResult("G", "1", "object {int}", null));
                    Verify(
                        children[7],
                        EvalResult(
                            "Message",
                            "\"Exception of type 'F' was thrown.\"",
                            "string",
                            null,
                            DkmEvaluationResultFlags.RawString | DkmEvaluationResultFlags.ReadOnly
                            )
                        );
                }
            }
        }
Exemple #21
0
        public void NamesFromTypeArguments()
        {
            var source =
                @"class A<T, U>
{
    T F;
    U[] G = new U[0];
}
class B<T>
{
    internal struct S { }
    (dynamic X, T Y) F = (null, default(T));
}
class C
{
    A<(dynamic A, object B)[], (object C, dynamic[] D)> F = new A<(dynamic A, object B)[], (object, dynamic[])>();
    B<(object E, B<(object F, dynamic G)>.S H)> G = new B<(object E, B<(object F, dynamic G)>.S H)>();
}";
            var assembly0    = GenerateTupleAssembly();
            var reference0   = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1    = compilation1.EmitToArray();
            var runtime      = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children   = GetChildren(evalResult);
                Verify(children,
                       EvalResult("F", "{A<(object, object)[], (object, object[])>}", "A<(dynamic A, object B)[], (object C, dynamic[] D)> {A<(object, object)[], (object, object[])>}", "o.F", DkmEvaluationResultFlags.Expandable),
                       EvalResult("G", "{B<(object, B<(object, object)>.S)>}", "B<(object E, B<(object F, dynamic G)>.S H)> {B<(object, B<(object, object)>.S)>}", "o.G", DkmEvaluationResultFlags.Expandable));
                var moreChildren = GetChildren(children[0]);
                Verify(moreChildren,
                       EvalResult("F", "null", "(dynamic A, object B)[] {(object, object)[]}", "o.F.F"),
                       EvalResult("G", "{(object, object[])[0]}", "(object C, dynamic[] D)[] {(object, object[])[]}", "o.F.G"));
                moreChildren = GetChildren(children[1]);
                Verify(moreChildren,
                       EvalResult("F", "(null, (null, {B<(object, object)>.S}))", "(dynamic X, (object E, B<(object F, dynamic G)>.S H) Y) {(object, (object, B<(object, object)>.S))}", "o.G.F", DkmEvaluationResultFlags.Expandable));
                moreChildren = GetChildren(moreChildren[0]);
                Verify(moreChildren,
                       EvalResult("Item1", "null", "dynamic {object}", "o.G.F.Item1"),
                       EvalResult("Item2", "(null, {B<(object, object)>.S})", "(object E, B<(object F, dynamic G)>.S H) {(object, B<(object, object)>.S)}", "o.G.F.Item2", DkmEvaluationResultFlags.Expandable));
            }
        }
Exemple #22
0
        public void NamesAndDynamic_Other()
        {
            var source =
                @"class C1 { }
class C2 { }
class C3 { }
class C4 { }
class C5 { }
class C6 { }
class C7 { }
class C8 { }
class C9 { }
class C10 { }
class C11 { }
class C12 { }
class C
{
    (((C1 C1, dynamic C2) B1, (C3 C3, dynamic C4)) A1, (dynamic B3, (C7 C7, C8 C8) B4) A2, ((C9 C9, C10 C10), dynamic B6) A3) F =
        ((
            ((new C1(), new C2()), (new C3(), new C4())),
            ((new C5(), new C6()), (new C7(), new C8())),
            ((new C9(), new C10()), (new C11(), new C12()))
        ));
}";
            var assembly0    = GenerateTupleAssembly();
            var reference0   = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1    = compilation1.EmitToArray();
            var runtime      = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children   = GetChildren(evalResult);
                Verify(children,
                       EvalResult(
                           "F",
                           "((({C1}, {C2}), ({C3}, {C4})), (({C5}, {C6}), ({C7}, {C8})), (({C9}, {C10}), ({C11}, {C12})))",
                           "(((C1 C1, dynamic C2) B1, (C3 C3, dynamic C4)) A1, (dynamic B3, (C7 C7, C8 C8) B4) A2, ((C9 C9, C10 C10), dynamic B6) A3) {(((C1, object), (C3, object)), (object, (C7, C8)), ((C9, C10), object))}",
                           "o.F",
                           DkmEvaluationResultFlags.Expandable));
            }
        }
Exemple #23
0
        public void PartialNames()
        {
            var source =
                @"class C
{
    ((int A, (int B, int C) D, int, int F, int G, int, int I, int J, int K, int L) M, (int N, int, int P) Q) F =
        ((1, (2, 3), 4, 5, 6, 7, 8, 9, 10, 11), (12, 13, 14));
    (int A, (int B, int)[] C, (object, object), (int, int D, int E, int F, int G, int H, int I, int J, int) K)[] G =
        new[] { (1, new[] { (2, 3) }, ((object, object))(4, 5), (6, 7, 8, 9, 10, 11, 12, 13, 14)) };
}";
            var assembly0    = GenerateTupleAssembly();
            var reference0   = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1    = compilation1.EmitToArray();
            var runtime      = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children   = GetChildren(evalResult);
                Verify(children,
                       EvalResult(
                           "F",
                           "((1, (2, 3), 4, 5, 6, 7, 8, 9, 10, 11), (12, 13, 14))",
                           "((int A, (int B, int C) D, int, int F, int G, int, int I, int J, int K, int L) M, (int N, int, int P) Q)",
                           "o.F",
                           DkmEvaluationResultFlags.Expandable),
                       EvalResult(
                           "G",
                           "{(int, (int, int)[], (object, object), (int, int, int, int, int, int, int, int, int))[1]}",
                           "(int A, (int B, int)[] C, (object, object), (int, int D, int E, int F, int G, int H, int I, int J, int) K)[]",
                           "o.G",
                           DkmEvaluationResultFlags.Expandable));
                children = GetChildren(children[1]);
                Verify(children,
                       EvalResult(
                           "[0]",
                           "(1, {(int, int)[1]}, (4, 5), (6, 7, 8, 9, 10, 11, 12, 13, 14))",
                           "(int A, (int B, int)[] C, (object, object), (int, int D, int E, int F, int G, int H, int I, int J, int) K)",
                           "o.G[0]",
                           DkmEvaluationResultFlags.Expandable));
            }
        }
Exemple #24
0
        public void Tuples()
        {
            var source =
                @"using System;
class C
{
    object _1 = new ValueTuple<int>(1);
    object _2 = new ValueTuple<int, int>(1, 2);
    object _3 = new ValueTuple<int, int, int>(1, 2, 3);
    object _4 = new ValueTuple<int, int, int, int>(1, 2, 3, 4);
    object _5 = new ValueTuple<int, int, int, int, int>(1, 2, 3, 4, 5);
    object _6 = new ValueTuple<int, int, int, int, int, int>(1, 2, 3, 4, 5, 6);
    object _7 = new ValueTuple<int, int, int, int, int, int, int>(1, 2, 3, 4, 5, 6, 7);
    object _8 = new ValueTuple<int, int, int, int, int, int, int, ValueTuple<int>>(1, 2, 3, 4, 5, 6, 7, new ValueTuple<int>(8));
    object _8A = new ValueTuple<int, int, int, int, int, int, int, int>(1, 2, 3, 4, 5, 6, 7, 8);
    object _9 = new ValueTuple<int, int, int, int, int, int, int, ValueTuple<int, int>>(1, 2, 3, 4, 5, 6, 7, new ValueTuple<int, int>(8, 9));
}";
            var assembly0    = GenerateTupleAssembly();
            var reference0   = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib(source, references: new[] { reference0 });
            var assembly1    = compilation1.EmitToArray();
            var runtime      = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                       EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult);
                Verify(children,
                       EvalResult("_1", "{System.ValueTuple<int>}", "object {System.ValueTuple<int>}", "o._1", DkmEvaluationResultFlags.Expandable),
                       EvalResult("_2", "(1, 2)", "object {(int, int)}", "o._2", DkmEvaluationResultFlags.Expandable),
                       EvalResult("_3", "(1, 2, 3)", "object {(int, int, int)}", "o._3", DkmEvaluationResultFlags.Expandable),
                       EvalResult("_4", "(1, 2, 3, 4)", "object {(int, int, int, int)}", "o._4", DkmEvaluationResultFlags.Expandable),
                       EvalResult("_5", "(1, 2, 3, 4, 5)", "object {(int, int, int, int, int)}", "o._5", DkmEvaluationResultFlags.Expandable),
                       EvalResult("_6", "(1, 2, 3, 4, 5, 6)", "object {(int, int, int, int, int, int)}", "o._6", DkmEvaluationResultFlags.Expandable),
                       EvalResult("_7", "(1, 2, 3, 4, 5, 6, 7)", "object {(int, int, int, int, int, int, int)}", "o._7", DkmEvaluationResultFlags.Expandable),
                       EvalResult("_8", "(1, 2, 3, 4, 5, 6, 7, 8)", "object {(int, int, int, int, int, int, int, int)}", "o._8", DkmEvaluationResultFlags.Expandable),
                       EvalResult("_8A", "{System.ValueTuple<int, int, int, int, int, int, int, int>}", "object {System.ValueTuple<int, int, int, int, int, int, int, int>}", "o._8A", DkmEvaluationResultFlags.Expandable),
                       EvalResult("_9", "(1, 2, 3, 4, 5, 6, 7, 8, 9)", "object {(int, int, int, int, int, int, int, int, int)}", "o._9", DkmEvaluationResultFlags.Expandable));
            }
        }
Exemple #25
0
        public void ResultsView_GetChildren()
        {
            var source =
                @"using System.Collections;
using System.Collections.Generic;
class C
{
    IEnumerable<int> F
    {
        get { yield return 1; }
    }
    IEnumerable G
    {
        get { yield return 2; }
    }
    int H
    {
        get { return 3; }
    }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", "o", value);
                Verify(evalResult,
                       EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable));
                // GetChildren without ResultsOnly
                var children = GetChildren(evalResult, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.None));
                Verify(children,
                       EvalResult("F", "{C.<get_F>d__1}", "System.Collections.Generic.IEnumerable<int> {C.<get_F>d__1}", "o.F", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly | DkmEvaluationResultFlags.CanFavorite),
                       EvalResult("G", "{C.<get_G>d__3}", "System.Collections.IEnumerable {C.<get_G>d__3}", "o.G", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly | DkmEvaluationResultFlags.CanFavorite),
                       EvalResult("H", "3", "int", "o.H", DkmEvaluationResultFlags.ReadOnly | DkmEvaluationResultFlags.CanFavorite));
                // GetChildren with ResultsOnly
                children = GetChildren(evalResult, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                Verify(children,
                       EvalResult("F", "{C.<get_F>d__1}", "System.Collections.Generic.IEnumerable<int> {C.<get_F>d__1}", "o.F, results", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly),
                       EvalResult("G", "{C.<get_G>d__3}", "System.Collections.IEnumerable {C.<get_G>d__3}", "o.G, results", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly),
                       EvalFailedResult("H", "Only Enumerable types can have Results View", fullName: null));
            }
        }
Exemple #26
0
        public void ResultsView_ExceptionThrown()
        {
            var source =
                @"using System;
using System.Collections;
class E : Exception, IEnumerable
{
    IEnumerator IEnumerable.GetEnumerator()
    {
        yield return 1;
    }
}
class C
{
    internal ArrayList P
    {
        get { throw new NotImplementedException(); }
    }
    internal ArrayList Q
    {
        get { throw new E(); }
    }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore(GetAssembly(source)));

            using (runtime.Load())
            {
                var type        = runtime.GetType("C");
                var value       = CreateDkmClrValue(type.Instantiate(), type: type);
                var memberValue = value.GetMemberValue("P", (int)System.Reflection.MemberTypes.Property, "C").
                                  WithInspectionContext(CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                var evalResult = FormatResult("o.P", "o.P, results", memberValue);
                Verify(evalResult,
                       EvalFailedResult("o.P", "'o.P' threw an exception of type 'System.NotImplementedException'"));
                memberValue = value.GetMemberValue("Q", (int)System.Reflection.MemberTypes.Property, "C").
                              WithInspectionContext(CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly));
                evalResult = FormatResult("o.Q", "o.Q, results", memberValue);
                Verify(evalResult,
                       EvalFailedResult("o.Q", "'o.Q' threw an exception of type 'E'"));
            }
        }
Exemple #27
0
        public void NullNullableAndArray()
        {
            var source =
                @"using System;
namespace System
{
    class ValueTuple<T1, T2>
    {
        public T1 Item1;
        public T2 Item2;
    }
    struct ValueTuple<T1, T2, T3>
    {
        public T1 Item1;
        public T2 Item2;
        public T3 Item3;
    }
}
class C
{
    ValueTuple<object, int> _1 = null;
    ValueTuple<object, int, object>? _2 = new ValueTuple<object, int, object>();
    ValueTuple<object, int>[] _3 = new ValueTuple<object, int>[1];
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value);
                Verify(evalResult,
                       EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult);
                Verify(children,
                       EvalResult("_1", "null", "(object, int)", "o._1"),
                       EvalResult("_2", "(null, 0, null)", "(object, int, object)?", "o._2", DkmEvaluationResultFlags.Expandable),
                       EvalResult("_3", "{(object, int)[1]}", "(object, int)[]", "o._3", DkmEvaluationResultFlags.Expandable));
            }
        }
Exemple #28
0
        public void IsTupleCompatible_NonStruct()
        {
            var source =
                @"namespace System
{
    class ValueTuple<T1, T2> { }
    delegate void ValueTuple<T1, T2, T3>();
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));

            using (runtime.Load())
            {
                var type = runtime.GetType("System.ValueTuple`2", typeof(object), typeof(object));
                int cardinality;
                Assert.True(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(2, cardinality);

                type = runtime.GetType("System.ValueTuple`3", typeof(object), typeof(object), typeof(object));
                Assert.True(type.GetLmrType().IsTupleCompatible(out cardinality));
                Assert.Equal(3, cardinality);
            }
        }
Exemple #29
0
        public void NamesAndValueTuple1()
        {
            var source =
                @"using System;
class C<T>
{
    internal C(T t) { }
}
class C
{
    (ValueTuple<int> A, int B) F = (new ValueTuple<int>(1), 2);
    (int A, ValueTuple<int> B) G = (3, new ValueTuple<int>(4));
    ValueTuple<(int A, int B)> H = new ValueTuple<(int, int)>((5, 6));
    (int A, ValueTuple<(int B, int C)> D) I = (7, new ValueTuple<(int, int)>((8, 9)));
    C<(int A, int B)> J = new C<(int, int)>((10, 11));
}";
            var assembly0    = GenerateTupleAssembly();
            var reference0   = AssemblyMetadata.CreateFromImage(assembly0).GetReference();
            var compilation1 = CSharpTestBaseBase.CreateCompilationWithMscorlib45AndCSruntime(source, additionalRefs: new[] { reference0 });
            var assembly1    = compilation1.EmitToArray();
            var runtime      = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(ReflectionUtilities.Load(assembly0), ReflectionUtilities.Load(assembly1)));

            using (runtime.Load())
            {
                var type       = runtime.GetType("C");
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", value);
                var children   = GetChildren(evalResult);
                Verify(children,
                       EvalResult("F", "({System.ValueTuple<int>}, 2)", "(System.ValueTuple<int> A, int B)", "o.F", DkmEvaluationResultFlags.Expandable),
                       EvalResult("G", "(3, {System.ValueTuple<int>})", "(int A, System.ValueTuple<int> B)", "o.G", DkmEvaluationResultFlags.Expandable),
                       EvalResult("H", "{System.ValueTuple<(int, int)>}", "System.ValueTuple<(int A, int B)>", "o.H", DkmEvaluationResultFlags.Expandable),
                       EvalResult("I", "(7, {System.ValueTuple<(int, int)>})", "(int A, System.ValueTuple<(int B, int C)> D)", "o.I", DkmEvaluationResultFlags.Expandable),
                       EvalResult("J", "{C<(int, int)>}", "C<(int A, int B)>", "o.J"));
            }
        }
Exemple #30
0
        public void RawView()
        {
            var source =
                @"using System.Diagnostics;
internal class P
{
    public P(C c)
    {
        this.G = c.F != null;
    }
    public readonly bool G;
}
[DebuggerTypeProxy(typeof(P))]
class C
{
    internal C() : this(new C(null))
    {
    }
    internal C(C f)
    {
        this.F = f;
    }
    internal readonly C F;
}
class Program
{
    static void Main()
    {
        var o = new C();
        System.Diagnostics.Debugger.Break();
    }
}";
            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(GetAssembly(source)));

            using (runtime.Load())
            {
                var type = runtime.GetType("C");

                // Non-null value.
                var value      = type.Instantiate();
                var evalResult = FormatResult("o", "o, raw", value, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ShowValueRaw));
                Verify(evalResult,
                       EvalResult("o", "{C}", "C", "o, raw", DkmEvaluationResultFlags.Expandable));
                var children = GetChildren(evalResult);
                Verify(children,
                       EvalResult("F", "{C}", "C", "o.F", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
                children = GetChildren(children[0]);
                // ShowValueRaw is not inherited.
                Verify(children,
                       EvalResult("G", "false", "bool", "new P(o.F).G", DkmEvaluationResultFlags.Boolean | DkmEvaluationResultFlags.ReadOnly),
                       EvalResult("Raw View", null, "", "o.F, raw", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Data));

                // Null value.
                value = CreateDkmClrValue(
                    value: null,
                    type: type);
                evalResult = FormatResult("o", "o, raw", value, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.ShowValueRaw));
                Verify(evalResult,
                       EvalResult("o", "null", "C", "o, raw"));
            }
        }