Esempio n. 1
0
    public EvaluationDataItem(DkmVisualizedExpression expression, DkmEvaluationResult evalResult)
    {
      expression_ = expression;
      evalResult_ = evalResult;

      VisualizerRegistrar.TryCreateVisualizer(expression, out visualizer_);
    }
Esempio n. 2
0
		void IDkmCustomVisualizer.EvaluateVisualizedExpression(DkmVisualizedExpression expression, out DkmEvaluationResult resultObject)
		{
			Debug.Print("UE4PV: EvaluateVisualizedExpression('{0}'/'{1}', [{2}])",
				Utility.GetExpressionFullName(expression),
				Utility.GetExpressionName(expression),
				expression.TagValue
				);

			// Sanity check to confirm this is only being invoked for UObject types. @TODO: Remove eventually.
			// Believe this method is only invoked on DkmRootVisualizedExpression instances, not children.
			Debug.Assert(expression.VisualizerId == Guids.Visualizer.UObject);

			UE4Visualizer visualizer = null;
			bool result = UE4VisualizerRegistrar.TryCreateVisualizer(expression, out visualizer);
			if(!result)
			{
				OnVisualizerMatchFailed(expression, out resultObject);
				return;
			}

			// Evaluate the visualization result
			DkmEvaluationResult eval = visualizer.EvaluationResult;
			resultObject = eval;

			// Associate the visualizer with the expression
			expression.SetDataItem<ExpressionDataItem>(
				DkmDataCreationDisposition.CreateAlways,
				new ExpressionDataItem(visualizer)
				);
		}
 public DkmEvaluationEnumAsyncResult(DkmEvaluationResult[] Items)
     : this()
 {
     if (Items == null)
     {
         throw new ArgumentNullException();
     }
     this.Items = Items;
 }
Esempio n. 4
0
        void IDkmCustomVisualizer.EvaluateVisualizedExpression(DkmVisualizedExpression expression, out DkmEvaluationResult resultObject)
        {
            BasicVisualizer visualizer = null;
            DkmFailedEvaluationResult failureResult = null;

            if (!TryGetRegisteredVisualizer(expression, out visualizer, out failureResult))
            {
              resultObject = failureResult;
              return;
            }

            DkmEvaluationResult evalResult = visualizer.EvaluationResult;
            EvaluationDataItem resultDataItem = new EvaluationDataItem(expression, evalResult);

            expression.SetDataItem(DkmDataCreationDisposition.CreateAlways, resultDataItem);

            string name = null;
            string fullName = null;
            Utility.GetExpressionName(expression, out name, out fullName);

            if (evalResult.TagValue == DkmEvaluationResult.Tag.SuccessResult)
            {
              DkmSuccessEvaluationResult successResult = (DkmSuccessEvaluationResult)evalResult;
              resultObject = DkmSuccessEvaluationResult.Create(
              successResult.InspectionContext,
              successResult.StackFrame,
              name,
              successResult.FullName,
              successResult.Flags,
              successResult.Value,
              successResult.EditableValue,
              successResult.Type,
              successResult.Category,
              successResult.Access,
              successResult.StorageType,
              successResult.TypeModifierFlags,
              successResult.Address,
              successResult.CustomUIVisualizers,
              successResult.ExternalModules,
              resultDataItem);
            }
            else
            {
              DkmFailedEvaluationResult failResult = (DkmFailedEvaluationResult)evalResult;

              resultObject = DkmFailedEvaluationResult.Create(
              failResult.InspectionContext,
              failResult.StackFrame,
              name,
              fullName,
              failResult.ErrorMessage,
              failResult.Flags,
              null);
              return;
            }
        }
 public DkmGetChildrenAsyncResult(DkmEvaluationResult[] InitialChildren, DkmEvaluationResultEnumContext EnumContext)
     : this()
 {
     if (InitialChildren == null)
     {
         throw new ArgumentNullException();
     }
     this.InitialChildren = InitialChildren;
     this.EnumContext = EnumContext;
 }
