Exemplo n.º 1
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"));
            }
        }
Exemplo n.º 2
0
        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      = type.Instantiate();
                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));
            }
        }
Exemplo n.º 3
0
        public void RootHidden_OnNonPublicMembers()
        {
            var source =
                @"using System.Diagnostics;
public class C<T>
{
    public C(params T[] items)
    {
        this.items = items;
    }
    [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
    private T[] items;
}";
            var assembly = GetAssembly(source);
            var runtime  = new DkmClrRuntimeInstance(new Assembly[0]);
            var type     = assembly.GetType("C`1").MakeGenericType(typeof(int));
            var value    = CreateDkmClrValue(
                value: type.Instantiate(1, 2, 3),
                type: new DkmClrType(runtime.DefaultModule, runtime.DefaultAppDomain, (TypeImpl)type),
                evalFlags: DkmEvaluationResultFlags.None);
            var evalResult = FormatResult("o", value, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.HideNonPublicMembers));

            Verify(evalResult,
                   EvalResult("o", "{C<int>}", "C<int>", "o", DkmEvaluationResultFlags.Expandable));
            var children = GetChildren(evalResult);

            Verify(children,
                   EvalResult("[0]", "1", "int", "o.items[0]"),
                   EvalResult("[1]", "2", "int", "o.items[1]"),
                   EvalResult("[2]", "3", "int", "o.items[2]"));
        }
Exemplo n.º 4
0
        public void NoQuotes_Char()
        {
            var runtime           = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib());
            var inspectionContext = CreateDkmInspectionContext(DkmEvaluationFlags.NoQuotes);
            var charType          = runtime.GetType(typeof(char));

            // 0
            var value      = CreateDkmClrValue((char)0, type: charType);
            var evalResult = FormatResult("c", value, inspectionContext: inspectionContext);

            Verify(evalResult,
                   EvalResult("c", "0 \0", "char", "c", editableValue: "'\\0'", flags: DkmEvaluationResultFlags.None));

            // '\''
            value      = CreateDkmClrValue('\'', type: charType);
            evalResult = FormatResult("c", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("c", "39 '", "char", "c", editableValue: "'\\''", flags: DkmEvaluationResultFlags.None));

            // '"'
            value      = CreateDkmClrValue('"', type: charType);
            evalResult = FormatResult("c", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("c", "34 \"", "char", "c", editableValue: "'\"'", flags: DkmEvaluationResultFlags.None));

            // '\\'
            value      = CreateDkmClrValue('\\', type: charType);
            evalResult = FormatResult("c", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("c", "92 \\", "char", "c", editableValue: "'\\\\'", flags: DkmEvaluationResultFlags.None));

            // '\n'
            value      = CreateDkmClrValue('\n', type: charType);
            evalResult = FormatResult("c", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("c", "10 \n", "char", "c", editableValue: "'\\n'", flags: DkmEvaluationResultFlags.None));

            // '\u001e'
            value      = CreateDkmClrValue('\u001e', type: charType);
            evalResult = FormatResult("c", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("c", "30 \u001e", "char", "c", editableValue: "'\\u001e'", flags: DkmEvaluationResultFlags.None));

            // '\u007f'
            value      = CreateDkmClrValue('\u007f', type: charType);
            evalResult = FormatResult("c", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("c", "127 \u007f", "char", "c", editableValue: "'\\u007f'", flags: DkmEvaluationResultFlags.None));

            // array
            value      = CreateDkmClrValue(new char[] { '1' }, type: charType.MakeArrayType());
            evalResult = FormatResult("a", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("a", "{char[1]}", "char[]", "a", editableValue: null, flags: DkmEvaluationResultFlags.Expandable));
            var children = GetChildren(evalResult);

            // DkmInspectionContext should not be inherited.
            Verify(children,
                   EvalResult("[0]", "49 '1'", "char", "a[0]", editableValue: "'1'", flags: DkmEvaluationResultFlags.None));
        }
Exemplo n.º 5
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));
            }
        }
Exemplo n.º 6
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]"));
            }
        }
