Ejemplo n.º 1
0
 internal abstract CompileResult CompileExpression(
     InspectionContext inspectionContext,
     string expr,
     DkmEvaluationFlags compilationFlags,
     DiagnosticBag diagnostics,
     out ResultProperties resultProperties,
     CompilationTestData testData);
 internal DkmInspectionContext(IDkmClrFormatter formatter, DkmEvaluationFlags evaluationFlags, uint radix, DkmRuntimeInstance runtimeInstance = null)
 {
     _formatter = formatter;
     this.EvaluationFlags = evaluationFlags;
     this.Radix = radix;
     this.RuntimeInstance = runtimeInstance ?? DkmClrRuntimeInstance.DefaultRuntime;
 }
Ejemplo n.º 3
0
 internal DkmInspectionContext CreateDkmInspectionContext(
     DkmEvaluationFlags flags = DkmEvaluationFlags.None,
     uint radix = 10,
     DkmRuntimeInstance runtimeInstance = null)
 {
     return(CreateDkmInspectionContext(_formatter, flags, radix, runtimeInstance));
 }
Ejemplo n.º 4
0
 internal DkmInspectionContext(DkmInspectionSession inspectionSession, DkmEvaluationFlags evaluationFlags, uint radix, DkmRuntimeInstance runtimeInstance)
 {
     this.InspectionSession = inspectionSession;
     this.EvaluationFlags   = evaluationFlags;
     this.Radix             = radix;
     this.RuntimeInstance   = runtimeInstance ?? DkmClrRuntimeInstance.DefaultRuntime;
 }
Ejemplo n.º 5
0
 internal abstract CompileResult CompileExpression(
     InspectionContext inspectionContext,
     string expr,
     DkmEvaluationFlags compilationFlags,
     DiagnosticBag diagnostics,
     out ResultProperties resultProperties,
     CompilationTestData testData);
Ejemplo n.º 6
0
 internal DkmInspectionContext(IDkmClrFormatter formatter, DkmEvaluationFlags evaluationFlags, uint radix, DkmRuntimeInstance runtimeInstance = null)
 {
     _formatter           = formatter;
     this.EvaluationFlags = evaluationFlags;
     this.Radix           = radix;
     this.RuntimeInstance = runtimeInstance ?? DkmClrRuntimeInstance.DefaultRuntime;
 }
        internal static CompileResult CompileExpression(
            this EvaluationContextBase evaluationContext,
            string expr,
            DkmEvaluationFlags compilationFlags,
            ImmutableArray <Alias> aliases,
            out string error,
            CompilationTestData testData  = null,
            DiagnosticFormatter formatter = null)
        {
            ResultProperties resultProperties;
            ImmutableArray <AssemblyIdentity> missingAssemblyIdentities;
            var result = evaluationContext.CompileExpression(
                expr,
                compilationFlags,
                aliases,
                formatter ?? DebuggerDiagnosticFormatter.Instance,
                out resultProperties,
                out error,
                out missingAssemblyIdentities,
                EnsureEnglishUICulture.PreferredOrNull,
                testData);

            Assert.Empty(missingAssemblyIdentities);
            return(result);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Compile C# expression and emit assembly with evaluation method.
 /// </summary>
 /// <returns>
 /// Result containing generated assembly, type and method names, and any format specifiers.
 /// </returns>
 internal CompileResult CompileExpression(
     InspectionContext inspectionContext,
     string expr,
     DkmEvaluationFlags compilationFlags,
     DiagnosticFormatter formatter,
     out ResultProperties resultProperties,
     out string error,
     out ImmutableArray<AssemblyIdentity> missingAssemblyIdentities,
     CultureInfo preferredUICulture,
     CompilationTestData testData)
 {
     var diagnostics = DiagnosticBag.GetInstance();
     var result = this.CompileExpression(inspectionContext, expr, compilationFlags, diagnostics, out resultProperties, testData);
     if (diagnostics.HasAnyErrors())
     {
         bool useReferencedModulesOnly;
         error = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out useReferencedModulesOnly, out missingAssemblyIdentities);
     }
     else
     {
         error = null;
         missingAssemblyIdentities = ImmutableArray<AssemblyIdentity>.Empty;
     }
     diagnostics.Free();
     return result;
 }
        internal static CompileResult CompileExpression(
            this EvaluationContextBase evaluationContext,
            string expr,
            DkmEvaluationFlags compilationFlags,
            ImmutableArray <Alias> aliases,
            DiagnosticFormatter formatter,
            out ResultProperties resultProperties,
            out string error,
            out ImmutableArray <AssemblyIdentity> missingAssemblyIdentities,
            CultureInfo preferredUICulture,
            CompilationTestData testData)
        {
            var diagnostics = DiagnosticBag.GetInstance();
            var result      = evaluationContext.CompileExpression(expr, compilationFlags, aliases, diagnostics, out resultProperties, testData);

            if (diagnostics.HasAnyErrors())
            {
                bool useReferencedModulesOnly;
                error = evaluationContext.GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, EvaluationContextBase.SystemCoreIdentity, out useReferencedModulesOnly, out missingAssemblyIdentities);
            }
            else
            {
                error = null;
                missingAssemblyIdentities = ImmutableArray <AssemblyIdentity> .Empty;
            }
            diagnostics.Free();
            return(result);
        }
Ejemplo n.º 10
0
 internal DkmInspectionContext(DkmInspectionSession inspectionSession, DkmEvaluationFlags evaluationFlags, uint radix, DkmRuntimeInstance runtimeInstance)
 {
     this.InspectionSession = inspectionSession;
     this.EvaluationFlags = evaluationFlags;
     this.Radix = radix;
     this.RuntimeInstance = runtimeInstance ?? DkmClrRuntimeInstance.DefaultRuntime;
 }