Esempio n. 6
0
        void IDkmClrResultProvider.GetChildren(DkmEvaluationResult evaluationResult, DkmWorkList workList, int initialRequestSize, DkmInspectionContext inspectionContext, DkmCompletionRoutine<DkmGetChildrenAsyncResult> completionRoutine)
        {
            var dataItem = evaluationResult.GetDataItem<EvalResultDataItem>();
            if (dataItem == null)
            {
                // We don't know about this result.  Call next implementation
                evaluationResult.GetChildren(workList, initialRequestSize, inspectionContext, completionRoutine);
                return;
            }

            completionRoutine(GetChildren(inspectionContext, evaluationResult, dataItem, initialRequestSize));
        }
Esempio n. 7
0
		void OnVisualizerMatchFailed(DkmVisualizedExpression expression, out DkmEvaluationResult result)
		{
			result = DkmFailedEvaluationResult.Create(
				expression.InspectionContext,
				expression.StackFrame,
				Utility.GetExpressionName(expression),
				Utility.GetExpressionFullName(expression),
				String.Format("UE4PropVis: No visualizer is registered for VisualizerId {0}", expression.VisualizerId),
				DkmEvaluationResultFlags.Invalid,
				null
				);
		}
        public static DebugCompilerContext CreateAssignmentContext(DkmEvaluationResult lValue, DkmClrInstructionAddress address, string expression)
        {
            MemoryStream input;
            StreamReader reader;
            CreateInputStream(expression, out input, out reader);

            InspectionSession session = InspectionSession.GetInstance(lValue.InspectionSession);
            InspectionScope scope = session.GetScope(address);

            DebugCompilerContext context = new DebugCompilerContext(
                null /* null because the context doesn't own the lifetime of the session */,
                scope,
                input,
                reader,
                typeof(AssignmentTranslator),
                "$.M1",
                null /* Generated locals is not applicable for assigments */,
                lValue.FullName,
                false /* "ArgumentsOnly" only applies to local variable query */);
            context.InitializeSymbols();

            return context;
        }
Esempio n. 9
0
    public void EvaluateChildren(DkmChildVisualizedExpression[] output, int startIndex, out int numWritten)
    {
      numWritten = 0;
      if (mode_ == ChildDisplayMode.Inline)
      {
        CreateDefaultEnumContext();

        int count = ChildCount;
        DkmEvaluationResult[] results = new DkmEvaluationResult[count];
        expression_.GetItemsCallback(defEnumContext_, 0, count, out results);
        for (int i = 0; i < count; ++i)
        {
          DkmSuccessEvaluationResult successResult = results[i] as DkmSuccessEvaluationResult;
          DkmExpressionValueHome home = null;
          if (successResult != null && successResult.Address != null) {
              home = DkmPointerValueHome.Create(successResult.Address.Value);
          } else {
              home = DkmFakeValueHome.Create(0);
          }

          output[startIndex+i] = DkmChildVisualizedExpression.Create(
              defEnumContext_.InspectionContext,
              Guids.CustomVisualizer.ForceDefault,
              expression_.SourceId,
              defEnumContext_.StackFrame,
              home,
              results[i],
              expression_,
              (uint)startIndex,
              null);
          EvaluationDataItem originalDataItem = results[i].GetDataItem<EvaluationDataItem>();
        }
        numWritten = count;
      }
      else
        numWritten = 1;
    }