Exemplo n.º 7
0
        public void SimpleDisplayString()
        {
            var source =
                @"class A
{
    string s1 = ""S1"";
    string s2 = ""S2"";
    string s3 = ""S3"";
    string s4 = ""S4"";
}";

            var assembly = GetAssembly(source);
            var type     = assembly.GetType("A");
            var rootExpr = "new A()";

            var favoritesByTypeName = new Dictionary <string, DkmClrObjectFavoritesInfo>()
            {
                { "A", new DkmClrObjectFavoritesInfo(new[] { "s4", "s2" }, "s4 = {s4}, s2 = {s2}", "{s4}, {s2}") }
            };

            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(assembly), favoritesByTypeName);

            var value = CreateDkmClrValue(
                value: Activator.CreateInstance(type),
                type: runtime.GetType((TypeImpl)type));

            var evalResult = FormatResult(rootExpr, value, null, CreateDkmInspectionContext(DkmEvaluationFlags.UseSimpleDisplayString));

            Verify(evalResult,
                   EvalResult(rootExpr, @"""S4"", ""S2""", "A", rootExpr, DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.HasFavorites));
        }
Exemplo n.º 8
0
        public void DynamicMetaObjectProviderDebugViewItemsException()
        {
            var     expression = "o";
            var     fullName   = expression + ", dynamic";
            dynamic o          = new ExpandoObject();

            o.Answer = 42;

            DkmClrRuntimeInstance runtime           = null;
            Func <DkmClrValue>    getExceptionValue = () => CreateDkmClrValue(new NotImplementedException(), evalFlags: DkmEvaluationResultFlags.ExceptionThrown);

            runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(), getMemberValue: (_, m) => (m == "Items") ? getExceptionValue() : null);
            var type  = new DkmClrType(runtime, (TypeImpl)o.GetType());
            var value = CreateDkmClrValue((object)o, type);

            var result = FormatResult(expression, fullName, value, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.DynamicView));

            Verify(result,
                   EvalResult(expression, Resources.DynamicViewValueWarning, "", fullName, DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
            var members = GetChildren(result);

            Assert.Equal(32, members.Length);
            Verify(members[1],
                   EvalResult("HResult", "-2147467263", "int", null, category: DkmEvaluationResultCategory.Property, access: DkmEvaluationResultAccessType.Public));

            getExceptionValue = () => CreateDkmClrValue(new NotImplementedException());
            result            = FormatResult(expression, fullName, value, inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.DynamicView));
            Verify(result,
                   EvalResult(expression, Resources.DynamicViewValueWarning, "", fullName, DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly));
            members = GetChildren(result);
            Assert.Equal(32, members.Length);
            Verify(members[1],
                   EvalResult("HResult", "-2147467263", "int", "((System.Exception)new Microsoft.CSharp.RuntimeBinder.DynamicMetaObjectProviderDebugView(o).Items).HResult", category: DkmEvaluationResultCategory.Property, access: DkmEvaluationResultAccessType.Public));
        }
Exemplo n.º 9
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;
            GetMemberValueDelegate getMemberValue = (v, 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      = CreateDkmClrValue(type.Instantiate(ptr), type);
                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));
            }
        }