Ejemplo n.º 11
0
 internal abstract CompileResult CompileExpression(
     string expr,
     DkmEvaluationFlags compilationFlags,
     ImmutableArray<Alias> aliases,
     DiagnosticBag diagnostics,
     out ResultProperties resultProperties,
     CompilationTestData testData);
Ejemplo n.º 12
0
 internal abstract CompileResult CompileExpression(
     string expr,
     DkmEvaluationFlags compilationFlags,
     ImmutableArray <Alias> aliases,
     DiagnosticBag diagnostics,
     out ResultProperties resultProperties,
     CompilationTestData testData);
        public static DkmSuccessEvaluationResult EvaluateSuccess(DkmVisualizedExpression expr, DkmEvaluationFlags flags, string text, DkmDataItem data)
        {
            DkmEvaluationResult result = Evaluate(expr, flags, text, data);
              if (result.TagValue != DkmEvaluationResult.Tag.SuccessResult)
            throw new EvaluationException(result);

              return (DkmSuccessEvaluationResult)result;
        }
Ejemplo n.º 14
0
        internal static DkmInspectionContext CreateDkmInspectionContext(
            DkmEvaluationFlags evalFlags
            )
        {
            var inspectionSession = CreateDkmInspectionSession();

            return(CreateDkmInspectionContext(inspectionSession, evalFlags, radix: 10));
        }
Ejemplo n.º 15
0
 internal static DkmInspectionContext CreateDkmInspectionContext(
     IDkmClrFormatter formatter,
     DkmEvaluationFlags flags,
     uint radix,
     DkmRuntimeInstance runtimeInstance = null)
 {
     return(new DkmInspectionContext(formatter, flags, radix, runtimeInstance));
 }
Ejemplo n.º 16
0
 internal static DkmInspectionContext CreateDkmInspectionContext(
     DkmInspectionSession inspectionSession,
     DkmEvaluationFlags flags,
     uint radix,
     DkmRuntimeInstance runtimeInstance = null)
 {
     return(new DkmInspectionContext(inspectionSession, flags, radix, runtimeInstance));
 }
Ejemplo n.º 17
0
        internal override CompileResult CompileExpression(
            string expr,
            DkmEvaluationFlags compilationFlags,
            ImmutableArray <Alias> aliases,
            DiagnosticBag diagnostics,
            out ResultProperties resultProperties,
            Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData)
        {
            ReadOnlyCollection <string> formatSpecifiers;
            var syntax = Parse(expr, (compilationFlags & DkmEvaluationFlags.TreatAsExpression) != 0, diagnostics, out formatSpecifiers);

            if (syntax == null)
            {
                resultProperties = default(ResultProperties);
                return(null);
            }

            var context       = this.CreateCompilationContext();
            var moduleBuilder = context.CompileExpression(syntax, TypeName, MethodName, aliases, testData, diagnostics, out var synthesizedMethod);

            if (moduleBuilder == null)
            {
                resultProperties = default(ResultProperties);
                return(null);
            }

            using (var stream = new MemoryStream())
            {
                Cci.PeWriter.WritePeToStream(
                    new EmitContext(moduleBuilder, null, diagnostics, metadataOnly: false, includePrivateMembers: true),
                    context.MessageProvider,
                    () => stream,
                    getPortablePdbStreamOpt: null,
                    nativePdbWriterOpt: null,
                    pdbPathOpt: null,
                    metadataOnly: false,
                    isDeterministic: false,
                    emitTestCoverageData: false,
                    privateKeyOpt: null,
                    cancellationToken: default(CancellationToken));

                if (diagnostics.HasAnyErrors())
                {
                    resultProperties = default(ResultProperties);
                    return(null);
                }

                Debug.Assert(synthesizedMethod.ContainingType.MetadataName == TypeName);
                Debug.Assert(synthesizedMethod.MetadataName == MethodName);

                resultProperties = synthesizedMethod.ResultProperties;
                return(new CSharpCompileResult(
                           stream.ToArray(),
                           synthesizedMethod,
                           formatSpecifiers: formatSpecifiers));
            }
        }