Esempio n. 10
0
        public unsafe void SetValueAsString(DkmEvaluationResult result, string value, int timeout, out string errorText) {
            var pyEvalResult = result.GetDataItem<PyObjectEvaluationResult>();
            if (pyEvalResult == null) {
                Debug.Fail("SetValueAsString called on a DkmEvaluationResult without an associated PyObjectEvaluationResult.");
                throw new NotSupportedException();
            }

            var proxy = pyEvalResult.ValueStore as IWritableDataProxy;
            if (proxy == null) {
                Debug.Fail("SetValueAsString called on a DkmEvaluationResult that does not correspond to an IWritableDataProxy.");
                throw new InvalidOperationException();
            }

            errorText = null;
            var process = result.StackFrame.Process;
            var pyrtInfo = process.GetPythonRuntimeInfo();

            var parserOptions = new ParserOptions { ErrorSink = new StringErrorSink() };
            var parser = Parser.CreateParser(new StringReader(value), pyrtInfo.LanguageVersion, parserOptions);
            var body = (ReturnStatement)parser.ParseTopExpression().Body;
            errorText = parserOptions.ErrorSink.ToString();
            if (!string.IsNullOrEmpty(errorText)) {
                return;
            }

            var expr = body.Expression;
            while (true) {
                var parenExpr = expr as ParenthesisExpression;
                if (parenExpr == null) {
                    break;
                }
                expr = parenExpr.Expression;
            }

            int sign;
            expr = ForceExplicitSign(expr, out sign);

            PyObject newObj = null;

            var constExpr = expr as ConstantExpression;
            if (constExpr != null) {
                if (constExpr.Value == null) {
                    newObj = PyObject.None(process);
                } else if (constExpr.Value is bool) {
                    // In 2.7, 'True' and 'False' are reported as identifiers, not literals, and are handled separately below.
                    newObj = PyBoolObject33.Create(process, (bool)constExpr.Value);
                } else if (constExpr.Value is string) {
                    if (pyrtInfo.LanguageVersion <= PythonLanguageVersion.V27) {
                        newObj = PyUnicodeObject27.Create(process, (string)constExpr.Value);
                    } else {
                        newObj = PyUnicodeObject33.Create(process, (string)constExpr.Value);
                    }
                } else if (constExpr.Value is AsciiString) {
                    newObj = PyBytesObject.Create(process, (AsciiString)constExpr.Value);
                }
            } else {
                var unaryExpr = expr as UnaryExpression;
                if (unaryExpr != null && sign != 0) {
                    constExpr = unaryExpr.Expression as ConstantExpression;
                    if (constExpr != null) {
                        if (constExpr.Value is BigInteger) {
                            newObj = PyLongObject.Create(process, (BigInteger)constExpr.Value * sign);
                        } else if (constExpr.Value is int) {
                            if (pyrtInfo.LanguageVersion <= PythonLanguageVersion.V27) {
                                newObj = PyIntObject.Create(process, (int)constExpr.Value * sign);
                            } else {
                                newObj = PyLongObject.Create(process, (int)constExpr.Value * sign);
                            }
                        } else if (constExpr.Value is double) {
                            newObj = PyFloatObject.Create(process, (double)constExpr.Value * sign);
                        } else if (constExpr.Value is Complex) {
                            newObj = PyComplexObject.Create(process, (Complex)constExpr.Value * sign);
                        }
                    }
                } else {
                    var binExpr = expr as BinaryExpression;
                    if (binExpr != null && (binExpr.Operator == PythonOperator.Add || binExpr.Operator == PythonOperator.Subtract)) {
                        int realSign;
                        var realExpr = ForceExplicitSign(binExpr.Left, out realSign) as UnaryExpression;
                        int imagSign;
                        var imagExpr = ForceExplicitSign(binExpr.Right, out imagSign) as UnaryExpression;
                        if (realExpr != null && realSign != 0 && imagExpr != null && imagSign != 0) {
                            var realConst = realExpr.Expression as ConstantExpression;
                            var imagConst = imagExpr.Expression as ConstantExpression;
                            if (realConst != null && imagConst != null) {
                                var realVal = (realConst.Value as int? ?? realConst.Value as double?) as IConvertible;
                                var imagVal = imagConst.Value as Complex?;
                                if (realVal != null && imagVal != null) {
                                    double real = realVal.ToDouble(null) * realSign;
                                    double imag = imagVal.Value.Imaginary * imagSign * (binExpr.Operator == PythonOperator.Add ? 1 : -1);
                                    newObj = PyComplexObject.Create(process, new Complex(real, imag));
                                }
                            }
                        }
                    } else {
                        if (pyrtInfo.LanguageVersion <= PythonLanguageVersion.V27) {
                            // 'True' and 'False' are not literals in 2.x, but we want to treat them as such.
                            var name = expr as NameExpression;
                            if (name != null) {
                                if (name.Name == "True") {
                                    newObj = PyBoolObject27.Create(process, true);
                                } else if (name.Name == "False") {
                                    newObj = PyBoolObject27.Create(process, false);
                                }
                            }
                        }
                    }
                }
            }

            if (newObj != null) {
                var oldObj = proxy.Read() as PyObject;
                if (oldObj != null) {
                    // We can't free the original value without running some code in the process, and it may be holding heap locks.
                    // So don't decrement refcount now, but instead add it to the list of objects for TraceFunc to GC when it gets
                    // a chance to run next time.
                    _process.GetDataItem<PyObjectAllocator>().QueueForDecRef(oldObj);
                }

                newObj.ob_refcnt.Increment();
                proxy.Write(newObj);
            } else {
                errorText = "Only boolean, numeric or string literals and None are supported.";
            }
        }