Exemplo n.º 10
0
        public void Expansion()
        {
            var source =
                @"class A
{
    string s1 = ""S1"";
    string s2 = ""S2"";
}
class B : A
{
    string s3 = ""S3"";
    string s4 = ""S4"";
}
class C
{
    A a = new A();
    B b = new B();
}";

            var assembly = GetAssembly(source);
            var type     = assembly.GetType("C");
            var rootExpr = "new C()";

            var favoritesByTypeName = new Dictionary <string, DkmClrObjectFavoritesInfo>()
            {
                { "C", new DkmClrObjectFavoritesInfo(new[] { "b" }) },
                { "B", new DkmClrObjectFavoritesInfo(new[] { "s4", "s2" }) }
            };

            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(assembly), favoritesByTypeName);

            var value = CreateDkmClrValue(
                value: Activator.CreateInstance(type),
                type: runtime.GetType((TypeImpl)type));

            var evalResult = FormatResult(rootExpr, value);

            Verify(evalResult,
                   EvalResult(rootExpr, "{C}", "C", rootExpr, DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.HasFavorites));
            var children = GetChildren(evalResult);

            Verify(children,
                   EvalResult("b", "{B}", "B", "(new C()).b", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.CanFavorite | DkmEvaluationResultFlags.IsFavorite | DkmEvaluationResultFlags.HasFavorites),
                   EvalResult("a", "{A}", "A", "(new C()).a", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.CanFavorite));

            // B b = new B();
            var more = GetChildren(children[0]);

            Verify(more,
                   EvalResult("s4", @"""S4""", "string", "(new C()).b.s4", DkmEvaluationResultFlags.RawString | DkmEvaluationResultFlags.CanFavorite | DkmEvaluationResultFlags.IsFavorite, editableValue: @"""S4"""),
                   EvalResult("s2", @"""S2""", "string", "(new C()).b.s2", DkmEvaluationResultFlags.RawString | DkmEvaluationResultFlags.CanFavorite | DkmEvaluationResultFlags.IsFavorite, editableValue: @"""S2"""),
                   EvalResult("s1", @"""S1""", "string", "(new C()).b.s1", DkmEvaluationResultFlags.RawString | DkmEvaluationResultFlags.CanFavorite, editableValue: @"""S1"""),
                   EvalResult("s3", @"""S3""", "string", "(new C()).b.s3", DkmEvaluationResultFlags.RawString | DkmEvaluationResultFlags.CanFavorite, editableValue: @"""S3"""));

            // A a = new A();
            more = GetChildren(children[1]);
            Verify(more,
                   EvalResult("s1", @"""S1""", "string", "(new C()).a.s1", DkmEvaluationResultFlags.RawString | DkmEvaluationResultFlags.CanFavorite, editableValue: @"""S1"""),
                   EvalResult("s2", @"""S2""", "string", "(new C()).a.s2", DkmEvaluationResultFlags.RawString | DkmEvaluationResultFlags.CanFavorite, editableValue: @"""S2"""));
        }
Exemplo n.º 11
0
        internal static DkmCompiledClrInspectionQuery ToQueryResult(
            this CompileResult compResult,
            DkmCompilerId languageId,
            ResultProperties resultProperties,
            DkmClrRuntimeInstance runtimeInstance)
        {
            if (compResult == null)
            {
                return(null);
            }

            Debug.Assert(compResult.Assembly != null);
            Debug.Assert(compResult.TypeName != null);
            Debug.Assert(compResult.MethodName != null);

            ReadOnlyCollection <byte> customTypeInfo;
            Guid customTypeInfoId = compResult.GetCustomTypeInfo(out customTypeInfo);

            return(DkmCompiledClrInspectionQuery.Create(
                       runtimeInstance,
                       Binary: new ReadOnlyCollection <byte>(compResult.Assembly),
                       DataContainer: null,
                       LanguageId: languageId,
                       TypeName: compResult.TypeName,
                       MethodName: compResult.MethodName,
                       FormatSpecifiers: compResult.FormatSpecifiers,
                       CompilationFlags: resultProperties.Flags,
                       ResultCategory: resultProperties.Category,
                       Access: resultProperties.AccessType,
                       StorageType: resultProperties.StorageType,
                       TypeModifierFlags: resultProperties.ModifierFlags,
                       CustomTypeInfo: customTypeInfo.ToCustomTypeInfo(customTypeInfoId)));
        }
Exemplo n.º 12
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]"
                        )
                    );
            }
        }
Exemplo n.º 13
0
        private void TestNativeView(bool enableNativeDebugging)
        {
            var source =
                @"class C
{
}";

            using (new EnsureEnglishUICulture())
            {
                var assembly   = GetAssembly(source);
                var assemblies = ReflectionUtilities.GetMscorlibAndSystemCore(assembly);
                using (ReflectionUtilities.LoadAssemblies(assemblies))
                {
                    var runtime = new DkmClrRuntimeInstance(
                        assemblies,
                        enableNativeDebugging: enableNativeDebugging
                        );
                    var inspectionContext = CreateDkmInspectionContext(runtimeInstance: runtime);
                    var type  = assembly.GetType("C");
                    var value = CreateDkmClrValue(
                        value: type.Instantiate(),
                        type: runtime.GetType((TypeImpl)type),
                        nativeComPointer: 0xfe
                        );
                    var evalResult = FormatResult("o", value, inspectionContext: inspectionContext);
                    Verify(
                        evalResult,
                        EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable)
                        );
                    var children = GetChildren(evalResult, inspectionContext);
                    if (enableNativeDebugging)
                    {
                        string      pointerString = $"(IUnknown*){PointerToString(new IntPtr(0xfe))}";
                        DkmLanguage language      = new DkmLanguage(
                            new DkmCompilerId(DkmVendorId.Microsoft, DkmLanguageId.Cpp)
                            );
                        Verify(
                            children,
                            EvalIntermediateResult(
                                "Native View",
                                "{C++}" + pointerString,
                                pointerString,
                                language
                                )
                            );
                    }
                    else
                    {
                        Verify(
                            children,
                            EvalFailedResult(
                                "Native View",
                                "To inspect the native object, enable native code debugging."
                                )
                            );
                    }
                }
            }
        }