Ejemplo n.º 18
0
        public static DkmEvaluationResult Evaluate(DkmVisualizedExpression expr, DkmEvaluationFlags flags, string text, DkmDataItem data)
        {
            using (DkmLanguageExpression vexpr = DkmLanguageExpression.Create(CppLanguage, flags, text, data))
            {
                DkmEvaluationResult result = null;
                expr.EvaluateExpressionCallback(expr.InspectionContext, vexpr, expr.StackFrame, out result);

                return(result);
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Compile C# expression and emit assembly with evaluation method.
 /// </summary>
 /// <returns>
 /// Result containing generated assembly, type and method names, and any format specifiers.
 /// </returns>
 internal abstract CompileResult CompileExpression(
     InspectionContext inspectionContext,
     string expr,
     DkmEvaluationFlags compilationFlags,
     DiagnosticFormatter formatter,
     out ResultProperties resultProperties,
     out string error,
     out ImmutableArray <AssemblyIdentity> missingAssemblyIdentities,
     CultureInfo preferredUICulture,
     CompilationTestData testData);
        public static DkmEvaluationResult Evaluate(DkmVisualizedExpression expr, DkmEvaluationFlags flags, string text, DkmDataItem data)
        {
            using (DkmLanguageExpression vexpr = DkmLanguageExpression.Create(CppLanguage, flags, text, data))
              {
            DkmEvaluationResult result = null;
            expr.EvaluateExpressionCallback(expr.InspectionContext, vexpr, expr.StackFrame, out result);

            return result;
              }
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Compile C# expression and emit assembly with evaluation method.
 /// </summary>
 /// <returns>
 /// Result containing generated assembly, type and method names, and any format specifiers.
 /// </returns>
 internal abstract CompileResult CompileExpression(
     InspectionContext inspectionContext,
     string expr,
     DkmEvaluationFlags compilationFlags,
     DiagnosticFormatter formatter,
     out ResultProperties resultProperties,
     out string error,
     out ImmutableArray<AssemblyIdentity> missingAssemblyIdentities,
     CultureInfo preferredUICulture,
     CompilationTestData testData);
Ejemplo n.º 22
0
        internal override CompileResult CompileExpression(
            string expr,
            DkmEvaluationFlags compilationFlags,
            ImmutableArray <Alias> aliases,
            DiagnosticBag diagnostics,
            out ResultProperties resultProperties,
            Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData)
        {
            ReadOnlyCollection <string> formatSpecifiers;
            var syntax = Parse(expr, (compilationFlags & DkmEvaluationFlags.TreatAsExpression) != 0, diagnostics, out formatSpecifiers);

            if (syntax == null)
            {
                resultProperties = default(ResultProperties);
                return(null);
            }

            var context = this.CreateCompilationContext(syntax);
            ResultProperties properties;
            var moduleBuilder = context.CompileExpression(TypeName, MethodName, aliases, testData, diagnostics, out properties);

            if (moduleBuilder == null)
            {
                resultProperties = default(ResultProperties);
                return(null);
            }

            using (var stream = new MemoryStream())
            {
                Cci.PeWriter.WritePeToStream(
                    new EmitContext((Cci.IModule)moduleBuilder, null, diagnostics),
                    context.MessageProvider,
                    () => stream,
                    getPortablePdbStreamOpt: null,
                    nativePdbWriterOpt: null,
                    pdbPathOpt: null,
                    allowMissingMethodBodies: false,
                    deterministic: false,
                    cancellationToken: default(CancellationToken));

                if (diagnostics.HasAnyErrors())
                {
                    resultProperties = default(ResultProperties);
                    return(null);
                }

                resultProperties = properties;
                return(new CSharpCompileResult(
                           stream.ToArray(),
                           GetSynthesizedMethod(moduleBuilder),
                           formatSpecifiers: formatSpecifiers));
            }
        }
Ejemplo n.º 23
0
 private string FormatString(string s, DkmEvaluationFlags flags)
 {
     if (flags.HasFlag(DkmEvaluationFlags.NoQuotes))
     {
         // No quotes - return the raw string.
         // If X# handled escaping aside from quotes, we would still want to do escaping.
         return(s);
     }
     else
     {
         // Escape special characters in the string and wrap in single quotes.
         s = s.Replace("\"", "\"\"");
         return("\"" + s + "\"");
     }
 }
Ejemplo n.º 24
0
 public static DkmInspectionContext Create(
     DkmInspectionSession InspectionSession,
     DkmRuntimeInstance RuntimeInstance,
     DkmThread Thread,
     uint Timeout,
     DkmEvaluationFlags EvaluationFlags,
     DkmFuncEvalFlags FuncEvalFlags,
     uint Radix,
     DkmLanguage Language,
     DkmRawReturnValue ReturnValue,
     DkmCompiledVisualizationData AdditionalVisualizationData,
     DkmCompiledVisualizationDataPriority AdditionalVisualizationDataPriority,
     ReadOnlyCollection<DkmRawReturnValueContainer> ReturnValues)
 {
     return new DkmInspectionContext(InspectionSession, EvaluationFlags, Radix, RuntimeInstance);
 }
 internal static DkmInspectionContext With(this DkmInspectionContext inspectionContext, DkmEvaluationFlags flags)
 {
     return DkmInspectionContext.Create(
         inspectionContext.InspectionSession,
         inspectionContext.RuntimeInstance,
         inspectionContext.Thread,
         inspectionContext.Timeout,
         inspectionContext.EvaluationFlags | flags,
         inspectionContext.FuncEvalFlags,
         inspectionContext.Radix,
         inspectionContext.Language,
         inspectionContext.ReturnValue,
         inspectionContext.AdditionalVisualizationData,
         inspectionContext.AdditionalVisualizationDataPriority,
         inspectionContext.ReturnValues);
 }
Ejemplo n.º 26
0
 public static DkmInspectionContext Create(
     DkmInspectionSession InspectionSession,
     DkmRuntimeInstance RuntimeInstance,
     DkmThread Thread,
     uint Timeout,
     DkmEvaluationFlags EvaluationFlags,
     DkmFuncEvalFlags FuncEvalFlags,
     uint Radix,
     DkmLanguage Language,
     DkmRawReturnValue ReturnValue,
     DkmCompiledVisualizationData AdditionalVisualizationData,
     DkmCompiledVisualizationDataPriority AdditionalVisualizationDataPriority,
     ReadOnlyCollection <DkmRawReturnValueContainer> ReturnValues)
 {
     return(new DkmInspectionContext(InspectionSession, EvaluationFlags, Radix, RuntimeInstance));
 }
 internal static DkmInspectionContext With(
     this DkmInspectionContext inspectionContext,
     DkmEvaluationFlags flags
     )
 {
     return(DkmInspectionContext.Create(
                inspectionContext.InspectionSession,
                inspectionContext.RuntimeInstance,
                inspectionContext.Thread,
                inspectionContext.Timeout,
                inspectionContext.EvaluationFlags | flags,
                inspectionContext.FuncEvalFlags,
                inspectionContext.Radix,
                inspectionContext.Language,
                inspectionContext.ReturnValue,
                inspectionContext.AdditionalVisualizationData,
                inspectionContext.AdditionalVisualizationDataPriority,
                inspectionContext.ReturnValues
                ));
 }
Ejemplo n.º 28
0
        internal EvalResultDataItem CreateDataItem(
            DkmInspectionContext inspectionContext,
            string name,
            Type typeDeclaringMember,
            Type declaredType,
            DkmClrValue value,
            EvalResultDataItem parent,
            ExpansionFlags expansionFlags,
            bool childShouldParenthesize,
            string fullName,
            ReadOnlyCollection<string> formatSpecifiers,
            DkmEvaluationResultCategory category,
            DkmEvaluationResultFlags flags,
            DkmEvaluationFlags evalFlags)
        {
            if ((evalFlags & DkmEvaluationFlags.ShowValueRaw) != 0)
            {
                formatSpecifiers = Formatter.AddFormatSpecifier(formatSpecifiers, "raw");
            }

            Expansion expansion;
            // If the declared type is Nullable<T>, the value should
            // have no expansion if null, or be expanded as a T.
            var lmrNullableTypeArg = declaredType.GetNullableTypeArgument();
            if (lmrNullableTypeArg != null && !value.HasExceptionThrown(parent))
            {
                Debug.Assert(value.Type.GetProxyType() == null);

                var nullableValue = value.GetNullableValue();
                if (nullableValue == null)
                {
                    Debug.Assert(declaredType.Equals(value.Type.GetLmrType()));
                    // No expansion of "null".
                    expansion = null;
                }
                else
                {
                    value = nullableValue;
                    Debug.Assert(lmrNullableTypeArg.Equals(value.Type.GetLmrType())); // If this is not the case, add a test for includeRuntimeTypeIfNecessary.
                    expansion = this.GetTypeExpansion(inspectionContext, lmrNullableTypeArg, value, ExpansionFlags.IncludeResultsView);
                }
            }
            else if (value.IsError() || (inspectionContext.EvaluationFlags & DkmEvaluationFlags.NoExpansion) != 0)
            {
                expansion = null;
            }
            else
            {
                expansion = DebuggerTypeProxyExpansion.CreateExpansion(
                    this,
                    inspectionContext,
                    name,
                    typeDeclaringMember,
                    declaredType,
                    value,
                    childShouldParenthesize,
                    fullName,
                    flags.Includes(DkmEvaluationResultFlags.ExceptionThrown) ? null : fullName,
                    formatSpecifiers,
                    flags,
                    this.Formatter.GetEditableValue(value));
                if (expansion == null)
                {
                    var expansionType = value.HasExceptionThrown(parent) ? value.Type.GetLmrType() : declaredType;
                    expansion = this.GetTypeExpansion(inspectionContext, expansionType, value, expansionFlags);
                }
            }

            return new EvalResultDataItem(
                name,
                typeDeclaringMember,
                declaredType,
                value,
                expansion,
                childShouldParenthesize,
                fullName,
                flags.Includes(DkmEvaluationResultFlags.ExceptionThrown) ? null : fullName,
                formatSpecifiers,
                category,
                flags,
                this.Formatter.GetEditableValue(value));
        }
Ejemplo n.º 29
0
        internal EvalResultDataItem CreateDataItem(
            DkmInspectionContext inspectionContext,
            string name,
            Type typeDeclaringMember,
            Type declaredType,
            DkmClrValue value,
            EvalResultDataItem parent,
            ExpansionFlags expansionFlags,
            bool childShouldParenthesize,
            string fullName,
            ReadOnlyCollection <string> formatSpecifiers,
            DkmEvaluationResultCategory category,
            DkmEvaluationResultFlags flags,
            DkmEvaluationFlags evalFlags)
        {
            if ((evalFlags & DkmEvaluationFlags.ShowValueRaw) != 0)
            {
                formatSpecifiers = Formatter.AddFormatSpecifier(formatSpecifiers, "raw");
            }

            Expansion expansion;
            // If the declared type is Nullable<T>, the value should
            // have no expansion if null, or be expanded as a T.
            var lmrNullableTypeArg = declaredType.GetNullableTypeArgument();

            if (lmrNullableTypeArg != null && !value.HasExceptionThrown(parent))
            {
                Debug.Assert(value.Type.GetProxyType() == null);

                var nullableValue = value.GetNullableValue(inspectionContext);
                if (nullableValue == null)
                {
                    Debug.Assert(declaredType.Equals(value.Type.GetLmrType()));
                    // No expansion of "null".
                    expansion = null;
                }
                else
                {
                    value = nullableValue;
                    Debug.Assert(lmrNullableTypeArg.Equals(value.Type.GetLmrType())); // If this is not the case, add a test for includeRuntimeTypeIfNecessary.
                    expansion = this.GetTypeExpansion(inspectionContext, lmrNullableTypeArg, value, ExpansionFlags.IncludeResultsView);
                }
            }
            else if (value.IsError() || (inspectionContext.EvaluationFlags & DkmEvaluationFlags.NoExpansion) != 0)
            {
                expansion = null;
            }
            else
            {
                expansion = DebuggerTypeProxyExpansion.CreateExpansion(
                    this,
                    inspectionContext,
                    name,
                    typeDeclaringMember,
                    declaredType,
                    value,
                    childShouldParenthesize,
                    fullName,
                    flags.Includes(DkmEvaluationResultFlags.ExceptionThrown) ? null : fullName,
                    formatSpecifiers,
                    flags,
                    this.Formatter.GetEditableValue(value, inspectionContext));
                if (expansion == null)
                {
                    var expansionType = value.HasExceptionThrown(parent) ? value.Type.GetLmrType() : declaredType;
                    expansion = this.GetTypeExpansion(inspectionContext, expansionType, value, expansionFlags);
                }
            }

            return(new EvalResultDataItem(
                       ExpansionKind.Default,
                       name,
                       typeDeclaringMember,
                       declaredType,
                       parent: parent,
                       value: value,
                       displayValue: null,
                       expansion: expansion,
                       childShouldParenthesize: childShouldParenthesize,
                       fullName: fullName,
                       childFullNamePrefixOpt: flags.Includes(DkmEvaluationResultFlags.ExceptionThrown) ? null : fullName,
                       formatSpecifiers: formatSpecifiers,
                       category: category,
                       flags: flags,
                       editableValue: this.Formatter.GetEditableValue(value, inspectionContext),
                       inspectionContext: inspectionContext));
        }
Ejemplo n.º 30
0
        internal override CompileResult CompileExpression(
            InspectionContext inspectionContext,
            string expr,
            DkmEvaluationFlags compilationFlags,
            DiagnosticFormatter formatter,
            out ResultProperties resultProperties,
            out string error,
            out ImmutableArray <AssemblyIdentity> missingAssemblyIdentities,
            System.Globalization.CultureInfo preferredUICulture,
            Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData)
        {
            resultProperties = default(ResultProperties);
            var diagnostics = DiagnosticBag.GetInstance();

            try
            {
                ReadOnlyCollection <string> formatSpecifiers;
                var syntax = Parse(expr, (compilationFlags & DkmEvaluationFlags.TreatAsExpression) != 0, diagnostics, out formatSpecifiers);
                if (syntax == null)
                {
                    error = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out missingAssemblyIdentities);
                    return(default(CompileResult));
                }

                var context = this.CreateCompilationContext(syntax);
                ResultProperties properties;
                var moduleBuilder = context.CompileExpression(inspectionContext, TypeName, MethodName, testData, diagnostics, out properties);
                if (moduleBuilder == null)
                {
                    error = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out missingAssemblyIdentities);
                    return(default(CompileResult));
                }

                using (var stream = new MemoryStream())
                {
                    Cci.PeWriter.WritePeToStream(
                        new EmitContext((Cci.IModule)moduleBuilder, null, diagnostics),
                        context.MessageProvider,
                        stream,
                        nativePdbWriterOpt: null,
                        allowMissingMethodBodies: false,
                        deterministic: false,
                        cancellationToken: default(CancellationToken));

                    if (diagnostics.HasAnyErrors())
                    {
                        error = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out missingAssemblyIdentities);
                        return(default(CompileResult));
                    }

                    resultProperties          = properties;
                    error                     = null;
                    missingAssemblyIdentities = ImmutableArray <AssemblyIdentity> .Empty;
                    return(new CompileResult(
                               stream.ToArray(),
                               typeName: TypeName,
                               methodName: MethodName,
                               formatSpecifiers: formatSpecifiers));
                }
            }
            finally
            {
                diagnostics.Free();
            }
        }