Esempio n. 11
0
        public string GetUnderlyingString(DkmEvaluationResult result) {
            var rawResult = result.GetDataItem<RawEvaluationResult>();
            if (rawResult != null && rawResult.Value is string) {
                return (string)rawResult.Value;
            }

            var objResult = result.GetDataItem<PyObjectEvaluationResult>();
            if (objResult == null) {
                return null;
            }

            var str = objResult.ValueStore.Read() as IPyBaseStringObject;
            return str.ToStringOrNull();
        }
Esempio n. 12
0
        public void GetChildren(DkmEvaluationResult result, DkmWorkList workList, int initialRequestSize, DkmInspectionContext inspectionContext, DkmCompletionRoutine<DkmGetChildrenAsyncResult> completionRoutine) {
            var asyncEvalResult = result.GetDataItem<CppViewEvaluationResult>();
            if (asyncEvalResult != null) {
                asyncEvalResult.GetChildren(result, workList, initialRequestSize, inspectionContext, completionRoutine);
                return;
            }

            var pyEvalResult =
                (IPythonEvaluationResult)result.GetDataItem<PyObjectEvaluationResult>() ??
                (IPythonEvaluationResult)result.GetDataItem<GlobalsEvaluationResult>();
            if (pyEvalResult != null) {
                var childResults = pyEvalResult.GetChildren(this, result, inspectionContext);
                completionRoutine(
                    new DkmGetChildrenAsyncResult(
                        new DkmEvaluationResult[0],
                        DkmEvaluationResultEnumContext.Create(
                            childResults.Count,
                            result.StackFrame,
                            inspectionContext,
                            new EvaluationResults { Results = childResults.ToArray() })));
                return;
            }

            Debug.Fail("GetChildren called on an unsupported DkmEvaluationResult.");
            throw new NotSupportedException();
        }
Esempio n. 13
0
 public void GetChildren(DkmEvaluationResult result, DkmWorkList workList, int initialRequestSize, DkmInspectionContext inspectionContext, DkmCompletionRoutine<DkmGetChildrenAsyncResult> completionRoutine) {
     CppEvaluationResult.GetChildren(workList, initialRequestSize, CppEvaluationResult.InspectionContext, (cppResult) => {
         completionRoutine(cppResult);
     });
 }
Esempio n. 14
0
            public List<DkmEvaluationResult> GetChildren(ExpressionEvaluator exprEval, DkmEvaluationResult result, DkmInspectionContext inspectionContext) {
                var stackFrame = result.StackFrame;
                var cppEval = new CppExpressionEvaluator(inspectionContext, stackFrame);
                var evalResults = new List<DkmEvaluationResult>();

                foreach (var pair in Globals.ReadElements()) {
                    var name = pair.Key as IPyBaseStringObject;
                    if (name == null) {
                        continue;
                    }

                    var evalResult = exprEval.CreatePyObjectEvaluationResult(inspectionContext, stackFrame, null, new PythonEvaluationResult(pair.Value, name.ToString()), cppEval);
                    evalResults.Add(evalResult);
                }

                return evalResults.OrderBy(er => er.Name).ToList();
            }