Exemplo n.º 14
0
        private static IEnumerable <DkmClrModuleInstance> GetModulesInAppDomain(this DkmClrRuntimeInstance runtime, DkmClrAppDomain appDomain)
        {
            var appDomainId = appDomain.Id;

            return(runtime.GetModuleInstances().
                   Cast <DkmClrModuleInstance>().
                   Where(module => module.AppDomain.Id == appDomainId));
        }
Exemplo n.º 15
0
        public void RootHidden_WithStaticAndNonPublicMembers()
        {
            var source =
                @"using System.Diagnostics;
public class A
{
    public static int PA { get { return 1; } }
    internal int FA = 2;
}
public class B
{
    internal int PB { get { return 3; } }
    public static int FB = 4;
}
public class C
{
    [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
    public readonly object FA = new A();
    [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
    public object PB { get { return new B(); } }
    public static int PC { get { return 5; } }
    internal int FC = 6;
}";
            var assembly = GetAssembly(source);
            var runtime  = new DkmClrRuntimeInstance(new Assembly[0]);
            var type     = assembly.GetType("C");
            var value    = CreateDkmClrValue(
                value: type.Instantiate(),
                type: new DkmClrType(runtime.DefaultModule, runtime.DefaultAppDomain, (TypeImpl)type),
                evalFlags: DkmEvaluationResultFlags.None);
            var inspectionContext = CreateDkmInspectionContext(DkmEvaluationFlags.HideNonPublicMembers);
            var evalResult        = FormatResult("o", value, inspectionContext: inspectionContext);

            Verify(evalResult,
                   EvalResult("o", "{C}", "C", "o", DkmEvaluationResultFlags.Expandable));
            var children = GetChildren(evalResult, inspectionContext: inspectionContext);

            Verify(children,
                   EvalResult("Static members", null, "", "A", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Class),
                   EvalResult("Non-Public members", null, "", "o.FA, hidden", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Data),
                   EvalResult("Static members", null, "", "B", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Class),
                   EvalResult("Non-Public members", null, "", "o.PB, hidden", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Data),
                   EvalResult("Static members", null, "", "C", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Class),
                   EvalResult("Non-Public members", null, "", "o, hidden", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Data));
            Verify(GetChildren(children[0]),
                   EvalResult("PA", "1", "int", "A.PA", DkmEvaluationResultFlags.ReadOnly));
            Verify(GetChildren(children[1]),
                   EvalResult("FA", "2", "int", "((A)o.FA).FA"));
            Verify(GetChildren(children[2]),
                   EvalResult("FB", "4", "int", "B.FB"));
            Verify(GetChildren(children[3]),
                   EvalResult("PB", "3", "int", "((B)o.PB).PB", DkmEvaluationResultFlags.ReadOnly));
            Verify(GetChildren(children[4]),
                   EvalResult("PC", "5", "int", "C.PC", DkmEvaluationResultFlags.ReadOnly));
            Verify(GetChildren(children[5]),
                   EvalResult("FC", "6", "int", "o.FC"));
        }
Exemplo n.º 16
0
        internal override ImmutableArray <MetadataBlock> GetMetadataBlocks(
            DkmClrAppDomain appDomain,
            DkmClrRuntimeInstance runtimeInstance
            )
        {
            var previous = appDomain.GetMetadataContext <CSharpMetadataContext>();

            return(runtimeInstance.GetMetadataBlocks(appDomain, previous.MetadataBlocks));
        }
Exemplo n.º 17
0
        internal static ImmutableArray <MetadataBlock> GetMetadataBlocks(
            this DkmClrRuntimeInstance runtime,
            DkmClrAppDomain appDomain,
            ImmutableArray <MetadataBlock> previousMetadataBlocks)
        {
            // Add a dummy data item to the appdomain to add it to the disposal queue when the debugged process is shutting down.
            // This should prevent from attempts to use the Metadata pointer for dead debugged processes.
            if (appDomain.GetDataItem <AppDomainLifetimeDataItem>() == null)
            {
                appDomain.SetDataItem(DkmDataCreationDisposition.CreateNew, new AppDomainLifetimeDataItem());
            }

            var builder = ArrayBuilder <MetadataBlock> .GetInstance();

            IntPtr ptr;
            uint   size;
            int    index = 0;

            foreach (DkmClrModuleInstance module in runtime.GetModulesInAppDomain(appDomain))
            {
                try
                {
                    ptr = module.GetMetaDataBytesPtr(out size);
                    Debug.Assert(size > 0);
                }
                catch (NotImplementedException e) when(module is DkmClrNcModuleInstance)
                {
                    // DkmClrNcModuleInstance.GetMetaDataBytesPtr not implemented in Dev14.
                    throw new NotImplementedMetadataException(e);
                }
                catch (Exception e) when(DkmExceptionUtilities.IsBadOrMissingMetadataException(e))
                {
                    continue;
                }

                if (!TryGetMetadataBlock(previousMetadataBlocks, index, ptr, size, out var block))
                {
                    // ignore modules with bad metadata headers
                    continue;
                }

                Debug.Assert(block.ModuleVersionId == module.Mvid);
                builder.Add(block);
                index++;
            }

            // Include "intrinsic method" assembly.
            ptr = runtime.GetIntrinsicAssemblyMetaDataBytesPtr(out size);
            if (!TryGetMetadataBlock(previousMetadataBlocks, index, ptr, size, out var intrinsicsBlock))
            {
                throw ExceptionUtilities.Unreachable;
            }

            builder.Add(intrinsicsBlock);
            return(builder.ToImmutableAndFree());
        }
Exemplo n.º 18
0
        public void RawView_NoProxy()
        {
            var runtime           = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib());
            var inspectionContext = CreateDkmInspectionContext(DkmEvaluationFlags.ShowValueRaw);

            // int
            var value      = CreateDkmClrValue(1, type: runtime.GetType(typeof(int)));
            var evalResult = FormatResult("i", value, inspectionContext: inspectionContext);

            Verify(
                evalResult,
                EvalResult(
                    "i",
                    "1",
                    "int",
                    "i, raw",
                    editableValue: null,
                    flags: DkmEvaluationResultFlags.None
                    )
                );

            // string
            value      = CreateDkmClrValue(string.Empty, type: runtime.GetType(typeof(string)));
            evalResult = FormatResult("s", value, inspectionContext: inspectionContext);
            Verify(
                evalResult,
                EvalResult(
                    "s",
                    "\"\"",
                    "string",
                    "s, raw",
                    editableValue: "\"\"",
                    flags: DkmEvaluationResultFlags.RawString
                    )
                );

            // object[]
            value = CreateDkmClrValue(
                new object[] { 1, 2, 3 },
                type: runtime.GetType(typeof(object)).MakeArrayType()
                );
            evalResult = FormatResult("a", value, inspectionContext: inspectionContext);
            Verify(
                evalResult,
                EvalResult(
                    "a",
                    "{object[3]}",
                    "object[]",
                    "a, raw",
                    editableValue: null,
                    flags: DkmEvaluationResultFlags.Expandable
                    )
                );
        }
Exemplo n.º 19
0
        public void Nullable()
        {
            var source =
                @"struct A
{
    public string s1;
    public string s2;

    public A(string s1, string s2)
    {
        this.s1 = s1;
        this.s2 = s2;
    }
}
class B 
{
    A? a1 = null;
    A? a2 = new A(""S1"", ""S2"");
}";

            var assembly = GetAssembly(source);
            var type     = assembly.GetType("B");
            var rootExpr = "new B()";

            var favoritesByTypeName = new Dictionary <string, DkmClrObjectFavoritesInfo>()
            {
                { "B", new DkmClrObjectFavoritesInfo(new[] { "a2" }) },
                { "A", new DkmClrObjectFavoritesInfo(new[] { "s2" }) }
            };

            var runtime = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib(assembly), favoritesByTypeName);

            var value = CreateDkmClrValue(
                value: Activator.CreateInstance(type),
                type: runtime.GetType((TypeImpl)type));

            var evalResult = FormatResult(rootExpr, value);

            Verify(evalResult,
                   EvalResult(rootExpr, "{B}", "B", rootExpr, DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.HasFavorites));
            var children = GetChildren(evalResult);

            Verify(children,
                   EvalResult("a2", "{A}", "A?", "(new B()).a2", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.CanFavorite | DkmEvaluationResultFlags.IsFavorite | DkmEvaluationResultFlags.HasFavorites),
                   EvalResult("a1", "null", "A?", "(new B()).a1", DkmEvaluationResultFlags.CanFavorite));

            // A? a2 = new A();
            var more = GetChildren(children[0]);

            Verify(more,
                   EvalResult("s2", @"""S2""", "string", "(new B()).a2.s2", DkmEvaluationResultFlags.RawString | DkmEvaluationResultFlags.CanFavorite | DkmEvaluationResultFlags.IsFavorite, editableValue: @"""S2"""),
                   EvalResult("s1", @"""S1""", "string", "(new B()).a2.s1", DkmEvaluationResultFlags.RawString | DkmEvaluationResultFlags.CanFavorite, editableValue: @"""S1"""));
        }