Ejemplo n.º 31
0
        internal override CompileResult CompileExpression(
            InspectionContext inspectionContext,
            string expr,
            DkmEvaluationFlags compilationFlags,
            DiagnosticFormatter formatter,
            out ResultProperties resultProperties,
            out string error,
            out ImmutableArray<AssemblyIdentity> missingAssemblyIdentities,
            System.Globalization.CultureInfo preferredUICulture,
            Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData)
        {
            resultProperties = default(ResultProperties);
            var diagnostics = DiagnosticBag.GetInstance();
            try
            {
                ReadOnlyCollection<string> formatSpecifiers;
                var syntax = Parse(expr, (compilationFlags & DkmEvaluationFlags.TreatAsExpression) != 0, diagnostics, out formatSpecifiers);
                if (syntax == null)
                {
                    error = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out missingAssemblyIdentities);
                    return default(CompileResult);
                }

                var context = this.CreateCompilationContext(syntax);
                ResultProperties properties;
                var moduleBuilder = context.CompileExpression(inspectionContext, TypeName, MethodName, testData, diagnostics, out properties);
                if (moduleBuilder == null)
                {
                    error = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out missingAssemblyIdentities);
                    return default(CompileResult);
                }

                using (var stream = new MemoryStream())
                {
                    Cci.PeWriter.WritePeToStream(
                        new EmitContext((Cci.IModule)moduleBuilder, null, diagnostics),
                        context.MessageProvider,
                        stream,
                        nativePdbWriterOpt: null,
                        allowMissingMethodBodies: false,
                        deterministic: false,
                        cancellationToken: default(CancellationToken));

                    if (diagnostics.HasAnyErrors())
                    {
                        error = GetErrorMessageAndMissingAssemblyIdentities(diagnostics, formatter, preferredUICulture, out missingAssemblyIdentities);
                        return default(CompileResult);
                    }

                    resultProperties = properties;
                    error = null;
                    missingAssemblyIdentities = ImmutableArray<AssemblyIdentity>.Empty;
                    return new CompileResult(
                        stream.ToArray(),
                        typeName: TypeName,
                        methodName: MethodName,
                        formatSpecifiers: formatSpecifiers);
                }
            }
            finally
            {
                diagnostics.Free();
            }
        }
