internal static void Verify(DkmEvaluationResult actual, DkmEvaluationResult expected) { Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.FullName, actual.FullName); var expectedSuccess = expected as DkmSuccessEvaluationResult; if (expectedSuccess != null) { var actualSuccess = (DkmSuccessEvaluationResult)actual; Assert.Equal(expectedSuccess.Value, actualSuccess.Value); Assert.Equal(expectedSuccess.Type, actualSuccess.Type); Assert.Equal(expectedSuccess.Flags, actualSuccess.Flags); Assert.Equal(expectedSuccess.Category, actualSuccess.Category); Assert.Equal(expectedSuccess.EditableValue, actualSuccess.EditableValue); // Verify the DebuggerVisualizerAttribute Assert.True( (expectedSuccess.CustomUIVisualizers == actualSuccess.CustomUIVisualizers) || (expectedSuccess.CustomUIVisualizers != null && actualSuccess.CustomUIVisualizers != null && expectedSuccess.CustomUIVisualizers.SequenceEqual(actualSuccess.CustomUIVisualizers, CustomUIVisualizerInfoComparer.Instance))); } else { var actualFailed = (DkmFailedEvaluationResult)actual; var expectedFailed = (DkmFailedEvaluationResult)expected; Assert.Equal(expectedFailed.ErrorMessage, actualFailed.ErrorMessage); Assert.Equal(expectedFailed.Type, actualFailed.Type); Assert.Equal(expectedFailed.Flags, actualFailed.Flags); } }
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))); } }
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); }
private void GetChild( DkmEvaluationResult parent, WorkList workList, EvalResult row, DkmCompletionRoutine <DkmEvaluationAsyncResult> completionRoutine) { var inspectionContext = row.InspectionContext; if ((row.Kind != ExpansionKind.Default) || (row.Value == null)) { CreateEvaluationResultAndContinue( row, workList, row.InspectionContext, parent.StackFrame, child => completionRoutine(new DkmEvaluationAsyncResult(child))); } else { var typeDeclaringMember = row.TypeDeclaringMemberAndInfo; var name = (typeDeclaringMember.Type == null) ? row.Name : GetQualifiedMemberName(row.InspectionContext, typeDeclaringMember, row.Name, FullNameProvider); row.Value.GetResult( workList.InnerWorkList, row.DeclaredTypeAndInfo.ClrType, row.DeclaredTypeAndInfo.Info, row.InspectionContext, Formatter.NoFormatSpecifiers, name, row.FullName, result => workList.ContinueWith(() => completionRoutine(result))); } }
public EvaluatedObjectContext(DkmVisualizedExpression expr, DkmVisualizedExpression callback_expr) : base(expr, callback_expr) { DkmEvaluationResult eval = null; if (expr_.TagValue == DkmVisualizedExpression.Tag.ChildVisualizedExpression) { eval = ((DkmChildVisualizedExpression)expr_).EvaluationResult; } else { eval = DefaultEE.DefaultEval(expr_, true); } eval_ = (DkmSuccessEvaluationResult)eval; // @NOTE: Pretty sure this is reliable is_pointer_ = eval_.Type.Contains('*'); string fullname = Utility.GetExpressionFullName(expr_); // Remove any trailing format specifiers. int comma = fullname.IndexOf(','); if (comma != -1) { fullname = fullname.Substring(0, comma); } string base_expr_stub_ = String.Format( "({0})", fullname ); ptr_expr_stub_ = is_pointer_ ? base_expr_stub_ : String.Format("(&{0})", base_expr_stub_); }
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) ); }
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]; GetEvaluationResultsAndContinue(rows, initialChildren, 0, numRows, workList, inspectionContext, stackFrame, () => ContinueWithExceptionHandling( () => { var enumContext = DkmEvaluationResultEnumContext.Create(index, stackFrame, inspectionContext, new EnumContextDataItem(dataItem)); completionRoutine(new DkmGetChildrenAsyncResult(initialChildren, enumContext)); rows.Free(); }, e => completionRoutine(DkmGetChildrenAsyncResult.CreateErrorResult(e)))); }
internal DkmEvaluationResult[] GetChildren( DkmEvaluationResult evalResult, int initialRequestSize, DkmInspectionContext inspectionContext, out DkmEvaluationResultEnumContext enumContext ) { DkmGetChildrenAsyncResult getChildrenResult = default(DkmGetChildrenAsyncResult); var workList = new DkmWorkList(); evalResult.GetChildren( workList, initialRequestSize, inspectionContext ?? DefaultInspectionContext, r => { getChildrenResult = r; } ); workList.Execute(); var exception = getChildrenResult.Exception; if (exception != null) { ExceptionDispatchInfo.Capture(exception).Throw(); } enumContext = getChildrenResult.EnumContext; return(getChildrenResult.InitialChildren); }
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]; GetEvaluationResultsAndContinue(rows, results, 0, numRows, workList, inspectionContext, value.StackFrame, () => ContinueWithExceptionHandling( () => { completionRoutine(new DkmEvaluationEnumAsyncResult(results)); rows.Free(); }, e => completionRoutine(DkmEvaluationEnumAsyncResult.CreateErrorResult(e)))); }
internal DkmEvaluationResult[] GetChildren(DkmEvaluationResult evalResult, DkmInspectionContext inspectionContext = null) { DkmEvaluationResultEnumContext enumContext; const int size = 1; var builder = ArrayBuilder <DkmEvaluationResult> .GetInstance(); // Request 0 children. var items = GetChildren(evalResult, 0, inspectionContext, out enumContext); Assert.Equal(items.Length, 0); // Request >0 children. items = GetChildren(evalResult, size, inspectionContext, out enumContext); while (items.Length > 0) { builder.AddRange(items); Assert.True(builder.Count <= enumContext.Count); int offset = builder.Count; // Request 0 items. items = GetItems(enumContext, offset, 0); Assert.Equal(items.Length, 0); // Request >0 items. items = GetItems(enumContext, offset, size); } Assert.Equal(builder.Count, enumContext.Count); return(builder.ToArrayAndFree()); }
public EvaluationDataItem(DkmVisualizedExpression expression, DkmEvaluationResult evalResult) { expression_ = expression; evalResult_ = evalResult; VisualizerRegistrar.TryCreateVisualizer(expression, out visualizer_); }
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); var inspectionContext = DkmInspectionContext.Create(inspectionSession, runtimeInstance, thread, 200, flags, DkmFuncEvalFlags.None, 10, language, null, null, DkmCompiledVisualizationDataPriority.None, null, workerConnection); 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); } }
private IReadOnlyList <DkmEvaluationResult> DepthFirstSearch(DkmEvaluationResult root, int maxDepth) { var builder = ArrayBuilder <DkmEvaluationResult> .GetInstance(); DepthFirstSearchInternal(builder, root, 0, maxDepth); return(builder.ToImmutableAndFree()); }
public DkmEvaluationAsyncResult(DkmEvaluationResult Result) { if (Result == null) { throw new ArgumentNullException("Result"); } _result = Result; }
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 DkmEvaluationAsyncResult(DkmEvaluationResult Result) : this() { if (Result == null) { throw new ArgumentNullException(nameof(Result)); } _result = Result; }
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); } }
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); }
void IDkmLanguageExpressionEvaluator.SetValueAsString(DkmEvaluationResult result, string value, int timeout, out string errorText) { var ee = result.StackFrame.Process.GetDataItem <ExpressionEvaluator>(); if (ee == null) { Debug.Fail("SetValueAsString called, but no instance of ExpressionEvaluator exists in this DkmProcess to handle it."); throw new InvalidOperationException(); } ee.SetValueAsString(result, value, timeout, out errorText); }
string IDkmLanguageExpressionEvaluator.GetUnderlyingString(DkmEvaluationResult result) { var ee = result.StackFrame.Process.GetDataItem <ExpressionEvaluator>(); if (ee == null) { Debug.Fail("GetUnderlyingString called, but no instance of ExpressionEvaluator exists in this DkmProcess to handle it."); throw new InvalidOperationException(); } return(ee.GetUnderlyingString(result)); }
void IDkmLanguageExpressionEvaluator.GetChildren(DkmEvaluationResult result, DkmWorkList workList, int initialRequestSize, DkmInspectionContext inspectionContext, DkmCompletionRoutine <DkmGetChildrenAsyncResult> completionRoutine) { var ee = result.StackFrame.Process.GetDataItem <ExpressionEvaluator>(); if (ee == null) { Debug.Fail("GetChildren called, but no instance of ExpressionEvaluator exists in this DkmProcess to handle it."); throw new InvalidOperationException(); } ee.GetChildren(result, workList, initialRequestSize, inspectionContext, completionRoutine); }
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); }
public DkmEvaluationResult TryEvaluate(string expr) { using (var cppExpr = DkmLanguageExpression.Create(CppLanguage, DkmEvaluationFlags.NoSideEffects, expr, null)) { DkmEvaluationResult cppEvalResult = null; var cppWorkList = DkmWorkList.Create(null); _cppInspectionContext.EvaluateExpression(cppWorkList, cppExpr, _nativeFrame, (result) => { cppEvalResult = result.ResultObject; }); cppWorkList.Execute(); return(cppEvalResult); } }
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 ); }
private void StoreResultAndContinue(DkmEvaluationResult result, ArrayBuilder <EvalResultDataItem> rows, DkmEvaluationResult[] results, int index, int numRows, DkmWorkList workList, DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame, CompletionRoutine completionRoutine) { results[index] = result; index++; if (index < numRows) { GetEvaluationResultsAndContinue(rows, results, index, numRows, workList, inspectionContext, stackFrame, completionRoutine); } else { completionRoutine(); } }
private bool VerifySuccess(DkmEvaluationResult result, out DkmSuccessEvaluationResult success) { // Only return the result if it was successful success = result as DkmSuccessEvaluationResult; if (success == null) { Debug.Fail("Query has failed"); Debug.WriteLine($"Failure during {result.FullName} evaluation"); return(false); } return(true); }
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)); }
internal static void Verify(DkmEvaluationResult actual, DkmEvaluationResult expected) { Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.FullName, actual.FullName); var expectedSuccess = expected as DkmSuccessEvaluationResult; var expectedIntermediate = expected as DkmIntermediateEvaluationResult; if (expectedSuccess != null) { var actualSuccess = (DkmSuccessEvaluationResult)actual; Assert.NotEqual(UnspecifiedValue, actualSuccess.Value); if (expectedSuccess.Value != UnspecifiedValue) { Assert.Equal(expectedSuccess.Value, actualSuccess.Value); } Assert.Equal(expectedSuccess.Type, actualSuccess.Type); Assert.Equal(expectedSuccess.Flags, actualSuccess.Flags); if (expectedSuccess.Category != UnspecifiedCategory) { Assert.Equal(expectedSuccess.Category, actualSuccess.Category); } if (expectedSuccess.Access != UnspecifiedAccessType) { Assert.Equal(expectedSuccess.Access, actualSuccess.Access); } Assert.Equal(expectedSuccess.EditableValue, actualSuccess.EditableValue); Assert.True( (expectedSuccess.CustomUIVisualizers == actualSuccess.CustomUIVisualizers) || (expectedSuccess.CustomUIVisualizers != null && actualSuccess.CustomUIVisualizers != null && expectedSuccess.CustomUIVisualizers.SequenceEqual(actualSuccess.CustomUIVisualizers, CustomUIVisualizerInfoComparer.Instance))); } else if (expectedIntermediate != null) { var actualIntermediate = (DkmIntermediateEvaluationResult)actual; Assert.Equal(expectedIntermediate.Expression, actualIntermediate.Expression); Assert.Equal(expectedIntermediate.IntermediateLanguage.Id.LanguageId, actualIntermediate.IntermediateLanguage.Id.LanguageId); Assert.Equal(expectedIntermediate.IntermediateLanguage.Id.VendorId, actualIntermediate.IntermediateLanguage.Id.VendorId); } else { var actualFailed = (DkmFailedEvaluationResult)actual; var expectedFailed = (DkmFailedEvaluationResult)expected; Assert.Equal(expectedFailed.ErrorMessage, actualFailed.ErrorMessage); Assert.Equal(expectedFailed.Type, actualFailed.Type); Assert.Equal(expectedFailed.Flags, actualFailed.Flags); } }
private static string ToString(DkmEvaluationResult result) { if (result is DkmSuccessEvaluationResult success) { return(ToString(success)); } if (result is DkmIntermediateEvaluationResult intermediate) { return(ToString(intermediate)); } return(ToString((DkmFailedEvaluationResult)result)); }
void IDkmClrResultProvider.GetChildren( DkmEvaluationResult evaluationResult, DkmWorkList workList, int initialRequestSize, DkmInspectionContext inspectionContext, DkmCompletionRoutine <DkmGetChildrenAsyncResult> completionRoutine ) { evaluationResult.GetChildren( workList, initialRequestSize, inspectionContext, completionRoutine ); }