Exemplo n.º 20
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));
            }
        }
Exemplo n.º 21
0
        private static IEnumerable <DkmClrModuleInstance> GetModulesInAppDomain(this DkmClrRuntimeInstance runtime, DkmClrAppDomain appDomain)
        {
            if (appDomain.IsUnloaded)
            {
                return(SpecializedCollections.EmptyEnumerable <DkmClrModuleInstance>());
            }

            var appDomainId = appDomain.Id;

            return(runtime.GetModuleInstances().
                   Cast <DkmClrModuleInstance>().
                   Where(module => module.AppDomain.Id == appDomainId));
        }
Exemplo n.º 22
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));
            }
        }
Exemplo n.º 23
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"));
            }
        }
Exemplo n.º 24
0
        public void ResultsView_FrameworkTypes()
        {
            var runtime           = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlibAndSystemCore());
            var inspectionContext = CreateDkmInspectionContext(DkmEvaluationFlags.ResultsOnly);

            // object: not enumerable
            var value      = CreateDkmClrValue(new object(), type: runtime.GetType(typeof(object)));
            var evalResult = FormatResult("o", value, inspectionContext: inspectionContext);

            Verify(evalResult,
                   EvalFailedResult("o", "Only Enumerable types can have Results View", fullName: null));

            // string: not considered enumerable which is consistent with legacy EE
            value      = CreateDkmClrValue("", type: runtime.GetType(typeof(string)));
            evalResult = FormatResult("s", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalFailedResult("s", "Only Enumerable types can have Results View"));

            // Array: not considered enumerable which is consistent with legacy EE
            value      = CreateDkmClrValue(new[] { 1 }, type: runtime.GetType(typeof(int[])));
            evalResult = FormatResult("i", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalFailedResult("i", "Only Enumerable types can have Results View"));

            // ArrayList
            value      = CreateDkmClrValue(new System.Collections.ArrayList(new[] { 2 }), type: runtime.GetType(typeof(System.Collections.ArrayList)));
            evalResult = FormatResult("a", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("a", "Count = 1", "System.Collections.ArrayList", "a, results", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Method));
            var children = GetChildren(evalResult);

            Verify(children,
                   EvalResult("[0]", "2", "object {int}", "new System.Linq.SystemCore_EnumerableDebugView(a).Items[0]"));

            // List<object>
            value      = CreateDkmClrValue(new System.Collections.Generic.List <object>(new object[] { 3 }), type: runtime.GetType(typeof(System.Collections.Generic.List <object>)));
            evalResult = FormatResult("l", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("l", "Count = 1", "System.Collections.Generic.List<object>", "l, results", DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly, DkmEvaluationResultCategory.Method));
            children = GetChildren(evalResult);
            Verify(children,
                   EvalResult("[0]", "3", "object {int}", "new System.Linq.SystemCore_EnumerableDebugView<object>(l).Items[0]"));

            // int?
            value      = CreateDkmClrValue(1, type: runtime.GetType(typeof(System.Nullable <>)).MakeGenericType(runtime.GetType(typeof(int))));
            evalResult = FormatResult("i", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalFailedResult("i", "Only Enumerable types can have Results View"));
        }