Ejemplo n.º 32
0
 internal DkmInspectionContext CreateDkmInspectionContext(DkmEvaluationFlags flags = DkmEvaluationFlags.None, uint radix = 10)
 {
     return(CreateDkmInspectionContext(_formatter, flags, radix));
 }
Ejemplo n.º 33
0
        internal EvalResult CreateDataItem(
            DkmInspectionContext inspectionContext,
            string name,
            TypeAndCustomInfo typeDeclaringMemberAndInfo,
            TypeAndCustomInfo declaredTypeAndInfo,
            DkmClrValue value,
            bool useDebuggerDisplay,
            ExpansionFlags expansionFlags,
            bool childShouldParenthesize,
            string fullName,
            ReadOnlyCollection <string> formatSpecifiers,
            DkmEvaluationResultCategory category,
            DkmEvaluationResultFlags flags,
            DkmEvaluationFlags evalFlags)
        {
            if ((evalFlags & DkmEvaluationFlags.ShowValueRaw) != 0)
            {
                formatSpecifiers = Formatter.AddFormatSpecifier(formatSpecifiers, "raw");
            }

            Expansion expansion;
            // If the declared type is Nullable<T>, the value should
            // have no expansion if null, or be expanded as a T.
            var declaredType       = declaredTypeAndInfo.Type;
            var lmrNullableTypeArg = declaredType.GetNullableTypeArgument();

            if (lmrNullableTypeArg != null && !value.HasExceptionThrown())
            {
                Debug.Assert(value.Type.GetProxyType() == null);

                DkmClrValue nullableValue;
                if (value.IsError())
                {
                    expansion = null;
                }
                else if ((nullableValue = value.GetNullableValue(lmrNullableTypeArg, inspectionContext)) == null)
                {
                    Debug.Assert(declaredType.Equals(value.Type.GetLmrType()));
                    // No expansion of "null".
                    expansion = null;
                }
                else
                {
                    value = nullableValue;
                    Debug.Assert(lmrNullableTypeArg.Equals(value.Type.GetLmrType())); // If this is not the case, add a test for includeRuntimeTypeIfNecessary.
                    // CONSIDER: The DynamicAttribute for the type argument should just be Skip(1) of the original flag array.
                    expansion = this.GetTypeExpansion(inspectionContext, new TypeAndCustomInfo(DkmClrType.Create(declaredTypeAndInfo.ClrType.AppDomain, lmrNullableTypeArg)), value, ExpansionFlags.IncludeResultsView);
                }
            }
            else if (value.IsError() || (inspectionContext.EvaluationFlags & DkmEvaluationFlags.NoExpansion) != 0)
            {
                expansion = null;
            }
            else
            {
                expansion = DebuggerTypeProxyExpansion.CreateExpansion(
                    this,
                    inspectionContext,
                    name,
                    typeDeclaringMemberAndInfo,
                    declaredTypeAndInfo,
                    value,
                    childShouldParenthesize,
                    fullName,
                    flags.Includes(DkmEvaluationResultFlags.ExceptionThrown) ? null : fullName,
                    formatSpecifiers,
                    flags,
                    Formatter2.GetEditableValueString(value, inspectionContext, declaredTypeAndInfo.Info));
                if (expansion == null)
                {
                    expansion = value.HasExceptionThrown()
                        ? this.GetTypeExpansion(inspectionContext, new TypeAndCustomInfo(value.Type), value, expansionFlags)
                        : this.GetTypeExpansion(inspectionContext, declaredTypeAndInfo, value, expansionFlags);
                }
            }

            return(new EvalResult(
                       ExpansionKind.Default,
                       name,
                       typeDeclaringMemberAndInfo,
                       declaredTypeAndInfo,
                       useDebuggerDisplay: useDebuggerDisplay,
                       value: value,
                       displayValue: null,
                       expansion: expansion,
                       childShouldParenthesize: childShouldParenthesize,
                       fullName: fullName,
                       childFullNamePrefixOpt: flags.Includes(DkmEvaluationResultFlags.ExceptionThrown) ? null : fullName,
                       formatSpecifiers: formatSpecifiers,
                       category: category,
                       flags: flags,
                       editableValue: Formatter2.GetEditableValueString(value, inspectionContext, declaredTypeAndInfo.Info),
                       inspectionContext: inspectionContext));
        }