Esempio n. 15
0
            public List<DkmEvaluationResult> GetChildren(ExpressionEvaluator exprEval, DkmEvaluationResult result, DkmInspectionContext inspectionContext) {
                var stackFrame = result.StackFrame;
                var cppEval = new CppExpressionEvaluator(inspectionContext, stackFrame);
                var obj = ValueStore.Read();
                var evalResults = new List<DkmEvaluationResult>();
                var reprOptions = new ReprOptions(inspectionContext);
                var reprBuilder = new ReprBuilder(reprOptions);

                if (DebuggerOptions.ShowCppViewNodes && !HasCppView) {
                    if (CppTypeName == null) {
                        // Try to guess the object's C++ type by looking at function pointers in its PyTypeObject. If they are pointing
                        // into a module for which symbols are available, C++ EE should be able to resolve them into something like
                        // "0x1e120d50 {python33_d.dll!list_dealloc(PyListObject *)}". If we are lucky, one of those functions will have
                        // the first argument declared as a strongly typed pointer, rather than PyObject* or void*.
                        CppTypeName = "PyObject";
                        CppTypeModuleName = null;
                        foreach (string methodField in _methodFields) {
                            var funcPtrEvalResult = cppEval.TryEvaluateObject(null, "PyObject", obj.Address, ".ob_type->" + methodField) as DkmSuccessEvaluationResult;
                            if (funcPtrEvalResult == null || funcPtrEvalResult.Value.IndexOf('{') < 0) {
                                continue;
                            }

                            var match = _cppFirstArgTypeFromFuncPtrRegex.Match(funcPtrEvalResult.Value);
                            string module = match.Groups["module"].Value;
                            string firstArgType = match.Groups["type"].Value;
                            if (firstArgType != "void" && firstArgType != "PyObject" && firstArgType != "_object") {
                                CppTypeName = firstArgType;
                                CppTypeModuleName = module;
                                break;
                            }
                        }
                    }

                    string cppExpr = CppExpressionEvaluator.GetExpressionForObject(CppTypeModuleName, CppTypeName, obj.Address, ",!");
                    var evalResult = DkmIntermediateEvaluationResult.Create(
                        inspectionContext, stackFrame, "[C++ view]", "{C++}" + cppExpr, cppExpr,
                        CppExpressionEvaluator.CppLanguage, stackFrame.Process.GetNativeRuntimeInstance(), null);
                    evalResults.Add(evalResult);
                }

                int i = 0;
                foreach (var child in obj.GetDebugChildren(reprOptions).Take(MaxDebugChildren)) {
                    if (child.Name == null) {
                        reprBuilder.Clear();
                        reprBuilder.AppendFormat("[{0:PY}]", i++);
                        child.Name = reprBuilder.ToString();
                    }

                    DkmEvaluationResult evalResult;
                    if (child.ValueStore is IValueStore<PyObject>) {
                        evalResult = exprEval.CreatePyObjectEvaluationResult(inspectionContext, stackFrame, FullName, child, cppEval);
                    } else {
                        var value = child.ValueStore.Read();
                        reprBuilder.Clear();
                        reprBuilder.AppendLiteral(value);

                        string type = null;
                        if (Process.GetPythonRuntimeInfo().LanguageVersion <= PythonLanguageVersion.V27) {
                            _typeMapping2x.TryGetValue(value.GetType(), out type);
                        }
                        if (type == null) {
                            _typeMapping.TryGetValue(value.GetType(), out type);
                        }

                        var flags = DkmEvaluationResultFlags.ReadOnly;
                        if (value is string) {
                            flags |= DkmEvaluationResultFlags.RawString;
                        }

                        string childFullName = child.Name;
                        if (FullName != null) {
                            if (childFullName.EndsWith("()")) { // len()
                                childFullName = childFullName.Substring(0, childFullName.Length - 2) + "(" + FullName + ")";
                            } else {
                                if (!childFullName.StartsWith("[")) { // [0], ['fob'] etc
                                    childFullName = "." + childFullName;
                                }
                                childFullName = FullName + childFullName;
                            }
                        }

                        evalResult = DkmSuccessEvaluationResult.Create(
                            inspectionContext, stackFrame, child.Name, childFullName, flags, reprBuilder.ToString(), null, type,
                            child.Category, child.AccessType, child.StorageType, child.TypeModifierFlags, null, null, null,
                            new RawEvaluationResult { Value = value });
                    }

                    evalResults.Add(evalResult);
                }

                return evalResults;
            }