Exemplo n.º 25
0
        public void NoQuotes_String()
        {
            var runtime           = new DkmClrRuntimeInstance(ReflectionUtilities.GetMscorlib());
            var inspectionContext = CreateDkmInspectionContext(DkmEvaluationFlags.NoQuotes);
            var stringType        = runtime.GetType(typeof(string));

            // null
            var value      = CreateDkmClrValue(null, type: stringType);
            var evalResult = FormatResult("s", value, inspectionContext: inspectionContext);

            Verify(evalResult,
                   EvalResult("s", "null", "string", "s", editableValue: null, flags: DkmEvaluationResultFlags.None));

            // ""
            value      = CreateDkmClrValue(string.Empty, type: stringType);
            evalResult = FormatResult("s", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("s", "", "string", "s", editableValue: "\"\"", flags: DkmEvaluationResultFlags.RawString));

            // "'"
            value      = CreateDkmClrValue("'", type: stringType);
            evalResult = FormatResult("s", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("s", "'", "string", "s", editableValue: "\"'\"", flags: DkmEvaluationResultFlags.RawString));

            // "\""
            value      = CreateDkmClrValue("\"", type: stringType);
            evalResult = FormatResult("s", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("s", "\"", "string", "s", editableValue: "\"\\\"\"", flags: DkmEvaluationResultFlags.RawString));

            // " " with alias
            value      = CreateDkmClrValue(" ", type: stringType, alias: "1", evalFlags: DkmEvaluationResultFlags.HasObjectId);
            evalResult = FormatResult("s", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("s", "  {$1}", "string", "s", editableValue: "\" \"", flags: DkmEvaluationResultFlags.RawString | DkmEvaluationResultFlags.HasObjectId));

            // array
            value      = CreateDkmClrValue(new string[] { "1" }, type: stringType.MakeArrayType());
            evalResult = FormatResult("a", value, inspectionContext: inspectionContext);
            Verify(evalResult,
                   EvalResult("a", "{string[1]}", "string[]", "a", editableValue: null, flags: DkmEvaluationResultFlags.Expandable));
            var children = GetChildren(evalResult);

            // DkmInspectionContext should not be inherited.
            Verify(children,
                   EvalResult("[0]", "\"1\"", "string", "a[0]", editableValue: "\"1\"", flags: DkmEvaluationResultFlags.RawString));
        }