Ejemplo n.º 34
0
 internal static string TryEvaluateStringExpression(string expression, DkmInspectionSession inspectionSession, DkmThread thread, DkmStackWalkFrame input, DkmEvaluationFlags flags)
 {
     return(ExecuteExpression(expression + ",sb", inspectionSession, thread, input, flags, false, out _));
 }
Ejemplo n.º 35
0
 internal DkmInspectionContext(IDkmClrFormatter formatter, DkmEvaluationFlags evaluationFlags, uint radix)
 {
     _formatter           = formatter;
     this.EvaluationFlags = evaluationFlags;
     this.Radix           = radix;
 }
Ejemplo n.º 36
0
 internal static DkmInspectionContext CreateDkmInspectionContext(IDkmClrFormatter formatter, DkmEvaluationFlags flags, uint radix)
 {
     return(new DkmInspectionContext(formatter, flags, radix));
 }
Ejemplo n.º 37
0
        internal static ulong?TryEvaluateAddressExpression(string expression, DkmInspectionSession inspectionSession, DkmThread thread, DkmStackWalkFrame input, DkmEvaluationFlags flags)
        {
            if (ExecuteExpression(expression, inspectionSession, thread, input, flags, true, out ulong address) != null)
            {
                return(address);
            }

            return(null);
        }