Esempio n. 16
0
        public void EvaluateVisualizedExpression(DkmVisualizedExpression visualizedExpression, out DkmEvaluationResult resultObject) {
            var rootExpr = visualizedExpression as DkmRootVisualizedExpression;
            if (rootExpr == null) {
                Debug.Fail("PythonViewNativeVisualizer.EvaluateVisualizedExpression was given a visualized expression that is not a DkmRootVisualizedExpression.");
                throw new NotSupportedException();
            }

            DkmEvaluationResult rawResult;
            RawEvaluationResultHolder rawResultHolder;
            using (var rawExpr = DkmLanguageExpression.Create(CppExpressionEvaluator.CppLanguage, DkmEvaluationFlags.ShowValueRaw, rootExpr.FullName + ",!", null)) {
                rootExpr.EvaluateExpressionCallback(rootExpr.InspectionContext, rawExpr, rootExpr.StackFrame, out rawResult);
                rawResultHolder = new RawEvaluationResultHolder { RawResult = rawResult };
                rootExpr.SetDataItem(DkmDataCreationDisposition.CreateAlways, rawResultHolder);
            }

            var rawSuccessResult = rawResult as DkmSuccessEvaluationResult;
            if (rawSuccessResult != null) {
                resultObject = DkmSuccessEvaluationResult.Create(
                    rawResult.InspectionContext,
                    rawResult.StackFrame,
                    rootExpr.Name,
                    rawSuccessResult.FullName,
                    rawSuccessResult.Flags,
                    rawSuccessResult.Value,
                    rawSuccessResult.EditableValue,
                    rawSuccessResult.Type,
                    rawSuccessResult.Category,
                    rawSuccessResult.Access,
                    rawSuccessResult.StorageType,
                    rawSuccessResult.TypeModifierFlags,
                    rawSuccessResult.Address,
                    rawSuccessResult.CustomUIVisualizers,
                    rawSuccessResult.ExternalModules,
                    rawResultHolder);
                return;
            }

            var rawFailedResult = rawResult as DkmFailedEvaluationResult;
            if (rawFailedResult != null) {
                resultObject = DkmFailedEvaluationResult.Create(
                    rawResult.InspectionContext,
                    rawResult.StackFrame,
                    rootExpr.Name,
                    rootExpr.FullName,
                    rawFailedResult.ErrorMessage,
                    rawFailedResult.Flags,
                    rawResultHolder);
                return;
            }

            Debug.Fail("Raw evaluation result was neither DkmSuccessEvaluationResult nor DkmFailedEvaluationResult.");
            throw new NotSupportedException();
        }
 private void GetChildrenAndContinue(EvalResultDataItem dataItem, DkmWorkList workList, DkmStackWalkFrame stackFrame, int initialRequestSize, DkmInspectionContext inspectionContext, DkmCompletionRoutine<DkmGetChildrenAsyncResult> completionRoutine)
 {
     var expansion = dataItem.Expansion;
     var rows = ArrayBuilder<EvalResultDataItem>.GetInstance();
     int index = 0;
     if (expansion != null)
     {
         expansion.GetRows(this, rows, inspectionContext, dataItem, dataItem.Value, 0, initialRequestSize, visitAll: true, index: ref index);
     }
     var numRows = rows.Count;
     Debug.Assert(index >= numRows);
     Debug.Assert(initialRequestSize >= numRows);
     var initialChildren = new DkmEvaluationResult[numRows];
     var wl = new WorkList(workList, e => completionRoutine(DkmGetChildrenAsyncResult.CreateErrorResult(e)));
     GetEvaluationResultsAndContinue(rows, initialChildren, 0, numRows, wl, inspectionContext, stackFrame,
         () => wl.ContinueWith(
             () =>
             {
                 var enumContext = DkmEvaluationResultEnumContext.Create(index, stackFrame, inspectionContext, new EnumContextDataItem(dataItem));
                 completionRoutine(new DkmGetChildrenAsyncResult(initialChildren, enumContext));
                 rows.Free();
             }));
     wl.Execute();
 }
