Ejemplo n.º 1
0
 DkmCompiledClrLocalsQuery IDkmClrExpressionCompiler.GetClrLocalVariableQuery(
     DkmInspectionContext inspectionContext,
     DkmClrInstructionAddress instructionAddress,
     bool argumentsOnly)
 {
     try
     {
         var moduleInstance  = instructionAddress.ModuleInstance;
         var runtimeInstance = instructionAddress.RuntimeInstance;
         var aliases         = argumentsOnly
             ? ImmutableArray <Alias> .Empty
             : GetAliases(runtimeInstance, inspectionContext); // NB: Not affected by retrying.
         string?error;
         var    r = CompileWithRetry(
             moduleInstance.AppDomain,
             runtimeInstance,
             (blocks, useReferencedModulesOnly) => CreateMethodContext(instructionAddress, blocks, useReferencedModulesOnly),
             (context, diagnostics) =>
         {
             var builder  = ArrayBuilder <LocalAndMethod> .GetInstance();
             var assembly = context.CompileGetLocals(
                 builder,
                 argumentsOnly,
                 aliases,
                 diagnostics,
                 out var typeName,
                 testData: null);
             Debug.Assert((builder.Count == 0) == (assembly.Count == 0));
             var locals = new ReadOnlyCollection <DkmClrLocalVariableInfo>(builder.SelectAsArray(ToLocalVariableInfo));
             builder.Free();
             return(new GetLocalsResult(typeName, locals, assembly));
         },
             out error);
         return(DkmCompiledClrLocalsQuery.Create(runtimeInstance, null, CompilerId, r.Assembly, r.TypeName, r.Locals));
     }
        /// <summary>
        /// This method is called by the debug engine to retrieve the current local variables.
        /// The result of this call will be a query containing the names of the local variables
        /// as well as IL code to retrieve each variable value.
        /// </summary>
        /// <param name="inspectionContext">Context of the evaluation.  This contains options/flags
        /// to be used during compilation. It also contains the InspectionSession.  The inspection
        /// session is the object that provides lifetime management for our objects.  When the user
        /// steps or continues the process, the debug engine will dispose of the inspection session</param>
        /// <param name="instructionAddress">Instruction address or code location to use as the
        /// reference point for where we need to retrieve the local variables</param>
        /// <param name="argumentsOnly">True if only arguments are needed</param>
        /// <returns>A local variables query</returns>
        DkmCompiledClrLocalsQuery IDkmClrExpressionCompiler.GetClrLocalVariableQuery(DkmInspectionContext inspectionContext, DkmClrInstructionAddress instructionAddress, bool argumentsOnly)
        {
            var  result    = inspectionContext.GetClrLocalVariableQuery(instructionAddress, argumentsOnly);
            var  newlocals = new List <DkmClrLocalVariableInfo>();
            bool changed   = false;

            foreach (var loc in result.LocalInfo)
            {
                if (loc.VariableName.Contains("$"))
                {
                    // do not add
                    changed = true;
                }
                else if (loc.VariableName == "this")
                {
                    // rename
                    var newloc = DkmClrLocalVariableInfo.Create("SELF", "SELF", loc.MethodName, loc.CompilationFlags, loc.ResultCategory, loc.CustomTypeInfo);
                    newlocals.Add(newloc);
                    changed = true;
                }
                else
                {
                    newlocals.Add(loc);
                }
            }
            if (changed)
            {
                result = DkmCompiledClrLocalsQuery.Create(result.RuntimeInstance,
                                                          result.DataContainer, result.LanguageId, result.Binary, result.TypeName,
                                                          new ReadOnlyCollection <DkmClrLocalVariableInfo>(newlocals));
            }
            return(result);
        }
Ejemplo n.º 3
0
        DkmCompiledClrLocalsQuery IDkmClrExpressionCompiler.GetClrLocalVariableQuery(
            DkmInspectionContext inspectionContext,
            DkmClrInstructionAddress instructionAddress,
            bool argumentsOnly)
        {
            try
            {
                var references = instructionAddress.Process.GetMetadataBlocks(instructionAddress.ModuleInstance.AppDomain);
                var context    = this.CreateMethodContext(instructionAddress, references);
                var builder    = ArrayBuilder <LocalAndMethod> .GetInstance();

                string typeName;
                var    assembly = context.CompileGetLocals(
                    builder,
                    argumentsOnly,
                    out typeName,
                    testData: null);
                Debug.Assert((builder.Count == 0) == (assembly.Count == 0));
                var locals = new ReadOnlyCollection <DkmClrLocalVariableInfo>(builder.SelectAsArray(l => DkmClrLocalVariableInfo.Create(l.LocalName, l.MethodName, l.Flags, DkmEvaluationResultCategory.Data)));
                builder.Free();
                return(DkmCompiledClrLocalsQuery.Create(inspectionContext.RuntimeInstance, null, this.CompilerId, assembly, typeName, locals));
            }
            catch (Exception e) when(ExpressionEvaluatorFatalError.CrashIfFailFastEnabled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This method is called by the debug engine to retrieve the current local variables.
        /// The result of this call will be a query containing the names of the local variables
        /// as well as IL code to retrieve each variable value.
        /// </summary>
        /// <param name="inspectionContext">Context of the evaluation.  This contains options/flags
        /// to be used during compilation. It also contains the InspectionSession.  The inspection
        /// session is the object that provides lifetime management for our objects.  When the user
        /// steps or continues the process, the debug engine will dispose of the inspection session</param>
        /// <param name="instructionAddress">Instruction address or code location to use as the
        /// reference point for where we need to retrieve the local variables</param>
        /// <param name="argumentsOnly">True if only arguments are needed</param>
        /// <returns>A local variables query</returns>
        DkmCompiledClrLocalsQuery IDkmClrExpressionCompiler.GetClrLocalVariableQuery(DkmInspectionContext inspectionContext, DkmClrInstructionAddress instructionAddress, bool argumentsOnly)
        {
            using (DebugCompilerContext context = ContextFactory.CreateLocalsContext(inspectionContext, instructionAddress, argumentsOnly))
            {
                context.GenerateQuery();

                return(DkmCompiledClrLocalsQuery.Create(
                           inspectionContext.RuntimeInstance,
                           null,
                           inspectionContext.Language.Id,
                           new ReadOnlyCollection <byte>(context.GetPeBytes()),
                           context.ClassName,
                           new ReadOnlyCollection <DkmClrLocalVariableInfo>(context.GeneratedLocals)));
            }
        }
Ejemplo n.º 5
0
 DkmCompiledClrLocalsQuery IDkmClrExpressionCompiler.GetClrLocalVariableQuery(
     DkmInspectionContext inspectionContext,
     DkmClrInstructionAddress instructionAddress,
     bool argumentsOnly)
 {
     try
     {
         var    moduleInstance           = instructionAddress.ModuleInstance;
         var    runtimeInstance          = instructionAddress.RuntimeInstance;
         var    runtimeInspectionContext = RuntimeInspectionContext.Create(inspectionContext);
         var    aliases = argumentsOnly ? null : s_NoAliases;
         string error;
         var    r = this.CompileWithRetry(
             moduleInstance,
             runtimeInstance.GetMetadataBlocks(moduleInstance.AppDomain),
             (blocks, useReferencedModulesOnly) => CreateMethodContext(instructionAddress, blocks, useReferencedModulesOnly),
             (context, diagnostics) =>
         {
             var builder = ArrayBuilder <LocalAndMethod> .GetInstance();
             string typeName;
             var assembly = context.CompileGetLocals(
                 aliases,
                 builder,
                 argumentsOnly,
                 diagnostics,
                 out typeName,
                 testData: null);
             Debug.Assert((builder.Count == 0) == (assembly.Count == 0));
             var locals = new ReadOnlyCollection <DkmClrLocalVariableInfo>(builder.SelectAsArray(ToLocalVariableInfo));
             builder.Free();
             return(new GetLocalsResult(typeName, locals, assembly));
         },
             out error);
         return(DkmCompiledClrLocalsQuery.Create(runtimeInstance, null, this.CompilerId, r.Assembly, r.TypeName, r.Locals));
     }
     catch (Exception e) when(ExpressionEvaluatorFatalError.CrashIfFailFastEnabled(e))
     {
         throw ExceptionUtilities.Unreachable;
     }
 }