Ejemplo n.º 38
0
 internal DkmInspectionContext(IDkmClrFormatter formatter, DkmEvaluationFlags evaluationFlags, uint radix)
 {
     _formatter = formatter;
     this.EvaluationFlags = evaluationFlags;
     this.Radix = radix;
 }
Ejemplo n.º 39
0
        internal static long?TryEvaluateNumberExpression(string expression, DkmInspectionSession inspectionSession, DkmThread thread, DkmStackWalkFrame input, DkmEvaluationFlags flags)
        {
            string result = ExecuteExpression(expression, inspectionSession, thread, input, flags, true, out _);

            if (result == null)
            {
                return(null);
            }

            if (long.TryParse(result, out long value))
            {
                return(value);
            }

            return(null);
        }
Ejemplo n.º 40
0
        internal override CompileResult CompileExpression(
            InspectionContext inspectionContext,
            string expr,
            DkmEvaluationFlags compilationFlags,
            DiagnosticBag diagnostics,
            out ResultProperties resultProperties,
            Microsoft.CodeAnalysis.CodeGen.CompilationTestData testData)
        {
            ReadOnlyCollection<string> formatSpecifiers;
            var syntax = Parse(expr, (compilationFlags & DkmEvaluationFlags.TreatAsExpression) != 0, diagnostics, out formatSpecifiers);
            if (syntax == null)
            {
                resultProperties = default(ResultProperties);
                return null;
            }

            var context = this.CreateCompilationContext(syntax);
            ResultProperties properties;
            var moduleBuilder = context.CompileExpression(inspectionContext, TypeName, MethodName, testData, diagnostics, out properties);
            if (moduleBuilder == null)
            {
                resultProperties = default(ResultProperties);
                return null;
            }

            using (var stream = new MemoryStream())
            {
                Cci.PeWriter.WritePeToStream(
                    new EmitContext((Cci.IModule)moduleBuilder, null, diagnostics),
                    context.MessageProvider,
                    () => stream,
                    nativePdbWriterOpt: null,
                    pdbPathOpt: null,
                    allowMissingMethodBodies: false,
                    deterministic: false,
                    cancellationToken: default(CancellationToken));

                if (diagnostics.HasAnyErrors())
                {
                    resultProperties = default(ResultProperties);
                    return null;
                }

                resultProperties = properties;
                return new CSharpCompileResult(
                    stream.ToArray(),
                    GetSynthesizedMethod(moduleBuilder),
                    formatSpecifiers: formatSpecifiers);
            }
        }
 private string FormatString(string s, DkmEvaluationFlags flags)
 {
     if (flags.HasFlag(DkmEvaluationFlags.NoQuotes))
     {
         // No quotes - return the raw string.
         // If Iris handled escaping aside from quotes, we would still want to do escaping.
         return s;
     }
     else
     {
         // Escape special characters in the string and wrap in single quotes.
         s = s.Replace("'", "''");
         return "'" + s + "'";
     }
 }
Ejemplo n.º 42
0
        internal EvalResultDataItem CreateDataItem(
            DkmInspectionContext inspectionContext,
            string name,
            TypeAndCustomInfo typeDeclaringMemberAndInfo,
            TypeAndCustomInfo declaredTypeAndInfo,
            DkmClrValue value,
            EvalResultDataItem parent,
            ExpansionFlags expansionFlags,
            bool childShouldParenthesize,
            string fullName,
            ReadOnlyCollection<string> formatSpecifiers,
            DkmEvaluationResultCategory category,
            DkmEvaluationResultFlags flags,
            DkmEvaluationFlags evalFlags)
        {
            if ((evalFlags & DkmEvaluationFlags.ShowValueRaw) != 0)
            {
                formatSpecifiers = Formatter.AddFormatSpecifier(formatSpecifiers, "raw");
            }

            Expansion expansion;
            // If the declared type is Nullable<T>, the value should
            // have no expansion if null, or be expanded as a T.
            var declaredType = declaredTypeAndInfo.Type;
            var lmrNullableTypeArg = declaredType.GetNullableTypeArgument();
            if (lmrNullableTypeArg != null && !value.HasExceptionThrown())
            {
                Debug.Assert(value.Type.GetProxyType() == null);

                DkmClrValue nullableValue;
                if (value.IsError())
                {
                    expansion = null;
                }
                else if ((nullableValue = value.GetNullableValue(inspectionContext)) == null)
                {
                    Debug.Assert(declaredType.Equals(value.Type.GetLmrType()));
                    // No expansion of "null".
                    expansion = null;
                }
                else
                {
                    value = nullableValue;
                    Debug.Assert(lmrNullableTypeArg.Equals(value.Type.GetLmrType())); // If this is not the case, add a test for includeRuntimeTypeIfNecessary.
                    // CONSIDER: The DynamicAttribute for the type argument should just be Skip(1) of the original flag array.
                    expansion = this.GetTypeExpansion(inspectionContext, new TypeAndCustomInfo(lmrNullableTypeArg), value, ExpansionFlags.IncludeResultsView);
                }
            }
            else if (value.IsError() || (inspectionContext.EvaluationFlags & DkmEvaluationFlags.NoExpansion) != 0)
            {
                expansion = null;
            }
            else
            {
                expansion = DebuggerTypeProxyExpansion.CreateExpansion(
                    this,
                    inspectionContext,
                    name,
                    typeDeclaringMemberAndInfo,
                    declaredTypeAndInfo,
                    value,
                    childShouldParenthesize,
                    fullName,
                    flags.Includes(DkmEvaluationResultFlags.ExceptionThrown) ? null : fullName,
                    formatSpecifiers,
                    flags,
                    this.Formatter.GetEditableValue(value, inspectionContext));
                if (expansion == null)
                {
                    expansion = value.HasExceptionThrown()
                        ? this.GetTypeExpansion(inspectionContext, new TypeAndCustomInfo(value.Type), value, expansionFlags)
                        : this.GetTypeExpansion(inspectionContext, declaredTypeAndInfo, value, expansionFlags);
                }
            }

            return new EvalResultDataItem(
                ExpansionKind.Default,
                name,
                typeDeclaringMemberAndInfo,
                declaredTypeAndInfo,
                parent: parent,
                value: value,
                displayValue: null,
                expansion: expansion,
                childShouldParenthesize: childShouldParenthesize,
                fullName: fullName,
                childFullNamePrefixOpt: flags.Includes(DkmEvaluationResultFlags.ExceptionThrown) ? null : fullName,
                formatSpecifiers: formatSpecifiers,
                category: category,
                flags: flags,
                editableValue: this.Formatter.GetEditableValue(value, inspectionContext),
                inspectionContext: inspectionContext);
        }