Esempio n. 18
0
        // In VS 2015+, the injection of the child [Python view] node is handled in the PythonDkm.natvis, and the visualizer is only responsible
        // for producing a DkmEvaluationResult for that node.

        public void EvaluateVisualizedExpression(DkmVisualizedExpression visualizedExpression, out DkmEvaluationResult resultObject) {
            resultObject = GetPythonView(visualizedExpression);
            if (resultObject == null) {
                resultObject = DkmFailedEvaluationResult.Create(
                    visualizedExpression.InspectionContext, visualizedExpression.StackFrame, "[Python view]",
                    null, "Python view is unavailable for this object", DkmEvaluationResultFlags.Invalid, null);
            }
        }
 private void GetEvaluationResultsAndContinue(ArrayBuilder<EvalResultDataItem> rows, DkmEvaluationResult[] results, int index, int numRows, WorkList workList, DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, CompletionRoutine completionRoutine)
 {
     if (index < numRows)
     {
         CreateEvaluationResultAndContinue(rows[index], workList, inspectionContext, stackFrame,
             result => workList.ContinueWith(
                 () =>
                 {
                     results[index] = result;
                     GetEvaluationResultsAndContinue(rows, results, index + 1, numRows, workList, inspectionContext, stackFrame, completionRoutine);
                 }));
     }
     else
     {
         completionRoutine();
     }
 }
Esempio n. 20
0
 private DkmGetChildrenAsyncResult GetChildren(DkmInspectionContext inspectionContext, DkmEvaluationResult evaluationResult, EvalResultDataItem dataItem, int initialRequestSize)
 {
     var expansion = dataItem.Expansion;
     var builder = ArrayBuilder<DkmEvaluationResult>.GetInstance();
     int index = 0;
     if (expansion != null)
     {
         expansion.GetRows(this, builder, inspectionContext, dataItem, dataItem.Value, 0, initialRequestSize, visitAll: true, index: ref index);
     }
     var rows = builder.ToArrayAndFree();
     Debug.Assert(index >= rows.Length);
     Debug.Assert(initialRequestSize >= rows.Length);
     var enumContext = DkmEvaluationResultEnumContext.Create(index, evaluationResult.StackFrame, evaluationResult.InspectionContext, new EnumContextDataItem(dataItem));
     return new DkmGetChildrenAsyncResult(rows, enumContext);
 }
Esempio n. 21
0
 public CppEvaluationException(DkmEvaluationResult evalResult = null) {
     EvaluationResult = evalResult;
 }