Exemplo n.º 26
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
                            )
                        );
                }
            }
        }
Exemplo n.º 27
0
        private TResult CompileWithRetry <TResult>(
            DkmClrAppDomain appDomain,
            DkmClrRuntimeInstance runtimeInstance,
            CreateContextDelegate createContext,
            CompileDelegate <TResult> compile,
            out string errorMessage)
        {
            var metadataBlocks = GetMetadataBlocks(appDomain, runtimeInstance);

            return(CompileWithRetry(
                       metadataBlocks,
                       this.DiagnosticFormatter,
                       createContext,
                       compile,
                       (AssemblyIdentity assemblyIdentity, out uint size) => appDomain.GetMetaDataBytesPtr(assemblyIdentity.GetDisplayName(), out size),
                       out errorMessage));
        }
Exemplo n.º 28
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));
            }
        }
Exemplo n.º 29
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));
            }
        }
Exemplo n.º 30
0
        public void DynamicMetaObjectProviderDebugViewItemsError()
        {
            var     expression = "o";
            dynamic o          = new ExpandoObject();

            o.Answer = 42;

            DkmClrRuntimeInstance runtime = null;

            runtime = new DkmClrRuntimeInstance(
                ReflectionUtilities.GetMscorlib(),
                getMemberValue: (_, m) =>
                (m == "Items")
                        ? CreateErrorValue(
                    runtime.GetType(typeof(Array)),
                    "Function evaluation timed out"
                    )
                        : null
                );
            var type  = new DkmClrType(runtime, (TypeImpl)o.GetType());
            var value = CreateDkmClrValue((object)o, type);

            var fullName = expression + ", dynamic";
            var result   = FormatResult(
                expression,
                fullName,
                value,
                inspectionContext: CreateDkmInspectionContext(DkmEvaluationFlags.DynamicView)
                );

            Verify(
                result,
                EvalResult(
                    expression,
                    Resources.DynamicViewValueWarning,
                    "",
                    fullName,
                    DkmEvaluationResultFlags.Expandable | DkmEvaluationResultFlags.ReadOnly
                    )
                );
            Verify(
                GetChildren(result),
                EvalFailedResult(Resources.ErrorName, "Function evaluation timed out")
                );
        }