Ejemplo n.º 43
0
        internal static string ExecuteExpression(string expression, DkmInspectionSession inspectionSession, DkmThread thread, DkmStackWalkFrame input, DkmEvaluationFlags flags, bool allowZero, out ulong address)
        {
            if (Log.instance != null)
            {
                Log.instance.Verbose($"ExecuteExpression begin evaluation of '{expression}'");
            }

            var compilerId         = new DkmCompilerId(DkmVendorId.Microsoft, DkmLanguageId.Cpp);
            var language           = DkmLanguage.Create("C++", compilerId);
            var languageExpression = DkmLanguageExpression.Create(language, DkmEvaluationFlags.None, expression, null);

            DkmInspectionContext inspectionContext;

            LuaWorkerConnectionWrapper workerConnectionWrapper = inspectionSession.Process.GetDataItem <LuaWorkerConnectionWrapper>();

            if (workerConnectionWrapper != null)
            {
                inspectionContext = workerConnectionWrapper.CreateInspectionSession(inspectionSession, input.RuntimeInstance, thread, flags, language);
            }
            else
            {
                inspectionContext = DkmInspectionContext.Create(inspectionSession, input.RuntimeInstance, thread, 200, flags, DkmFuncEvalFlags.None, 10, language, null);
            }

            var workList = DkmWorkList.Create(null);

            try
            {
                string resultText    = null;
                ulong  resultAddress = 0;

                inspectionContext.EvaluateExpression(workList, languageExpression, input, res =>
                {
                    if (res.ErrorCode == 0)
                    {
                        var result = res.ResultObject as DkmSuccessEvaluationResult;

                        if (result != null && result.TagValue == DkmEvaluationResult.Tag.SuccessResult && (allowZero || result.Address.Value != 0))
                        {
                            resultText    = result.Value;
                            resultAddress = result.Address.Value;
                        }

                        res.ResultObject.Close();
                    }
                });

                workList.Execute();

                if (Log.instance != null)
                {
                    Log.instance.Verbose($"ExecuteExpression completed");
                }

                address = resultAddress;
                return(resultText);
            }
            catch (OperationCanceledException)
            {
                address = 0;
                return(null);
            }
        }
Ejemplo n.º 44
0
        internal static DkmEvaluationResult ExecuteRawExpression(string expression, DkmInspectionSession inspectionSession, DkmThread thread, DkmStackWalkFrame input, DkmRuntimeInstance runtimeInstance, DkmEvaluationFlags flags)
        {
            var compilerId         = new DkmCompilerId(DkmVendorId.Microsoft, DkmLanguageId.Cpp);
            var language           = DkmLanguage.Create("C++", compilerId);
            var languageExpression = DkmLanguageExpression.Create(language, DkmEvaluationFlags.None, expression, null);

            DkmInspectionContext inspectionContext;

            LuaWorkerConnectionWrapper workerConnectionWrapper = inspectionSession.Process.GetDataItem <LuaWorkerConnectionWrapper>();

            if (workerConnectionWrapper != null)
            {
                inspectionContext = workerConnectionWrapper.CreateInspectionSession(inspectionSession, runtimeInstance, thread, flags, language);
            }
            else
            {
                inspectionContext = DkmInspectionContext.Create(inspectionSession, runtimeInstance, thread, 200, flags, DkmFuncEvalFlags.None, 10, language, null);
            }

            var workList = DkmWorkList.Create(null);

            try
            {
                DkmEvaluationResult result = null;

                inspectionContext.EvaluateExpression(workList, languageExpression, input, res =>
                {
                    if (res.ErrorCode == 0)
                    {
                        result = res.ResultObject;
                    }
                });

                workList.Execute();

                return(result);
            }
            catch (OperationCanceledException)
            {
                return(null);
            }
        }
Ejemplo n.º 45
0
        public static DkmSuccessEvaluationResult EvaluateSuccess(DkmVisualizedExpression expr, DkmEvaluationFlags flags, string text, DkmDataItem data)
        {
            DkmEvaluationResult result = Evaluate(expr, flags, text, data);

            if (result.TagValue != DkmEvaluationResult.Tag.SuccessResult)
            {
                throw new EvaluationException(result);
            }

            return((DkmSuccessEvaluationResult)result);
        }