Esempio n. 22
0
        public void UseDefaultEvaluationBehavior(DkmVisualizedExpression visualizedExpression, out bool useDefaultEvaluationBehavior, out DkmEvaluationResult defaultEvaluationResult) {
            // If it is a child expression, we want to fall back to default visualizer ...
            var childExpr = visualizedExpression as DkmChildVisualizedExpression;
            if (childExpr != null) {
                var childResult = childExpr.EvaluationResult;
                // ... unless the child is also of a type which uses this visualizer, in which case just recurse.
                var rawResultHolder = childResult.GetDataItem<RawEvaluationResultHolder>();
                if (rawResultHolder == null) {
                    useDefaultEvaluationBehavior = true;
                    defaultEvaluationResult = childResult;
                    return;
                } 
            }

            useDefaultEvaluationBehavior = false;
            defaultEvaluationResult = null;
        }
 public EvaluationException(DkmEvaluationResult result)
 {
     result_ = result;
 }
        private void DepthFirstSearchInternal(ArrayBuilder<DkmEvaluationResult> builder, DkmEvaluationResult curr, int depth, int maxDepth)
        {
            Assert.InRange(depth, 0, maxDepth);
            builder.Add(curr);

            var childDepth = depth + 1;
            if (childDepth <= maxDepth)
            {
                foreach (var child in GetChildren(curr))
                {
                    DepthFirstSearchInternal(builder, child, childDepth, maxDepth);
                }
            }
        }
        string IDkmClrResultProvider.GetUnderlyingString(DkmEvaluationResult result)
        {
            try
            {
                var dataItem = result.GetDataItem<EvalResultDataItem>();
                if (dataItem == null)
                {
                    // We don't know about this result.  Call next implementation
                    return result.GetUnderlyingString();
                }

                return dataItem.Value?.GetUnderlyingString(result.InspectionContext);
            }
            catch (Exception e) when (ExpressionEvaluatorFatalError.CrashIfFailFastEnabled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
Esempio n. 26
0
 public void UseDefaultEvaluationBehavior(DkmVisualizedExpression visualizedExpression, out bool useDefaultEvaluationBehavior, out DkmEvaluationResult defaultEvaluationResult) {
     useDefaultEvaluationBehavior = true;
     defaultEvaluationResult = GetPythonView(visualizedExpression);
     if (defaultEvaluationResult == null) {
         throw new NotSupportedException();
     }
 }
 private void GetItemsAndContinue(EvalResultDataItem dataItem, DkmWorkList workList, int startIndex, int count, DkmInspectionContext inspectionContext, DkmCompletionRoutine<DkmEvaluationEnumAsyncResult> completionRoutine)
 {
     var expansion = dataItem.Expansion;
     var value = dataItem.Value;
     var rows = ArrayBuilder<EvalResultDataItem>.GetInstance();
     if (expansion != null)
     {
         int index = 0;
         expansion.GetRows(this, rows, inspectionContext, dataItem, value, startIndex, count, visitAll: false, index: ref index);
     }
     var numRows = rows.Count;
     Debug.Assert(count >= numRows);
     var results = new DkmEvaluationResult[numRows];
     var wl = new WorkList(workList, e => completionRoutine(DkmEvaluationEnumAsyncResult.CreateErrorResult(e)));
     GetEvaluationResultsAndContinue(rows, results, 0, numRows, wl, inspectionContext, value.StackFrame,
         () => wl.ContinueWith(
             () =>
             {
                 completionRoutine(new DkmEvaluationEnumAsyncResult(results));
                 rows.Free();
             }));
     wl.Execute();
 }
        private IReadOnlyList<DkmEvaluationResult> DepthFirstSearch(DkmEvaluationResult root, int maxDepth)
        {
            var builder = ArrayBuilder<DkmEvaluationResult>.GetInstance();

            DepthFirstSearchInternal(builder, root, 0, maxDepth);

            return builder.ToImmutableAndFree();
        }
Esempio n. 29
0
 public DkmEvaluationResult[] GetAllProperties()
 {
     DkmEvaluationResult[] props = new DkmEvaluationResult[prop_evals_.Count];
     int idx = 0;
     foreach(var eval in prop_evals_)
     {
         props[idx] = eval.Value;
         ++idx;
     }
     return props;
 }
Esempio n. 30
0
        public void LazyExpansion()
        {
            var rootExpr = "new byte[10, 1000, 1000]";
            var parenthesizedExpr = string.Format("({0})", rootExpr);
            var value = CreateDkmClrValue(new byte[10, 1000, 1000]); // Array with 10M elements
            var evalResults = new DkmEvaluationResult[100]; // 100 distinct evaluations of the array
            for (int i = 0; i < evalResults.Length; i++)
            {
                var evalResult = FormatResult(rootExpr, value);
                evalResults[i] = evalResult;
                // Expand a subset.
                int offset = i * 100 * 1000;

                DkmEvaluationResultEnumContext enumContext;
                GetChildren(evalResult, 0, null, out enumContext);

                var items = GetItems(enumContext, offset, 2);
                var indices1 = string.Format("{0}, {1}, {2}", offset / 1000000, (offset % 1000000) / 1000, 0);
                var indices2 = string.Format("{0}, {1}, {2}", (offset + 1) / 1000000, ((offset + 1) % 1000000) / 1000, 1);
                Verify(items,
                    EvalResult(string.Format("[{0}]", indices1), "0", "byte", string.Format("{0}[{1}]", parenthesizedExpr, indices1)),
                    EvalResult(string.Format("[{0}]", indices2), "0", "byte", string.Format("{0}[{1}]", parenthesizedExpr, indices2)));
            }
        }